From dce8683be70dd15693a2b5bebb0cf70ba4cdccab Mon Sep 17 00:00:00 2001 From: ZwerOxotnik Date: Wed, 22 Dec 2021 13:40:47 +0300 Subject: [PATCH] Update to 2.12.1 --- changelog.txt | 6 ++ diplomacy/gui/frames/diplomacy.lua | 95 ++++++++++++-------- diplomacy/gui/frames/diplomacy_selection.lua | 4 +- info.json | 2 +- 4 files changed, 68 insertions(+), 39 deletions(-) diff --git a/changelog.txt b/changelog.txt index 13337ff..c02af8c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,10 @@ --------------------------------------------------------------------------------------------------- +Version: 2.12.1 +Date: 2021-12-22 + Changes: + - Changed position of frame + - Refactored slightly +--------------------------------------------------------------------------------------------------- Version: 2.12.0 Date: 2021-12-22 Changes: diff --git a/diplomacy/gui/frames/diplomacy.lua b/diplomacy/gui/frames/diplomacy.lua index 44bcc56..79b8c0b 100644 --- a/diplomacy/gui/frames/diplomacy.lua +++ b/diplomacy/gui/frames/diplomacy.lua @@ -14,6 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. ]]-- +local LABEL = {type = "label"} +local LABEL_FONT_COLORS = { + [FILTER_DIPLOMACY_TYPE_ALLY] = {r = 0.5, g = 1, b = 0.5}, + [FILTER_DIPLOMACY_TYPE_ENEMY] = {r = 1, g = 0.5, b = 0.5} +} + + local get_stance_diplomacy_type = require("diplomacy/util").get_stance_diplomacy_type local get_stance_name_diplomacy_by_type = require("diplomacy/util").get_stance_name_diplomacy_by_type local diplomacy_frame = {} @@ -22,7 +29,7 @@ local function add_player_list_gui(force, gui) if not (force and force.valid) then return end if #force.players == 0 then - gui.add{type = "label", caption = {"size.none"}} + gui.add(LABEL).caption = {"size.none"} return end @@ -51,7 +58,7 @@ local function add_player_list_gui(force, gui) first = true if #force.players > #force.connected_players then local offline_names = "" - for _, player in pairs( force.players ) do + for _, player in pairs(force.players) do if not added[player.name] then if not first then offline_names = offline_names .. ", " @@ -101,7 +108,7 @@ local function create_diplomacy_table(gui, player_settings) if player_settings.show_players_state == false then column_count = column_count - 1 end - diplomacy_table = gui.add{type = "table", name = "diplomacy_table", column_count = column_count} + local diplomacy_table = gui.add{type = "table", name = "diplomacy_table", column_count = column_count} diplomacy_table.style.horizontal_spacing = 16 diplomacy_table.style.vertical_spacing = 8 diplomacy_table.draw_horizontal_lines = true @@ -129,6 +136,7 @@ diplomacy_frame.fill = function(player) else diplomacy_table = gui.diplomacy_scrollpane.diplomacy_table is_changed = true + -- TODO: check for _, child in pairs(diplomacy_table.children) do if child.type == "checkbox" then temp_diplomacy_table[child.name] = {state = child.state} @@ -136,76 +144,89 @@ diplomacy_frame.fill = function(player) end diplomacy_table = create_diplomacy_table(diplomacy_scrollpane, player_settings) end + local add = diplomacy_table.add - local table_list = {} + local table_list if player_settings.show_players_state then table_list = {"team-name", "gui-browse-games.players", "stance", "enemy", "neutral", "ally"} else table_list = {"team-name", "stance", "enemy", "neutral", "ally"} end - for _, name in pairs(table_list) do - local label = diplomacy_table.add{type = "label", name = name, caption = {name}} + + -- TODO: improve + for i=1, #table_list do + local name = table_list[i] + local label = add(LABEL) + label.name = name + label.caption = {name} label.style.font = "default-bold" end local diplomacy = global.diplomacy -- Find teams + local forces = game.forces local teams local is_show_all_teams = false if settings.global["diplomacy_visible_all_teams"].value then - teams = game.forces + teams = forces is_show_all_teams = true else - teams = diplomacy.teams or game.forces + teams = diplomacy.teams or forces end -- Fill the table for _, team in pairs(teams) do - local force = game.forces[team.name] + local force = forces[team.name] if force and force.valid then local stance_type = get_stance_diplomacy_type(player.force, force) if is_show_all_teams or diplomacy.teams ~= nil or #force.players ~= 0 then if player_settings.filter_of_diplomacy_stance == FILTER_DIPLOMACY_TYPE_ALL or stance_type == player_settings.filter_of_diplomacy_stance then - local label = diplomacy_table.add{type = "label", name = team.name .. "_name", caption = team.name} + -- TODO: improve + local label = add(LABEL) + label.name = team.name .. "_name" + label.caption = team.name label.style.single_line = false label.style.maximal_width = 150 label.style.font = "default-semibold" label.style.font_color = get_color_team(team, true) + if player_settings.show_players_state then add_player_list_gui(force, diplomacy_table) end if force.name == player.force.name then - diplomacy_table.add{type = "label"} - diplomacy_table.add{type = "label"} - diplomacy_table.add{type = "label"} - diplomacy_table.add{type = "label"} + add(LABEL) + add(LABEL) + add(LABEL) + add(LABEL) else - local stance_label = diplomacy_table.add{type = "label", name = team.name .. "_stance", caption = {get_stance_name_diplomacy_by_type(stance_type)}} - if stance_type == FILTER_DIPLOMACY_TYPE_ALLY then - stance_label.style.font_color = {r = 0.5, g = 1, b = 0.5} - elseif stance_type == FILTER_DIPLOMACY_TYPE_ENEMY then - stance_label.style.font_color = {r = 1, g = 0.5, b = 0.5} + local stance_label = add(LABEL) + stance_label.name = team.name .. "_stance" + stance_label.caption = {get_stance_name_diplomacy_by_type(stance_type)} + local font_color = LABEL_FONT_COLORS[stance_type] + if font_color then + stance_label.style.font_color = font_color end if is_changed then + -- TODO: improve if temp_diplomacy_table[team.name .. "_enemy"] ~= nil then local state state = temp_diplomacy_table[team.name .. "_enemy"].state - diplomacy_table.add{type = "checkbox", name = team.name .. "_enemy", state = state} + add{type = "checkbox", name = team.name .. "_enemy", state = state} state = temp_diplomacy_table[team.name .. "_neutral"].state - diplomacy_table.add{type = "checkbox", name = team.name .. "_neutral", state = state} + add{type = "checkbox", name = team.name .. "_neutral", state = state} state = temp_diplomacy_table[team.name .. "_ally"].state - diplomacy_table.add{type = "checkbox", name = team.name .. "_ally", state = state} + add{type = "checkbox", name = team.name .. "_ally", state = state} else - diplomacy_table.add{type = "checkbox", name = team.name .. "_enemy", state = (stance_type == FILTER_DIPLOMACY_TYPE_ENEMY)} - diplomacy_table.add{type = "checkbox", name = team.name .. "_neutral", state = (stance_type == FILTER_DIPLOMACY_TYPE_NEUTRAL)} - diplomacy_table.add{type = "checkbox", name = team.name .. "_ally", state = (stance_type == FILTER_DIPLOMACY_TYPE_ALLY)} + add{type = "checkbox", name = team.name .. "_enemy", state = (stance_type == FILTER_DIPLOMACY_TYPE_ENEMY)} + add{type = "checkbox", name = team.name .. "_neutral", state = (stance_type == FILTER_DIPLOMACY_TYPE_NEUTRAL)} + add{type = "checkbox", name = team.name .. "_ally", state = (stance_type == FILTER_DIPLOMACY_TYPE_ALLY)} end else - diplomacy_table.add{type = "checkbox", name = team.name .. "_enemy", state = (stance_type == FILTER_DIPLOMACY_TYPE_ENEMY), enabled = not global.diplomacy.locked_teams} - diplomacy_table.add{type = "checkbox", name = team.name .. "_neutral", state = (stance_type == FILTER_DIPLOMACY_TYPE_NEUTRAL), enabled = not global.diplomacy.locked_teams} - diplomacy_table.add{type = "checkbox", name = team.name .. "_ally", state = (stance_type == FILTER_DIPLOMACY_TYPE_ALLY), enabled = not global.diplomacy.locked_teams} + add{type = "checkbox", name = team.name .. "_enemy", state = (stance_type == FILTER_DIPLOMACY_TYPE_ENEMY), enabled = not global.diplomacy.locked_teams} + add{type = "checkbox", name = team.name .. "_neutral", state = (stance_type == FILTER_DIPLOMACY_TYPE_NEUTRAL), enabled = not global.diplomacy.locked_teams} + add{type = "checkbox", name = team.name .. "_ally", state = (stance_type == FILTER_DIPLOMACY_TYPE_ALLY), enabled = not global.diplomacy.locked_teams} end end end @@ -215,7 +236,7 @@ diplomacy_frame.fill = function(player) end end - -- Creat button "confirm" + -- Create button "confirm" if not flow.confirm_diplomacy then local button = flow.add{type = "button", name = "confirm_diplomacy", caption = {"gui-tag-edit.confirm"}} -- if global.is_blacklist_diplomacy[player.force.name] ~= nil then @@ -228,25 +249,25 @@ diplomacy_frame.update = function(player) if player and player.valid and player.connected then diplomacy_frame.fill(player) else - for _, player in pairs(game.connected_players) do - diplomacy_frame.fill(player) + for _, _player in pairs(game.connected_players) do + diplomacy_frame.fill(_player) end end end diplomacy_frame.create = function(player) - local flow = player.gui.screen - local frame = flow.diplomacy_frame + local screen = player.gui.screen + local frame = screen.diplomacy_frame if frame then frame.destroy() return end - frame = flow.add{type = "frame", name = "diplomacy_frame", caption = {"mod-name.diplomacy"}, direction = "vertical"} + frame = screen.add{type = "frame", name = "diplomacy_frame", caption = {"mod-name.diplomacy"}, direction = "vertical"} frame.visible = true - frame.auto_center = true - flow.add{type = "empty-widget", drag_target = frame} + frame.location = {x = 0, y = 50} + screen.add{type = "empty-widget", drag_target = frame} local player_settings = global.diplomacy.players[player.index] local table_settings = frame.add{type = "table", name = 'settings', column_count = 4} table_settings.add{type = "label", caption = {"", {"diplomacy.gui.show_players_state"}, {"colon"}}} @@ -269,4 +290,4 @@ diplomacy_frame.create = function(player) diplomacy_frame.fill(player) end -return diplomacy_frame \ No newline at end of file +return diplomacy_frame diff --git a/diplomacy/gui/frames/diplomacy_selection.lua b/diplomacy/gui/frames/diplomacy_selection.lua index 8c5acef..2bae357 100644 --- a/diplomacy/gui/frames/diplomacy_selection.lua +++ b/diplomacy/gui/frames/diplomacy_selection.lua @@ -23,6 +23,7 @@ diplomacy_selection_frame.destroy = function(player) end end +-- TODO: improve diplomacy_selection_frame.create = function(force, int_force_name, stance) local diplomacy = global.diplomacy local selected_players @@ -33,7 +34,8 @@ diplomacy_selection_frame.create = function(force, int_force_name, stance) end if selected_players == nil then return end - for _, player in pairs(selected_players) do + for i=1, #selected_players do + local player = selected_players[i] local gui = player.gui.left diplomacy_selection_frame.destroy(player) local frame = gui.add{type = "frame", name = "diplomacy_selection_frame", caption = {stance}} diff --git a/info.json b/info.json index 450e345..483a1ec 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "diplomacy", - "version": "2.12.0", + "version": "2.12.1", "factorio_version": "1.1", "title": "Diplomacy", "author": "ZwerOxotnik",