Commit c6cb1d225c2d8359daa02931a226d972b9c4fe49
1 parent
25940b88
Bugfix 0.18.1 - based on first user feedback
Showing
8 changed files
with
167 additions
and
138 deletions
.gitignore
0 → 100644
1 | +calculator-ui_*.zip | ... | ... |
.vscode/launch.json
... | ... | @@ -11,6 +11,8 @@ |
11 | 11 | "modsPath": "C:/Program Files/Factorio/mods", |
12 | 12 | "configPath": "C:/Program Files/Factorio/config/config.ini", |
13 | 13 | "factorioPath": "C:/Program Files/Factorio/bin/x64/factorio.exe" |
14 | + // "hookSettings": true, | |
15 | + // "hookData": true | |
14 | 16 | } |
15 | 17 | ] |
16 | 18 | } |
17 | 19 | \ No newline at end of file | ... | ... |
CHANGELOG.md
... | ... | @@ -6,6 +6,15 @@ and this project adheres to the versioning of Factorio, so 0.18.x will be at lea |
6 | 6 | |
7 | 7 | ## [Released] |
8 | 8 | |
9 | +## [0.18.1] - 2020-06-06 | |
10 | +Based on user feedback updated the mod | |
11 | +### Added | |
12 | +- Shortcut for opening the calculator and automatically focus on the input (Default: Ctrl+Shift+C) | |
13 | + | |
14 | +### Fixed | |
15 | +- Rounding removed 0 at the end, will now stand as it should. So 2.0000001 -> 2.00 | |
16 | +- Interpreting "," as "." in the equation, because of some European countries do have a weird keyboard layout | |
17 | + | |
9 | 18 | ## [0.18.0] - 2020-06-06 |
10 | 19 | ### General |
11 | 20 | - Initial Release of the mod | ... | ... |
calcui-hotkey.lua
... | ... | @@ -2,14 +2,7 @@ data:extend({ |
2 | 2 | { |
3 | 3 | type = "custom-input", |
4 | 4 | name = "calcui_hotkey", |
5 | - key_sequence = "CONTROL + N", | |
6 | - consuming = "none" | |
7 | - }, | |
8 | - { | |
9 | - type = "custom-input", | |
10 | - name = "calcui_toggle", | |
11 | - key_sequence = "CONTROL + ENTER", | |
5 | + key_sequence = "CONTROL + SHIFT + C", | |
12 | 6 | consuming = "none" |
13 | 7 | } |
14 | -} | |
15 | -) | |
16 | 8 | \ No newline at end of file |
9 | +}) | |
17 | 10 | \ No newline at end of file | ... | ... |
calculator.lua
... | ... | @@ -29,135 +29,136 @@ end |
29 | 29 | -- ---------------------------------------------------------------- |
30 | 30 | function show_calculator(player) |
31 | 31 | local root = get_gui_root(player) |
32 | - destroy_calculator(player) | |
33 | - | |
34 | - local calcui = root.add({ | |
35 | - type = "frame", | |
36 | - name = "calcui", | |
37 | - style = "dialog_frame", | |
38 | - direction = "vertical" | |
39 | - }) | |
40 | - | |
41 | - local flow = calcui.add({ | |
42 | - type = "flow", | |
43 | - name = "calcui_flow" | |
44 | - }) | |
45 | - flow.style.horizontally_stretchable = "on" | |
46 | - | |
47 | - flow.add({ | |
48 | - type = "label", | |
49 | - caption = {"calculator-ui.title"}, | |
50 | - style = "frame_title" | |
51 | - }).drag_target = calcui | |
52 | - | |
53 | - local widget = flow.add({ | |
54 | - type = "empty-widget", | |
55 | - style = "draggable_space_header", | |
56 | - name = "calcui_drag" | |
57 | - }) | |
58 | - widget.drag_target = calcui | |
59 | - widget.style.horizontally_stretchable = "on" | |
60 | - widget.style.minimal_width = 24 | |
61 | - widget.style.natural_height = 24 | |
62 | - | |
63 | - flow.add({ | |
64 | - type = "sprite-button", | |
65 | - sprite = "utility/close_white", | |
66 | - style = "frame_action_button", | |
67 | - name = "calcui_close" | |
68 | - }) | |
69 | - | |
70 | - local table = calcui.add({ | |
71 | - type = "table", | |
72 | - name = "calcui_table", | |
73 | - column_count = "2", | |
74 | - vertical_centering = "false" | |
75 | - }) | |
76 | - | |
77 | - local col1 = table.add({ | |
78 | - type = "flow", | |
79 | - name = "calcui_table_col1", | |
80 | - direction = "vertical" | |
81 | - }) | |
82 | - | |
83 | - local display = col1.add({ | |
84 | - type = "textfield", | |
85 | - style = "calcui_textfield_style", | |
86 | - caption = "", | |
87 | - name = "calcui_display" | |
88 | - }) | |
89 | 32 | |
90 | - local row1 = col1.add({type="flow", name="calcui_col1_row1", direction="horizontal"}) | |
91 | - row1.add({type="button", style="calcui_button_style", caption="CE", name="calcui_button_CE"}) -- CE = Clear Entry (just this line) | |
92 | - row1.add({type="button", style="calcui_button_style", caption="C", name="calcui_button_C"}) -- C = Clear (all, past results as well) | |
93 | - row1.add({type="button", style="calcui_button_style", caption="BS", name="calcui_button_BS"}) | |
94 | - row1.add({type="button", style="calcui_button_style", caption="/", name="calcui_button_DIV"}) | |
33 | + if not root.calcui then | |
34 | + local calcui = root.add({ | |
35 | + type = "frame", | |
36 | + name = "calcui", | |
37 | + style = "dialog_frame", | |
38 | + direction = "vertical" | |
39 | + }) | |
40 | + | |
41 | + local flow = calcui.add({ | |
42 | + type = "flow", | |
43 | + name = "calcui_flow" | |
44 | + }) | |
45 | + flow.style.horizontally_stretchable = "on" | |
46 | + | |
47 | + flow.add({ | |
48 | + type = "label", | |
49 | + caption = {"calculator-ui.title"}, | |
50 | + style = "frame_title" | |
51 | + }).drag_target = calcui | |
52 | + | |
53 | + local widget = flow.add({ | |
54 | + type = "empty-widget", | |
55 | + style = "draggable_space_header", | |
56 | + name = "calcui_drag" | |
57 | + }) | |
58 | + widget.drag_target = calcui | |
59 | + widget.style.horizontally_stretchable = "on" | |
60 | + widget.style.minimal_width = 24 | |
61 | + widget.style.natural_height = 24 | |
62 | + | |
63 | + flow.add({ | |
64 | + type = "sprite-button", | |
65 | + sprite = "utility/close_white", | |
66 | + style = "frame_action_button", | |
67 | + name = "calcui_close" | |
68 | + }) | |
69 | + | |
70 | + local table = calcui.add({ | |
71 | + type = "table", | |
72 | + name = "calcui_table", | |
73 | + column_count = "2", | |
74 | + vertical_centering = "false" | |
75 | + }) | |
76 | + | |
77 | + local col1 = table.add({ | |
78 | + type = "flow", | |
79 | + name = "calcui_table_col1", | |
80 | + direction = "vertical" | |
81 | + }) | |
82 | + | |
83 | + local display = col1.add({ | |
84 | + type = "textfield", | |
85 | + style = "calcui_textfield_style", | |
86 | + caption = "", | |
87 | + name = "calcui_display" | |
88 | + }) | |
95 | 89 | |
96 | - local row2 = col1.add({type="flow", name="calcui_col1_row2", direction="horizontal"}) | |
97 | - row2.add({type="button", style="calcui_button_style", caption="7", name="calcui_button_7"}) | |
98 | - row2.add({type="button", style="calcui_button_style", caption="8", name="calcui_button_8"}) | |
99 | - row2.add({type="button", style="calcui_button_style", caption="9", name="calcui_button_9"}) | |
100 | - row2.add({type="button", style="calcui_button_style", caption="*", name="calcui_button_MUL"}) | |
90 | + local row1 = col1.add({type="flow", name="calcui_col1_row1", direction="horizontal"}) | |
91 | + row1.add({type="button", style="calcui_button_style", caption="CE", name="calcui_button_CE"}) -- CE = Clear Entry (just this line) | |
92 | + row1.add({type="button", style="calcui_button_style", caption="C", name="calcui_button_C"}) -- C = Clear (all, past results as well) | |
93 | + row1.add({type="button", style="calcui_button_style", caption="BS", name="calcui_button_BS"}) | |
94 | + row1.add({type="button", style="calcui_button_style", caption="/", name="calcui_button_DIV"}) | |
101 | 95 | |
102 | - local row3 = col1.add({type="flow", name="calcui_col1_row3", direction="horizontal"}) | |
103 | - row3.add({type="button", style="calcui_button_style", caption="4", name="calcui_button_4"}) | |
104 | - row3.add({type="button", style="calcui_button_style", caption="5", name="calcui_button_5"}) | |
105 | - row3.add({type="button", style="calcui_button_style", caption="6", name="calcui_button_6"}) | |
106 | - row3.add({type="button", style="calcui_button_style", caption="-", name="calcui_button_SUB"}) | |
96 | + local row2 = col1.add({type="flow", name="calcui_col1_row2", direction="horizontal"}) | |
97 | + row2.add({type="button", style="calcui_button_style", caption="7", name="calcui_button_7"}) | |
98 | + row2.add({type="button", style="calcui_button_style", caption="8", name="calcui_button_8"}) | |
99 | + row2.add({type="button", style="calcui_button_style", caption="9", name="calcui_button_9"}) | |
100 | + row2.add({type="button", style="calcui_button_style", caption="*", name="calcui_button_MUL"}) | |
107 | 101 | |
108 | - local row4 = col1.add({type="flow", name="calcui_col1_row4", direction="horizontal"}) | |
109 | - row4.add({type="button", style="calcui_button_style", caption="1", name="calcui_button_1"}) | |
110 | - row4.add({type="button", style="calcui_button_style", caption="2", name="calcui_button_2"}) | |
111 | - row4.add({type="button", style="calcui_button_style", caption="3", name="calcui_button_3"}) | |
112 | - row4.add({type="button", style="calcui_button_style", caption="+", name="calcui_button_ADD"}) | |
102 | + local row3 = col1.add({type="flow", name="calcui_col1_row3", direction="horizontal"}) | |
103 | + row3.add({type="button", style="calcui_button_style", caption="4", name="calcui_button_4"}) | |
104 | + row3.add({type="button", style="calcui_button_style", caption="5", name="calcui_button_5"}) | |
105 | + row3.add({type="button", style="calcui_button_style", caption="6", name="calcui_button_6"}) | |
106 | + row3.add({type="button", style="calcui_button_style", caption="-", name="calcui_button_SUB"}) | |
113 | 107 | |
114 | - local row5 = col1.add({type="flow", name="calcui_col1_row5", direction="horizontal"}) | |
115 | - row5.add({type="button", style="calcui_button_style", caption="%", name="calcui_button_PERC"}) | |
116 | - row5.add({type="button", style="calcui_button_style", caption="0", name="calcui_button_0"}) | |
117 | - row5.add({type="button", style="calcui_button_style", caption=".", name="calcui_button_DOT"}) | |
118 | - row5.add({type="button", style="calcui_button_style", caption="=", name="calcui_button_EQU"}) | |
108 | + local row4 = col1.add({type="flow", name="calcui_col1_row4", direction="horizontal"}) | |
109 | + row4.add({type="button", style="calcui_button_style", caption="1", name="calcui_button_1"}) | |
110 | + row4.add({type="button", style="calcui_button_style", caption="2", name="calcui_button_2"}) | |
111 | + row4.add({type="button", style="calcui_button_style", caption="3", name="calcui_button_3"}) | |
112 | + row4.add({type="button", style="calcui_button_style", caption="+", name="calcui_button_ADD"}) | |
119 | 113 | |
114 | + local row5 = col1.add({type="flow", name="calcui_col1_row5", direction="horizontal"}) | |
115 | + row5.add({type="button", style="calcui_button_style", caption="%", name="calcui_button_PERC"}) | |
116 | + row5.add({type="button", style="calcui_button_style", caption="0", name="calcui_button_0"}) | |
117 | + row5.add({type="button", style="calcui_button_style", caption=".", name="calcui_button_DOT"}) | |
118 | + row5.add({type="button", style="calcui_button_style", caption="=", name="calcui_button_EQU"}) | |
120 | 119 | |
121 | - local col2 = table.add({ | |
122 | - type = "flow", | |
123 | - name = "calcui_table_col2", | |
124 | - direction = "vertical" | |
125 | - }) | |
126 | 120 | |
127 | - local result = col2.add({ | |
128 | - type = "label", | |
129 | - caption = "= ", | |
130 | - name = "calcui_display_result" | |
131 | - }) | |
132 | - result.style.font = "default-large" | |
133 | - | |
134 | - local rant = col2.add({ | |
135 | - type = "sprite", | |
136 | - name = "calcui_rant" | |
137 | - }) | |
138 | - | |
139 | - col2.add({ | |
140 | - type = "line", | |
141 | - direction = "horizontal" | |
142 | - }) | |
143 | - | |
144 | - local scroll = col2.add({ | |
145 | - type = "scroll-pane", | |
146 | - name = "calcui_scroll_pane" | |
147 | - }) | |
148 | - scroll.style.height = 252 | |
149 | - | |
150 | - local recents = scroll.add({ | |
151 | - type = "table", | |
152 | - caption = "", | |
153 | - name = "calcui_result_table", | |
154 | - column_count = "2" | |
155 | - }) | |
156 | - recents.style.column_alignments[1] = "right" | |
157 | - | |
158 | - | |
159 | - -- center the gui | |
160 | - calcui.force_auto_center() | |
121 | + local col2 = table.add({ | |
122 | + type = "flow", | |
123 | + name = "calcui_table_col2", | |
124 | + direction = "vertical" | |
125 | + }) | |
126 | + | |
127 | + local result = col2.add({ | |
128 | + type = "label", | |
129 | + caption = "= ", | |
130 | + name = "calcui_display_result" | |
131 | + }) | |
132 | + result.style.font = "default-large" | |
133 | + | |
134 | + local rant = col2.add({ | |
135 | + type = "sprite", | |
136 | + name = "calcui_rant" | |
137 | + }) | |
138 | + | |
139 | + col2.add({ | |
140 | + type = "line", | |
141 | + direction = "horizontal" | |
142 | + }) | |
143 | + | |
144 | + local scroll = col2.add({ | |
145 | + type = "scroll-pane", | |
146 | + name = "calcui_scroll_pane" | |
147 | + }) | |
148 | + scroll.style.height = 252 | |
149 | + | |
150 | + local recents = scroll.add({ | |
151 | + type = "table", | |
152 | + caption = "", | |
153 | + name = "calcui_result_table", | |
154 | + column_count = "2" | |
155 | + }) | |
156 | + recents.style.column_alignments[1] = "right" | |
157 | + | |
158 | + | |
159 | + -- center the gui | |
160 | + calcui.force_auto_center() | |
161 | + end | |
161 | 162 | end |
162 | 163 | |
163 | 164 | -- ---------------------------------------------------------------- |
... | ... | @@ -176,6 +177,12 @@ function toggle_calculator(player) |
176 | 177 | end |
177 | 178 | |
178 | 179 | -- ---------------------------------------------------------------- |
180 | +function focus_on_input(player) | |
181 | + local root = get_gui_root(player) | |
182 | + root.calcui.calcui_table.calcui_table_col1.calcui_display.focus() | |
183 | +end | |
184 | + | |
185 | +-- ---------------------------------------------------------------- | |
179 | 186 | function clear_equation(player) |
180 | 187 | local root = get_gui_root(player) |
181 | 188 | root.calcui.calcui_table.calcui_table_col1.calcui_display.text = "" |
... | ... | @@ -234,6 +241,9 @@ function fix_equation(equation) |
234 | 241 | -- fix percentage |
235 | 242 | result = result:gsub("(%%)", "/100") |
236 | 243 | |
244 | + -- fix danish keyboard | |
245 | + result = result:gsub(",", ".") | |
246 | + | |
237 | 247 | return result |
238 | 248 | end |
239 | 249 | |
... | ... | @@ -253,14 +263,18 @@ function process_equal_key(player, button) |
253 | 263 | return load("return " .. equation)() |
254 | 264 | end) |
255 | 265 | root.calcui.calcui_table.calcui_table_col2.calcui_display_result.tooltip = retval |
256 | - status, retval = pcall(function() | |
257 | - return tonumber(string.format("%." .. settings.get_player_settings(player)["calcui-decimal-places"].value .. "f", retval)) | |
266 | + status, retval_show = pcall(function() | |
267 | + local result = string.format("%0." .. settings.get_player_settings(player)["calcui-decimal-places"].value .. "f", retval) | |
268 | + if result:len() > tostring(retval):len() then | |
269 | + result = retval | |
270 | + end | |
271 | + return result | |
258 | 272 | end) |
259 | - if retval == nil or retval == "" then | |
273 | + if retval_show == nil or retval_show == "" then | |
260 | 274 | status = false |
261 | 275 | end |
262 | 276 | if not status then |
263 | - retval = "NaN" | |
277 | + retval_show = "NaN" | |
264 | 278 | show_rant(player, true) |
265 | 279 | else |
266 | 280 | if retval <= 0 then |
... | ... | @@ -269,7 +283,7 @@ function process_equal_key(player, button) |
269 | 283 | show_rant(player, false) |
270 | 284 | end |
271 | 285 | end |
272 | - root.calcui.calcui_table.calcui_table_col2.calcui_display_result.caption = "= " .. retval | |
286 | + root.calcui.calcui_table.calcui_table_col2.calcui_display_result.caption = "= " .. retval_show | |
273 | 287 | |
274 | 288 | -- only write in recent table if actually a result |
275 | 289 | if status then |
... | ... | @@ -370,7 +384,7 @@ function handle_calcui_click(event, player) |
370 | 384 | -- copy equation to display |
371 | 385 | local root = get_gui_root(player) |
372 | 386 | root.calcui.calcui_table.calcui_table_col1.calcui_display.text = root.calcui.calcui_table.calcui_table_col2.calcui_scroll_pane.calcui_result_table[event_name].caption |
373 | - root.calcui.calcui_table.calcui_table_col1.calcui_display.focus() | |
387 | + focus_on_input(player) | |
374 | 388 | end |
375 | 389 | end |
376 | 390 | end | ... | ... |
control.lua
... | ... | @@ -86,7 +86,14 @@ local function on_calcui_command(event) |
86 | 86 | end |
87 | 87 | |
88 | 88 | -- ---------------------------------------------------------------- |
89 | ---script.on_event( "calcui_hotkey", on_hotkey_main ) | |
89 | +local function on_hotkey_main(event) | |
90 | + local player = game.players[event.player_index] | |
91 | + show_calculator(player) | |
92 | + focus_on_input(player) | |
93 | +end | |
94 | + | |
95 | +-- ---------------------------------------------------------------- | |
96 | +script.on_event( "calcui_hotkey", on_hotkey_main ) | |
90 | 97 | script.on_event( defines.events.on_lua_shortcut, shortcut ) |
91 | 98 | script.on_event( defines.events.on_gui_click, on_gui_click) |
92 | 99 | script.on_event( defines.events.on_gui_confirmed, on_gui_confirmed) | ... | ... |
info.json