From ae0df041b2d7aa56f38942310aacdf54b28b0980 Mon Sep 17 00:00:00 2001 From: Wichu Date: Sun, 7 Jun 2020 21:28:45 +0200 Subject: [PATCH] Fixed multiplayer issue when dragging the window. Now the UI won't auto center anymore after moved. If moved out of bounds, it will return fully in sight. --- CHANGELOG.md | 11 +++++++++++ calculator.lua | 46 +++++++++++++++++++++++++++++++++++++++------- info.json | 2 +- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa92e67..9317d24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,17 @@ and this project adheres to the versioning of Factorio, so 0.18.x will be at lea ## [Released] +## [0.18.4] - 2020-06-07 +### General +Based onyuser feedback updated the mod + +### Changed +- Window now remember last location when opened + +### Fixed +- On multiplayer session the window would lag behind while dragging, because the location would be saved on server. This isn't going to happen anymore, hopefully (not tested yet). +- When window is moved out of boundaries, when reopened, it will correct itself to be fully in sight again. + ## [0.18.3] - 2020-06-07 ### General A small visual overhaul of the mod diff --git a/calculator.lua b/calculator.lua index 1940ac1..aa5f15f 100644 --- a/calculator.lua +++ b/calculator.lua @@ -40,6 +40,28 @@ local function destroy_calculator(player) end -- ---------------------------------------------------------------- +function fix_oob_ui(player) + if global.gui_position[player.index].x < 0 then + global.gui_position[player.index].x = 0 + end + if global.gui_position[player.index].y < 0 then + global.gui_position[player.index].y = 0 + end + + -- TODO fixed box size, because there is no API call for that + local width = 255 + local height = 350 + + if global.gui_position[player.index].x + width > player.display_resolution.width then + global.gui_position[player.index].x = player.display_resolution.width - width + end + if global.gui_position[player.index].y + height > player.display_resolution.height then + global.gui_position[player.index].y = player.display_resolution.height - height + end + --global.gui_position[player.index] +end + +-- ---------------------------------------------------------------- function show_calculator(player) local root = get_gui_root(player) @@ -130,8 +152,6 @@ function show_calculator(player) row5.add({type="sprite-button", style="calcui_button_style_dark", caption=".", name="calcui_button_DOT"}).sprite = "sprite_calcui_dark" row5.add({type="sprite-button", style="calcui_button_style_red", caption="=", name="calcui_button_EQU"}).sprite = "sprite_calcui_red" - --.sprite = "sprite_calcui_dark" - local col2 = table.add({ type = "flow", name = "calcui_table_col2", @@ -170,8 +190,18 @@ function show_calculator(player) recents.style.column_alignments[1] = "right" - -- center the gui - calcui.force_auto_center() + -- use last saved location or center the gui + if not global.gui_position then + global.gui_position = {} + end + if global.gui_position[player.index] then + -- fix weird saved positions (out of reach) + fix_oob_ui(player) + + calcui.location = global.gui_position[player.index] + else + calcui.force_auto_center() + end end end @@ -447,8 +477,10 @@ end -- ---------------------------------------------------------------- function calcui_on_gui_location_changed(event) if event.element.name == "calcui" then - local player = game.players[event.player_index] - local root = get_gui_root(player) - root.calcui.location = event.element.location + local root = get_gui_root(game.players[event.player_index]) + if not global.gui_position then + global.gui_position = {} + end + global.gui_position[event.player_index] = event.element.location end end \ No newline at end of file diff --git a/info.json b/info.json index 1672cd0..ed26d3f 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "calculator-ui", - "version": "0.18.3", + "version": "0.18.4", "title": "Calculator UI", "author": "Wichu", "factorio_version": "0.18", -- libgit2 0.22.2