#pragma once

#include <Trie.h>
#include <Zeichnung.h>

#include "ChunkMap.h"
#include "MapOptions.h"

struct MapPlayer
{
    Framework::Vec3<float> position;
    Framework::Text name;
};

class DimensionMap : public Framework::ZeichnungHintergrund
{
private:
    MapOptions* zOptions;
    Framework::RCTrie<ChunkMap>* chunks;
    Framework::Array<ChunkMap*> chunkList;
    Framework::Punkt originChunkCenter;
    Framework::Punkt scrollOffset;
    int chunkCount;
    int pixelsPerBlock;
    int requestCount;
    bool drag;
    Framework::Punkt lastMouse;
    Framework::Punkt lastSize;
    Framework::Array<MapPlayer> players;
    double nextPlayersRequest;
    Framework::Bild* playerIcon;

    void getAddrOf(Framework::Punkt cPos, char* addr) const;
    void getAddrOfWorld(Framework::Punkt wPos, char* addr) const;
    Framework::Punkt getMinVisibleChunkCenter(
        Framework::Punkt& screenPos) const;
    Framework::Punkt getMaxVisibleChunkCenter(
        Framework::Punkt& screenPos) const;
    void removeUnused() const;

public:
    DimensionMap(MapOptions* zOptions);
    ~DimensionMap();

    void updatePlayers(char* data);
    void requestNextChunk();
    void addChunk(ChunkMap* chunk);
    bool tick(double time) override;
    void render(Framework::Bild& rObj) override;
    void doMausEreignis(Framework::MausEreignis& me, bool userRet) override;
};