summaryrefslogtreecommitdiff
path: root/src/new_menu_helpers.c
blob: a4aad405864d7ede222c9e8125289436e3f6cfb6 (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
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
#include "global.h"
#include "bg.h"
#include "palette.h"
#include "window.h"
#include "text.h"
#include "new_menu_helpers.h"
#include "text_window.h"
#include "menu.h"
#include "menu_helpers.h"

#define STD_WINDOW_PALETTE_NUM 14
#define STD_WINDOW_BASE_TILE_NUM 0x214
#define DLG_WINDOW_PALETTE_NUM 15
#define DLG_WINDOW_BASE_TILE_NUM 0x200

static EWRAM_DATA u8 gUnknown_0203CD8C = 0;
static EWRAM_DATA u8 gUnknown_0203CD8D = 0;

const u16 gUnknown_0860F074[] = INCBIN_U16("graphics/interface/860F074.gbapal");
static const u8 gUnknown_0860F094[] = { 8, 4, 1 };

static const struct WindowTemplate gUnknown_0860F098[] = 
{
    { 0x00, 0x02, 0x0F, 0x1B, 0x04, 0x0F, 0x194 },
    DUMMY_WIN_TEMPLATE
};

static const struct WindowTemplate gUnknown_0860F0A8 =
{
    0x00, 0x15, 0x09, 0x05, 0x04, 0x0F, 0x125
};

// Forward declarations
extern void sub_81973A4(void);
extern void DrawStandardFrame(u8, u8, u8, u8, u8, u8);
extern void DrawDialogueFrame(u8, u8, u8, u8, u8, u8);
extern void sub_81977BC(u8, u8, u8, u8, u8, u8);
extern void sub_8197804(u8, u8, u8, u8, u8, u8);

void sub_81971D0(void)
{
    InitWindows(gUnknown_0860F098);
    gUnknown_0203CD8C = 0xFF;
    gUnknown_0203CD8D = 0xFF;
}

void sub_81971F4(void)
{
    FreeAllWindowBuffers();
}

void sub_8197200(void)
{
    ChangeBgX(0, 0, 0);
    ChangeBgY(0, 0, 0);
    DeactivateAllTextPrinters();
    sub_81973A4();
}

u16 sub_8197224(void)
{
    RunTextPrinters();
    return IsTextPrinterActive(0);
}

u16 AddTextPrinterParameterized(u8 windowId, u8 fontId, const u8 *str, u8 speed, void (*callback)(struct TextSubPrinter *, u16), u8 fgColor, u8 bgColor, u8 shadowColor)
{
    struct TextSubPrinter printer;
    
    printer.current_text_offset = str;
    printer.windowId = windowId;
    printer.fontId = fontId;
    printer.x = 0;
    printer.y = 1;
    printer.currentX = 0;
    printer.currentY = 1;
    printer.letterSpacing = 0;
    printer.lineSpacing = 0;
    printer.fontColor_l = 0;
    printer.fgColor = fgColor;
    printer.bgColor = bgColor;
    printer.shadowColor = shadowColor;
    
    gTextFlags.flag_1 = 0;
    return AddTextPrinter(&printer, speed, callback); 
}

void AddTextPrinterForMessage(bool8 allowSkippingDelayWithButtonPress)
{
    void (*callback)(struct TextSubPrinter *, u16) = NULL;
    gTextFlags.flag_0 = allowSkippingDelayWithButtonPress;
    AddTextPrinterParameterized(0, 1, gStringVar4, GetPlayerTextSpeed(), callback, 2, 1, 3);
}

void AddTextPrinterForMessage_2(bool8 allowSkippingDelayWithButtonPress)
{
    gTextFlags.flag_0 = allowSkippingDelayWithButtonPress;
    AddTextPrinterParameterized(0, 1, gStringVar4, GetPlayerTextSpeed(), NULL, 2, 1, 3);
}

void AddTextPrinterWithCustomSpeedForMessage(bool8 allowSkippingDelayWithButtonPress, u8 speed)
{
    gTextFlags.flag_0 = allowSkippingDelayWithButtonPress;
    AddTextPrinterParameterized(0, 1, gStringVar4, speed, NULL, 2, 1, 3);
}

void sub_81973A4(void)
{
    copy_textbox_border_tile_patterns_to_vram(0, DLG_WINDOW_BASE_TILE_NUM, 0xF0);
    sub_809882C(0, STD_WINDOW_BASE_TILE_NUM, 0xE0);
}

void NewMenuHelpers_DrawDialogueFrame(u8 windowId, bool8 copyToVram)
{
    CallWindowFunction(windowId, DrawDialogueFrame);
    FillWindowPixelBuffer(windowId, 0x11);
    PutWindowTilemap(windowId);
    if (copyToVram == TRUE)
        CopyWindowToVram(windowId, 3);
}

void NewMenuHelpers_DrawStdWindowFrame(u8 windowId, bool8 copyToVram)
{
    CallWindowFunction(windowId, DrawStandardFrame);
    FillWindowPixelBuffer(windowId, 0x11);
    PutWindowTilemap(windowId);
    if (copyToVram == TRUE)
        CopyWindowToVram(windowId, 3);
}

void sub_8197434(u8 windowId, bool8 copyToVram)
{
    CallWindowFunction(windowId, sub_8197804);
    FillWindowPixelBuffer(windowId, 0x11);
    ClearWindowTilemap(windowId);
    if (copyToVram == TRUE)
        CopyWindowToVram(windowId, 3);
}

void sub_819746C(u8 windowId, bool8 copyToVram)
{
    CallWindowFunction(windowId, sub_81977BC);
    FillWindowPixelBuffer(windowId, 0x11);
    ClearWindowTilemap(windowId);
    if (copyToVram == TRUE)
        CopyWindowToVram(windowId, 3);
}

void DrawStandardFrame(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum)
{
    int i;
    
    FillBgTilemapBufferRect(bg,
                            STD_WINDOW_BASE_TILE_NUM + 0,
                            tilemapLeft - 1,
                            tilemapTop - 1,
                            1,
                            1,
                            STD_WINDOW_PALETTE_NUM);
    FillBgTilemapBufferRect(bg,
                            STD_WINDOW_BASE_TILE_NUM + 1,
                            tilemapLeft,
                            tilemapTop - 1,
                            width,
                            1,
                            STD_WINDOW_PALETTE_NUM);
    FillBgTilemapBufferRect(bg,
                            STD_WINDOW_BASE_TILE_NUM + 2,
                            tilemapLeft + width,
                            tilemapTop - 1,
                            1,
                            1,
                            STD_WINDOW_PALETTE_NUM);
    
    for (i = tilemapTop; i < tilemapTop + height; i++)
    {
        FillBgTilemapBufferRect(bg,
                                STD_WINDOW_BASE_TILE_NUM + 3,
                                tilemapLeft - 1,
                                i,
                                1,
                                1,
                                STD_WINDOW_PALETTE_NUM);
        FillBgTilemapBufferRect(bg,
                                STD_WINDOW_BASE_TILE_NUM + 5,
                                tilemapLeft + width,
                                i,
                                1,
                                1,
                                STD_WINDOW_PALETTE_NUM);
    }
    
    FillBgTilemapBufferRect(bg,
                            STD_WINDOW_BASE_TILE_NUM + 6,
                            tilemapLeft - 1,
                            tilemapTop + height,
                            1,
                            1,
                            STD_WINDOW_PALETTE_NUM);
    FillBgTilemapBufferRect(bg,
                            STD_WINDOW_BASE_TILE_NUM + 7,
                            tilemapLeft,
                            tilemapTop + height,
                            width,
                            1,
                            STD_WINDOW_PALETTE_NUM);
    FillBgTilemapBufferRect(bg,
                            STD_WINDOW_BASE_TILE_NUM + 8,
                            tilemapLeft + width,
                            tilemapTop + height,
                            1,
                            1,
                            STD_WINDOW_PALETTE_NUM);
}

void DrawDialogueFrame(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum)
{
    FillBgTilemapBufferRect(bg,
                            DLG_WINDOW_BASE_TILE_NUM + 1,
                            tilemapLeft - 2,
                            tilemapTop - 1,
                            1,
                            1,
                            DLG_WINDOW_PALETTE_NUM);
    FillBgTilemapBufferRect(bg,
                            DLG_WINDOW_BASE_TILE_NUM + 3,
                            tilemapLeft - 1,
                            tilemapTop - 1,
                            1,
                            1,
                            DLG_WINDOW_PALETTE_NUM);
    FillBgTilemapBufferRect(bg,
                            DLG_WINDOW_BASE_TILE_NUM + 4,
                            tilemapLeft,
                            tilemapTop - 1,
                            width - 1,
                            1,
                            DLG_WINDOW_PALETTE_NUM);
    FillBgTilemapBufferRect(bg,
                            DLG_WINDOW_BASE_TILE_NUM + 5,
                            tilemapLeft + width - 1,
                            tilemapTop - 1,
                            1,
                            1,
                            DLG_WINDOW_PALETTE_NUM);
    FillBgTilemapBufferRect(bg,
                            DLG_WINDOW_BASE_TILE_NUM + 6,
                            tilemapLeft + width,
                            tilemapTop - 1,
                            1,
                            1,
                            DLG_WINDOW_PALETTE_NUM);
    FillBgTilemapBufferRect(bg,
                            DLG_WINDOW_BASE_TILE_NUM + 7,
                            tilemapLeft - 2,
                            tilemapTop,
                            1,
                            5,
                            DLG_WINDOW_PALETTE_NUM);
    FillBgTilemapBufferRect(bg,
                            DLG_WINDOW_BASE_TILE_NUM + 9,
                            tilemapLeft - 1,
                            tilemapTop,
                            width + 1,
                            5,
                            DLG_WINDOW_PALETTE_NUM);
    FillBgTilemapBufferRect(bg,
                            DLG_WINDOW_BASE_TILE_NUM + 10,
                            tilemapLeft + width,
                            tilemapTop,
                            1,
                            5,
                            DLG_WINDOW_PALETTE_NUM);
    FillBgTilemapBufferRect(bg,
                            BG_TILE_V_FLIP(DLG_WINDOW_BASE_TILE_NUM + 1),
                            tilemapLeft - 2,
                            tilemapTop + height,
                            1,
                            1,
                            DLG_WINDOW_PALETTE_NUM);
    FillBgTilemapBufferRect(bg,
                            BG_TILE_V_FLIP(DLG_WINDOW_BASE_TILE_NUM + 3),
                            tilemapLeft - 1,
                            tilemapTop + height,
                            1,
                            1,
                            DLG_WINDOW_PALETTE_NUM);
    FillBgTilemapBufferRect(bg,
                            BG_TILE_V_FLIP(DLG_WINDOW_BASE_TILE_NUM + 4),
                            tilemapLeft,
                            tilemapTop + height,
                            width - 1,
                            1,
                            DLG_WINDOW_PALETTE_NUM);
    FillBgTilemapBufferRect(bg,
                            BG_TILE_V_FLIP(DLG_WINDOW_BASE_TILE_NUM + 5),
                            tilemapLeft + width - 1,
                            tilemapTop + height,
                            1,
                            1,
                            DLG_WINDOW_PALETTE_NUM);
    FillBgTilemapBufferRect(bg,
                            BG_TILE_V_FLIP(DLG_WINDOW_BASE_TILE_NUM + 6),
                            tilemapLeft + width,
                            tilemapTop + height,
                            1,
                            1,
                            DLG_WINDOW_PALETTE_NUM);
}

void sub_81977BC(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum)
{
    FillBgTilemapBufferRect(bg, 0, tilemapLeft - 1, tilemapTop - 1, width + 2, height + 2, STD_WINDOW_PALETTE_NUM);
}

void sub_8197804(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum)
{
    FillBgTilemapBufferRect(bg, 0, tilemapLeft - 3, tilemapTop - 1, width + 6, height + 2, STD_WINDOW_PALETTE_NUM);
}

void SetStandardWindowBorderStyle(u8 windowId, bool8 copyToVram)
{
    SetWindowBorderStyle(windowId, copyToVram, STD_WINDOW_BASE_TILE_NUM, STD_WINDOW_PALETTE_NUM);
}

void sub_819786C(u8 windowId, bool8 copyToVram)
{
    copy_textbox_border_tile_patterns_to_vram(windowId, DLG_WINDOW_BASE_TILE_NUM, 0xF0);
    sub_8197B1C(windowId, copyToVram, DLG_WINDOW_BASE_TILE_NUM, 0xF);
}

void sub_819789C(void)
{
    LoadPalette(gUnknown_0860F074, 0xE0, 0x14);
}

void sub_81978B0(u16 offset)
{
    LoadPalette(gUnknown_0860F074, offset, 0x14);
}

const u16 *sub_81978C8(void)
{
    return gUnknown_0860F074;
}

u16 sub_81978D0(u8 colorNum)
{
    if (colorNum > 15)
        colorNum = 0;
    return gUnknown_0860F074[colorNum];
}

void DisplayItemMessageOnField(u8 taskId, const u8 *string, TaskFunc callback)
{
    sub_81973A4();
    DisplayMessageAndContinueTask(taskId, 0, DLG_WINDOW_BASE_TILE_NUM, DLG_WINDOW_PALETTE_NUM, 1, GetPlayerTextSpeed(), string, callback);
    CopyWindowToVram(0, 3);
}

void sub_8197930(void)
{
    CreateYesNoMenu(&gUnknown_0860F0A8, STD_WINDOW_BASE_TILE_NUM, STD_WINDOW_PALETTE_NUM, 0);
}

void sub_8197948(u8 initialCursorPos)
{
    CreateYesNoMenu(&gUnknown_0860F0A8, STD_WINDOW_BASE_TILE_NUM, STD_WINDOW_PALETTE_NUM, initialCursorPos);
}

u32 sub_8197964(void)
{
    if (gTextFlags.flag_3)
        return 1;
    return gSaveBlock2Ptr->optionsTextSpeed;
}

u8 GetPlayerTextSpeed(void)
{
    u32 speed;
    if (gSaveBlock2Ptr->optionsTextSpeed > 2)
        gSaveBlock2Ptr->optionsTextSpeed = 1;
    speed = sub_8197964();
    return gUnknown_0860F094[speed];
}

u8 sub_81979C4(u8 a1)
{
    if (gUnknown_0203CD8C == 0xFF)
        gUnknown_0203CD8C = sub_8198AA4(0, 0x16, 1, 7, (a1 * 2) + 2, 0xF, 0x139);
    return gUnknown_0203CD8C;
}

u8 GetStartMenuWindowId(void)
{
    return gUnknown_0203CD8C;
}

void remove_start_menu_window_maybe(void)
{
    if (gUnknown_0203CD8C != 0xFF)
    {
        RemoveWindow(gUnknown_0203CD8C);
        gUnknown_0203CD8C = 0xFF;
    }
}

u16 sub_8197A30(void)
{
    return DLG_WINDOW_BASE_TILE_NUM;
}

u16 sub_8197A38(void)
{
    return STD_WINDOW_BASE_TILE_NUM;
}

u8 AddMapNamePopUpWindow(void)
{
    if (gUnknown_0203CD8D == 0xFF)
        gUnknown_0203CD8D = sub_8198AA4(0, 1, 1, 10, 3, 14, 0x107);
    return gUnknown_0203CD8D;
}

u8 GetMapNamePopUpWindowId(void)
{
    return gUnknown_0203CD8D;
}

void RemoveMapNamePopUpWindow(void)
{
    if (gUnknown_0203CD8D != 0xFF)
    {
        RemoveWindow(gUnknown_0203CD8D);
        gUnknown_0203CD8D = 0xFF;
    }
}