-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
209 lines (182 loc) · 5.79 KB
/
main.cpp
File metadata and controls
209 lines (182 loc) · 5.79 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include "main.hpp"
#include "assets.hpp"
#include "src/mouse.hpp"
#include "src/editor.hpp"
#include "src/preview.hpp"
#include "src/dialog.hpp"
#include "src/file-browser.hpp"
#include "src/keyboard.hpp"
#include "engine/api_private.hpp"
using namespace blit;
Screen currentscreen = Screen::Edit;
constexpr int PADDING = 17;
Mouse mouse;
Palette palette(Point(175, PADDING));
Editor editor(Point(PADDING, PADDING), &palette);
Preview preview(Point(PADDING, 240 - 50 - PADDING), &editor);
Keyboard keyboard(Point(PADDING, 240 - PADDING - 99));
static const Font file_font(font8x8);
Dialog dialog;
FileBrowser file_browser(file_font);
Surface *icons;
std::string load_filename;
void palette_load(std::string filename) {
palette.load(filename);
currentscreen = Screen::Edit;
}
void editor_load(std::string filename) {
load_filename = filename;
dialog.show("Load file?", filename, [](bool yes){
if(yes) {
editor.load(load_filename);
currentscreen = Screen::Edit;
}
});
}
void editor_save(std::string filename) {
editor.current_file = filename;
if(file_exists(filename)) {
dialog.show("Sure?", "Overwrite " + filename, [](bool yes){
if(yes) {
editor.save();
}
currentscreen = Screen::Edit;
});
}
else {
if(editor.save()) {
dialog.show("Done!", "Saved to " + filename);
}
else {
dialog.show("Uh oh!", "Could not save to " + filename);
}
currentscreen = Screen::Edit;
}
}
void keyboard_select(std::string filename) {
keyboard.text = filename;
}
void init() {
set_screen_mode(ScreenMode::hires);
auto launchPath = blit::get_launch_path();
if(launchPath) {
editor.load(launchPath);
}
screen.sprites = icons = Surface::load(icon_sprites);
icons->palette[1] = Pen(255, 255, 255, 255);
}
void render(uint32_t time) {
screen.sprites = icons;
screen.pen = Pen(0, 0, 0, 255);
screen.clear();
if(currentscreen == Screen::Edit) {
editor.render(time, &mouse);
palette.render(time, &mouse);
preview.render(time, &mouse);
}
if(currentscreen == Screen::LoadSprites) {
file_browser.render();
}
if(currentscreen == Screen::SaveSprites) {
file_browser.render();
keyboard.render(time, &mouse);
}
dialog.draw(&mouse);
mouse.render(time);
}
void update(uint32_t time) {
mouse.update(time);
if(dialog.update(&mouse)) return;
if(mouse.button_menu_pressed) {
switch(currentscreen) {
case Screen::Edit:
currentscreen = Screen::Menu;
break;
case Screen::Menu:
currentscreen = Screen::Edit;
break;
default:
break;
}
}
if(currentscreen == Screen::LoadSprites) {
if(file_browser.update(time, &mouse)) {
currentscreen = Screen::Edit;
}
return;
}
if(currentscreen == Screen::SaveSprites) {
keyboard.update(time, &mouse);
if(file_browser.update(time, &mouse)) {
currentscreen = Screen::Edit;
}
return;
}
if(currentscreen == Screen::Edit) {
// TODO: fix this eldritch horror, nor... not?
int editor_action = editor.update(time, &mouse);
int palette_action = palette.update(time, &mouse);
int preview_action = preview.update(time, &mouse);
switch(palette_action) {
case 0:
currentscreen = Screen::LoadPalette;
file_browser.set_extensions({".act", ".pal"});
file_browser.set_on_file_open(palette_load);
file_browser.init();
break;
case 1:
currentscreen = Screen::SavePalette;
break;
case 2:
dialog.show("Sure?", "Really reset palette?", [](bool yes){
if(yes) {
palette.reset();
}
});
break;
case 3:
dialog.show("Sure?", "Really clear palette?", [](bool yes){
if(yes) {
palette.clear();
}
});
break;
default:
break;
}
switch(editor_action) {
case 0:
currentscreen = Screen::LoadSprites;
file_browser.set_extensions({".bmp", ".blim"});
file_browser.set_on_file_open(editor_load);
file_browser.set_height(240);
file_browser.init();
break;
case 1:
currentscreen = Screen::SaveSprites;
file_browser.set_extensions({".bmp", ".blim"});
file_browser.set_on_file_open(keyboard_select);
file_browser.set_height(120);
file_browser.init();
keyboard.set_text(editor.current_file);
keyboard.set_on_done(editor_save);
break;
case 2:
dialog.show("Sure?", "Really clear sprites?", [](bool yes){
if(yes) {
editor.reset();
}
});
break;
case 6:
dialog.show("Tip", "Use the d-pad to configure sprite size");
break;
default:
break;
}
} else {
/*if(mouse.button_b_pressed) {
currentscreen = Screen::Edit;
}*/
}
}