diff options
author | ProjectRevoTPP <projectrevotpp@hotmail.com> | 2016-12-29 21:02:45 -0500 |
---|---|---|
committer | YamaArashi <YamaArashi@users.noreply.github.com> | 2016-12-29 18:02:45 -0800 |
commit | 6b12bb0b52b2a65b6033b7d1c2eae7a182fc4279 (patch) | |
tree | bcd5d89e34c1ea5969d05b076f607d52840cac92 /src/script_menu.c | |
parent | 47f0942e21381b871d95a9e4e25c9ddd810c542f (diff) |
decompile more of script_menu.c (#141)
* begin decompiling script_menu.c
* update MultichoiceStructs to use both structs
* decompile 2 more functions
* decompile more of script_menu.c
* do a bit more of script_menu.c
* whoops
* decompile task_yes_no_maybe
Diffstat (limited to 'src/script_menu.c')
-rw-r--r-- | src/script_menu.c | 221 |
1 files changed, 202 insertions, 19 deletions
diff --git a/src/script_menu.c b/src/script_menu.c index d8d76c27c..1fdaba0c1 100644 --- a/src/script_menu.c +++ b/src/script_menu.c @@ -1,46 +1,229 @@ #include "global.h" #include "task.h" -#include "text.h" #include "menu.h" +#include "palette.h" +#include "script.h" +#include "sound.h" -extern void sub_80B52B4(u8); -extern void DrawMultichoiceMenu(u8, u8, u8, u8 *, int, int); - -struct MultichoiceStruct +struct MultichoiceListStruct { - u8 *textPtr; - u8 var; + struct MenuAction *list; + u8 count; }; -extern struct MultichoiceStruct gMultichoiceLists[]; +extern struct MultichoiceListStruct gMultichoiceLists[]; extern u16 gScriptResult; -bool8 sub_80B5054(u8 var1, u8 var2, u8 var3, u8 var4) +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); + +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; - DrawMultichoiceMenu(var1, var2, gMultichoiceLists[var3].var, gMultichoiceLists[var3].textPtr, var4, 0); + sub_80B53B4(var1, var2, gMultichoiceLists[var3].count, gMultichoiceLists[var3].list, var4); return TRUE; } } -bool8 sub_80B50B0(u8 var1, u8 var2, u8 var3, u8 var4, u8 var5) +void sub_80B53B4(u8 left, u8 top, u8 count, struct MenuAction *list, u8 var4) { - if(FuncIsActiveTask(sub_80B52B4) == 1) - return FALSE; - else + u16 width = GetStringWidthInTilesForScriptMenu(list[0].text); + u16 newWidth; + u8 i; + u8 right; + u8 bottom; + + for(i = 1; i < count; i++) { - gScriptResult = 0xFF; - DrawMultichoiceMenu(var1, var2, gMultichoiceLists[var3].var, gMultichoiceLists[var3].textPtr, var4, var5); - return TRUE; + 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); } -u8 GetStringWidthInTilesForScriptMenu(u8 *str) +bool8 yes_no_box(u8 var1, u8 var2) { - return (GetStringWidthGivenWindowConfig((struct WindowConfig *)&gWindowConfig_81E6CE4, str) + 7) / 8; + 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(); } |