Commit ae0df041b2d7aa56f38942310aacdf54b28b0980
1 parent
8595b9ad
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.
Showing
3 changed files
with
51 additions
and
8 deletions
CHANGELOG.md
| @@ -6,6 +6,17 @@ and this project adheres to the versioning of Factorio, so 0.18.x will be at lea | @@ -6,6 +6,17 @@ and this project adheres to the versioning of Factorio, so 0.18.x will be at lea | ||
| 6 | 6 | ||
| 7 | ## [Released] | 7 | ## [Released] |
| 8 | 8 | ||
| 9 | +## [0.18.4] - 2020-06-07 | ||
| 10 | +### General | ||
| 11 | +Based onyuser feedback updated the mod | ||
| 12 | + | ||
| 13 | +### Changed | ||
| 14 | +- Window now remember last location when opened | ||
| 15 | + | ||
| 16 | +### Fixed | ||
| 17 | +- 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). | ||
| 18 | +- When window is moved out of boundaries, when reopened, it will correct itself to be fully in sight again. | ||
| 19 | + | ||
| 9 | ## [0.18.3] - 2020-06-07 | 20 | ## [0.18.3] - 2020-06-07 |
| 10 | ### General | 21 | ### General |
| 11 | A small visual overhaul of the mod | 22 | A small visual overhaul of the mod |
calculator.lua
| @@ -40,6 +40,28 @@ local function destroy_calculator(player) | @@ -40,6 +40,28 @@ local function destroy_calculator(player) | ||
| 40 | end | 40 | end |
| 41 | 41 | ||
| 42 | -- ---------------------------------------------------------------- | 42 | -- ---------------------------------------------------------------- |
| 43 | +function fix_oob_ui(player) | ||
| 44 | + if global.gui_position[player.index].x < 0 then | ||
| 45 | + global.gui_position[player.index].x = 0 | ||
| 46 | + end | ||
| 47 | + if global.gui_position[player.index].y < 0 then | ||
| 48 | + global.gui_position[player.index].y = 0 | ||
| 49 | + end | ||
| 50 | + | ||
| 51 | + -- TODO fixed box size, because there is no API call for that | ||
| 52 | + local width = 255 | ||
| 53 | + local height = 350 | ||
| 54 | + | ||
| 55 | + if global.gui_position[player.index].x + width > player.display_resolution.width then | ||
| 56 | + global.gui_position[player.index].x = player.display_resolution.width - width | ||
| 57 | + end | ||
| 58 | + if global.gui_position[player.index].y + height > player.display_resolution.height then | ||
| 59 | + global.gui_position[player.index].y = player.display_resolution.height - height | ||
| 60 | + end | ||
| 61 | + --global.gui_position[player.index] | ||
| 62 | +end | ||
| 63 | + | ||
| 64 | +-- ---------------------------------------------------------------- | ||
| 43 | function show_calculator(player) | 65 | function show_calculator(player) |
| 44 | local root = get_gui_root(player) | 66 | local root = get_gui_root(player) |
| 45 | 67 | ||
| @@ -130,8 +152,6 @@ function show_calculator(player) | @@ -130,8 +152,6 @@ function show_calculator(player) | ||
| 130 | row5.add({type="sprite-button", style="calcui_button_style_dark", caption=".", name="calcui_button_DOT"}).sprite = "sprite_calcui_dark" | 152 | row5.add({type="sprite-button", style="calcui_button_style_dark", caption=".", name="calcui_button_DOT"}).sprite = "sprite_calcui_dark" |
| 131 | row5.add({type="sprite-button", style="calcui_button_style_red", caption="=", name="calcui_button_EQU"}).sprite = "sprite_calcui_red" | 153 | row5.add({type="sprite-button", style="calcui_button_style_red", caption="=", name="calcui_button_EQU"}).sprite = "sprite_calcui_red" |
| 132 | 154 | ||
| 133 | - --.sprite = "sprite_calcui_dark" | ||
| 134 | - | ||
| 135 | local col2 = table.add({ | 155 | local col2 = table.add({ |
| 136 | type = "flow", | 156 | type = "flow", |
| 137 | name = "calcui_table_col2", | 157 | name = "calcui_table_col2", |
| @@ -170,8 +190,18 @@ function show_calculator(player) | @@ -170,8 +190,18 @@ function show_calculator(player) | ||
| 170 | recents.style.column_alignments[1] = "right" | 190 | recents.style.column_alignments[1] = "right" |
| 171 | 191 | ||
| 172 | 192 | ||
| 173 | - -- center the gui | ||
| 174 | - calcui.force_auto_center() | 193 | + -- use last saved location or center the gui |
| 194 | + if not global.gui_position then | ||
| 195 | + global.gui_position = {} | ||
| 196 | + end | ||
| 197 | + if global.gui_position[player.index] then | ||
| 198 | + -- fix weird saved positions (out of reach) | ||
| 199 | + fix_oob_ui(player) | ||
| 200 | + | ||
| 201 | + calcui.location = global.gui_position[player.index] | ||
| 202 | + else | ||
| 203 | + calcui.force_auto_center() | ||
| 204 | + end | ||
| 175 | end | 205 | end |
| 176 | end | 206 | end |
| 177 | 207 | ||
| @@ -447,8 +477,10 @@ end | @@ -447,8 +477,10 @@ end | ||
| 447 | -- ---------------------------------------------------------------- | 477 | -- ---------------------------------------------------------------- |
| 448 | function calcui_on_gui_location_changed(event) | 478 | function calcui_on_gui_location_changed(event) |
| 449 | if event.element.name == "calcui" then | 479 | if event.element.name == "calcui" then |
| 450 | - local player = game.players[event.player_index] | ||
| 451 | - local root = get_gui_root(player) | ||
| 452 | - root.calcui.location = event.element.location | 480 | + local root = get_gui_root(game.players[event.player_index]) |
| 481 | + if not global.gui_position then | ||
| 482 | + global.gui_position = {} | ||
| 483 | + end | ||
| 484 | + global.gui_position[event.player_index] = event.element.location | ||
| 453 | end | 485 | end |
| 454 | end | 486 | end |
| 455 | \ No newline at end of file | 487 | \ No newline at end of file |