-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.cpp
81 lines (61 loc) · 1.75 KB
/
settings.cpp
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
#include "settings.hpp"
#include <iostream>
#include <fstream>
#include <cstring>
#include "storage.hpp"
Settings :: Settings() {
set_title("settings");
set_default_size(300, 300);
set_visible(true);
set_resizable(false);
set_position(Gtk::WIN_POS_CENTER_ALWAYS);
draw_widgets();
set_hierarchy();
show_all_children();
Storage st("data/cache.dat");
vsPlayer.set_active(!st.getEnemy());
}
Settings :: ~Settings() {
}
void Settings :: on_save_clicked() {
Storage st("data/cache.dat");
if(vsCpu.get_active() != st.getEnemy()) {
int p1 {}, p2 {}, first {}, table[8][8];
memset(&table[0][0], -1, sizeof table);
st.saveEnemy(vsCpu.get_active());
st.saveTable(table);
st.saveScore(p1, p2);
st.saveFirst(first);
}
st.close();
}
void Settings :: on_reset_clicked() {
vsPlayer.set_active(true);
}
void Settings :: set_hierarchy() {
add(outerBox);
outerBox.pack_start(framePlayer, Gtk :: PACK_SHRINK);
outerBox.pack_end(boxAction, Gtk :: PACK_SHRINK);
//framePlayer
framePlayer.add(boxVs);
boxVs.pack_start(vsPlayer);
boxVs.pack_start(vsCpu);
vsPlayer.join_group(vsCpu);
//boxSave
boxAction.pack_end(btnSave, Gtk :: PACK_SHRINK);
boxAction.pack_end(btnReset, Gtk :: PACK_SHRINK);
//btnSave
btnSave.signal_clicked().connect(sigc :: mem_fun(*this, &Settings :: on_save_clicked));
//btnReset
btnReset.signal_clicked().connect(sigc :: mem_fun(*this, &Settings :: on_reset_clicked));
}
void Settings :: draw_widgets() {
outerBox = Gtk :: Box(Gtk :: ORIENTATION_VERTICAL);
boxAction = Gtk :: Box(Gtk :: ORIENTATION_HORIZONTAL);
boxVs = Gtk :: Box(Gtk :: ORIENTATION_HORIZONTAL);
btnSave.set_label("salvar");
btnReset.set_label("resetar");
framePlayer.set_label("Escolha seu inimigo");
vsPlayer.set_label("player 2");
vsCpu.set_label("cpu");
}