From 4d2c63f4ac5c368e74f3402bd41a3ab456006c11 Mon Sep 17 00:00:00 2001 From: Andrettin <6322423+Andrettin@users.noreply.github.com> Date: Sat, 25 Jun 2022 21:54:53 +0200 Subject: [PATCH] Reworked the remaining parts of the game results menu which were in Lua to be in QML --- interface/Viewport.qml | 1 - interface/menus/ResultsMenu.qml | 136 +++++++++++++++++++++++++++++++- readme.txt | 1 + scripts/guichan.lua | 1 - scripts/menus/results.lua | 91 --------------------- 5 files changed, 136 insertions(+), 94 deletions(-) delete mode 100644 scripts/menus/results.lua diff --git a/interface/Viewport.qml b/interface/Viewport.qml index 36b01b02d4..9c822a2eb6 100644 --- a/interface/Viewport.qml +++ b/interface/Viewport.qml @@ -104,7 +104,6 @@ Item { if (wyrmgus.game.results !== null) { if (wyrmgus.game.results.victory || wyrmgus.game.results.defeat || wyrmgus.game.results.draw) { menu_stack.push("menus/ResultsMenu.qml") - wyrmgus.call_lua_command("RunResultsMenu();") } } map_view_underlay.destroy() diff --git a/interface/menus/ResultsMenu.qml b/interface/menus/ResultsMenu.qml index 0a146906dd..a338b9bb9e 100644 --- a/interface/menus/ResultsMenu.qml +++ b/interface/menus/ResultsMenu.qml @@ -17,12 +17,146 @@ MenuBase { font.bold: true } + LargeText { + id: units_label + anchors.right: buildings_label.left + anchors.rightMargin: 32 * wyrmgus.scale_factor + anchors.top: outcome_label.bottom + anchors.topMargin: 64 * wyrmgus.scale_factor + text: "Units" + } + + LargeText { + id: buildings_label + anchors.right: copper_label.left + anchors.rightMargin: 32 * wyrmgus.scale_factor + anchors.top: units_label.top + text: "Buildings" + } + + LargeText { + id: copper_label + anchors.right: lumber_label.left + anchors.rightMargin: 32 * wyrmgus.scale_factor + anchors.top: units_label.top + text: "Copper" + } + + LargeText { + id: lumber_label + anchors.horizontalCenter: parent.horizontalCenter + anchors.top: units_label.top + text: "Lumber" + } + + LargeText { + id: stone_label + anchors.left: lumber_label.right + anchors.leftMargin: 32 * wyrmgus.scale_factor + anchors.top: units_label.top + text: "Stone" + } + + LargeText { + id: kills_label + anchors.left: stone_label.right + anchors.leftMargin: 32 * wyrmgus.scale_factor + anchors.top: units_label.top + text: "Kills" + } + + LargeText { + id: razings_label + anchors.left: kills_label.right + anchors.leftMargin: 32 * wyrmgus.scale_factor + anchors.top: units_label.top + text: "Razings" + } + + ListView { + id: player_results_list + anchors.left: parent.left + anchors.right: parent.right + anchors.top: units_label.bottom + anchors.topMargin: 16 * wyrmgus.scale_factor + anchors.bottom: continue_button.top + anchors.bottomMargin: 16 * wyrmgus.scale_factor + leftMargin: 0 + rightMargin: 0 + topMargin: 0 + bottomMargin: 0 + boundsBehavior: Flickable.StopAtBounds + clip: true + spacing: 16 * wyrmgus.scale_factor + model: wyrmgus.game.results.player_results + delegate: Item { + height: player_units_label.height + 8 * wyrmgus.scale_factor + player_label.height + + LargeText { + id: player_units_label + text: modelData.unit_count + x: units_label.x - player_results_list.contentItem.x + units_label.width / 2 - width / 2 + anchors.top: parent.top + } + + LargeText { + id: player_buildings_label + text: modelData.building_count + x: buildings_label.x - player_results_list.contentItem.x + buildings_label.width / 2 - width / 2 + anchors.top: parent.top + } + + LargeText { + id: player_copper_label + text: modelData.get_resource_count("copper") + x: copper_label.x - player_results_list.contentItem.x + copper_label.width / 2 - width / 2 + anchors.top: parent.top + } + + LargeText { + id: player_lumber_label + text: modelData.get_resource_count("lumber") + x: lumber_label.x - player_results_list.contentItem.x + lumber_label.width / 2 - width / 2 + anchors.top: parent.top + } + + LargeText { + id: player_stone_label + text: modelData.get_resource_count("stone") + x: stone_label.x - player_results_list.contentItem.x + stone_label.width / 2 - width / 2 + anchors.top: parent.top + } + + LargeText { + id: player_kills_label + text: modelData.kill_count + x: kills_label.x - player_results_list.contentItem.x + kills_label.width / 2 - width / 2 + anchors.top: parent.top + } + + LargeText { + id: player_razings_label + text: modelData.razing_count + x: razings_label.x - player_results_list.contentItem.x + razings_label.width / 2 - width / 2 + anchors.top: parent.top + } + + LargeText { + id: player_label + text: modelData.name + " - " + (modelData.this_player ? "You" : (modelData.ally ? "Ally" : (modelData.enemy ? "Enemy" : "Neutral"))) + x: player_results_list.contentItem.width / 2 - width / 2 + anchors.top: player_units_label.bottom + anchors.topMargin: 8 * wyrmgus.scale_factor + } + } + } + PreviousMenuButton { id: continue_button anchors.bottom: parent.bottom anchors.bottomMargin: 8 * wyrmgus.scale_factor text: "Continue" hotkey: "c" - lua_command: "CleanPlayers(); results_menu:stop();" + lua_command: "CleanPlayers();" } } diff --git a/readme.txt b/readme.txt index f42207e485..aa716a60e9 100644 --- a/readme.txt +++ b/readme.txt @@ -77,6 +77,7 @@ https://github.com/Andrettin/Wyrmsun * User Interface - Reworked the multiplayer host and client game menus. - Fixed issue which caused the screen to shake when mousewheel-scrolling to the edge of the map. +- Reworked the game results menu. ----------------------------------------------------------------------- - 5.3.5 diff --git a/scripts/guichan.lua b/scripts/guichan.lua index ddcb5262aa..48e84722e5 100644 --- a/scripts/guichan.lua +++ b/scripts/guichan.lua @@ -425,7 +425,6 @@ Load("scripts/menus/options.lua") Load("scripts/menus/editor.lua") Load("scripts/menus/game.lua") Load("scripts/menus/objectives.lua") -Load("scripts/menus/results.lua") Load("scripts/menus/mods.lua") Load("scripts/grand_strategy/grand_strategy.lua") diff --git a/scripts/menus/results.lua b/scripts/menus/results.lua deleted file mode 100644 index a51046974f..0000000000 --- a/scripts/menus/results.lua +++ /dev/null @@ -1,91 +0,0 @@ -results_menu = nil - -function RunResultsMenu() - if (GameResult == GameVictory) then - elseif (GameResult == GameDefeat) then - elseif (GameResult == GameDraw) then - else - return -- quit to menu - end - - local menu = WarMenu(nil, nil) - results_menu = menu - local offx = (Video.Width - 640 * get_scale_factor()) / 2 - local offy = (Video.Height - 480 * get_scale_factor()) / 2 - --- local names_font = Fonts["small-title"] - local names_font = Fonts["large"] - local top_offset = 57 * get_scale_factor() - local bottom_offset = 178 * get_scale_factor() - local description_offset = 30 * get_scale_factor() - - local c = 0 - for i=0,7 do - if (GetPlayerData(i, "TotalUnits") > 0 and GetPlayerData(i, "Type") ~= PlayerRescuePassive and GetPlayerData(i, "Type") ~= PlayerRescueActive) then - c = c + 1 - end - end - - local line_spacing = (432 * get_scale_factor() - bottom_offset - description_offset) / c - local player_name_spacing = 104 * get_scale_factor() / c - - menu:addLabel(_("Units"), offx + 50 * get_scale_factor(), offy + bottom_offset, Fonts["large"], true) - menu:addLabel(_("Buildings"), offx + 140 * get_scale_factor(), offy + bottom_offset, Fonts["large"], true) - menu:addLabel(_("Copper"), offx + 230 * get_scale_factor(), offy + bottom_offset, Fonts["large"], true) - menu:addLabel(_("Lumber"), offx + 320 * get_scale_factor(), offy + bottom_offset, Fonts["large"], true) - menu:addLabel(_("Stone"), offx + 410 * get_scale_factor(), offy + bottom_offset, Fonts["large"], true) --- menu:addLabel("Oil", offx + 410, offy + bottom_offset, Fonts["large"], true) - menu:addLabel(_("Kills"), offx + 500 * get_scale_factor(), offy + bottom_offset, Fonts["large"], true) - menu:addLabel(_("Razings"), offx + 590 * get_scale_factor(), offy + bottom_offset, Fonts["large"], true) - - c = 0 - for i=0,(PlayerMax - 2) do - if (GetPlayerData(i, "TotalUnits") > 0 and GetPlayerData(i, "Type") ~= PlayerRescuePassive and GetPlayerData(i, "Type") ~= PlayerRescueActive and GetPlayerData(GetThisPlayer(), "HasContactWith", i)) then - local name = _(GetPlayerData(i, "Name")) - if (GetThisPlayer() == i) then - name = name .. " - " .. _("You") - elseif (GetPlayerData(GetThisPlayer(), "IsAllied", i)) then - name = name .. " - " .. _("Ally") - elseif (GetPlayerData(GetThisPlayer(), "IsEnemy", i)) then - name = name .. " - " .. _("Enemy") - else - name = name .. " - " .. _("Neutral") - end - menu:addLabel(name, offx + 320 * get_scale_factor(), - offy + bottom_offset + description_offset + player_name_spacing + line_spacing * c + 5 * get_scale_factor(), - names_font, true) - menu:addLabel(GetPlayerData(i, "TotalUnits"), offx + (10 + 40) * get_scale_factor(), - offy + bottom_offset + description_offset + line_spacing * c + 5 * get_scale_factor(), - Fonts["large"], true) - menu:addLabel(GetPlayerData(i, "TotalBuildings"), offx + (100 + 40) * get_scale_factor(), - offy + bottom_offset + description_offset + line_spacing * c + 5 * get_scale_factor(), - Fonts["large"], true) - menu:addLabel(GetPlayerData(i, "TotalResources", "copper"), offx + (190 + 40) * get_scale_factor(), - offy + bottom_offset + description_offset + line_spacing * c + 5 * get_scale_factor(), - Fonts["large"], true) - menu:addLabel(GetPlayerData(i, "TotalResources", "lumber"), offx + (280 + 40) * get_scale_factor(), - offy + bottom_offset + description_offset + line_spacing * c + 5 * get_scale_factor(), - Fonts["large"], true) - menu:addLabel(GetPlayerData(i, "TotalResources", "stone"), offx + (370 + 40) * get_scale_factor(), - offy + bottom_offset + description_offset + line_spacing * c + 5 * get_scale_factor(), - Fonts["large"], true) --- menu:addLabel(GetPlayerData(i, "TotalResources", "oil"), offx + 370 + 40, --- offy + bottom_offset + description_offset + line_spacing * c + 5, --- Fonts["large"], true) - menu:addLabel(GetPlayerData(i, "TotalKills"), offx + (460 + 40) * get_scale_factor(), - offy + bottom_offset + description_offset + line_spacing * c + 5 * get_scale_factor(), - Fonts["large"], true) - menu:addLabel(GetPlayerData(i, "TotalRazings"), offx + (550 + 40) * get_scale_factor(), - offy + bottom_offset + description_offset + line_spacing * c + 5 * get_scale_factor(), - Fonts["large"], true) - - c = c + 1 - - if (c >= 8) then - break - end - end - end - - menu:run() -end