-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcallback_project.cpp
240 lines (204 loc) · 5.96 KB
/
callback_project.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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
This file is part of Retro Graphics Toolkit
Retro Graphics Toolkit is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or any later version.
Retro Graphics Toolkit is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Retro Graphics Toolkit. If not, see <http://www.gnu.org/licenses/>.
Copyright Sega16 (or whatever you wish to call me) (2012-2017)
*/
#include <FL/fl_ask.H>
#include "project.h"
#include "undo.h"
#include "class_global.h"
#include "palette.h"
#include "gui.h"
static const char * warningDelete = "Warning this will delete this project's data\nDo you wish to continue?";
void setSegaPalType(Fl_Widget*, void*x) {
currentProject->subSystem &= ~sgSHmask;
currentProject->subSystem |= (uintptr_t)x;
set_palette_type();
window->redraw();
}
void setNesTile(Fl_Widget*o, void*) {
Fl_Choice *c = (Fl_Choice*)o;
bool t = c->value();
if (t)
currentProject->subSystem |= NES2x2;
else
currentProject->subSystem &= ~NES2x2;
}
void saveAllProjectsCB(Fl_Widget*, void*) {
std::string the_file;
if (!loadOrSaveFile(the_file, "Save projects group as...", true))
return;
saveAllProjects(the_file.c_str());
}
void loadAllProjectsCB(Fl_Widget*, void*) {
std::string the_file;
if (!loadOrSaveFile(the_file, "Load projects group"))
return;
pushProjectAll();
loadAllProjects(the_file.c_str());
switchProject(curProjectID, curProjectID);
}
void haveCB(Fl_Widget*o, void*mask) {
Fl_Check_Button* b = (Fl_Check_Button*)o;
uint32_t m = (uintptr_t)mask;
bool set = b->value() ? true : false;
if (!set) {
if (!fl_ask(warningDelete)) {
b->value(1);
window->redraw();
return;
}
}
if ((m & pjHavePal) && (!set)) { //cannot have tiles without a palette
if (currentProject->containsDataOR(pjNeedsPalette)) {
fl_alert("You cannot have these/this without a palette");
b->value(1);
window->redraw();
return;
}
}
if ((m & pjHaveTiles) && (!set)) {
if (currentProject->containsDataOR(pjNeedsTiles)) {
fl_alert("You cannot have these/this without tiles");
b->value(1);
window->redraw();
return;
}
}
if ((m & (~pjHavePal)) && set) { //Ensure that a palette exists before enabling anything else
if (!currentProject->containsData(pjHavePal)) {
fl_alert("You need a palette to do this");
b->value(0);
window->redraw();
return;
}
}
if ((m & pjNeedsTiles) && set) { //Are we trying to enable something that needs tiles?
if (!currentProject->containsData(pjHaveTiles)) {
fl_alert("You cannot have that without tiles");
b->value(0);
window->redraw();
return;
}
}
setHaveProject(curProjectID, m, set);
unsigned off = __builtin_ctz(m);
if (set) {
if (window->tabsHidden[off]) {
window->the_tabs->insert(*window->tabsMain[off], off);
window->tabsHidden[off] = false;
}
} else {
if (!window->tabsHidden[off]) {
if (currentProject->share[off] < 0) {
window->the_tabs->remove(window->tabsMain[off]);
window->tabsHidden[off] = true;
}
}
}
window->redraw();
}
static void updateShareHave(void) {
for (int x = 0; x < shareAmtPj; ++x) {
if (currentProject->share[x] < 0)
window->havePrj[x]->show();
else
window->havePrj[x]->hide();
}
}
void switchShareCB(Fl_Widget*o, void*mask) {
Fl_Slider* s = (Fl_Slider*)o;
uint32_t m = (uintptr_t)mask;
bool share = window->sharePrj[__builtin_ctz(m)]->value() ? true : false;
printf("Change mask %d %d\n", m, share);
if (share)
shareProject(curProjectID, s->value(), m, true);
updateShareHave();
if (m & pjHaveTiles)
updateTileSelectAmt();
if (m & pjHaveMap) {
window->updateMapWH();
char tmp[16];
snprintf(tmp, 16, "%d", currentProject->tms->maps[currentProject->curPlane].offset);
window->tmapOffset->value(tmp);
}
if (m & pjHaveChunks) {
window->updateBlockTilesChunk();
window->updateChunkSize();
}
if (m & pjHaveSprites)
window->updateSpriteSliders();
window->redraw();
}
void shareProjectCB(Fl_Widget*o, void*mask) {
Fl_Check_Button* b = (Fl_Check_Button*)o;
if (projects->size() <= 1) {
fl_alert("Cannot share when there is only one project");
b->value(0);
window->redraw();
return;
}
uint32_t m = (uintptr_t)mask;
uint32_t with = window->shareWith[__builtin_ctz(m)]->value();
if (curProjectID == with) {
fl_alert("One does not simply share with itself");
b->value(0);
window->redraw();
return;
}
if (b->value()) {
if (!fl_ask(warningDelete)) {
b->value(0);
window->redraw();
return;
}
}
printf("%d with %d %d %d\n", curProjectID, with, m, __builtin_ctz(m));
shareProject(curProjectID, with, m, b->value() ? true : false);
updateShareHave();
window->redraw();
}
void loadProjectCB(Fl_Widget*, void*) {
std::string the_file;
if (!loadOrSaveFile(the_file, "Load project", false))
return;
pushProject();
loadProject(curProjectID, the_file.c_str());
switchProject(curProjectID, curProjectID, true);
}
void saveProjectCB(Fl_Widget*, void*) {
currentProject->Name.assign(window->TxtBufProject->text());//Update the project text.
std::string fname;
if (loadOrSaveFile(fname, "Save project as ...", true))
saveProject(curProjectID, fname.c_str());
}
void switchProjectCB(Fl_Widget*o, void*) {
Fl_Slider* s = (Fl_Slider*)o;
switchProjectSlider(s->value());
}
void appendProjectCB(Fl_Widget*, void*) {
pushProjectAppend();
appendProject();
window->redraw();
}
void deleteProjectCB(Fl_Widget*, void*) {
if (projects->size() <= 1) {
fl_alert("You must have at least one project.");
return;
}
removeProject(curProjectID);
if (curProjectID) {
curProjectID--;
window->projectSelect->value(curProjectID);
}
currentProject = &projects->at(curProjectID);
switchProject(curProjectID, curProjectID);
}