Skip to content

Commit

Permalink
Update to 2.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ZwerOxotnik committed Mar 11, 2022
1 parent 2a056ce commit 6e339ed
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 50 deletions.
14 changes: 14 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
---------------------------------------------------------------------------------------------------
Version: 2.13.0
Date: 2022-03-11
Locale:
- Updated French translation (thanks to @daikyraraga (DaiKy RaRaga) on crowdin)
- Updated French translation (thanks to @Wiwiweb on crowdin)
- Translations: https://crowdin.com/project/factorio-mods-localization (thank you for contributions, I really appreciate it)
Bugfixes:
- Fixed potential incompatibility with some
Changes:
- Changed icon color of diplomacy
Scripting:
- Renamed button name "diplomacy_button" to "ZD_diplomacy_button"
- Renamed button style "diplomacy_button" to "ZD_diplomacy_button"
---------------------------------------------------------------------------------------------------
Version: 2.12.2
Date: 2021-01-09
Locale:
Expand Down
10 changes: 5 additions & 5 deletions data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ end
local styles = data.raw["gui-style"].default
local slot_button = styles.slot_button

styles.diplomacy_button = {
styles.ZD_diplomacy_button = {
type = "button_style",
parent = "slot_button",
tooltip = "mod-name.diplomacy",
default_graphical_set = deepcopy(slot_button.default_graphical_set),
hovered_graphical_set = deepcopy(slot_button.hovered_graphical_set),
clicked_graphical_set = deepcopy(slot_button.clicked_graphical_set)
}
local diplomacy_button = styles.diplomacy_button
diplomacy_button.default_graphical_set.glow = {
local ZD_diplomacy_button = styles.ZD_diplomacy_button
ZD_diplomacy_button.default_graphical_set.glow = {
top_outer_border_shift = 4,
bottom_outer_border_shift = -4,
left_outer_border_shift = 4,
Expand All @@ -51,13 +51,13 @@ diplomacy_button.default_graphical_set.glow = {
size = 32,
scale = 1
}
diplomacy_button.hovered_graphical_set.glow.center = {
ZD_diplomacy_button.hovered_graphical_set.glow.center = {
filename = "__diplomacy__/graphics/diplomacy_black.png",
flags = {"gui-icon"},
size = 32,
scale = 1
}
diplomacy_button.clicked_graphical_set.glow = {
ZD_diplomacy_button.clicked_graphical_set.glow = {
top_outer_border_shift = 2,
bottom_outer_border_shift = -2,
left_outer_border_shift = 2,
Expand Down
2 changes: 1 addition & 1 deletion diplomacy/commands.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--[[
Copyright 2018-2021 ZwerOxotnik <zweroxotnik@gmail.com>
Copyright 2018-2022 ZwerOxotnik <zweroxotnik@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
69 changes: 39 additions & 30 deletions diplomacy/control.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--[[
Copyright 2018-2021 ZwerOxotnik <zweroxotnik@gmail.com>
Copyright 2018-2022 ZwerOxotnik <zweroxotnik@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -22,9 +22,9 @@ limitations under the License.
local color_map = require("diplomacy/color_map")
local set_politice = require("diplomacy/util").set_politice
local destroy_diplomacy_selection_frame = require("diplomacy/gui/frames/diplomacy_selection").destroy
local update_diplomacy_frame = require("diplomacy/gui/frames/diplomacy").update
local select_diplomacy = require("diplomacy/gui/select_diplomacy")
local confirm_diplomacy = require("diplomacy/gui/confirm_diplomacy")
local DIPLOMACY_FRAME = require("diplomacy/gui/frames/diplomacy")
local mod_gui = require("mod-gui")

local mod = {}
Expand Down Expand Up @@ -59,23 +59,23 @@ local diplomacy_HP_forbidden_entity_on_mined = settings.global["diplomacy_HP_for


local function destroy_button(player)
local diplomacy_button = player.gui.relative.diplomacy_button
local diplomacy_button = player.gui.relative.ZD_diplomacy_button
if diplomacy_button then
diplomacy_button.destroy()
end
end

local function create_button(player)
local relative = player.gui.relative
if relative.diplomacy_button then
if relative.ZD_diplomacy_button then
return
end

local left_anchor = {gui = defines.relative_gui_type.controller_gui, position = defines.relative_gui_position.left}
relative.add{
type = "sprite-button",
name = "diplomacy_button",
style = "diplomacy_button", -- see data.lua
name = "ZD_diplomacy_button",
style = "ZD_diplomacy_button", -- see data.lua
anchor = left_anchor
}
end
Expand Down Expand Up @@ -266,7 +266,7 @@ local STATE_GUIS = {
end,
["d_show_players_state"] = function(event, player, element)
global.diplomacy.players[event.player_index].show_players_state = element.state
update_diplomacy_frame(player)
DIPLOMACY_FRAME.update(player)
end,
}
local function on_gui_checked_state_changed(event)
Expand All @@ -278,14 +278,11 @@ local function on_gui_selection_state_changed(event)
if event.element.name == "d_filter_of_diplomacy_stance" then
local player = game.get_player(event.player_index)
global.diplomacy.players[event.player_index].filter_of_diplomacy_stance = event.element.selected_index
update_diplomacy_frame(player)
DIPLOMACY_FRAME.update(player)
end
end


local GUIS = {
diplomacy_button = select_diplomacy.diplomacy_button_press
}
local DEEP_GUIS = {
["mod_gui_inner_frame"] = function(element, player, event)
select_diplomacy.on_gui_click(event)
Expand All @@ -303,11 +300,17 @@ local DEEP_GUIS = {
-- TODO: refactor
local function on_gui_click(event)
local element = event.element
local f = GUIS[element.name]
if f then f(event) return end
if not (element and element.valid) then return end

f = DEEP_GUIS[element.parent.name]
if f then f(element, game.get_player(event.player_index), event) end
if element.name == "ZD_diplomacy_button" then
local player = game.get_player(event.player_index)
DIPLOMACY_FRAME.create(player)
else
f = DEEP_GUIS[element.parent.name]
if f then
f(element, game.get_player(event.player_index), event)
end
end
end

local function on_player_changed_force(event)
Expand All @@ -317,15 +320,15 @@ local function on_player_changed_force(event)
-- between "on_player_changed_force" and "on_forces_merging" and "on_forces_merged"

destroy_diplomacy_selection_frame(player)
update_diplomacy_frame()
DIPLOMACY_FRAME.update()
end

-- local function on_forces_merging(event)
-- for _, player in pairs(event.source.players) do
-- destroy_diplomacy_selection_frame(player)
-- end

-- update_diplomacy_frame()
-- DIPLOMACY_FRAME.update()
-- end


Expand All @@ -334,7 +337,7 @@ local mod_settings = {
global.diplomacy.who_decides_diplomacy = value
end,
["diplomacy_visible_all_teams"] = function(value)
update_diplomacy_frame()
DIPLOMACY_FRAME.update()
end,
["diplomacy_HP_forbidden_entity_on_killed"] = function(value)
diplomacy_HP_forbidden_entity_on_killed = value
Expand Down Expand Up @@ -405,7 +408,7 @@ local function on_force_created(event)
local force = event.force
if not (force and force.valid) then return end

update_diplomacy_frame()
DIPLOMACY_FRAME.update()
end

local function update_global_data()
Expand Down Expand Up @@ -436,13 +439,19 @@ mod.on_configuration_changed = function(event)

local version = tonumber(string.gmatch(mod_changes.old_version, "%d+.%d+")())

if version < 2.12 then
if version < 2.13 then
for _, player in pairs(game.players) do
local diplomacy_button = mod_gui.get_button_flow(player).diplomacy_button
if diplomacy_button then
diplomacy_button.destroy()
if player.valid then
local diplomacy_button = mod_gui.get_button_flow(player).diplomacy_button
if diplomacy_button then
diplomacy_button.destroy()
end
diplomacy_button = player.gui.relative.diplomacy_button
if diplomacy_button then
diplomacy_button.destroy()
end
create_button(player)
end
create_button(player)
end
end
end
Expand All @@ -452,15 +461,15 @@ local function on_player_joined_game(event)
local player = game.get_player(event.player_index)
if not (player and player.valid) then return end

update_diplomacy_frame()
DIPLOMACY_FRAME.update()
end

-- local function on_forces_merged(event)

-- end

local function on_player_removed(event)
update_diplomacy_frame()
DIPLOMACY_FRAME.update()
global.diplomacy.players[event.player_index] = nil
end

Expand Down Expand Up @@ -516,7 +525,7 @@ mod.add_remote_interface = function()
end,
set_locked_teams = function(bool)
global.diplomacy.locked_teams = bool
update_diplomacy_frame()
DIPLOMACY_FRAME.update()
end
})
end
Expand All @@ -532,12 +541,12 @@ mod.events[defines.events.on_player_created] = on_player_created
mod.events[defines.events.on_player_left_game] = on_player_left_game
mod.events[defines.events.on_player_removed] = on_player_removed
mod.events[defines.events.on_player_joined_game] = on_player_joined_game
mod.events[defines.events.on_gui_click] = function(e) pcall(on_gui_click, e) end
mod.events[defines.events.on_gui_click] = on_gui_click
mod.events[defines.events.on_gui_checked_state_changed] = function(e) pcall(on_gui_checked_state_changed, e) end
mod.events[defines.events.on_runtime_mod_setting_changed] = on_runtime_mod_setting_changed
mod.events[defines.events.on_force_created] = on_force_created
-- mod.events[defines.events.on_force_friends_changed] = update_diplomacy_frame -- TODO: test it thoroughly
-- mod.events[defines.events.on_force_cease_fire_changed] = update_diplomacy_frame -- TODO: test it thoroughly
-- mod.events[defines.events.on_force_friends_changed] = DIPLOMACY_FRAME.update -- TODO: test it thoroughly
-- mod.events[defines.events.on_force_cease_fire_changed] = DIPLOMACY_FRAME.update -- TODO: test it thoroughly
mod.events[defines.events.on_gui_selection_state_changed] = function(e) pcall(on_gui_selection_state_changed, e) end
-- mod.events[defines.events.on_forces_merged] = on_forces_merged

Expand Down
2 changes: 1 addition & 1 deletion diplomacy/gui/confirm_diplomacy.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--[[
Copyright 2018-2021 ZwerOxotnik <zweroxotnik@gmail.com>
Copyright 2018-2022 ZwerOxotnik <zweroxotnik@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion diplomacy/gui/frames/diplomacy.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--[[
Copyright 2018-2021 ZwerOxotnik <zweroxotnik@gmail.com>
Copyright 2018-2022 ZwerOxotnik <zweroxotnik@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion diplomacy/gui/frames/diplomacy_selection.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--[[
Copyright 2018-2021 ZwerOxotnik <zweroxotnik@gmail.com>
Copyright 2018-2022 ZwerOxotnik <zweroxotnik@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
9 changes: 1 addition & 8 deletions diplomacy/gui/select_diplomacy.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--[[
Copyright 2018-2021 ZwerOxotnik <zweroxotnik@gmail.com>
Copyright 2018-2022 ZwerOxotnik <zweroxotnik@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,6 @@ local destroy_diplomacy_selection_frame = require("diplomacy/gui/frames/diplomac
local cancel_request_diplomacy_force = require("diplomacy/util").cancel_request_diplomacy_force
local get_stance_diplomacy_type = require("diplomacy/util").get_stance_diplomacy_type
local update_diplomacy_frame = require("diplomacy/gui/frames/diplomacy").update
local create_diplomacy_frame = require("diplomacy/gui/frames/diplomacy").create
local create_diplomacy_selection_frame = require("diplomacy/gui/frames/diplomacy_selection").create

local function confirm_diplomacy(event)
Expand Down Expand Up @@ -85,12 +84,6 @@ end

local select_diplomacy = {}

-- TODO: refactor
select_diplomacy.diplomacy_button_press = function(event)
local player = game.get_player(event.player_index)
create_diplomacy_frame(player)
end

select_diplomacy.diplomacy_check_press = function(event)
local gui = event.element
if not gui.valid then return end
Expand Down
2 changes: 1 addition & 1 deletion diplomacy/util.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--[[
Copyright 2018-2021 ZwerOxotnik <zweroxotnik@gmail.com>
Copyright 2018-2022 ZwerOxotnik <zweroxotnik@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Binary file modified graphics/diplomacy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "diplomacy",
"version": "2.12.2",
"version": "2.13.0",
"factorio_version": "1.1",
"title": "Diplomacy",
"author": "ZwerOxotnik",
Expand Down
2 changes: 1 addition & 1 deletion libs.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--[[
Copyright 2018-2021 ZwerOxotnik <zweroxotnik@gmail.com>
Copyright 2018-2022 ZwerOxotnik <zweroxotnik@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down

0 comments on commit 6e339ed

Please sign in to comment.