#include "MapOptions.h"

#include <DateiSystem.h>

#include "Globals.h"
#include "Initialisierung.h"

MapOptions::MapOptions()
    : Fenster()
{
    Framework::LTDBDatei iconsDat;
    iconsDat.setDatei(new Framework::Text("data/images/gui_icons.ltdb"));
    iconsDat.leseDaten(0);

    setStyle(
        Fenster::Style::Erlaubt | Fenster::Style::Rahmen
        | Fenster::Style::BodyHAlpha | Fenster::Style::Titel
        | Fenster::Style::TitelHAlpha | Fenster::Style::Closable
        | Fenster::Style::ClosingHAlpha | Fenster::Style::ClosingKlickBuffer
        | Fenster::Style::TitelHintergrund | Fenster::Style::BodyHintergrund
        | Fenster::Style::ClosingHintergrund | Fenster::Style::MEIgnoreInside
        | Fenster::Style::Beweglich | Style::ClosingHBild
        | Style::ClosingBuffer);
    removeStyle(Fenster::Style::Sichtbar);
    setTitel("Map options");
    setClosingMe([this](void* p, void* o, Framework::MausEreignis me) {
        if (me.id == Framework::ME_RLinks)
        {
            removeStyle(Fenster::Style::Sichtbar);
        }
        return 1;
    });
    setSize(210, 125);
    setPosition(uiFactory.initParam.bildschirm->getBackBufferSize().x / 2
                    - getBreite() / 2,
        uiFactory.initParam.bildschirm->getBackBufferSize().y / 2
            - getHeight() / 2);
    setMausEreignis(Framework::_ret1ME);
    setTastaturEreignis(Framework::_ret1TE);
    setRBreite(1);
    setRFarbe(0xFF52525E);
    setKBgFarbe(0xA0000000);
    setTBgFarbe(0xA0000000);
    setSBgFarbe(0xA0000000);
    setTSchriftZ(
        dynamic_cast<Schrift*>(uiFactory.initParam.schrift->getThis()));
    zTTextFeld()->setSize(0, 20);
    zTTextFeld()->addStyle(TextFeld::Style::Center);
    setSAfStrength(10);
    setSAfFarbe(0x5F9C0A0A);
    setSBgBildZ(iconsDat.laden(0, new Text("close.png")));
    setSKAfFarbe(0xFF9C0A0A);
    setSKAfStrength(10);

    underground = initKontrollKnopf(5,
        5,
        200,
        20,
        Framework::KontrollKnopf::Style::Normal
            & ~Framework::KontrollKnopf::Style::Rahmen,
        "Show underground map");
    underground->setNMausEreignis(_ret1ME);
    addMember(underground);

    followPlayer = initKontrollKnopf(5,
        30,
        200,
        20,
        Framework::KontrollKnopf::Style::Normal
            & ~Framework::KontrollKnopf::Style::Rahmen,
        "Follow player");
    followPlayer->setNMausEreignis(_ret1ME);
    addMember(followPlayer);

    showPlayers = initKontrollKnopf(5,
        55,
        200,
        20,
        (Framework::KontrollKnopf::Style::Normal
            | Framework::KontrollKnopf::Style::Selected)
            & ~Framework::KontrollKnopf::Style::Rahmen,
        "Show Players");
    showPlayers->setNMausEreignis(_ret1ME);
    addMember(showPlayers);

    showChunkBorders = initKontrollKnopf(5,
        80,
        200,
        20,
        (Framework::KontrollKnopf::Style::Normal
            | Framework::KontrollKnopf::Style::Selected)
            & ~Framework::KontrollKnopf::Style::Rahmen,
        "Show Chunk Borders");
    showChunkBorders->setNMausEreignis(_ret1ME);
    addMember(showChunkBorders);
}

bool MapOptions::isUnderground()
{
    return underground->hatStyle(KontrollKnopf::Style::Selected);
}

bool MapOptions::isFollowPlayer()
{
    return followPlayer->hatStyle(KontrollKnopf::Style::Selected);
}

bool MapOptions::isShowPlayers()
{
    return showPlayers->hatStyle(KontrollKnopf::Style::Selected);
}

bool MapOptions::isShowChunkBorders()
{
    return showChunkBorders->hatStyle(KontrollKnopf::Style::Selected);
}