/** * 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); }
/** * Handles Click event for list in mentat window. * * @param w The widget. */ bool GUI_Mentat_List_Click(Widget *w) { uint16 index; Widget *w2; index = s_selectedHelpSubject + 3; if (w->index != index) { w2 = GUI_Widget_Get_ByIndex(g_widgetMentatTail, index); GUI_Widget_MakeNormal(w, false); GUI_Widget_MakeNormal(w2, false); if (w2->stringID == 0x31) { w2->fgColourDown = 15; w2->fgColourNormal = 15; GUI_Widget_Draw(w2); } if (w->stringID == 0x31) { w->fgColourDown = 8; w->fgColourNormal = 8; GUI_Widget_Draw(w); } s_selectedHelpSubject = w->index - 3; return true; } if ((w->state.buttonState & 0x11) == 0 && !s_selectMentatHelp) return true; if (w->stringID != 0x31) return true; GUI_Widget_MakeNormal(w, false); GUI_Mentat_ShowHelp(); GUI_Mentat_Draw(true); Input_HandleInput(0x841); Input_HandleInput(0x842); return false; }
/** Create the widgets of the mentat help screen. */ void GUI_Mentat_Create_HelpScreen_Widgets(void) { static char empty[2] = ""; uint16 ypos; Widget *w; int i; if (g_widgetMentatScrollbar != NULL) { GUI_Widget_Free_WithScrollbar(g_widgetMentatScrollbar); g_widgetMentatScrollbar = NULL; } free(g_widgetMentatScrollUp); g_widgetMentatScrollUp = NULL; free(g_widgetMentatScrollDown); g_widgetMentatScrollDown = NULL; g_widgetMentatTail = NULL; ypos = 8; w = (Widget *)GFX_Screen_Get_ByIndex(SCREEN_2); memset(w, 0, 13 * sizeof(Widget)); for (i = 0; i < 13; i++) { w->index = i + 2; memset(&w->flags, 0, sizeof(w->flags)); w->flags.buttonFilterLeft = 9; w->flags.buttonFilterRight = 1; w->clickProc = &GUI_Mentat_List_Click; w->drawParameterDown.text = empty; w->drawParameterSelected.text = empty; w->drawParameterNormal.text = empty; w->drawModeNormal = DRAW_MODE_TEXT; memset(&w->state, 0, sizeof(w->state)); w->offsetX = 24; w->offsetY = ypos; w->width = 0x88; w->height = 8; w->parentID = 8; if (g_widgetMentatTail != NULL) { g_widgetMentatTail = GUI_Widget_Link(g_widgetMentatTail, w); } else { g_widgetMentatTail = w; } ypos += 8; w++; } GUI_Widget_MakeInvisible(g_widgetMentatTail); GUI_Widget_MakeInvisible(w - 1); g_widgetMentatScrollbar = GUI_Widget_Allocate_WithScrollbar(15, 8, 168, 24, 8, 72, &GUI_Mentat_ScrollBar_Draw); g_widgetMentatTail = GUI_Widget_Link(g_widgetMentatTail, g_widgetMentatScrollbar); g_widgetMentatScrollDown = GUI_Widget_Allocate3(16, 0, 168, 96, g_sprites[385], g_sprites[386], GUI_Widget_Get_ByIndex(g_widgetMentatTail, 15), 1); g_widgetMentatScrollDown->shortcut = 0; g_widgetMentatScrollDown->shortcut2 = 0; g_widgetMentatScrollDown->parentID = 8; g_widgetMentatTail = GUI_Widget_Link(g_widgetMentatTail, g_widgetMentatScrollDown); g_widgetMentatScrollUp = GUI_Widget_Allocate3(17, 0, 168, 16, g_sprites[383], g_sprites[384], GUI_Widget_Get_ByIndex(g_widgetMentatTail, 15), 0); g_widgetMentatScrollUp->shortcut = 0; g_widgetMentatScrollUp->shortcut2 = 0; g_widgetMentatScrollUp->parentID = 8; g_widgetMentatTail = GUI_Widget_Link(g_widgetMentatTail, g_widgetMentatScrollUp); g_widgetMentatTail = GUI_Widget_Link(g_widgetMentatTail, g_widgetMentatFirst); GUI_Widget_Draw(g_widgetMentatFirst); }
static void GUI_Mentat_Draw(bool force) { static uint16 displayedHelpSubject = 0; Screen oldScreenID; Widget *line; Widget *w = g_widgetMentatTail; uint8 *helpSubjects = s_helpSubjects; uint16 i; if (!force && s_topHelpList == displayedHelpSubject) return; displayedHelpSubject = s_topHelpList; oldScreenID = GFX_Screen_SetActive(SCREEN_1); Widget_SetAndPaintCurrentWidget(8); GUI_DrawSprite(SCREEN_1, g_sprites[397 + g_playerHouseID * 15], g_shoulderLeft, g_shoulderTop, 0, 0); GUI_DrawText_Wrapper(String_Get_ByIndex(STR_SELECT_SUBJECT), (g_curWidgetXBase << 3) + 16, g_curWidgetYBase + 2, 12, 0, 0x12); GUI_DrawText_Wrapper(NULL, 0, 0, 0, 0, 0x11); line = GUI_Widget_Get_ByIndex(w, 3); for (i = 0; i < 11; i++) { line->drawParameterDown.text = (char *)helpSubjects + 7; line->drawParameterSelected.text = (char *)helpSubjects + 7; line->drawParameterNormal.text = (char *)helpSubjects + 7; if (helpSubjects[6] == '0') { line->offsetX = 16; line->fgColourSelected = 11; line->fgColourDown = 11; line->fgColourNormal = 11; line->stringID = 0x30; } else { uint8 colour = (i == s_selectedHelpSubject) ? 8 : 15; line->offsetX = 24; line->fgColourSelected = colour; line->fgColourDown = colour; line->fgColourNormal = colour; line->stringID = 0x31; } GUI_Widget_MakeNormal(line, false); GUI_Widget_Draw(line); line = GUI_Widget_GetNext(line); helpSubjects = String_NextString(helpSubjects); } GUI_Widget_Scrollbar_Init(GUI_Widget_Get_ByIndex(w, 15), s_numberHelpSubjects, 11, s_topHelpList); GUI_Widget_Draw(GUI_Widget_Get_ByIndex(w, 16)); GUI_Widget_Draw(GUI_Widget_Get_ByIndex(w, 17)); GUI_Mouse_Hide_Safe(); GUI_Screen_Copy(g_curWidgetXBase, g_curWidgetYBase, g_curWidgetXBase, g_curWidgetYBase, g_curWidgetWidth, g_curWidgetHeight, SCREEN_1, SCREEN_0); GUI_Mouse_Show_Safe(); GFX_Screen_SetActive(oldScreenID); }
static void GUI_Window_Create(WindowDesc *desc) { uint8 i; if (desc == NULL) return; g_widgetLinkedListTail = NULL; GFX_Screen_SetActive(SCREEN_1); Widget_SetCurrentWidget(desc->index); GUI_Widget_DrawBorder(g_curWidgetIndex, 2, true); if (GUI_String_Get_ByIndex(desc->stringID) != NULL) { GUI_DrawText_Wrapper(GUI_String_Get_ByIndex(desc->stringID), (g_curWidgetXBase << 3) + (g_curWidgetWidth << 2), g_curWidgetYBase + 6 + ((desc == &g_yesNoWindowDesc) ? 2 : 0), 238, 0, 0x122); } if (GUI_String_Get_ByIndex(desc->widgets[0].stringID) == NULL) { GUI_DrawText_Wrapper(String_Get_ByIndex(STR_THERE_ARE_NO_SAVED_GAMES_TO_LOAD), (g_curWidgetXBase + 2) << 3, g_curWidgetYBase + 42, 232, 0, 0x22); } for (i = 0; i < desc->widgetCount; i++) { Widget *w = &g_table_windowWidgets[i]; if (GUI_String_Get_ByIndex(desc->widgets[i].stringID) == NULL) continue; w->next = NULL; w->offsetX = desc->widgets[i].offsetX; w->offsetY = desc->widgets[i].offsetY; w->width = desc->widgets[i].width; w->height = desc->widgets[i].height; w->shortcut = 0; w->shortcut2 = 0; if (desc != &g_savegameNameWindowDesc) { if (desc->widgets[i].labelStringId != STR_NULL) { w->shortcut = GUI_Widget_GetShortcut(*GUI_String_Get_ByIndex(desc->widgets[i].labelStringId)); } else { w->shortcut = GUI_Widget_GetShortcut(*GUI_String_Get_ByIndex(desc->widgets[i].stringID)); } } w->shortcut2 = desc->widgets[i].shortcut2; if (w->shortcut == 0x1B) { w->shortcut2 = 0x13; } w->stringID = desc->widgets[i].stringID; w->drawModeNormal = DRAW_MODE_CUSTOM_PROC; w->drawModeSelected = DRAW_MODE_CUSTOM_PROC; w->drawModeDown = DRAW_MODE_CUSTOM_PROC; w->drawParameterNormal.proc = &GUI_Widget_TextButton_Draw; w->drawParameterSelected.proc = &GUI_Widget_TextButton_Draw; w->drawParameterDown.proc = &GUI_Widget_TextButton_Draw; w->parentID = desc->index; memset(&w->state, 0, sizeof(w->state)); g_widgetLinkedListTail = GUI_Widget_Link(g_widgetLinkedListTail, w); GUI_Widget_MakeVisible(w); GUI_Widget_MakeNormal(w, false); GUI_Widget_Draw(w); if (desc->widgets[i].labelStringId == STR_NULL) continue; if (g_config.language == LANGUAGE_FRENCH) { GUI_DrawText_Wrapper(GUI_String_Get_ByIndex(desc->widgets[i].labelStringId), (g_widgetProperties[w->parentID].xBase << 3) + 40, w->offsetY + g_widgetProperties[w->parentID].yBase + 3, 232, 0, 0x22); } else { GUI_DrawText_Wrapper(GUI_String_Get_ByIndex(desc->widgets[i].labelStringId), w->offsetX + (g_widgetProperties[w->parentID].xBase << 3) - 10, w->offsetY + g_widgetProperties[w->parentID].yBase + 3, 232, 0, 0x222); } } if (s_savegameCountOnDisk >= 5 && desc->addArrows) { Widget *w = &g_table_windowWidgets[7]; w->drawParameterNormal.sprite = g_sprites[59]; w->drawParameterSelected.sprite = g_sprites[60]; w->drawParameterDown.sprite = g_sprites[60]; w->next = NULL; w->parentID = desc->index; GUI_Widget_MakeNormal(w, false); GUI_Widget_MakeInvisible(w); GUI_Widget_Undraw(w, 233); g_widgetLinkedListTail = GUI_Widget_Link(g_widgetLinkedListTail, w); w = &g_table_windowWidgets[8]; w->drawParameterNormal.sprite = g_sprites[61]; w->drawParameterSelected.sprite = g_sprites[62]; w->drawParameterDown.sprite = g_sprites[62]; w->next = NULL; w->parentID = desc->index; GUI_Widget_MakeNormal(w, false); GUI_Widget_MakeInvisible(w); GUI_Widget_Undraw(w, 233); g_widgetLinkedListTail = GUI_Widget_Link(g_widgetLinkedListTail, w); } GUI_Mouse_Hide_Safe(); Widget_SetCurrentWidget(desc->index); GUI_Screen_Copy(g_curWidgetXBase, g_curWidgetYBase, g_curWidgetXBase, g_curWidgetYBase, g_curWidgetWidth, g_curWidgetHeight, SCREEN_1, SCREEN_0); GUI_Mouse_Show_Safe(); GFX_Screen_SetActive(SCREEN_0); }