aboutsummaryrefslogtreecommitdiffstats
path: root/src/testscreen.cpp
blob: b0c04d941eed8b4060a67fe36db380450fc98ec0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "testscreen.h"
#include "game.h"
#include "world/map.h"

#include "boxii/boxii.h"
#include "boxii/input.h"

static const int optionCount = 2;
static const std::string optionStrings[optionCount] = 
{
    "Seed:",
    "Plates:"
};

static void
printSelections(std::shared_ptr<Boxii::TextWindow> window, int selection, int *values)
{
    int optx = 0;
    int opty = 0;

    for(int i = 0; i < optionCount; i++){
        window->setfg(0xFFFFFF);
        window->setbg(0x0);
        if(selection == i){
            window->setfg(0x0);
            window->setbg(0xFFFFFF);
        }

        window->moveCursor(optx, opty++);
        window->print("%s %i", optionStrings[i].c_str(), values[i]);
    }
}

TestScreen::TestScreen() :
    m_canvasWindow(nullptr), m_infoWindow(nullptr),
    m_option(0), m_optionValues(new int[optionCount])
{
    int sw = Boxii::getTerminalWidth();
    int sh = Boxii::getTerminalHeight();

    m_canvasWindow = Boxii::makeWindow<Boxii::Window>(0, 0, sw, sh);
    m_infoWindow = Boxii::makeWindow<Boxii::TextWindow>(0, 0, 24, 16);

    Boxii::remove(m_canvasWindow);
    Boxii::remove(m_infoWindow);

    m_infoWindow->border('+', '+', '+', '+', '-', '|', 0xFFFFFF, 0x0);

    m_optionValues[0] = 0;
    m_optionValues[1] = 20;
    refresh();
}

TestScreen::~TestScreen()
{
    delete[] m_optionValues;
}

void
TestScreen::activate()
{
    Boxii::pushToFront(m_canvasWindow);
    Boxii::pushToFront(m_infoWindow);
}

void
TestScreen::deactivate()
{
    Boxii::remove(m_canvasWindow);
    Boxii::remove(m_infoWindow);
}

void 
TestScreen::update()
{
    int c = Boxii::Input::getch(true);
    if(c == Boxii::KEY_ESCAPE) {
        Game::pushScreen("pause");
    }

    if(c == Boxii::KEY_DOWN){
        m_option++;
        if(m_option == optionCount) m_option = 0;
    }

    if(c == Boxii::KEY_UP){
        m_option--;
        if(m_option == -1) m_option = optionCount - 1;
    }

    if(c == Boxii::KEY_LEFT){
        m_optionValues[m_option]--;
        if(m_optionValues[m_option] < 0) m_optionValues[m_option] = 0;
        refresh();
    }

    if(c == Boxii::KEY_RIGHT){
        m_optionValues[m_option]++;
        refresh();
    }

    printSelections(m_infoWindow, m_option, m_optionValues);
}

#include "world/tectonicphase.h"
void
TestScreen::refresh()
{
    int sw = Boxii::getTerminalWidth();
    int sh = Boxii::getTerminalHeight();

    TectonicPhase::setPlateCount(m_optionValues[1]);

    std::shared_ptr<WorldMap> world = std::make_shared<WorldMap>(sw, sh, m_optionValues[0]);
    world->begin(world);

    world->draw(m_canvasWindow, 0);
}