blob: 6349f2988cd2dea1b54e8a3cf07219acb65c4254 (
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
|
#include <iostream>
#include "menu.h"
void Menu::close () {
active = false;
}
void Menu::open (vec2 res) {
over = -1;
active = true;
pos = vec2 { (float)res.x, (float)res.y };
float height = options.size() * 20;
size = vec2 { 150, height+10 };
pos *= 0.5f;
pos -= size/2;
}
int Menu::mouse_option (vec2 mouse) {
int i=0;
for (Option opt : options) {
vec2 off { 0, 5.0f + i*20 };
vec2 sizeopt { 150, 20 };
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.id;
}
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;
}
|