#include "MapOptions.h"

#include <FileSystem.h>

#include "Globals.h"
#include "Initialization.h"

MapOptions::MapOptions()
    : Window()
{
    Framework::LTDBFile iconsDat;
    iconsDat.setFile(new Framework::Text("data/images/gui_icons.ltdb"));
    iconsDat.readData(0);

    setStyle(Window::Style::Allowed | Window::Style::Border
             | Window::Style::BodyBAlpha | Window::Style::Title
             | Window::Style::TitleBAlpha | Window::Style::Closable
             | Window::Style::ClosingBAlpha | Window::Style::ClosingBuffer
             | Window::Style::TitleBackground | Window::Style::BodyBackground
             | Window::Style::ClosingBackground | Window::Style::MEIgnoreInside
             | Window::Style::Movable | Style::ClosingBImage
             | Style::ClosingBuffer);
    removeStyle(Window::Style::Visible);
    setTitel("Map options");
    setClosingMe([this](void* p, void* o, Framework::MouseEvent me) {
        if (me.id == Framework::ME_RLeft)
        {
            removeStyle(Window::Style::Visible);
        }
        return 1;
    });
    setSize(210, 125);
    setPosition(uiFactory.initParam.bildschirm->getBackBufferSize().x / 2
                    - getWidth() / 2,
        uiFactory.initParam.bildschirm->getBackBufferSize().y / 2
            - getHeight() / 2);
    setMouseEvent(Framework::_ret1ME);
    setKeyboardEvent(Framework::_ret1TE);
    setBorderWidth(1);
    setBorderColor(0xFF52525E);
    setBodyBgColor(0xA0000000);
    setTBgColor(0xA0000000);
    setCloseBgColor(0xA0000000);
    setTFontZ(dynamic_cast<Font*>(uiFactory.initParam.font->getThis()));
    zTTextField()->setSize(0, 20);
    zTTextField()->addStyle(TextField::Style::Center);
    setCloseAfStrength(10);
    setCloseAfColor(0x5F9C0A0A);
    setCloseBgImageZ(iconsDat.load(0, new Text("close.png")));
    setCloseClickAfColor(0xFF9C0A0A);
    setCloseClickAfStrength(10);

    underground = initCheckBox(5,
        5,
        200,
        20,
        Framework::CheckBox::Style::Normal
            & ~Framework::CheckBox::Style::Border,
        "Show underground map");
    underground->setPostMouseEvent(_ret1ME);
    addMember(underground);

    followPlayer = initCheckBox(5,
        30,
        200,
        20,
        Framework::CheckBox::Style::Normal
            & ~Framework::CheckBox::Style::Border,
        "Follow player");
    followPlayer->setPostMouseEvent(_ret1ME);
    addMember(followPlayer);

    showPlayers = initCheckBox(5,
        55,
        200,
        20,
        (Framework::CheckBox::Style::Normal
            | Framework::CheckBox::Style::Selected)
            & ~Framework::CheckBox::Style::Border,
        "Show Players");
    showPlayers->setPostMouseEvent(_ret1ME);
    addMember(showPlayers);

    showChunkBorders = initCheckBox(5,
        80,
        200,
        20,
        (Framework::CheckBox::Style::Normal
            | Framework::CheckBox::Style::Selected)
            & ~Framework::CheckBox::Style::Border,
        "Show Chunk Borders");
    showChunkBorders->setPostMouseEvent(_ret1ME);
    addMember(showChunkBorders);
}

bool MapOptions::isUnderground()
{
    return underground->hasStyle(CheckBox::Style::Selected);
}

bool MapOptions::isFollowPlayer()
{
    return followPlayer->hasStyle(CheckBox::Style::Selected);
}

bool MapOptions::isShowPlayers()
{
    return showPlayers->hasStyle(CheckBox::Style::Selected);
}

bool MapOptions::isShowChunkBorders()
{
    return showChunkBorders->hasStyle(CheckBox::Style::Selected);
}