/** * Shake the screen. * @param e The Explosion. * @param parameter Unused parameter. */ static void Explosion_Func_ScreenShake(Explosion *e, uint16 parameter) { int i; #ifdef _DEBUG Debug("Explosion_Func_ScreenShake(%p, %d)\n", e, parameter); #else VARIABLE_NOT_USED(e); VARIABLE_NOT_USED(parameter); #endif for(i = 0; i < 2; i++) { #if defined(_WIN32) msleep(30); #else sleepIdle(); sleepIdle(); #endif Video_SetOffset(320); #if defined(_WIN32) msleep(30); #else sleepIdle(); sleepIdle(); #endif Video_SetOffset(0); } }
/** * Updates the radar state for the given house. * @param h The house. * @return True if and only if the radar has been activated. */ bool House_UpdateRadarState(House *h) { void *wsa; uint16 frame; uint16 frameCount; bool activate; if (h == NULL || h->index != g_playerHouseID) return false; wsa = NULL; activate = h->flags.radarActivated; if (h->flags.radarActivated) { /* Deactivate radar */ if ((h->structuresBuilt & (1 << STRUCTURE_OUTPOST)) == 0 || h->powerProduction < h->powerUsage) activate = false; } else { /* Activate radar */ if ((h->structuresBuilt & (1 << STRUCTURE_OUTPOST)) != 0 && h->powerProduction >= h->powerUsage) activate = true; } if (h->flags.radarActivated == activate) return false; wsa = WSA_LoadFile("STATIC.WSA", GFX_Screen_Get_ByIndex(3), GFX_Screen_GetSize_ByIndex(3), true); frameCount = WSA_GetFrameCount(wsa); g_textDisplayNeedsUpdate = true; GUI_Mouse_Hide_Safe(); while (Driver_Voice_IsPlaying()) sleepIdle(); Voice_Play(62); Sound_Output_Feedback(activate ? 28 : 29); frameCount = WSA_GetFrameCount(wsa); for (frame = 0; frame < frameCount; frame++) { WSA_DisplayFrame(wsa, activate ? frameCount - frame : frame, 256, 136, 0); GUI_PaletteAnimate(); g_timerTimeout = 3; while (g_timerTimeout != 0) sleepIdle(); } h->flags.radarActivated = activate; WSA_Unload(wsa); g_viewport_forceRedraw = true; GUI_Mouse_Show_Safe(); GUI_Widget_Viewport_RedrawMap(0); return activate; }
static bool GUI_YesNo(uint16 stringID) { WindowDesc *desc = &g_yesNoWindowDesc; bool loop; bool ret = false; desc->stringID = stringID; GUI_Window_BackupScreen(desc); GUI_Window_Create(desc); for (loop = true; loop; sleepIdle()) { uint16 key = GUI_Widget_HandleEvents(g_widgetLinkedListTail); if ((key & 0x8000) != 0) { switch (key & 0x7FFF) { case 0x1E: ret = true; break; case 0x1F: ret = false; break; default: break; } loop = false; } GUI_PaletteAnimate(); } GUI_Window_RestoreScreen(desc); return ret; }
/** * Show the Mentat screen with a dialog (Proceed / Repeat). * @param houseID The house to show the mentat of. * @param stringID The string to show. * @param wsaFilename The WSA to show. * @param musicID The Music to play. */ static void GUI_Mentat_ShowDialog(uint8 houseID, uint16 stringID, const char *wsaFilename, uint16 musicID) { Widget *w1, *w2; if (g_debugSkipDialogs) return; w1 = GUI_Widget_Allocate(1, GUI_Widget_GetShortcut(String_Get_ByIndex(STR_PROCEED)[0]), 168, 168, 379, 0); w2 = GUI_Widget_Allocate(2, GUI_Widget_GetShortcut(String_Get_ByIndex(STR_REPEAT)[0]), 240, 168, 381, 0); w1 = GUI_Widget_Link(w1, w2); Sound_Output_Feedback(0xFFFE); Driver_Voice_Play(NULL, 0xFF); Music_Play(musicID); stringID += STR_HOUSE_HARKONNENFROM_THE_DARK_WORLD_OF_GIEDI_PRIME_THE_SAVAGE_HOUSE_HARKONNEN_HAS_SPREAD_ACROSS_THE_UNIVERSE_A_CRUEL_PEOPLE_THE_HARKONNEN_ARE_RUTHLESS_TOWARDS_BOTH_FRIEND_AND_FOE_IN_THEIR_FANATICAL_PURSUIT_OF_POWER + houseID * 40; do { strncpy(g_readBuffer, String_Get_ByIndex(stringID), g_readBufferSize); sleepIdle(); } while (GUI_Mentat_Show(g_readBuffer, wsaFilename, w1, true) == 0x8002); free(w2); free(w1); if (musicID != 0xFFFF) Driver_Music_FadeOut(); }
/** * Handles Click event for "Game controls" button. * * @param w The widget. */ static void GUI_Widget_GameControls_Click(Widget *w) { WindowDesc *desc = &g_gameControlWindowDesc; bool loop; GUI_Window_BackupScreen(desc); GUI_Window_Create(desc); loop = true; while (loop) { Widget *w2 = g_widgetLinkedListTail; uint16 key = GUI_Widget_HandleEvents(w2); if ((key & 0x8000) != 0) { w = GUI_Widget_Get_ByIndex(w2, key & 0x7FFF); switch ((key & 0x7FFF) - 0x1E) { case 0: g_gameConfig.music ^= 0x1; if (g_gameConfig.music == 0) Driver_Music_Stop(); break; case 1: g_gameConfig.sounds ^= 0x1; if (g_gameConfig.sounds == 0) Driver_Sound_Stop(); break; case 2: if (++g_gameConfig.gameSpeed >= 5) g_gameConfig.gameSpeed = 0; break; case 3: g_gameConfig.hints ^= 0x1; break; case 4: g_gameConfig.autoScroll ^= 0x1; break; case 5: loop = false; break; default: break; } GUI_Widget_MakeNormal(w, false); GUI_Widget_Draw(w); } GUI_PaletteAnimate(); sleepIdle(); } GUI_Window_RestoreScreen(desc); }
void async_GUI_Mentat_ShowLoop() { GUI_Widget_DrawAll(asyncMentatShow.w); asyncMentatShow.ret = GUI_Widget_HandleEvents(asyncMentatShow.w); GUI_PaletteAnimate(); GUI_Mentat_Animation(0); sleepIdle(); }
/** * Show the Mentat screen. * @param spriteBuffer The buffer of the strings. * @param wsaFilename The WSA to show. * @param w The widgets to handle. Can be NULL for no widgets. * @param unknown A boolean. * @return Return value of GUI_Widget_HandleEvents() or f__B4DA_0AB8_002A_AAB2() (latter when no widgets). */ uint16 GUI_Mentat_Show(char *stringBuffer, const char *wsaFilename, Widget *w, bool unknown) { uint16 ret; Sprites_UnloadTiles(); GUI_Mentat_Display(wsaFilename, g_playerHouseID); GFX_Screen_SetActive(SCREEN_1); Widget_SetAndPaintCurrentWidget(8); if (wsaFilename != NULL) { void *wsa; wsa = WSA_LoadFile(wsaFilename, GFX_Screen_Get_ByIndex(SCREEN_2), GFX_Screen_GetSize_ByIndex(SCREEN_2), false); WSA_DisplayFrame(wsa, 0, g_curWidgetXBase * 8, g_curWidgetYBase, SCREEN_1); WSA_Unload(wsa); } GUI_DrawSprite(SCREEN_1, g_sprites[397 + g_playerHouseID * 15], g_shoulderLeft, g_shoulderTop, 0, 0); GFX_Screen_SetActive(SCREEN_0); GUI_Mouse_Hide_Safe(); GUI_Screen_Copy(0, 0, 0, 0, SCREEN_WIDTH / 8, SCREEN_HEIGHT, SCREEN_1, SCREEN_0); GUI_Mouse_Show_Safe(); GUI_SetPaletteAnimated(g_palette1, 15); ret = GUI_Mentat_Loop(wsaFilename, NULL, stringBuffer, true, NULL); if (w != NULL) { do { GUI_Widget_DrawAll(w); ret = GUI_Widget_HandleEvents(w); GUI_PaletteAnimate(); GUI_Mentat_Animation(0); sleepIdle(); } while ((ret & 0x8000) == 0); } Input_History_Clear(); if (unknown) { Load_Palette_Mercenaries(); Sprites_LoadTiles(); } return ret; }
/** * Test whether the mouse cursor is at the border or inside the given rectangle. * @param left Left edge. * @param top Top edge. * @param right Right edge. * @param bottom Bottom edge. * @return Mouse is at the border or inside the rectangle. */ uint16 Mouse_InsideRegion(int16 left, int16 top, int16 right, int16 bottom) { int16 mx, my; uint16 inside; while (g_mouseLock != 0) sleepIdle(); g_mouseLock++; mx = g_mouseX; my = g_mouseY; inside = (mx < left || mx > right || my < top || my > bottom) ? 0 : 1; g_mouseLock--; return inside; }
/** * Handles Click event for the "Up" button in production window. * * @return True, always. */ bool GUI_Production_Up_Click(Widget *w) { bool locdi = false; if (g_factoryWindowSelected != 0) { g_timerTimeout = 10; GUI_FactoryWindow_B495_0F30(); g_factoryWindowSelected--; GUI_FactoryWindow_UpdateSelection(true); locdi = true; } else { if (g_factoryWindowBase != 0) { g_timerTimeout = 10; g_factoryWindowBase--; locdi = true; GUI_FactoryWindow_ScrollList(-1); GUI_FactoryWindow_UpdateSelection(true); } else { locdi = false; GUI_FactoryWindow_DrawDetails(); GUI_FactoryWindow_FailScrollList(-1); } } do { GUI_FactoryWindow_UpdateSelection(false); sleepIdle(); } while (g_timerTimeout != 0); if (locdi) GUI_FactoryWindow_DrawDetails(); GUI_Widget_MakeNormal(w, false); return true; }
/** * Handles Click event for the "Down" button in production window. * * @return True, always. */ bool GUI_Production_Down_Click(Widget *w) { bool locdi = false; if (g_factoryWindowSelected < 3 && (g_factoryWindowSelected + 1) < g_factoryWindowTotal) { g_timerTimeout = 10; GUI_FactoryWindow_B495_0F30(); g_factoryWindowSelected++; GUI_FactoryWindow_UpdateSelection(true); locdi = true; } else { if (g_factoryWindowBase + 4 < g_factoryWindowTotal) { g_timerTimeout = 10; g_factoryWindowBase++; locdi = true; GUI_FactoryWindow_ScrollList(1); GUI_FactoryWindow_UpdateSelection(true); } else { locdi = false; GUI_FactoryWindow_DrawDetails(); GUI_FactoryWindow_FailScrollList(1); } } for (; g_timerTimeout != 0; sleepIdle()) { GUI_FactoryWindow_UpdateSelection(false); } if (locdi) GUI_FactoryWindow_DrawDetails(); GUI_Widget_MakeNormal(w, false); return true; }
static void GUI_Mentat_HelpListLoop(void) { uint16 key; for (key = 0; key != 0x8001; sleepIdle()) { Widget *w = g_widgetMentatTail; GUI_Mentat_Animation(0); key = GUI_Widget_HandleEvents(w); if ((key & 0x800) != 0) key = 0; if (key == 0x8001) break; key &= 0x80FF; s_selectMentatHelp = true; switch (key) { case 0x0053: case 0x0060: /* NUMPAD 8 / ARROW UP */ case 0x0453: case 0x0460: if (s_selectedHelpSubject != 0) { GUI_Mentat_List_Click(GUI_Widget_Get_ByIndex(w, s_selectedHelpSubject + 2)); break; } GUI_Widget_Scrollbar_ArrowUp_Click(g_widgetMentatScrollbar); break; case 0x0054: case 0x0062: /* NUMPAD 2 / ARROW DOWN */ case 0x0454: case 0x0462: if (s_selectedHelpSubject < 10) { GUI_Mentat_List_Click(GUI_Widget_Get_ByIndex(w, s_selectedHelpSubject + 4)); break; } GUI_Widget_Scrollbar_ArrowDown_Click(g_widgetMentatScrollbar); break; case 0x0055: case 0x0065: /* NUMPAD 9 / PAGE UP */ case 0x0455: case 0x0465: { uint8 i; for (i = 0; i < 11; i++) GUI_Widget_Scrollbar_ArrowUp_Click(g_widgetMentatScrollbar); } break; case 0x0056: case 0x0067: /* NUMPAD 3 / PAGE DOWN */ case 0x0456: case 0x0467: { uint8 i; for (i = 0; i < 11; i++) GUI_Widget_Scrollbar_ArrowDown_Click(g_widgetMentatScrollbar); } break; case 0x0041: /* MOUSE LEFT BUTTON */ break; case 0x002B: /* NUMPAD 5 / RETURN */ case 0x003D: /* SPACE */ case 0x042B: case 0x043D: GUI_Mentat_List_Click(GUI_Widget_Get_ByIndex(w, s_selectedHelpSubject + 3)); break; default: break; } s_selectMentatHelp = false; } }
uint16 GUI_Mentat_Loop(const char *wsaFilename, char *pictureDetails, char *text, bool arg12, Widget *w) { Screen oldScreenID; uint16 old07AE; void *wsa; uint16 descLines; bool dirty; bool done; bool textDone; uint16 frame; uint32 descTick; uint16 mentatSpeakingMode; uint16 result; uint32 textTick; uint32 textDelay; uint16 lines; uint16 textLines; uint16 step; dirty = false; textTick = 0; textDelay = 0; old07AE = Widget_SetCurrentWidget(8); oldScreenID = GFX_Screen_SetActive(SCREEN_2); wsa = NULL; if (wsaFilename != NULL) { wsa = WSA_LoadFile(wsaFilename, GFX_Screen_Get_ByIndex(SCREEN_1), GFX_Screen_GetSize_ByIndex(SCREEN_1), false); } step = 0; if (wsa == NULL) { Widget_PaintCurrentWidget(); step = 1; } GUI_DrawText_Wrapper(NULL, 0, 0, 0, 0, 0x31); descLines = GUI_SplitText(pictureDetails, (g_curWidgetWidth << 3) + 10, '\0'); GUI_DrawText_Wrapper(NULL, 0, 0, 0, 0, 0x32); textLines = GUI_Mentat_SplitText(text, 304); mentatSpeakingMode = 2; lines = 0; frame = 0; g_timerTimeout = 0; descTick = g_timerGUI + 30; Input_History_Clear(); textDone = false; result = 0; for (done = false; !done; sleepIdle()) { uint16 key; GFX_Screen_SetActive(SCREEN_0); key = GUI_Widget_HandleEvents(w); GUI_PaletteAnimate(); if (key != 0) { if ((key & 0x800) == 0) { if (w != NULL) { if ((key & 0x8000) != 0 && result == 0) result = key; } else { if (textDone) result = key; } } else { key = 0; } } switch (step) { case 0: if (key == 0) break; step = 1; /* FALL-THROUGH */ case 1: if (key != 0) { if (result != 0) { step = 5; break; } lines = descLines; dirty = true; } else { if (g_timerGUI > descTick) { descTick = g_timerGUI + 15; lines++; dirty = true; } } if (lines < descLines && lines <= 12) break; step = (text != NULL) ? 2 : 4; lines = descLines; break; case 2: GUI_Mouse_Hide_InRegion(0, 0, SCREEN_WIDTH, 40); GUI_Screen_Copy(0, 0, 0, 160, SCREEN_WIDTH / 8, 40, SCREEN_0, SCREEN_2); GUI_Mouse_Show_InRegion(); step = 3; key = 1; /* FALL-THROUGH */ case 3: if (mentatSpeakingMode == 2 && textTick < g_timerGUI) key = 1; if ((key != 0 && textDone) || result != 0) { GUI_Mouse_Hide_InRegion(0, 0, SCREEN_WIDTH, 40); GUI_Screen_Copy(0, 160, 0, 0, SCREEN_WIDTH / 8, 40, SCREEN_2, SCREEN_0); GUI_Mouse_Show_InRegion(); step = 4; mentatSpeakingMode = 0; break; } if (key != 0) { GUI_Screen_Copy(0, 160, 0, 0, SCREEN_WIDTH / 8, 40, SCREEN_2, SCREEN_2); if (textLines-- != 0) { GFX_Screen_SetActive(SCREEN_2); GUI_DrawText_Wrapper(text, 4, 1, g_curWidgetFGColourBlink, 0, 0x32); mentatSpeakingMode = 1; textDelay = (uint32)strlen(text) * 4; textTick = g_timerGUI + textDelay; if (textLines != 0) { while (*text++ != '\0') {} } else { textDone = true; } GFX_Screen_SetActive(SCREEN_0); } GUI_Mouse_Hide_InRegion(0, 0, SCREEN_WIDTH, 40); GUI_Screen_Copy(0, 0, 0, 0, SCREEN_WIDTH / 8, 40, SCREEN_2, SCREEN_0); GUI_Mouse_Show_InRegion(); break; } if (mentatSpeakingMode == 0 || textTick > g_timerGUI) break; mentatSpeakingMode = 2; textTick += textDelay + textDelay / 2; break; case 4: if (result != 0 || w == NULL) step = 5; break; case 5: dirty = true; done = true; break; default: break; } GUI_Mentat_Animation(mentatSpeakingMode); if (wsa != NULL && g_timerTimeout == 0) { g_timerTimeout = 7; do { if (step == 0 && frame > 4) step = 1; if (!WSA_DisplayFrame(wsa, frame++, g_curWidgetXBase << 3, g_curWidgetYBase, SCREEN_2)) { if (step == 0) step = 1; if (arg12 != 0) { frame = 0; } else { WSA_Unload(wsa); wsa = NULL; } } } while (frame == 0); dirty = true; } if (!dirty) continue; GUI_Mentat_DrawInfo(pictureDetails, (g_curWidgetXBase << 3) + 5, g_curWidgetYBase + 3, 8, 0, lines, 0x31); GUI_DrawSprite(SCREEN_2, g_sprites[397 + g_playerHouseID * 15], g_shoulderLeft, g_shoulderTop, 0, 0); GUI_Mouse_Hide_InWidget(g_curWidgetIndex); GUI_Screen_Copy(g_curWidgetXBase, g_curWidgetYBase, g_curWidgetXBase, g_curWidgetYBase, g_curWidgetWidth, g_curWidgetHeight, SCREEN_2, SCREEN_0); GUI_Mouse_Show_InWidget(); dirty = false; } if (wsa != NULL) WSA_Unload(wsa); GFX_Screen_SetActive(SCREEN_2); GUI_DrawSprite(SCREEN_2, g_sprites[397 + g_playerHouseID * 15], g_shoulderLeft, g_shoulderTop, 0, 0); GUI_Mouse_Hide_InWidget(g_curWidgetIndex); GUI_Screen_Copy(g_curWidgetXBase, g_curWidgetYBase, g_curWidgetXBase, g_curWidgetYBase, g_curWidgetWidth, g_curWidgetHeight, SCREEN_2, SCREEN_0); GUI_Mouse_Show_InWidget(); Widget_SetCurrentWidget(old07AE); GFX_Screen_SetActive(oldScreenID); Input_History_Clear(); return result; }
/** * Shows the game credits. */ static void GameLoop_GameCredits(void) { static const uint8 colours[] = {0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint16 i; uint8 *memory; GUI_Mouse_Hide_Safe(); Widget_SetCurrentWidget(20); Sprites_LoadImage("BIGPLAN.CPS", SCREEN_1, g_palette_998A); GUI_ClearScreen(SCREEN_0); GUI_Screen_Copy(g_curWidgetXBase, g_curWidgetYBase, g_curWidgetXBase, g_curWidgetYBase, g_curWidgetWidth, g_curWidgetHeight, SCREEN_1, SCREEN_0); GUI_SetPaletteAnimated(g_palette_998A, 60); Music_Play(0); GameLoop_Uninit(); Music_Play(33); memory = GFX_Screen_Get_ByIndex(SCREEN_2); for (i = 0; i < 256; i++) { uint8 loc06; uint8 loc04; memory[i] = i & 0xFF; loc06 = i / 16; loc04 = i % 16; if (loc06 == 9 && loc04 <= 6) { memory[i] = (g_playerHouseID * 16) + loc04 + 144; } } Sprites_LoadImage("MAPPLAN.CPS", SCREEN_1, g_palette_998A); GUI_Palette_RemapScreen(g_curWidgetXBase << 3, g_curWidgetYBase, g_curWidgetWidth << 3, g_curWidgetHeight, SCREEN_1, memory); GUI_Screen_FadeIn2(g_curWidgetXBase << 3, g_curWidgetYBase, g_curWidgetWidth << 3, g_curWidgetHeight, SCREEN_1, SCREEN_0, 1, false); GameCredits_LoadPalette(); GUI_Mouse_Hide_Safe(); GUI_InitColors(colours, 0, lengthof(colours) - 1); g_fontCharOffset = -1; GFX_SetPalette(g_palette1); for (;; sleepIdle()) { File_ReadBlockFile(String_GenerateFilename("CREDITS"), s_buffer_1832, GFX_Screen_GetSize_ByIndex(SCREEN_3)); GameCredits_Play(s_buffer_1832, 20, SCREEN_1, SCREEN_2, 6); if (Input_Keyboard_NextKey() != 0) break; Music_Play(33); } GUI_SetPaletteAnimated(g_palette2, 60); Driver_Music_FadeOut(); GFX_ClearScreen(); }
/** * Handles Click event for "Save Game" or "Load Game" button. * * @param save Wether to save or load. * @return True if a game has been saved or loaded, False otherwise. */ bool GUI_Widget_SaveLoad_Click(bool save) { WindowDesc *desc = &g_saveLoadWindowDesc; bool loop; s_savegameCountOnDisk = GetSavegameCount(); s_savegameIndexBase = max(0, s_savegameCountOnDisk - (save ? 0 : 1)); FillSavegameDesc(save); desc->stringID = save ? STR_SELECT_A_POSITION_TO_SAVE_TO : STR_SELECT_A_SAVED_GAME_TO_LOAD; GUI_Window_BackupScreen(desc); GUI_Window_Create(desc); UpdateArrows(save, true); for (loop = true; loop; sleepIdle()) { Widget *w = g_widgetLinkedListTail; uint16 key = GUI_Widget_HandleEvents(w); UpdateArrows(save, false); if ((key & 0x8000) != 0) { Widget *w2; key &= 0x7FFF; w2 = GUI_Widget_Get_ByIndex(w, key); switch (key) { case 0x25: s_savegameIndexBase = min(s_savegameCountOnDisk - (save ? 0 : 1), s_savegameIndexBase + 1); FillSavegameDesc(save); GUI_Widget_DrawAll(w); break; case 0x26: s_savegameIndexBase = max(0, s_savegameIndexBase - 1); FillSavegameDesc(save); GUI_Widget_DrawAll(w); break; case 0x23: loop = false; break; default: { GUI_Window_RestoreScreen(desc); key -= 0x1E; if (!save) { LoadFile(GenerateSavegameFilename(s_savegameIndexBase - key)); return true; } if (GUI_Widget_Savegame_Click(key)) return true; GUI_Window_BackupScreen(desc); UpdateArrows(save, true); GUI_Window_Create(desc); UpdateArrows(save, true); } break; } GUI_Widget_MakeNormal(w2, false); } GUI_PaletteAnimate(); } GUI_Window_RestoreScreen(desc); return false; }
/** * Handles Click event for savegame button. * * @param key The index of the clicked button. * @return True if a game has been saved, False otherwise. */ static bool GUI_Widget_Savegame_Click(uint16 key) { WindowDesc *desc = &g_savegameNameWindowDesc; bool loop; char *saveDesc = g_savegameDesc[key]; uint16 loc08; uint16 loc0A; bool ret; if (*saveDesc == '[') *saveDesc = 0; GUI_Window_BackupScreen(desc); GUI_Window_Create(desc); ret = false; loc08 = 1; if (*saveDesc == '[') key = s_savegameCountOnDisk; GFX_Screen_SetActive(SCREEN_0); Widget_SetCurrentWidget(15); GUI_Mouse_Hide_Safe(); GUI_DrawBorder((g_curWidgetXBase << 3) - 1, g_curWidgetYBase - 1, (g_curWidgetWidth << 3) + 2, g_curWidgetHeight + 2, 4, false); GUI_Mouse_Show_Safe(); for (loop = true; loop; sleepIdle()) { Widget *w = g_widgetLinkedListTail; GUI_DrawText_Wrapper(NULL, 0, 0, 232, 235, 0x22); loc0A = GUI_EditBox(saveDesc, 50, 15, g_widgetLinkedListTail, NULL, loc08); loc08 = 2; if ((loc0A & 0x8000) == 0) continue; GUI_Widget_MakeNormal(GUI_Widget_Get_ByIndex(w, loc0A & 0x7FFF), false); switch (loc0A & 0x7FFF) { case 0x1E: if (*saveDesc == 0) break; SaveFile(GenerateSavegameFilename(s_savegameIndexBase - key), saveDesc); loop = false; ret = true; break; case 0x1F: loop = false; ret = false; FillSavegameDesc(true); break; default: break; } } GUI_Window_RestoreScreen(desc); return ret; }
void async_GUI_Mentat_Loop() { uint16 key; GFX_Screen_SetActive(0); key = GUI_Widget_HandleEvents(asyncMentatLoop.w); GUI_PaletteAnimate(); if (key != 0) { if ((key & 0x800) == 0) { if (asyncMentatLoop.w != NULL) { if ((key & 0x8000) != 0 && asyncMentatLoop.result == 0) asyncMentatLoop.result = key; } else { if (asyncMentatLoop.textDone) asyncMentatLoop.result = key; } } else { key = 0; } } switch (asyncMentatLoop.step) { case 0: if (key == 0) break; asyncMentatLoop.step = 1; /* FALL-THROUGH */ case 1: if (key != 0) { if (asyncMentatLoop.result != 0) { asyncMentatLoop.step = 5; break; } asyncMentatLoop.lines = asyncMentatLoop.descLines; asyncMentatLoop.dirty = true; } else { if (g_timerGUI > asyncMentatLoop.descTick) { asyncMentatLoop.descTick = g_timerGUI + 15; asyncMentatLoop.lines++; asyncMentatLoop.dirty = true; } } if (asyncMentatLoop.lines < asyncMentatLoop.descLines && asyncMentatLoop.lines <= 12) break; asyncMentatLoop.step = (asyncMentatLoop.text != NULL) ? 2 : 4; asyncMentatLoop.lines = asyncMentatLoop.descLines; break; case 2: GUI_Mouse_Hide_InRegion(0, 0, SCREEN_WIDTH, 40); GUI_Screen_Copy(0, 0, 0, 160, SCREEN_WIDTH / 8, 40, 0, 4); GUI_Mouse_Show_InRegion(); asyncMentatLoop.step = 3; key = 1; /* FALL-THROUGH */ case 3: if (asyncMentatLoop.mentatSpeakingMode == 2 && asyncMentatLoop.textTick < g_timerGUI) key = 1; if ((key != 0 && asyncMentatLoop.textDone) || asyncMentatLoop.result != 0) { GUI_Mouse_Hide_InRegion(0, 0, SCREEN_WIDTH, 40); GUI_Screen_Copy(0, 160, 0, 0, SCREEN_WIDTH / 8, 40, 4, 0); GUI_Mouse_Show_InRegion(); asyncMentatLoop.step = 4; asyncMentatLoop.mentatSpeakingMode = 0; break; } if (key != 0) { GUI_Screen_Copy(0, 160, 0, 0, SCREEN_WIDTH / 8, 40, 4, 4); if (asyncMentatLoop.textLines-- != 0) { GFX_Screen_SetActive(4); GUI_DrawText_Wrapper(asyncMentatLoop.text, 4, 1, g_curWidgetFGColourBlink, 0, 0x32); asyncMentatLoop.mentatSpeakingMode = 1; asyncMentatLoop.textDelay = strlen(asyncMentatLoop.text) * 4; asyncMentatLoop.textTick = g_timerGUI + asyncMentatLoop.textDelay; if (asyncMentatLoop.textLines != 0) { while (*asyncMentatLoop.text++ != '\0') {} } else { asyncMentatLoop.textDone = true; } GFX_Screen_SetActive(0); } GUI_Mouse_Hide_InRegion(0, 0, SCREEN_WIDTH, 40); GUI_Screen_Copy(0, 0, 0, 0, SCREEN_WIDTH / 8, 40, 4, 0); GUI_Mouse_Show_InRegion(); break; } if (asyncMentatLoop.mentatSpeakingMode == 0 || asyncMentatLoop.textTick > g_timerGUI) break; asyncMentatLoop.mentatSpeakingMode = 2; asyncMentatLoop.textTick += asyncMentatLoop.textDelay + asyncMentatLoop.textDelay / 2; break; case 4: if (asyncMentatLoop.result != 0 || asyncMentatLoop.w == NULL) asyncMentatLoop.step = 5; break; case 5: asyncMentatLoop.dirty = true; asyncMentatLoop.done = true; break; default: break; } GUI_Mentat_Animation(asyncMentatLoop.mentatSpeakingMode); if (asyncMentatLoop.wsa != NULL && g_timerTimeout == 0) { g_timerTimeout = 7; do { if (asyncMentatLoop.step == 0 && asyncMentatLoop.frame > 4) asyncMentatLoop.step = 1; if (!WSA_DisplayFrame(asyncMentatLoop.wsa, asyncMentatLoop.frame++, g_curWidgetXBase << 3, g_curWidgetYBase, 4)) { if (asyncMentatLoop.step == 0) asyncMentatLoop.step = 1; if (asyncMentatLoop.arg12 != 0) { asyncMentatLoop.frame = 0; } else { WSA_Unload(asyncMentatLoop.wsa); asyncMentatLoop.wsa = NULL; } } } while (asyncMentatLoop.frame == 0); asyncMentatLoop.dirty = true; } if (!asyncMentatLoop.dirty) { sleepIdle(); return; } GUI_Mentat_DrawInfo(asyncMentatLoop.pictureDetails, (g_curWidgetXBase << 3) + 5, g_curWidgetYBase + 3, 8, 0, asyncMentatLoop.lines, 0x31); GUI_DrawSprite(4, g_sprites[397 + g_playerHouseID * 15], g_shoulderLeft, g_shoulderTop, 0, 0); GUI_Mouse_Hide_InWidget(g_curWidgetIndex); GUI_Screen_Copy(g_curWidgetXBase, g_curWidgetYBase, g_curWidgetXBase, g_curWidgetYBase, g_curWidgetWidth, g_curWidgetHeight, 4, 0); GUI_Mouse_Show_InWidget(); asyncMentatLoop.dirty = false; sleepIdle(); }
static void GameLoop_PlayAnimation(void) { const HouseAnimation_Animation *animation; uint8 animationMode = 0; animation = s_houseAnimation_animation; while (animation->duration != 0) { uint16 loc04; uint16 posX = 0; uint16 posY = 0; uint32 loc10 = g_timerGUI + animation->duration * 6; uint32 loc14 = loc10 + 30; uint32 loc18; uint32 loc1C; uint16 mode = animation->flags & 0x3; bool loc20; uint32 loc24; uint16 locdi; uint16 frame; void *wsa; if ((animation->flags & 0x20) == 0) { posX = 8; posY = 24; } s_var_8068 = 0; if (mode == 0) { wsa = NULL; frame = 0; } else { char filenameBuffer[16]; if (mode == 3) { frame = animation->frameCount; loc20 = true; } else { frame = 0; loc20 = ((animation->flags & 0x40) != 0) ? true : false; } if ((animation->flags & 0x480) != 0) { GUI_ClearScreen(SCREEN_1); wsa = GFX_Screen_Get_ByIndex(SCREEN_2); loc24 = GFX_Screen_GetSize_ByIndex(SCREEN_2) + GFX_Screen_GetSize_ByIndex(SCREEN_3); loc20 = false; } else { wsa = GFX_Screen_Get_ByIndex(SCREEN_1); loc24 = GFX_Screen_GetSize_ByIndex(SCREEN_1) + GFX_Screen_GetSize_ByIndex(SCREEN_2) + GFX_Screen_GetSize_ByIndex(SCREEN_3); } snprintf(filenameBuffer, sizeof(filenameBuffer), "%s.WSA", animation->string); wsa = WSA_LoadFile(filenameBuffer, wsa, loc24, loc20); } locdi = 0; if ((animation->flags & 0x8) != 0) { loc10 -= 45; locdi++; } else { if ((animation->flags & 0x10) != 0) { loc10 -= 15; locdi++; } } if ((animation->flags & 0x4) != 0) { GameLoop_PlaySubtitle(animationMode); WSA_DisplayFrame(wsa, frame++, posX, posY, SCREEN_0); GameLoop_PalettePart_Update(true); memcpy(&g_palette1[215 * 3], s_palettePartCurrent, 18); GUI_SetPaletteAnimated(g_palette1, 45); locdi++; } else { if ((animation->flags & 0x480) != 0) { GameLoop_PlaySubtitle(animationMode); WSA_DisplayFrame(wsa, frame++, posX, posY, SCREEN_1); locdi++; if ((animation->flags & 0x480) == 0x80) { GUI_Screen_FadeIn2(8, 24, 304, 120, SCREEN_1, SCREEN_0, 1, false); } else if ((animation->flags & 0x480) == 0x400) { GUI_Screen_FadeIn(1, 24, 1, 24, 38, 120, SCREEN_1, SCREEN_0); } } } loc1C = loc10 - g_timerGUI; loc18 = 0; loc04 = 1; switch (mode) { case 0: loc04 = animation->frameCount - locdi; loc18 = loc1C / loc04; break; case 1: loc04 = WSA_GetFrameCount(wsa); loc18 = loc1C / animation->frameCount; break; case 2: loc04 = WSA_GetFrameCount(wsa) - locdi; loc18 = loc1C / loc04; loc10 -= loc18; break; case 3: frame = animation->frameCount; loc04 = 1; loc18 = loc1C / 20; break; default: PrepareEnd(); Error("Bad mode in animation #%i.\n", animationMode); exit(0); } while (loc10 > g_timerGUI) { g_timerTimeout = loc18; GameLoop_PlaySubtitle(animationMode); WSA_DisplayFrame(wsa, frame++, posX, posY, SCREEN_0); if (mode == 1 && frame == loc04) { frame = 0; } else { if (mode == 3) frame--; } if (Input_Keyboard_NextKey() != 0 && g_canSkipIntro) { WSA_Unload(wsa); return; } do { GameLoop_PalettePart_Update(false); sleepIdle(); } while (g_timerTimeout != 0 && loc10 > g_timerGUI); } if (mode == 2) { bool displayed; do { GameLoop_PlaySubtitle(animationMode); displayed = WSA_DisplayFrame(wsa, frame++, posX, posY, SCREEN_0); } while (displayed); } if ((animation->flags & 0x10) != 0) { memset(&g_palette_998A[3 * 1], 63, 255 * 3); memcpy(&g_palette_998A[215 * 3], s_palettePartCurrent, 18); GUI_SetPaletteAnimated(g_palette_998A, 15); memcpy(g_palette_998A, g_palette1, 256 * 3); } if ((animation->flags & 0x8) != 0) { GameLoop_PalettePart_Update(true); memcpy(&g_palette_998A[215 * 3], s_palettePartCurrent, 18); GUI_SetPaletteAnimated(g_palette_998A, 45); } WSA_Unload(wsa); animationMode++; animation++; while (loc14 > g_timerGUI) sleepIdle(); } }
static void GUI_Purchase_ShowInvoice(void) { Widget *w = g_widgetInvoiceTail; Screen oldScreenID; uint16 y = 48; uint16 total = 0; uint16 x; char textBuffer[12]; oldScreenID = GFX_Screen_SetActive(SCREEN_1); GUI_DrawFilledRectangle(128, 48, 311, 159, 20); GUI_DrawText_Wrapper(String_Get_ByIndex(STR_ITEM_NAME_QTY_TOTAL), 128, y, 12, 0, 0x11); y += 7; GUI_DrawLine(129, y, 310, y, 12); y += 2; if (g_factoryWindowOrdered != 0) { uint16 i; for (i = 0; i < g_factoryWindowTotal; i++) { ObjectInfo *oi; uint16 amount; if (g_factoryWindowItems[i].amount == 0) continue; amount = g_factoryWindowItems[i].amount * g_factoryWindowItems[i].credits; total += amount; snprintf(textBuffer, sizeof(textBuffer), "%02d %5d", g_factoryWindowItems[i].amount, amount); oi = g_factoryWindowItems[i].objectInfo; GUI_DrawText_Wrapper(String_Get_ByIndex(oi->stringID_full), 128, y, 8, 0, 0x11); GUI_DrawText_Monospace(textBuffer, 311 - strlen(textBuffer) * 6, y, 15, 0, 6); y += 8; } } else { GUI_DrawText_Wrapper(String_Get_ByIndex(STR_NO_UNITS_ON_ORDER), 220, 99, 6, 0, 0x112); } GUI_DrawLine(129, 148, 310, 148, 12); GUI_DrawLine(129, 150, 310, 150, 12); snprintf(textBuffer, sizeof(textBuffer), "%d", total); x = 311 - strlen(textBuffer) * 6; /* "Total Cost :" */ GUI_DrawText_Wrapper(GUI_String_Get_ByIndex(STR_TOTAL_COST_), x - 3, 152, 11, 0, 0x211); GUI_DrawText_Monospace(textBuffer, x, 152, 11, 0, 6); GUI_Mouse_Hide_Safe(); GUI_Screen_Copy(16, 48, 16, 48, 23, 112, SCREEN_1, SCREEN_0); GUI_Mouse_Show_Safe(); GFX_Screen_SetActive(SCREEN_0); GUI_FactoryWindow_DrawCaption(String_Get_ByIndex(STR_INVOICE_OF_UNITS_ON_ORDER)); Input_History_Clear(); for (; GUI_Widget_HandleEvents(w) == 0; sleepIdle()) { GUI_DrawCredits(g_playerHouseID, 0); GUI_FactoryWindow_UpdateSelection(false); GUI_PaletteAnimate(); } GFX_Screen_SetActive(oldScreenID); w = GUI_Widget_Get_ByIndex(w, 10); if (w != NULL && Mouse_InsideRegion(w->offsetX, w->offsetY, w->offsetX + w->width, w->offsetY + w->height) != 0) { while (Input_Test(0x41) != 0 || Input_Test(0x42) != 0) sleepIdle(); Input_History_Clear(); } if (g_factoryWindowResult == FACTORY_CONTINUE) GUI_FactoryWindow_DrawDetails(); }
/** * Ask the security question to the user. Give him 3 times. If he fails, * return false, otherwise true. * @return True if and only if the user answered one of the three questions * correct. */ bool GUI_Security_Show(void) { const char *wsaHouseFilename; uint16 questionsCount; uint16 oldCurrentWidget; Screen oldScreenID; uint16 i; bool valid; g_disableOtherMovement = true; g_interrogation = true; wsaHouseFilename = House_GetWSAHouseFilename(g_playerHouseID); if (wsaHouseFilename == NULL) return true; GUI_SetPaletteAnimated(g_palette2, 15); GUI_Mentat_Display(wsaHouseFilename, g_playerHouseID); GUI_Mouse_Hide_Safe(); GUI_Screen_Copy(0, 0, 0, 0, SCREEN_WIDTH / 8, SCREEN_HEIGHT, SCREEN_1, SCREEN_0); GUI_Mouse_Show_Safe(); GUI_SetPaletteAnimated(g_palette1, 15); strncpy(g_readBuffer, String_Get_ByIndex(STR_SECURITY_TEXT_HARKONNEN + g_playerHouseID * 3), g_readBufferSize); GUI_Mentat_Loop(wsaHouseFilename, NULL, g_readBuffer, true, NULL); questionsCount = atoi(String_Get_ByIndex(STR_SECURITY_COUNT)); oldCurrentWidget = Widget_SetCurrentWidget(8); oldScreenID = GFX_Screen_SetActive(SCREEN_2); for (i = 0, valid = false; i < 3 && !valid; i++) { void *wsa; uint16 questionIndex; uint32 tickWaitTill; char buffer[81]; questionIndex = Tools_RandomLCG_Range(0, questionsCount - 1) * 3 + STR_SECURITY_QUESTIONS; Widget_SetCurrentWidget(8); wsa = WSA_LoadFile(String_Get_ByIndex(questionIndex + 1), GFX_Screen_Get_ByIndex(SCREEN_1), GFX_Screen_GetSize_ByIndex(SCREEN_1), false); WSA_DisplayFrame(wsa, 0, g_curWidgetXBase << 3, g_curWidgetYBase, SCREEN_2); WSA_Unload(wsa); GUI_DrawSprite(SCREEN_2, g_sprites[397 + g_playerHouseID * 15], g_shoulderLeft, g_shoulderTop, 0, 0); GUI_Mouse_Hide_InWidget(g_curWidgetIndex); GUI_Screen_Copy(g_curWidgetXBase, g_curWidgetYBase, g_curWidgetXBase, g_curWidgetYBase, g_curWidgetWidth, g_curWidgetHeight, SCREEN_2, SCREEN_0); GUI_Mouse_Show_InWidget(); strncpy(g_readBuffer, String_Get_ByIndex(questionIndex), g_readBufferSize); GUI_Security_DrawText(g_readBuffer); g_interrogationTimer = g_timerGUI + (uint32)strlen(g_readBuffer) * 4; Widget_SetCurrentWidget(9); GUI_Mouse_Hide_Safe(); GUI_Screen_Copy(g_curWidgetXBase - 1, g_curWidgetYBase - 8, 0, 0, g_curWidgetWidth + 2, g_curWidgetHeight + 16, SCREEN_0, SCREEN_2); GUI_Mouse_Show_Safe(); GFX_Screen_SetActive(SCREEN_0); GUI_Mouse_Hide_Safe(); GUI_DrawBorder((g_curWidgetXBase << 3) - 6, g_curWidgetYBase - 6, (g_curWidgetWidth << 3) + 12, g_curWidgetHeight + 12, 1, true); GUI_DrawBorder((g_curWidgetXBase << 3) - 2, g_curWidgetYBase - 2, (g_curWidgetWidth << 3) + 4, g_curWidgetHeight + 4, 2, false); GUI_Mouse_Show_Safe(); Input_History_Clear(); buffer[0] = 0; GUI_DrawText_Wrapper(NULL, 0, 0, 0, 0, 0x22); GUI_EditBox(buffer, sizeof(buffer) - 1, 9, NULL, &GUI_Mentat_Tick, false); GUI_Security_UndrawText(); GUI_Mouse_Hide_Safe(); GUI_Screen_Copy(0, 0, g_curWidgetXBase - 1, g_curWidgetYBase - 8, g_curWidgetWidth + 2, g_curWidgetHeight + 16, SCREEN_2, SCREEN_0); GUI_Mouse_Show_Safe(); GUI_Security_NormaliseText(buffer); strncpy(g_readBuffer, String_Get_ByIndex(questionIndex + 2), g_readBufferSize); GUI_Security_NormaliseText(g_readBuffer); if (strcasecmp(g_readBuffer, buffer) != 0) { strncpy(g_readBuffer, String_Get_ByIndex(STR_SECURITY_WRONG_HARKONNEN + g_playerHouseID * 3), g_readBufferSize); } else { strncpy(g_readBuffer, String_Get_ByIndex(STR_SECURITY_CORRECT_HARKONNEN + g_playerHouseID * 3), g_readBufferSize); valid = true; } GUI_Security_DrawText(g_readBuffer); tickWaitTill = g_timerGUI + (uint32)strlen(g_readBuffer) * 4; Input_History_Clear(); /* ENHANCEMENT -- In Dune2, the + 120 is on the other side, causing the 'You are wrong! / Well done.' screen to appear very short (close to invisible, so to say) */ while (g_timerGUI + (g_dune2_enhanced ? 0 : 120) < tickWaitTill + (g_dune2_enhanced ? 120 : 0)) { if (Input_Keyboard_NextKey() != 0) break; if (g_timerGUI < tickWaitTill) { GUI_Mentat_Animation(1); } else { GUI_Mentat_Animation(0); } sleepIdle(); } GUI_Security_UndrawText(); } Widget_SetCurrentWidget(oldCurrentWidget); GFX_Screen_SetActive(oldScreenID); Input_History_Clear(); Load_Palette_Mercenaries(); g_disableOtherMovement = false; g_interrogation = false; return valid; }
/** * Show an EditBox and handles the input. * @param text The text to edit. Uses the pointer to make the modifications. * @param maxLength The maximum length of the text. * @param unknown1 Unknown. * @param w The widget this editbox is attached to. * @param tickProc The function to call every tick, for animation etc. * @param unknown4 Unknown. * @return Unknown. */ uint16 GUI_EditBox(char *text, uint16 maxLength, uint16 unknown1, Widget *w, uint16 (*tickProc)(void), uint16 unknown4) { Screen oldScreenID; uint16 oldValue_07AE_0000; uint16 positionX; uint16 maxWidth; uint16 textWidth; uint16 textLength; uint16 returnValue; char *t; /* Initialize */ { Input_Flags_SetBits(INPUT_FLAG_NO_TRANSLATE); Input_Flags_ClearBits(INPUT_FLAG_UNKNOWN_2000); oldScreenID = GFX_Screen_SetActive(SCREEN_0); oldValue_07AE_0000 = Widget_SetCurrentWidget(unknown1); returnValue = 0x0; } positionX = g_curWidgetXBase << 3; textWidth = 0; textLength = 0; maxWidth = (g_curWidgetWidth << 3) - Font_GetCharWidth('W') - 1; t = text; /* Calculate the length and width of the current string */ for (; *t != '\0'; t++) { textWidth += Font_GetCharWidth(*t); textLength++; if (textWidth >= maxWidth) break; } *t = '\0'; if ((unknown4 & 0x1) != 0) { unknown4 |= 0x4; } GUI_Mouse_Hide_Safe(); if ((unknown4 & 0x4) != 0) Widget_PaintCurrentWidget(); GUI_DrawText_Wrapper(text, positionX, g_curWidgetYBase, g_curWidgetFGColourBlink, g_curWidgetFGColourNormal, 0); GUI_EditBox_BlinkCursor(positionX + textWidth, false); GUI_Mouse_Show_Safe(); for (;; sleepIdle()) { uint16 keyWidth; uint16 key; if (tickProc != NULL) { returnValue = tickProc(); if (returnValue != 0) break; } key = GUI_Widget_HandleEvents(w); GUI_EditBox_BlinkCursor(positionX + textWidth, false); if (key == 0x0) continue; if ((key & 0x8000) != 0) { returnValue = key; break; } if (key == 0x2B) { returnValue = 0x2B; break; } if (key == 0x6E) { *t = '\0'; returnValue = 0x6B; break; } /* Handle backspace */ if (key == 0x0F) { if (textLength == 0) continue; GUI_EditBox_BlinkCursor(positionX + textWidth, true); textWidth -= Font_GetCharWidth(*(t - 1)); textLength--; *(--t) = '\0'; GUI_EditBox_BlinkCursor(positionX + textWidth, false); continue; } key = Input_Keyboard_HandleKeys(key) & 0xFF; /* Names can't start with a space, and should be alpha-numeric */ if ((key == 0x20 && textLength == 0) || key < 0x20 || key > 0x7E) continue; keyWidth = Font_GetCharWidth(key & 0xFF); if (textWidth + keyWidth >= maxWidth || textLength >= maxLength) continue; /* Add char to the text */ *t = key & 0xFF; *(++t) = '\0'; textLength++; GUI_Mouse_Hide_Safe(); GUI_EditBox_BlinkCursor(positionX + textWidth, true); /* Draw new character */ GUI_DrawText_Wrapper(text + textLength - 1, positionX + textWidth, g_curWidgetYBase, g_curWidgetFGColourBlink, g_curWidgetFGColourNormal, 0x020); GUI_Mouse_Show_Safe(); textWidth += keyWidth; GUI_EditBox_BlinkCursor(positionX + textWidth, false); } /* Deinitialize */ { Input_Flags_ClearBits(INPUT_FLAG_NO_TRANSLATE); Input_Flags_SetBits(INPUT_FLAG_UNKNOWN_2000); Widget_SetCurrentWidget(oldValue_07AE_0000); GFX_Screen_SetActive(oldScreenID); } return returnValue; }
/** * Load voices. * voiceSet 0xFFFE is for Game Intro. * voiceSet 0xFFFF is for Game End. * @param voiceSet Voice set to load : either a HouseID, or special values 0xFFFE or 0xFFFF. */ void Voice_LoadVoices(uint16 voiceSet) { static uint16 currentVoiceSet = 0xFFFE; int prefixChar = ' '; uint16 voice; if (g_enableVoices == 0) return; for (voice = 0; voice < NUM_VOICES; voice++) { switch (g_table_voices[voice].string[0]) { case '%': if (g_config.language != LANGUAGE_ENGLISH || currentVoiceSet == voiceSet) { if (voiceSet != 0xFFFF && voiceSet != 0xFFFE) break; } free(g_voiceData[voice]); g_voiceData[voice] = NULL; break; case '+': if (voiceSet != 0xFFFF && voiceSet != 0xFFFE) break; free(g_voiceData[voice]); g_voiceData[voice] = NULL; break; case '-': if (voiceSet == 0xFFFF) break; free(g_voiceData[voice]); g_voiceData[voice] = NULL; break; case '/': if (voiceSet != 0xFFFE) break; free(g_voiceData[voice]); g_voiceData[voice] = NULL; break; case '?': if (voiceSet == 0xFFFF) break; /* No free() as there was never a malloc(). */ g_voiceData[voice] = NULL; break; default: break; } } if (currentVoiceSet == voiceSet) return; for (voice = 0; voice < NUM_VOICES; voice++) { char filename[16]; const char *str = g_table_voices[voice].string; sleepIdle(); /* let a chance to update screen, etc. */ switch (*str) { case '%': if (g_voiceData[voice] != NULL || currentVoiceSet == voiceSet || voiceSet == 0xFFFF || voiceSet == 0xFFFE) break; switch (g_config.language) { case LANGUAGE_FRENCH: prefixChar = 'F'; break; case LANGUAGE_GERMAN: prefixChar = 'G'; break; default: prefixChar = g_table_houseInfo[voiceSet].prefixChar; } snprintf(filename, sizeof(filename), str, prefixChar); g_voiceData[voice] = Sound_LoadVoc(filename, &g_voiceDataSize[voice]); break; case '+': if (voiceSet == 0xFFFF || g_voiceData[voice] != NULL) break; switch (g_config.language) { case LANGUAGE_FRENCH: prefixChar = 'F'; break; case LANGUAGE_GERMAN: prefixChar = 'G'; break; default: prefixChar = 'Z'; break; } snprintf(filename, sizeof(filename), str + 1, prefixChar); /* XXX - In the 1.07us datafiles, a few files are named differently: * * moveout.voc * overout.voc * report1.voc * report2.voc * report3.voc * * They come without letter in front of them. To make things a bit * easier, just check if the file exists, then remove the first * letter and see if it works then. */ if (!File_Exists(filename)) { memmove(filename, filename + 1, strlen(filename)); } g_voiceData[voice] = Sound_LoadVoc(filename, &g_voiceDataSize[voice]); break; case '-': if (voiceSet != 0xFFFF || g_voiceData[voice] != NULL) break; g_voiceData[voice] = Sound_LoadVoc(str + 1, &g_voiceDataSize[voice]); break; case '/': if (voiceSet != 0xFFFE) break; g_voiceData[voice] = Sound_LoadVoc(str + 1, &g_voiceDataSize[voice]); break; case '?': break; default: if (g_voiceData[voice] != NULL) break; g_voiceData[voice] = Sound_LoadVoc(str, &g_voiceDataSize[voice]); break; } } currentVoiceSet = voiceSet; }
void async_GUI_Mentat_ShowDialogLoop() { strncpy(g_readBuffer, String_Get_ByIndex(asyncMentatShowDialog.stringID), g_readBufferSize); sleepIdle(); }
static void GameCredits_Play(char *data, uint16 windowID, Screen memory, Screen screenID, uint16 delay) { uint16 loc02; uint16 stringCount = 0; uint32 loc0C; uint16 spriteID = 514; bool loc10 = false; uint16 spriteX; uint16 spriteY; uint16 spritePos = 0; struct { uint16 x; int16 y; char *text; uint8 separator; uint8 charHeight; uint8 type; } strings[33]; struct { uint16 x; uint16 y; } positions[6]; uint16 stage = 4; uint16 counter = 60; Widget_SetCurrentWidget(windowID); spriteX = (g_curWidgetWidth << 3) - Sprite_GetWidth(g_sprites[spriteID]); spriteY = g_curWidgetHeight - Sprite_GetHeight(g_sprites[spriteID]); positions[0].x = spriteX; positions[0].y = 0; positions[1].x = 0; positions[1].y = spriteY / 2; positions[2].x = spriteX; positions[2].y = spriteY; positions[3].x = 0; positions[3].y = 0; positions[4].x = spriteX; positions[4].y = spriteY / 2; positions[5].x = 0; positions[5].y = spriteY; GUI_Screen_Copy(0, 0, 0, 0, SCREEN_WIDTH / 8, SCREEN_HEIGHT, SCREEN_0, memory); GUI_Screen_Copy(0, 0, 0, 0, SCREEN_WIDTH / 8, SCREEN_HEIGHT, memory, screenID); GameCredits_SwapScreen(g_curWidgetYBase, g_curWidgetHeight, memory, s_buffer_182E); GFX_Screen_SetActive(SCREEN_0); loc0C = g_timerSleep; Input_History_Clear(); while (true) { while (loc0C > g_timerSleep) sleepIdle(); loc0C = g_timerSleep + delay; while ((g_curWidgetHeight / 6) + 2 > stringCount && *data != 0) { char *text = data; uint16 y; if (stringCount != 0) { y = strings[stringCount - 1].y; if (strings[stringCount - 1].separator != 5) y += strings[stringCount - 1].charHeight + strings[stringCount - 1].charHeight / 8; } else { y = g_curWidgetHeight; } text = data; data = strpbrk(data, "\x05\r"); if (data == NULL) data = strchr(text, '\0'); strings[stringCount].separator = *data; *data = '\0'; if (strings[stringCount].separator != 0) data++; strings[stringCount].type = 0; if (*text == 3 || *text == 4) strings[stringCount].type = *text++; if (*text == 1) { text++; Font_Select(g_fontNew6p); } else if (*text == 2) { text++; Font_Select(g_fontNew8p); } strings[stringCount].charHeight = g_fontCurrent->height; switch (strings[stringCount].type) { case 3: strings[stringCount].x = 157 - Font_GetStringWidth(text); break; case 4: strings[stringCount].x = 161; break; default: strings[stringCount].x = 1 + (SCREEN_WIDTH - Font_GetStringWidth(text)) / 2; break; } strings[stringCount].y = y; strings[stringCount].text = text; stringCount++; } switch (stage) { case 0: GUI_ClearScreen(memory); if (spriteID == 514) GUI_ClearScreen(screenID); stage++; counter = 2; break; case 1: case 4: if (counter-- == 0) { counter = 0; stage++; } break; case 2: if (spriteID == 525) spriteID = 514; GUI_DrawSprite(memory, g_sprites[spriteID], positions[spritePos].x, positions[spritePos].y, windowID, 0x4000); counter = 8; stage++; spriteID++; if (++spritePos > 5) spritePos = 0;; break; case 3: if (counter < 8) GFX_SetPalette(g_palette1 + 256 * 3 * counter); if (counter-- == 0) { stage++; counter = 20; } break; case 5: if (counter > 0) GFX_SetPalette(g_palette1 + 256 * 3 * counter); if (counter++ >= 8) stage = 0; break; default: break; } GUI_Screen_Copy(g_curWidgetXBase, g_curWidgetYBase, g_curWidgetXBase, g_curWidgetYBase, g_curWidgetWidth, g_curWidgetHeight, memory, screenID); for (loc02 = 0; loc02 < stringCount; loc02++) { if ((int16)strings[loc02].y < g_curWidgetHeight) { GFX_Screen_SetActive(screenID); Font_Select(g_fontNew8p); if (strings[loc02].charHeight != g_fontCurrent->height) Font_Select(g_fontNew6p); GUI_DrawText(strings[loc02].text, strings[loc02].x, strings[loc02].y + g_curWidgetYBase, 255, 0); GFX_Screen_SetActive(SCREEN_0); } strings[loc02].y--; } GameCredits_SwapScreen(g_curWidgetYBase, g_curWidgetHeight, screenID, s_buffer_182E); if ((int16)strings[0].y < -10) { strings[0].text += strlen(strings[0].text); *strings[0].text = strings[0].separator; stringCount--; memcpy(&strings[0], &strings[1], stringCount * sizeof(*strings)); } if ((g_curWidgetHeight / 6 + 2) > stringCount) { if (strings[stringCount - 1].y + strings[stringCount - 1].charHeight < g_curWidgetYBase + g_curWidgetHeight) loc10 = true; } if (loc10 && stage == 0) break; if (Input_Keyboard_NextKey() != 0) break; } GUI_SetPaletteAnimated(g_palette2, 120); GUI_ClearScreen(SCREEN_0); GUI_ClearScreen(memory); GUI_ClearScreen(screenID); }
/** * Logos at begin of intro. */ static void Gameloop_Logos(void) { Screen oldScreenID; void *wsa; uint16 frame; oldScreenID = GFX_Screen_SetActive(SCREEN_0); GFX_SetPalette(g_palette2); GFX_ClearScreen(); File_ReadBlockFile("WESTWOOD.PAL", g_palette_998A, 256 * 3); frame = 0; wsa = WSA_LoadFile("WESTWOOD.WSA", GFX_Screen_Get_ByIndex(SCREEN_1), GFX_Screen_GetSize_ByIndex(SCREEN_1) + GFX_Screen_GetSize_ByIndex(SCREEN_2) + GFX_Screen_GetSize_ByIndex(SCREEN_3), true); WSA_DisplayFrame(wsa, frame++, 0, 0, SCREEN_0); GUI_SetPaletteAnimated(g_palette_998A, 60); Music_Play(0x24); g_timerTimeout = 360; while (WSA_DisplayFrame(wsa, frame++, 0, 0, SCREEN_0)) Timer_Sleep(6); WSA_Unload(wsa); if (Input_Keyboard_NextKey() != 0 && g_canSkipIntro) goto logos_exit; Voice_LoadVoices(0xFFFF); for (; g_timerTimeout != 0; sleepIdle()) { if (Input_Keyboard_NextKey() != 0 && g_canSkipIntro) goto logos_exit; } GUI_SetPaletteAnimated(g_palette2, 60); while (Driver_Music_IsPlaying()) sleepIdle(); GUI_SetPaletteAnimated(g_palette2, 60); GFX_ClearScreen(); Sprites_LoadImage(String_GenerateFilename("AND"), SCREEN_1, g_palette_998A); GUI_Screen_Copy(0, 0, 0, 0, SCREEN_WIDTH / 8, SCREEN_HEIGHT, SCREEN_1, SCREEN_0); GUI_SetPaletteAnimated(g_palette_998A, 30); for (g_timerTimeout = 60; g_timerTimeout != 0; sleepIdle()) { if (Input_Keyboard_NextKey() != 0 && g_canSkipIntro) goto logos_exit; } GUI_SetPaletteAnimated(g_palette2, 30); GUI_ClearScreen(SCREEN_0); Sprites_LoadImage("VIRGIN.CPS", SCREEN_1, g_palette_998A); GUI_Screen_Copy(0, 0, 0, 0, SCREEN_WIDTH / 8, SCREEN_HEIGHT, SCREEN_1, SCREEN_0); GUI_SetPaletteAnimated(g_palette_998A, 30); for (g_timerTimeout = 180; g_timerTimeout != 0; sleepIdle()) { if (Input_Keyboard_NextKey() != 0 && g_canSkipIntro) goto logos_exit; } logos_exit: GUI_SetPaletteAnimated(g_palette2, 30); GUI_ClearScreen(SCREEN_0); GFX_Screen_SetActive(oldScreenID); }
static void GameLoop_PlayAnimation(const HouseAnimation_Animation *animation) { uint8 animationMode = 0; while (animation->duration != 0) { uint16 frameCount; uint16 posX = 0; uint16 posY = 0; uint32 timeout = g_timerGUI + animation->duration * 6; uint32 timeout2 = timeout + 30; /* timeout + 0.5 s */ uint32 timeLeftForFrame; uint32 timeLeft; uint16 mode = animation->flags & 0x3; uint16 addFrameCount; /* additional frame count */ uint16 frame; void *wsa; if ((animation->flags & 0x20) == 0) { posX = 8; posY = 24; } s_var_8068 = 0; if (mode == 0) { wsa = NULL; frame = 0; } else { char filenameBuffer[16]; uint32 wsaSize; bool wsaReservedDisplayFrame; if (mode == 3) { frame = animation->frameCount; wsaReservedDisplayFrame = true; } else { frame = 0; wsaReservedDisplayFrame = ((animation->flags & 0x40) != 0) ? true : false; } if ((animation->flags & 0x480) != 0) { GUI_ClearScreen(SCREEN_1); wsa = GFX_Screen_Get_ByIndex(SCREEN_2); wsaSize = GFX_Screen_GetSize_ByIndex(SCREEN_2) + GFX_Screen_GetSize_ByIndex(SCREEN_3); wsaReservedDisplayFrame = false; } else { wsa = GFX_Screen_Get_ByIndex(SCREEN_1); wsaSize = GFX_Screen_GetSize_ByIndex(SCREEN_1) + GFX_Screen_GetSize_ByIndex(SCREEN_2) + GFX_Screen_GetSize_ByIndex(SCREEN_3); } snprintf(filenameBuffer, sizeof(filenameBuffer), "%s.WSA", animation->string); wsa = WSA_LoadFile(filenameBuffer, wsa, wsaSize, wsaReservedDisplayFrame); } addFrameCount = 0; if ((animation->flags & 0x8) != 0) { timeout -= 45; addFrameCount++; } else if ((animation->flags & 0x10) != 0) { timeout -= 15; addFrameCount++; } if ((animation->flags & 0x4) != 0) { GameLoop_PlaySubtitle(animationMode); WSA_DisplayFrame(wsa, frame++, posX, posY, SCREEN_0); GameLoop_PalettePart_Update(true); memcpy(&g_palette1[215 * 3], s_palettePartCurrent, 18); GUI_SetPaletteAnimated(g_palette1, 45); addFrameCount++; } else { if ((animation->flags & 0x480) != 0) { GameLoop_PlaySubtitle(animationMode); WSA_DisplayFrame(wsa, frame++, posX, posY, SCREEN_1); addFrameCount++; if ((animation->flags & 0x480) == 0x80) { GUI_Screen_FadeIn2(8, 24, 304, 120, SCREEN_1, SCREEN_0, 1, false); } else if ((animation->flags & 0x480) == 0x400) { GUI_Screen_FadeIn(1, 24, 1, 24, 38, 120, SCREEN_1, SCREEN_0); } } } timeLeft = timeout - g_timerGUI; timeLeftForFrame = 0; frameCount = 1; switch (mode) { case 0: frameCount = animation->frameCount - addFrameCount; timeLeftForFrame = timeLeft / frameCount; break; case 1: frameCount = WSA_GetFrameCount(wsa); timeLeftForFrame = timeLeft / animation->frameCount; break; case 2: frameCount = WSA_GetFrameCount(wsa) - addFrameCount; timeLeftForFrame = timeLeft / frameCount; timeout -= timeLeftForFrame; break; case 3: frame = animation->frameCount; frameCount = 1; timeLeftForFrame = timeLeft / 20; break; default: PrepareEnd(); Error("Bad mode in animation #%i.\n", animationMode); exit(0); } while (timeout > g_timerGUI) { g_timerTimeout = timeLeftForFrame; GameLoop_PlaySubtitle(animationMode); WSA_DisplayFrame(wsa, frame++, posX, posY, SCREEN_0); if (mode == 1 && frame == frameCount) { frame = 0; } else { if (mode == 3) frame--; } if (Input_Keyboard_NextKey() != 0 && g_canSkipIntro) { WSA_Unload(wsa); return; } do { GameLoop_PalettePart_Update(false); sleepIdle(); } while (g_timerTimeout != 0 && timeout > g_timerGUI); } if (mode == 2) { bool displayed; do { GameLoop_PlaySubtitle(animationMode); displayed = WSA_DisplayFrame(wsa, frame++, posX, posY, SCREEN_0); } while (displayed); } if ((animation->flags & 0x10) != 0) { memset(&g_palette_998A[3 * 1], 63, 255 * 3); memcpy(&g_palette_998A[215 * 3], s_palettePartCurrent, 18); GUI_SetPaletteAnimated(g_palette_998A, 15); memcpy(g_palette_998A, g_palette1, 256 * 3); } if ((animation->flags & 0x8) != 0) { GameLoop_PalettePart_Update(true); memcpy(&g_palette_998A[215 * 3], s_palettePartCurrent, 18); GUI_SetPaletteAnimated(g_palette_998A, 45); } WSA_Unload(wsa); animationMode++; animation++; while (timeout2 > g_timerGUI) sleepIdle(); } }
/** * Handles Click event for "Options" button. * * @param w The widget. * @return False, always. */ bool GUI_Widget_Options_Click(Widget *w) { WindowDesc *desc = &g_optionsWindowDesc; uint16 cursor = g_cursorSpriteID; bool loop; g_cursorSpriteID = 0; Sprites_SetMouseSprite(0, 0, g_sprites[0]); Sprites_UnloadTiles(); memmove(g_palette_998A, g_paletteActive, 256 * 3); Driver_Voice_Play(NULL, 0xFF); Timer_SetTimer(TIMER_GAME, false); GUI_DrawText_Wrapper(NULL, 0, 0, 0, 0, 0x22); ShadeScreen(); GUI_Window_BackupScreen(desc); GUI_Window_Create(desc); for (loop = true; loop; sleepIdle()) { Widget *w2 = g_widgetLinkedListTail; uint16 key = GUI_Widget_HandleEvents(w2); if ((key & 0x8000) != 0) { w = GUI_Widget_Get_ByIndex(w2, key); GUI_Window_RestoreScreen(desc); switch ((key & 0x7FFF) - 0x1E) { case 0: if (GUI_Widget_SaveLoad_Click(false)) loop = false; break; case 1: if (GUI_Widget_SaveLoad_Click(true)) loop = false; break; case 2: GUI_Widget_GameControls_Click(w); break; case 3: /* "Are you sure you wish to restart?" */ if (!GUI_YesNo(0x76)) break; loop = false; g_gameMode = GM_RESTART; break; case 4: /* "Are you sure you wish to pick a new house?" */ if (!GUI_YesNo(0x77)) break; loop = false; Driver_Music_FadeOut(); g_gameMode = GM_PICKHOUSE; break; case 5: loop = false; break; case 6: /* "Are you sure you want to quit playing?" */ loop = !GUI_YesNo(0x65); g_running = loop; Sound_Output_Feedback(0xFFFE); while (Driver_Voice_IsPlaying()) sleepIdle(); break; default: break; } if (g_running && loop) { GUI_Window_BackupScreen(desc); GUI_Window_Create(desc); } } GUI_PaletteAnimate(); } g_textDisplayNeedsUpdate = true; Sprites_LoadTiles(); GUI_DrawInterfaceAndRadar(SCREEN_0); UnshadeScreen(); GUI_Widget_MakeSelected(w, false); Timer_SetTimer(TIMER_GAME, true); GameOptions_Save(); Structure_Recount(); Unit_Recount(); g_cursorSpriteID = cursor; Sprites_SetMouseSprite(0, 0, g_sprites[cursor]); return false; }
/** * Main game loop. */ static void GameLoop_Main(void) { static uint32 l_timerNext = 0; static uint32 l_timerUnitStatus = 0; static int16 l_selectionState = -2; uint16 key; String_Init(); Sprites_Init(); Input_Flags_SetBits(INPUT_FLAG_KEY_REPEAT | INPUT_FLAG_UNKNOWN_0010 | INPUT_FLAG_UNKNOWN_0200 | INPUT_FLAG_UNKNOWN_2000); Input_Flags_ClearBits(INPUT_FLAG_KEY_RELEASE | INPUT_FLAG_UNKNOWN_0400 | INPUT_FLAG_UNKNOWN_0100 | INPUT_FLAG_UNKNOWN_0080 | INPUT_FLAG_UNKNOWN_0040 | INPUT_FLAG_UNKNOWN_0020 | INPUT_FLAG_UNKNOWN_0008 | INPUT_FLAG_UNKNOWN_0004 | INPUT_FLAG_NO_TRANSLATE); Timer_SetTimer(TIMER_GAME, true); Timer_SetTimer(TIMER_GUI, true); g_campaignID = 0; g_scenarioID = 1; g_playerHouseID = HOUSE_INVALID; g_debugScenario = false; g_selectionType = SELECTIONTYPE_MENTAT; g_selectionTypeNew = SELECTIONTYPE_MENTAT; g_palette1 = calloc(1, 256 * 3); g_palette2 = calloc(1, 256 * 3); g_readBufferSize = 12000; g_readBuffer = calloc(1, g_readBufferSize); ReadProfileIni("PROFILE.INI"); free(g_readBuffer); g_readBuffer = NULL; File_ReadBlockFile("IBM.PAL", g_palette_998A, 256 * 3); memmove(g_palette1, g_palette_998A, 256 * 3); GUI_ClearScreen(SCREEN_0); Video_SetPalette(g_palette1, 0, 256); GFX_SetPalette(g_palette1); GFX_SetPalette(g_palette2); g_paletteMapping1 = malloc(256); g_paletteMapping2 = malloc(256); GUI_Palette_CreateMapping(g_palette1, g_paletteMapping1, 0xC, 0x55); g_paletteMapping1[0xFF] = 0xFF; g_paletteMapping1[0xDF] = 0xDF; g_paletteMapping1[0xEF] = 0xEF; GUI_Palette_CreateMapping(g_palette1, g_paletteMapping2, 0xF, 0x55); g_paletteMapping2[0xFF] = 0xFF; g_paletteMapping2[0xDF] = 0xDF; g_paletteMapping2[0xEF] = 0xEF; Script_LoadFromFile("TEAM.EMC", g_scriptTeam, g_scriptFunctionsTeam, NULL); Script_LoadFromFile("BUILD.EMC", g_scriptStructure, g_scriptFunctionsStructure, NULL); GUI_Palette_CreateRemap(HOUSE_MERCENARY); g_cursorSpriteID = 0; Sprites_SetMouseSprite(0, 0, g_sprites[0]); while (g_mouseHiddenDepth > 1) { GUI_Mouse_Show_Safe(); } Window_WidgetClick_Create(); GameOptions_Load(); Unit_Init(); Team_Init(); House_Init(); Structure_Init(); GUI_Mouse_Show_Safe(); if (g_debugSkipDialogs) { Music_Play(0); free(g_readBuffer); g_readBufferSize = (g_enableVoices == 0) ? 12000 : 20000; g_readBuffer = calloc(1, g_readBufferSize); g_gameMode = GM_NORMAL; } for (;; sleepIdle()) { if (g_gameMode == GM_MENU) { GameLoop_GameIntroAnimationMenu(); if (!g_running) break; if (g_gameMode == GM_MENU) continue; GUI_Mouse_Hide_Safe(); g_canSkipIntro = false; GUI_DrawFilledRectangle(g_curWidgetXBase << 3, g_curWidgetYBase, (g_curWidgetXBase + g_curWidgetWidth) << 3, g_curWidgetYBase + g_curWidgetHeight, 12); Input_History_Clear(); if (s_enableLog != 0) Mouse_SetMouseMode((uint8)s_enableLog, "DUNE.LOG"); GFX_SetPalette(g_palette1); GUI_Mouse_Show_Safe(); } if (g_gameMode == GM_PICKHOUSE) { Music_Play(28); g_playerHouseID = HOUSE_MERCENARY; g_playerHouseID = GUI_PickHouse(); GUI_Mouse_Hide_Safe(); GFX_ClearBlock(SCREEN_0); Sprites_LoadTiles(); GUI_Palette_CreateRemap(g_playerHouseID); Voice_LoadVoices(g_playerHouseID); GUI_Mouse_Show_Safe(); g_gameMode = GM_RESTART; g_scenarioID = 1; g_campaignID = 0; g_strategicRegionBits = 0; } if (g_selectionTypeNew != g_selectionType) { GUI_ChangeSelectionType(g_selectionTypeNew); } GUI_PaletteAnimate(); if (g_gameMode == GM_RESTART) { GUI_ChangeSelectionType(SELECTIONTYPE_MENTAT); Game_LoadScenario(g_playerHouseID, g_scenarioID); if (!g_debugScenario && !g_debugSkipDialogs) GUI_Mentat_ShowBriefing(); g_gameMode = GM_NORMAL; GUI_ChangeSelectionType(g_debugScenario ? SELECTIONTYPE_DEBUG : SELECTIONTYPE_STRUCTURE); Music_Play(Tools_RandomLCG_Range(0, 8) + 8); l_timerNext = g_timerGUI + 300; } if (l_selectionState != g_selectionState) { Map_SetSelectionObjectPosition(0xFFFF); Map_SetSelectionObjectPosition(g_selectionRectanglePosition); l_selectionState = g_selectionState; } if (!Driver_Voice_IsPlaying() && !Sound_StartSpeech()) { if (g_gameConfig.music == 0) { Music_Play(2); g_musicInBattle = 0; } else if (g_musicInBattle > 0) { Music_Play(Tools_RandomLCG_Range(0, 5) + 17); l_timerNext = g_timerGUI + 300; g_musicInBattle = -1; } else { g_musicInBattle = 0; if (g_enableSoundMusic != 0 && g_timerGUI > l_timerNext) { if (!Driver_Music_IsPlaying()) { Music_Play(Tools_RandomLCG_Range(0, 8) + 8); l_timerNext = g_timerGUI + 300; } } } } GFX_Screen_SetActive(SCREEN_0); key = GUI_Widget_HandleEvents(g_widgetLinkedListHead); if (g_selectionType == SELECTIONTYPE_TARGET || g_selectionType == SELECTIONTYPE_PLACE || g_selectionType == SELECTIONTYPE_UNIT || g_selectionType == SELECTIONTYPE_STRUCTURE) { if (g_unitSelected != NULL) { if (l_timerUnitStatus < g_timerGame) { Unit_DisplayStatusText(g_unitSelected); l_timerUnitStatus = g_timerGame + 300; } if (g_selectionType != SELECTIONTYPE_TARGET) { g_selectionPosition = Tile_PackTile(Tile_Center(g_unitSelected->o.position)); } } GUI_Widget_ActionPanel_Draw(false); InGame_Numpad_Move(key); GUI_DrawCredits(g_playerHouseID, 0); GameLoop_Team(); GameLoop_Unit(); GameLoop_Structure(); GameLoop_House(); GUI_DrawScreen(SCREEN_0); } GUI_DisplayText(NULL, 0); if (g_running && !g_debugScenario) { GameLoop_LevelEnd(); } if (!g_running) break; } GUI_Mouse_Hide_Safe(); if (s_enableLog != 0) Mouse_SetMouseMode(INPUT_MOUSE_MODE_NORMAL, "DUNE.LOG"); GUI_Mouse_Hide_Safe(); Widget_SetCurrentWidget(0); GFX_Screen_SetActive(SCREEN_1); GFX_ClearScreen(); GUI_Screen_FadeIn(g_curWidgetXBase, g_curWidgetYBase, g_curWidgetXBase, g_curWidgetYBase, g_curWidgetWidth, g_curWidgetHeight, SCREEN_1, SCREEN_0); }
/** * Handles Click event for savegame button. * * @param index The index of the clicked button. * @return True if a game has been saved, False otherwise. */ static bool GUI_Widget_Savegame_Click(uint16 index) { WindowDesc *desc = &g_savegameNameWindowDesc; bool loop; char *saveDesc = g_savegameDesc[index]; bool widgetPaint; bool ret; if (*saveDesc == '[') *saveDesc = 0; GUI_Window_BackupScreen(desc); GUI_Window_Create(desc); ret = false; widgetPaint = true; if (*saveDesc == '[') index = s_savegameCountOnDisk; GFX_Screen_SetActive(SCREEN_0); Widget_SetCurrentWidget(15); GUI_Mouse_Hide_Safe(); GUI_DrawBorder((g_curWidgetXBase << 3) - 1, g_curWidgetYBase - 1, (g_curWidgetWidth << 3) + 2, g_curWidgetHeight + 2, 4, false); GUI_Mouse_Show_Safe(); for (loop = true; loop; sleepIdle()) { uint16 eventKey; Widget *w = g_widgetLinkedListTail; GUI_DrawText_Wrapper(NULL, 0, 0, 232, 235, 0x22); eventKey = GUI_EditBox(saveDesc, 50, 15, g_widgetLinkedListTail, NULL, widgetPaint); widgetPaint = false; if ((eventKey & 0x8000) == 0) continue; GUI_Widget_MakeNormal(GUI_Widget_Get_ByIndex(w, eventKey & 0x7FFF), false); switch (eventKey & 0x7FFF) { case 0x1E: /* RETURN / Save Button */ if (*saveDesc == 0) break; SaveGame_SaveFile(GenerateSavegameFilename(s_savegameIndexBase - index), saveDesc); loop = false; ret = true; break; case 0x1F: /* ESCAPE / Cancel Button */ loop = false; ret = false; FillSavegameDesc(true); break; default: break; } } GUI_Window_RestoreScreen(desc); return ret; }