Exemplo n.º 1
0
/**
 * 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);
}
Exemplo n.º 2
0
/**
 * 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;
}
Exemplo n.º 3
0
/** 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);
}
Exemplo n.º 4
0
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);
}
Exemplo n.º 5
0
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;
    }
}
Exemplo n.º 6
0
/**
 * 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;
}
Exemplo n.º 7
0
/**
 * 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;
}
Exemplo n.º 8
0
/**
 * 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;
}
Exemplo n.º 9
0
/**
 * Handles Click event for unit commands button.
 *
 * @param w The widget.
 * @return True, always.
 */
bool GUI_Widget_TextButton_Click(Widget *w)
{
	const UnitInfo *ui;
	const ActionInfo *ai;
	const uint16 *actions;
	ActionType action;
	Unit *u;
	uint16 *found;
	ActionType unitAction;

	u = g_unitSelected;
	ui = &g_table_unitInfo[u->o.type];

	actions = ui->o.actionsPlayer;
	if (Unit_GetHouseID(u) != g_playerHouseID && u->o.type != UNIT_HARVESTER) {
		actions = g_table_actionsAI;
	}

	action = actions[w->index - 8];

	unitAction = u->nextActionID;
	if (unitAction == ACTION_INVALID) {
		unitAction = u->actionID;
	}

	if (u->deviated != 0) {
		Unit_Deviation_Decrease(u, 5);
		if (u->deviated == 0) {
			GUI_Widget_MakeNormal(w, false);
			return true;
		}
	}

	GUI_Widget_MakeSelected(w, false);

	ai = &g_table_actionInfo[action];

	if (ai->selectionType != g_selectionType) {
		g_unitActive = g_unitSelected;
		g_activeAction = action;
		GUI_ChangeSelectionType(ai->selectionType);

		return true;
	}

	Object_Script_Variable4_Clear(&u->o);
	u->targetAttack = 0;
	u->targetMove = 0;
	u->route[0] = 0xFF;

	Unit_SetAction(u, action);

	if (ui->movementType == MOVEMENT_FOOT) Sound_StartSound(ai->soundID);

	if (unitAction == action) return true;

	found = memchr(actions, unitAction, 4);
	if (found == NULL) return true;

	GUI_Widget_MakeNormal(GUI_Widget_Get_ByIndex(g_widgetLinkedListHead, found - actions + 8), false);

	return true;
}
Exemplo n.º 10
0
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();
}
Exemplo n.º 11
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;
}
Exemplo n.º 12
0
/* Process input not caught by widgets, including keypad scrolling,
 * squad selection, and changing zoom levels.  Also handles screen
 * shake logic.
 */
static void GameLoop_ProcessUnhandledInput(uint16 key)
{
	const struct
	{
		Scancode code;
		int dx, dy;
	} keypad[8] = {
		{SCANCODE_KEYPAD_1, -1, 1},
		{SCANCODE_KEYPAD_2, 0, 1},
		{SCANCODE_KEYPAD_3, 1, 1},
		{SCANCODE_KEYPAD_4, -1, 0},
		{SCANCODE_KEYPAD_6, 1, 0},
		{SCANCODE_KEYPAD_7, -1, -1},
		{SCANCODE_KEYPAD_8, 0, -1},
		{SCANCODE_KEYPAD_9, 1, -1}
	};

	int dx = 0, dy = 0;

	for (unsigned int i = 0; i < lengthof(keypad); i++)
	{
		if ((key == keypad[i].code) ||
			(key == 0 && Input_Test(keypad[i].code)))
		{
			dx += keypad[i].dx;
			dy += keypad[i].dy;
		}
	}

	if (dx != 0 || dy != 0)
	{
		dx = g_gameConfig.scrollSpeed * clamp(-1, dx, 1);
		dy = g_gameConfig.scrollSpeed * clamp(-1, dy, 1);
	}

	if ((fabsf(g_viewport_desiredDX) >= 4.0f) || (fabsf(g_viewport_desiredDY) >= 4.0f))
	{
		dx += 0.25 * g_viewport_desiredDX;
		dy += 0.25 * g_viewport_desiredDY;
		if (fabsf(g_viewport_desiredDX) >= 4.0f)
			g_viewport_desiredDX *= 0.75;
		if (fabsf(g_viewport_desiredDY) >= 4.0f)
			g_viewport_desiredDY *= 0.75;
	}

	if (dx != 0 || dy != 0)
	{
		Map_MoveDirection(dx, dy);
	}

	switch (key)
	{
	case SCANCODE_1:
	case SCANCODE_2:
	case SCANCODE_3:
	case SCANCODE_4:
	case SCANCODE_5:
	case SCANCODE_6:
	case SCANCODE_7:
	case SCANCODE_8:
	case SCANCODE_9:
	case SCANCODE_0:
		Viewport_Hotkey((SquadID)(key - SCANCODE_1 + SQUADID_1));
		break;

	case SCANCODE_H:
		Viewport_Homekey();
		break;

	case SCANCODE_F5:
		Audio_DisplayMusicName();
		break;

	case SCANCODE_F6:
	case SCANCODE_F7:
		{
			const bool increase = (key == SCANCODE_F7);
			const bool adjust_current_track_only = Input_Test(SCANCODE_LSHIFT);

			Audio_AdjustMusicVolume(increase ? 0.05f : -0.05f, adjust_current_track_only);
			Audio_DisplayMusicName();
		}
		break;

	case SCANCODE_OPENBRACE:
	case SCANCODE_CLOSEBRACE:
		{
			ScreenDivID divID = (key == SCANCODE_OPENBRACE) ? SCREENDIV_MENUBAR : SCREENDIV_SIDEBAR;
			ScreenDiv* viewport = &g_screenDiv[SCREENDIV_VIEWPORT];
			ScreenDiv* div = &g_screenDiv[divID];
			const int oldh = viewport->height;

			div->scalex = (div->scalex >= 1.5f) ? 1.0f : 2.0f;
			div->scaley = div->scalex;
			A5_InitTransform(false);
			GameLoop_TweakWidgetDimensions();
			g_factoryWindowTotal = -1;
			Map_MoveDirection(0, oldh - viewport->height);
		}
		return;

	case 0x80 | MOUSE_ZAXIS:
		if (g_mouseDZ == 0)
			break;

		if (g_gameConfig.holdControlToZoom)
		{
			if (!Input_Test(SCANCODE_LCTRL))
			{
				Widget* w = GUI_Widget_Get_ByIndex(g_widgetLinkedListHead, 5);

				if ((w != NULL) && !w->flags.invisible)
					GUI_Widget_SpriteTextButton_Click(w);

				break;
			}
		}
		else
		{
			const WidgetProperties* w = &g_widgetProperties[WINDOWID_ACTIONPANEL_FRAME];

			if (Mouse_InRegion_Div(SCREENDIV_SIDEBAR, w->xBase, w->yBase, w->xBase + w->width - 1, w->yBase + w->height - 1))
				break;
		}
		/* Fall though. */
	case SCANCODE_MINUS:
	case SCANCODE_EQUALS:
	case SCANCODE_KEYPAD_MINUS:
	case SCANCODE_KEYPAD_PLUS:
		{
			const float scaling_factor[] = {1.0f, 1.5f, 2.0f, 3.0f};
			ScreenDiv* viewport = &g_screenDiv[SCREENDIV_VIEWPORT];

			int curr;
			for (curr = 0; curr < (int)lengthof(scaling_factor); curr++)
			{
				if (viewport->scalex <= scaling_factor[curr])
					break;
			}

			const int tilex = Tile_GetPackedX(g_viewportPosition);
			const int tiley = Tile_GetPackedY(g_viewportPosition);
			int viewport_cx = g_viewport_scrollOffsetX + viewport->width / 2;
			int viewport_cy = g_viewport_scrollOffsetY + viewport->height / 2;
			int new_scale;

			/* For mouse wheel zooming in, zoom towards the cursor. */
			if ((key == (0x80 | MOUSE_ZAXIS)) && (g_mouseDZ > 0))
			{
				const ScreenDiv* div = &g_screenDiv[SCREENDIV_VIEWPORT];

				if (Mouse_InRegion_Div(SCREENDIV_VIEWPORT, 0, 0, div->width, div->height))
				{
					int mousex, mousey;

					new_scale = curr + 1;

					Mouse_TransformToDiv(SCREENDIV_VIEWPORT, &mousex, &mousey);
					viewport_cx = (0.50 * viewport_cx) + (0.50 * mousex);
					viewport_cy = (0.50 * viewport_cy) + (0.50 * mousey);
				}
				else
				{
					new_scale = curr + 1;
				}
			}
			else
			{
				if (key == SCANCODE_EQUALS || key == SCANCODE_KEYPAD_PLUS)
				{
					new_scale = curr + 1;
				}
				else
				{
					new_scale = curr - 1;
				}
			}

			new_scale = clamp(0, new_scale, (int)lengthof(scaling_factor) - 1);
			viewport_cx += TILE_SIZE * tilex;
			viewport_cy += TILE_SIZE * tiley;

			if (new_scale != curr)
			{
				viewport->scalex = scaling_factor[new_scale];
				viewport->scaley = scaling_factor[new_scale];
				A5_InitTransform(false);
				GameLoop_TweakWidgetDimensions();
				Map_CentreViewport(viewport_cx, viewport_cy);
				return;
			}
		}
		break;

	default:
		break;
	}

	/* If we did not init the transform, we may still need to do some
	 * translation transforms for screen shakes.
	 */
	if (GFX_ScreenShake_Tick())
		A5_InitTransform(false);
}