aboutsummaryrefslogtreecommitdiffstats
path: root/src/testscreen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/testscreen.cpp')
-rw-r--r--src/testscreen.cpp103
1 files changed, 102 insertions, 1 deletions
diff --git a/src/testscreen.cpp b/src/testscreen.cpp
index 43dcd3f..b0c04d9 100644
--- a/src/testscreen.cpp
+++ b/src/testscreen.cpp
@@ -1,17 +1,118 @@
#include "testscreen.h"
+#include "game.h"
+#include "world/map.h"
-TestScreen::TestScreen()
+#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);
}