/** ** Display update. ** ** This functions updates everything on screen. The map, the gui, the ** cursors. */ void UpdateDisplay() { if (GameRunning || Editor.Running == EditorEditing) { DrawMapArea(); DrawMessages(); if (CursorState == CursorStateRectangle) { DrawCursor(); } if ((Preference.BigScreen && !BigMapMode) || (!Preference.BigScreen && BigMapMode)) { UiToggleBigMap(); } if (!BigMapMode) { for (size_t i = 0; i < UI.Fillers.size(); ++i) { UI.Fillers[i].G->DrawSubClip(0, 0, UI.Fillers[i].G->Width, UI.Fillers[i].G->Height, UI.Fillers[i].X, UI.Fillers[i].Y); } DrawMenuButtonArea(); DrawUserDefinedButtons(); UI.Minimap.Draw(); UI.Minimap.DrawViewportArea(*UI.SelectedViewport); UI.InfoPanel.Draw(); DrawResources(); UI.StatusLine.Draw(); UI.StatusLine.DrawCosts(); UI.ButtonPanel.Draw(); } DrawTimer(); } DrawPieMenu(); // draw pie menu only if needed DrawGuichanWidgets(); if (CursorState != CursorStateRectangle) { DrawCursor(); } // // Update changes to display. // Invalidate(); }
/** ** Handle keys in command mode. ** ** @param key Key scancode. ** ** @return True, if key is handled; otherwise false. */ static bool CommandKey(int key) { const char *ptr = strchr(UiGroupKeys.c_str(), key); // FIXME: don't handle unicode well. Should work on all latin keyboard. if (ptr) { key = '0' + ptr - UiGroupKeys.c_str(); if (key > '9') { key = SDLK_BACKQUOTE; } } switch (key) { // Return enters chat/input mode. case SDLK_RETURN: case SDLK_KP_ENTER: // RETURN UiBeginInput(); return true; // Unselect everything case SDLK_CARET: case SDLK_BACKQUOTE: UiUnselectAll(); break; // Group selection case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': CommandKey_Group(key - '0'); break; case SDLK_F2: case SDLK_F3: case SDLK_F4: // Set/Goto place CommandKey_MapPosition(key - SDLK_F2); break; case SDLK_SPACE: // center on last action CenterOnMessage(); break; case SDLK_EQUALS: // plus is shift-equals. case SDLK_KP_PLUS: UiIncreaseGameSpeed(); break; case SDLK_MINUS: // - Slower case SDLK_KP_MINUS: UiDecreaseGameSpeed(); break; case SDLK_KP_MULTIPLY: UiSetDefaultGameSpeed(); break; case 'b': // ALT+B, CTRL+B Toggle big map if (!(KeyModifiers & (ModifierAlt | ModifierControl))) { break; } UiToggleBigMap(); break; case 'c': // ALT+C, CTRL+C C center on units UiCenterOnSelected(); break; case 'f': // ALT+F, CTRL+F toggle fullscreen if (!(KeyModifiers & (ModifierAlt | ModifierControl))) { break; } ToggleFullScreen(); SavePreferences(); break; case 'g': // ALT+G, CTRL+G grab mouse pointer if (!(KeyModifiers & (ModifierAlt | ModifierControl))) { break; } UiToggleGrabMouse(); break; case 'i': if (!(KeyModifiers & (ModifierAlt | ModifierControl))) { break; } // FALL THROUGH case SDLK_PERIOD: // ., ALT+I, CTRL+I: Find idle worker UiFindIdleWorker(); break; case 'm': // CTRL+M Turn music on / off if (KeyModifiers & ModifierControl) { UiToggleMusic(); SavePreferences(); break; } break; case 'p': // CTRL+P, ALT+P Toggle pause if (!(KeyModifiers & (ModifierAlt | ModifierControl))) { break; } // FALL THROUGH (CTRL+P, ALT+P) case SDLK_PAUSE: UiTogglePause(); break; case 's': // CTRL+S - Turn sound on / off if (KeyModifiers & ModifierControl) { UiToggleSound(); SavePreferences(); break; } break; case 't': // ALT+T, CTRL+T Track unit if (!(KeyModifiers & (ModifierAlt | ModifierControl))) { break; } UiTrackUnit(); break; case 'v': // ALT+V, CTRL+V: Viewport if (KeyModifiers & ModifierControl) { CycleViewportMode(-1); } else if (KeyModifiers & ModifierAlt) { CycleViewportMode(1); } break; case 'e': // CTRL+E Turn messages on / off if (KeyModifiers & ModifierControl) { ToggleShowMessages(); } #ifdef DEBUG else if (KeyModifiers & ModifierAlt) { ToggleShowBuilListMessages(); } #endif break; case SDLK_TAB: // TAB toggles minimap. // FIXME: more... // FIXME: shift+TAB if (KeyModifiers & ModifierAlt) { break; } UiToggleTerrain(); break; case SDLK_UP: case SDLK_KP8: KeyScrollState |= ScrollUp; break; case SDLK_DOWN: case SDLK_KP2: KeyScrollState |= ScrollDown; break; case SDLK_LEFT: case SDLK_KP4: KeyScrollState |= ScrollLeft; break; case SDLK_RIGHT: case SDLK_KP6: KeyScrollState |= ScrollRight; break; default: if (HandleCommandKey(key)) { break; } return false; } return true; }
/** ** Display update. ** ** This functions updates everything on screen. The map, the gui, the ** cursors. */ void UpdateDisplay() { if (GameRunning || Editor.Running == EditorEditing) { // to prevent empty spaces in the UI #if defined(USE_OPENGL) || defined(USE_GLES) Video.FillRectangleClip(ColorBlack, 0, 0, Video.ViewportWidth, Video.ViewportHeight); #else Video.FillRectangleClip(ColorBlack, 0, 0, Video.Width, Video.Height); #endif DrawMapArea(); DrawMessages(); if (CursorState == CursorStateRectangle) { DrawCursor(); } //Wyrmgus start if (CursorBuilding && CursorOn == CursorOnMap) { DrawBuildingCursor(); } //Wyrmgus end if ((Preference.BigScreen && !BigMapMode) || (!Preference.BigScreen && BigMapMode)) { UiToggleBigMap(); } if (!BigMapMode) { for (size_t i = 0; i < UI.Fillers.size(); ++i) { UI.Fillers[i].G->DrawSubClip(0, 0, UI.Fillers[i].G->Width, UI.Fillers[i].G->Height, UI.Fillers[i].X, UI.Fillers[i].Y); } DrawMenuButtonArea(); DrawUserDefinedButtons(); UI.Minimap.Draw(); UI.Minimap.DrawViewportArea(*UI.SelectedViewport); UI.InfoPanel.Draw(); DrawResources(); UI.StatusLine.Draw(); UI.StatusLine.DrawCosts(); UI.ButtonPanel.Draw(); } DrawTimer(); //Wyrmgus start //draw worker icon if there are idle workers if (UI.IdleWorkerButton && !ThisPlayer->FreeWorkers.empty()) { int worker_unit_type_id = PlayerRaces.GetFactionClassUnitType(ThisPlayer->Race, ThisPlayer->Faction, GetUnitTypeClassIndexByName("worker")); if (worker_unit_type_id != -1) { const CUnitType &type = *UnitTypes[worker_unit_type_id]; const PixelPos pos(UI.IdleWorkerButton->X, UI.IdleWorkerButton->Y); const int flag = (ButtonAreaUnderCursor == ButtonAreaIdleWorker && ButtonUnderCursor == 0) ? (IconActive | (MouseButtons & LeftButton)) : 0; VariationInfo *varinfo = type.GetDefaultVariation(*ThisPlayer); if (varinfo && varinfo->Icon.Icon) { // check if the default variation is valid, and if it is, then make the button use the variation's icon varinfo->Icon.Icon->DrawUnitIcon(*UI.IdleWorkerButton->Style, flag, pos, ".", ThisPlayer->Index); } else { type.Icon.Icon->DrawUnitIcon(*UI.IdleWorkerButton->Style, flag, pos, ".", ThisPlayer->Index); } if (ButtonAreaUnderCursor == ButtonAreaIdleWorker && ButtonUnderCursor == 0) { //if the mouse is hovering over the idle worker button, draw a tooltip std::string idle_worker_tooltip = "Find Idle Worker (~!.)"; if (!Preference.NoStatusLineTooltips) { CLabel label(GetGameFont()); label.Draw(2 + 16, Video.Height + 2 - 16, idle_worker_tooltip); } DrawGenericPopup(idle_worker_tooltip, UI.IdleWorkerButton->X, UI.IdleWorkerButton->Y); } } } //draw icon if there are units with available level up upgrades if (UI.LevelUpUnitButton && !ThisPlayer->LevelUpUnits.empty()) { const PixelPos pos(UI.LevelUpUnitButton->X, UI.LevelUpUnitButton->Y); const int flag = (ButtonAreaUnderCursor == ButtonAreaLevelUpUnit && ButtonUnderCursor == 0) ? (IconActive | (MouseButtons & LeftButton)) : 0; ThisPlayer->LevelUpUnits[0]->GetIcon().Icon->DrawUnitIcon(*UI.LevelUpUnitButton->Style, flag, pos, "", ThisPlayer->Index); if (ButtonAreaUnderCursor == ButtonAreaLevelUpUnit && ButtonUnderCursor == 0) { //if the mouse is hovering over the level up unit button, draw a tooltip std::string level_up_unit_tooltip = "Find Unit with Available Level Up"; if (!Preference.NoStatusLineTooltips) { CLabel label(GetGameFont()); label.Draw(2 + 16, Video.Height + 2 - 16, level_up_unit_tooltip); } DrawGenericPopup(level_up_unit_tooltip, UI.LevelUpUnitButton->X, UI.LevelUpUnitButton->Y); } } //Wyrmgus end //Wyrmgus start } else if (GrandStrategy && !GameRunning && GameResult == GameNoResult) { //grand strategy mode if (!GrandStrategyGamePaused) { //scroll map if mouse is in the scroll area int scroll_up = 7; //the scroll area in the upper part of the screen is smaller to allow clicking on the menu buttons and etc. more comfortably int scroll_down = (Video.Height - 16); int scroll_left = 15; int scroll_right = (Video.Width - 16); bool scrolled = false; if (CursorScreenPos.y < scroll_up) { if (WorldMapOffsetY > 0) { if (GrandStrategyMapHeightIndent == 0) { WorldMapOffsetY = WorldMapOffsetY - 1; } GrandStrategyMapHeightIndent -= 32; } else if (WorldMapOffsetY == 0 && GrandStrategyMapHeightIndent == -32) { //this is to make the entire y 0 tiles be shown scrolling to the northmost part of the map GrandStrategyMapHeightIndent -= 32; } GameCursor = UI.ArrowN.Cursor; scrolled = true; } else if (CursorScreenPos.y > scroll_down) { if (WorldMapOffsetY < GetWorldMapHeight() - 1 - ((UI.MapArea.EndY - UI.MapArea.Y) / 64)) { if (GrandStrategyMapHeightIndent == -32) { WorldMapOffsetY = WorldMapOffsetY + 1; } GrandStrategyMapHeightIndent += 32; } else if (WorldMapOffsetY == GetWorldMapHeight() - 1 - ((UI.MapArea.EndY - UI.MapArea.Y) / 64) && GrandStrategyMapHeightIndent == 0) { GrandStrategyMapHeightIndent += 32; } GameCursor = UI.ArrowS.Cursor; scrolled = true; } if (CursorScreenPos.x < scroll_left) { if (WorldMapOffsetX > 0) { if (GrandStrategyMapWidthIndent == 0) { WorldMapOffsetX = WorldMapOffsetX - 1; } GrandStrategyMapWidthIndent -= 32; } else if (WorldMapOffsetX == 0 && GrandStrategyMapWidthIndent == -32) { //this is to make the entire x 0 tiles be shown scrolling to the westmost part of the map GrandStrategyMapWidthIndent -= 32; } if (GameCursor == UI.ArrowN.Cursor) { GameCursor = UI.ArrowNW.Cursor; } else if (GameCursor == UI.ArrowS.Cursor) { GameCursor = UI.ArrowSW.Cursor; } else { GameCursor = UI.ArrowW.Cursor; } scrolled = true; } else if (CursorScreenPos.x > scroll_right) { if (WorldMapOffsetX < GetWorldMapWidth() - 1 - ((UI.MapArea.EndX - UI.MapArea.X) / 64)) { if (GrandStrategyMapWidthIndent == -32) { WorldMapOffsetX = WorldMapOffsetX + 1; } GrandStrategyMapWidthIndent += 32; } else if (WorldMapOffsetX == GetWorldMapWidth() - 1 - ((UI.MapArea.EndX - UI.MapArea.X) / 64) && GrandStrategyMapWidthIndent == 0) { GrandStrategyMapWidthIndent += 32; } if (GameCursor == UI.ArrowN.Cursor) { GameCursor = UI.ArrowNE.Cursor; } else if (GameCursor == UI.ArrowS.Cursor) { GameCursor = UI.ArrowSE.Cursor; } else { GameCursor = UI.ArrowE.Cursor; } scrolled = true; } if (scrolled) { if (GrandStrategyMapWidthIndent <= -64) { GrandStrategyMapWidthIndent = 0; } if (GrandStrategyMapHeightIndent <= -64) { GrandStrategyMapHeightIndent = 0; } if (GrandStrategyMapWidthIndent > 0) { GrandStrategyMapWidthIndent *= -1; } if (GrandStrategyMapHeightIndent > 0) { GrandStrategyMapHeightIndent *= -1; } } else { GameCursor = UI.Point.Cursor; } } //draw map GrandStrategyGame.DrawMap(); // Fillers for (size_t i = 0; i != UI.Fillers.size(); ++i) { UI.Fillers[i].G->DrawClip(UI.Fillers[i].X, UI.Fillers[i].Y); } GrandStrategyGame.DrawMinimap(); GrandStrategyGame.DrawInterface(); if (UI.MapArea.Contains(CursorScreenPos) && GrandStrategyGame.WorldMapTiles[GrandStrategyGame.GetTileUnderCursor().x][GrandStrategyGame.GetTileUnderCursor().y] && !GrandStrategyGamePaused) { GrandStrategyGame.DrawTileTooltip(GrandStrategyGame.GetTileUnderCursor().x, GrandStrategyGame.GetTileUnderCursor().y); } //Wyrmgus end } DrawPieMenu(); // draw pie menu only if needed DrawGuichanWidgets(); if (CursorState != CursorStateRectangle) { DrawCursor(); } // // Update changes to display. // Invalidate(); }