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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
#include "global.h"
#include "task.h"
#include "menu.h"
#include "palette.h"
#include "script.h"
#include "sound.h"
struct MultichoiceListStruct
{
struct MenuAction *list;
u8 count;
};
extern const struct MultichoiceListStruct gMultichoiceLists[];
extern u16 gScriptResult;
void DrawMultichoiceMenu(u8, u8, u8, struct MenuAction *list, u8, u8);
void sub_80B53B4(u8, u8, u8, struct MenuAction *list, u8);
void sub_80B52B4(u8);
void sub_80B5230(u8, u8, u8, u8, u8, u8);
void task_yes_no_maybe(u8);
void sub_80B5684(u8);
bool8 sub_80B5054(u8 left, u8 top, u8 var3, u8 var4)
{
if(FuncIsActiveTask(sub_80B52B4) == 1)
return FALSE;
else
{
gScriptResult = 0xFF;
DrawMultichoiceMenu(left, top, gMultichoiceLists[var3].count, gMultichoiceLists[var3].list, var4, 0);
return TRUE;
}
}
bool8 sub_80B50B0(u8 left, u8 top, u8 var3, u8 var4, u8 var5)
{
if(FuncIsActiveTask(sub_80B52B4) == 1)
return FALSE;
else
{
gScriptResult = 0xFF;
DrawMultichoiceMenu(left, top, gMultichoiceLists[var3].count, gMultichoiceLists[var3].list, var4, var5);
return TRUE;
}
}
u16 GetStringWidthInTilesForScriptMenu(u8 *str)
{
// each tile on screen is 8x8, so it needs the number of tiles and not pixels, hence the division by 8.
return (GetStringWidthGivenWindowConfig((struct WindowConfig *)&gWindowConfig_81E6CE4, str) + 7) / 8;
}
void DrawMultichoiceMenu(u8 left, u8 top, u8 count, struct MenuAction *list, u8 var4, u8 cursorPos)
{
u16 width = GetStringWidthInTilesForScriptMenu(list[0].text);
u16 newWidth;
u8 i;
u8 right;
u8 bottom;
for(i = 1; i < count; i++)
{
newWidth = GetStringWidthInTilesForScriptMenu(list[i].text);
if(width < newWidth)
width = newWidth;
}
right = width;
right = (right + left) + 1;
if(right > 29)
{
left = left + (29 - right);
right = 29;
}
bottom = top + (2 * count + 1);
MenuDrawTextWindow(left, top, right, bottom);
PrintMenuItems(left + 1, top + 1, count, list);
InitMenu(0, left + 1, top + 1, count, cursorPos, right - left - 1);
sub_80B5230(left, top, right, bottom, var4, count);
}
void sub_80B5230(u8 left, u8 top, u8 right, u8 bottom, u8 unkVar, u8 count)
{
u8 taskId = CreateTask(sub_80B52B4, 80);
gTasks[taskId].data[0] = left;
gTasks[taskId].data[1] = top;
gTasks[taskId].data[2] = right;
gTasks[taskId].data[3] = bottom;
gTasks[taskId].data[4] = unkVar;
if(count > 3)
gTasks[taskId].data[5] = TRUE;
else
gTasks[taskId].data[5] = FALSE;
}
void sub_80B52B4(u8 taskId)
{
s8 var;
if(!gPaletteFade.active)
{
if(!gTasks[taskId].data[5])
var = ProcessMenuInputNoWrap();
else
var = ProcessMenuInput();
if(var != -2)
{
if(var == -1)
{
if(!gTasks[taskId].data[4])
{
PlaySE(5);
gScriptResult = 127;
}
else
{
return;
}
}
else
{
gScriptResult = var;
}
sub_8072DEC();
MenuZeroFillWindowRect(gTasks[taskId].data[0], gTasks[taskId].data[1], gTasks[taskId].data[2], gTasks[taskId].data[3]);
DestroyTask(taskId);
EnableBothScriptContexts();
}
}
}
bool8 Multichoice(u8 var1, u8 var2, u8 var3, u8 var4)
{
if(FuncIsActiveTask(sub_80B52B4) == 1)
return FALSE;
else
{
gScriptResult = 0xFF;
sub_80B53B4(var1, var2, gMultichoiceLists[var3].count, gMultichoiceLists[var3].list, var4);
return TRUE;
}
}
void sub_80B53B4(u8 left, u8 top, u8 count, struct MenuAction *list, u8 var4)
{
u16 width = GetStringWidthInTilesForScriptMenu(list[0].text);
u16 newWidth;
u8 i;
u8 right;
u8 bottom;
for(i = 1; i < count; i++)
{
newWidth = GetStringWidthInTilesForScriptMenu(list[i].text);
if(width < newWidth)
width = newWidth;
}
right = width;
right = (right + left) + 2;
bottom = top + (2 * count + 1);
PrintMenuItems(left, top, count, list);
InitMenu(0, left, top, count, 0, right - left - 1);
sub_80B5230(left, top, right, bottom, var4, count);
}
bool8 yes_no_box(u8 var1, u8 var2)
{
u8 taskId;
if(FuncIsActiveTask(task_yes_no_maybe) == 1)
return FALSE;
else
{
gScriptResult = 0xFF;
DisplayYesNoMenu(var1, var2, 1);
taskId = CreateTask(task_yes_no_maybe, 0x50);
gTasks[taskId].data[0] = var1;
gTasks[taskId].data[1] = var2;
return TRUE;
}
}
// unused
bool8 IsScriptActive(void)
{
if(gScriptResult == 0xFF)
return FALSE;
else
return TRUE;
}
void task_yes_no_maybe(u8 taskId)
{
u8 left, top;
if (gTasks[taskId].data[2] < 5)
{
gTasks[taskId].data[2]++;
return;
}
switch (ProcessMenuInputNoWrap())
{
case -2:
return;
case -1:
case 1:
PlaySE(5);
gScriptResult = 0;
break;
case 0:
gScriptResult = 1;
break;
}
left = gTasks[taskId].data[0];
top = gTasks[taskId].data[1];
MenuZeroFillWindowRect(left, top, left + 6, top + 5);
DestroyTask(taskId);
EnableBothScriptContexts();
}
bool8 sub_80B5578(u8 left, u8 top, u8 multichoiceId, u8 a4, u8 columnCount)
{
u8 bottom = 0;
if (FuncIsActiveTask(sub_80B5684) == TRUE)
{
return FALSE;
}
else
{
u8 taskId;
u8 width;
gScriptResult = 255;
sub_807274C(left, top, gMultichoiceLists[multichoiceId].count, 0, gMultichoiceLists[multichoiceId].list, columnCount, 0);
taskId = CreateTask(sub_80B5684, 80);
if (!((gMultichoiceLists[multichoiceId].count >> 1) < columnCount || (gMultichoiceLists[multichoiceId].count & 1))
|| columnCount == 1 || gMultichoiceLists[multichoiceId].count == columnCount)
{
bottom = (2 * (gMultichoiceLists[multichoiceId].count / columnCount)) + 1 + top;
}
else
{
bottom = (2 * (gMultichoiceLists[multichoiceId].count / columnCount)) + 3 + top;
}
width = sub_807288C(columnCount);
gTasks[taskId].data[0] = left;
gTasks[taskId].data[1] = top;
gTasks[taskId].data[2] = width + left + 2;
gTasks[taskId].data[3] = bottom;
gTasks[taskId].data[4] = a4;
return TRUE;
}
}
void sub_80B5684(u8 taskId)
{
s8 var = sub_80727CC();
if (var != -2)
{
if (var == -1)
{
if (!gTasks[taskId].data[4])
{
PlaySE(5);
gScriptResult = 127;
}
else
{
return;
}
}
else
{
gScriptResult = var;
}
sub_8072DEC();
MenuZeroFillWindowRect(gTasks[taskId].data[0], gTasks[taskId].data[1], gTasks[taskId].data[2], gTasks[taskId].data[3]);
DestroyTask(taskId);
EnableBothScriptContexts();
}
}
|