aboutsummaryrefslogtreecommitdiff
path: root/game/menu.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'game/menu.cpp')
-rw-r--r--game/menu.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/game/menu.cpp b/game/menu.cpp
index a9ec886..b5a91b9 100644
--- a/game/menu.cpp
+++ b/game/menu.cpp
@@ -1,3 +1,5 @@
+#include <iostream>
+
#include "menu.h"
void Menu::close () {
@@ -5,6 +7,7 @@ void Menu::close () {
}
void Menu::open (vec2 res) {
+ over = -1;
active = true;
pos = vec2 { (float)res.x, (float)res.y };
float height = options.size() * 20;
@@ -26,4 +29,49 @@ int Menu::mouse_option (vec2 mouse) {
i++;
}
return -1;
+}
+
+
+void Menu_tech::open (vec2 res) {
+ over = -1;
+ active = true;
+ pos = vec2 { (float)res.x, (float)res.y };
+
+ tech_opt_ordered.clear();
+ tech_opt_ordered.emplace_back();
+ tech_opt_ordered.emplace_back();
+ tech_opt_ordered.emplace_back();
+ tech_opt_ordered.emplace_back();
+
+ for (OptionTech opt : tech_options) {
+ tech_opt_ordered[opt.tech->level].emplace_back(opt);
+ }
+ int maxsize = 0;
+ for (auto v : tech_opt_ordered) {
+ maxsize = maxsize < v.size() ? v.size() : maxsize;
+ }
+
+ float width = 150 * tech_opt_ordered.size();
+ float height = maxsize * 10;
+ size = vec2 { width, height+20 };
+ pos *= 0.5f;
+ pos -= size/2;
+}
+
+int Menu_tech::mouse_option (vec2 mouse) {
+ float x = 0, y = 0;
+ for (auto v : tech_opt_ordered) {
+ for (auto opt : v) {
+ vec2 off { x*150, 10.0f + y*10 };
+ vec2 sizeopt { 150, 10 };
+ off += pos;
+ if (off.x < mouse.x && mouse.x < off.x+sizeopt.x
+ && off.y < mouse.y && mouse.y < off.y+sizeopt.y ) {
+ return opt.tech->id;
+ }
+ y++;
+ }
+ x++; y=0;
+ }
+ return -1;
} \ No newline at end of file