summaryrefslogtreecommitdiffstats
path: root/src/timeman.cpp
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2022-06-22 17:41:59 -0400
committerJon Santmyer <jon@jonsantmyer.com>2022-06-22 17:41:59 -0400
commit5e3a2492c7bb73daa4e27398daaf490d09980ff3 (patch)
tree75178d823d596b6a898002c3f1d45b9ceede0e1e /src/timeman.cpp
downloadsystemviewer-5e3a2492c7bb73daa4e27398daaf490d09980ff3.tar.gz
systemviewer-5e3a2492c7bb73daa4e27398daaf490d09980ff3.tar.bz2
systemviewer-5e3a2492c7bb73daa4e27398daaf490d09980ff3.zip
Base system viewer with data loaded from csv files
Diffstat (limited to 'src/timeman.cpp')
-rw-r--r--src/timeman.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/timeman.cpp b/src/timeman.cpp
new file mode 100644
index 0000000..f043894
--- /dev/null
+++ b/src/timeman.cpp
@@ -0,0 +1,49 @@
+#include "timeman.hpp"
+#include "keybind.hpp"
+#include "window.hpp"
+#include "game.hpp"
+
+unit::Time TimeMan::m_time(0);
+unit::Time TimeMan::m_step(unit::DAY_SECONDS);
+bool TimeMan::m_auto;
+bool TimeMan::m_changed;
+
+void
+TimeMan::init()
+{
+ KeyMan::registerBind('.', BIND_TIMEMAN_STEP, CTX_TIMEMAN, "Move time ahead by a step");
+ KeyMan::registerBind('+', BIND_TIMEMAN_INCSTEP, CTX_TIMEMAN, "Increase the timestep");
+ KeyMan::registerBind('-', BIND_TIMEMAN_DECSTEP, CTX_TIMEMAN, "Decrease the timestep");
+ KeyMan::registerBind('a', BIND_TIMEMAN_TOGGLEAUTO, CTX_TIMEMAN, "Toggle if time will move automatically");
+ m_changed = true;
+}
+
+void
+TimeMan::update(int c)
+{
+ WindowContext &context = Game::contexts();
+ m_changed = false;
+ if(!Game::paused()) {
+ if(m_auto) {
+ m_time += (m_step);
+ m_changed = true;
+ }
+ }
+ if(context.getFocusedString() != WINDOW_TIMEMAN_ID) return;
+ if(c == KeyMan::binds[BIND_TIMEMAN_INCSTEP].code) m_step = unit::Time(std::max<long>(1, m_step() * 2));
+ if(c == KeyMan::binds[BIND_TIMEMAN_DECSTEP].code) m_step = unit::Time(std::max<long>(1, m_step() / 2));
+ if(c == KeyMan::binds[BIND_TIMEMAN_TOGGLEAUTO].code) m_auto = !m_auto;
+ if(c == KeyMan::binds[BIND_TIMEMAN_STEP].code && !Game::paused()) { m_time += m_step; m_changed = true; }
+}
+
+void
+TimeMan::draw()
+{
+ WindowContext &context = Game::contexts();
+ Window &timeWindow = context[WINDOW_TIMEMAN_ID];
+ timeWindow << straw::clear(' ');
+
+ timeWindow << straw::move(0, 0) << straw::resetcolor() << m_time.format("%S %D, %C \n%H:%m\n\n");
+ timeWindow << m_step.format("Step:\n%Y Years, %M Months\n%D Days, %H Hours\n%m Minutes, %s Seconds\n\n");
+ if(m_auto) timeWindow << "Auto";
+}