/** * 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, 0); 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); } } GUI_Security_UndrawText(); } Widget_SetCurrentWidget(oldCurrentWidget); GFX_Screen_SetActive(oldScreenID); Input_History_Clear(); Load_Palette_Mercenaries(); g_disableOtherMovement = false; g_interrogation = false; return valid; }
/** * 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; }
/** * 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; }