Commit 2de482165862fe94791c77a01d1e0f3b8b6d1e4c
1 parent
ae0df041
Version 0.18.4 published
Showing
6 changed files
with
161 additions
and
112 deletions
CHANGELOG.md
@@ -8,14 +8,22 @@ and this project adheres to the versioning of Factorio, so 0.18.x will be at lea | @@ -8,14 +8,22 @@ and this project adheres to the versioning of Factorio, so 0.18.x will be at lea | ||
8 | 8 | ||
9 | ## [0.18.4] - 2020-06-07 | 9 | ## [0.18.4] - 2020-06-07 |
10 | ### General | 10 | ### General |
11 | -Based onyuser feedback updated the mod | 11 | +Based on user feedback updated the mod |
12 | + | ||
13 | +### Added | ||
14 | +- Added the possibility to copy the results (from recent and also the current) to the display | ||
12 | 15 | ||
13 | ### Changed | 16 | ### Changed |
14 | - Window now remember last location when opened | 17 | - Window now remember last location when opened |
18 | +- Updated the BS button (it's backspace people...) so it now has a nice icon instead of the letters | ||
19 | +- Recent results now add to the top, instead of the bottom | ||
20 | +- When calculator is opened it focues on the display for entering the equation | ||
21 | +- You can click pretty much anywhere now and it focues on the display for entering the equation | ||
15 | 22 | ||
16 | ### Fixed | 23 | ### 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). | 24 | - 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. | 25 | - When window is moved out of boundaries, when reopened, it will correct itself to be fully in sight again. |
26 | +- Settings had weird default values (were set 2 times) | ||
19 | 27 | ||
20 | ## [0.18.3] - 2020-06-07 | 28 | ## [0.18.3] - 2020-06-07 |
21 | ### General | 29 | ### General |
calcui-styles.lua
@@ -53,6 +53,13 @@ data:extend({ | @@ -53,6 +53,13 @@ data:extend({ | ||
53 | }, | 53 | }, |
54 | { | 54 | { |
55 | type = "sprite", | 55 | type = "sprite", |
56 | + name = "sprite_calcui_backspace", | ||
57 | + filename = "__calculator-ui__/graphics/backspace.png", | ||
58 | + width = 50, | ||
59 | + height = 50 | ||
60 | + }, | ||
61 | + { | ||
62 | + type = "sprite", | ||
56 | name = "sprite_calcui_red", | 63 | name = "sprite_calcui_red", |
57 | filename = "__calculator-ui__/graphics/red.png", | 64 | filename = "__calculator-ui__/graphics/red.png", |
58 | width = 50, | 65 | width = 50, |
calculator.lua
@@ -6,9 +6,9 @@ local function get_gui_root(player) | @@ -6,9 +6,9 @@ local function get_gui_root(player) | ||
6 | end | 6 | end |
7 | 7 | ||
8 | -- ---------------------------------------------------------------- | 8 | -- ---------------------------------------------------------------- |
9 | -function show_think(player, enabled) | 9 | +local function show_think(player, enabled) |
10 | local root = get_gui_root(player) | 10 | local root = get_gui_root(player) |
11 | - | 11 | + |
12 | if enabled then | 12 | if enabled then |
13 | root.calcui.calcui_table.calcui_table_col2.calcui_rant.sprite = "sprite_calcui_think" | 13 | root.calcui.calcui_table.calcui_table_col2.calcui_rant.sprite = "sprite_calcui_think" |
14 | root.calcui.calcui_table.calcui_table_col2.calcui_scroll_pane.style.height = 196 | 14 | root.calcui.calcui_table.calcui_table_col2.calcui_scroll_pane.style.height = 196 |
@@ -19,9 +19,9 @@ function show_think(player, enabled) | @@ -19,9 +19,9 @@ function show_think(player, enabled) | ||
19 | end | 19 | end |
20 | 20 | ||
21 | -- ---------------------------------------------------------------- | 21 | -- ---------------------------------------------------------------- |
22 | -function show_rant(player, enabled) | 22 | +local function show_rant(player, enabled) |
23 | local root = get_gui_root(player) | 23 | local root = get_gui_root(player) |
24 | - | 24 | + |
25 | if enabled then | 25 | if enabled then |
26 | root.calcui.calcui_table.calcui_table_col2.calcui_rant.sprite = "sprite_calcui_rant" | 26 | root.calcui.calcui_table.calcui_table_col2.calcui_rant.sprite = "sprite_calcui_rant" |
27 | root.calcui.calcui_table.calcui_table_col2.calcui_scroll_pane.style.height = 196 | 27 | root.calcui.calcui_table.calcui_table_col2.calcui_scroll_pane.style.height = 196 |
@@ -40,7 +40,7 @@ local function destroy_calculator(player) | @@ -40,7 +40,7 @@ local function destroy_calculator(player) | ||
40 | end | 40 | end |
41 | 41 | ||
42 | -- ---------------------------------------------------------------- | 42 | -- ---------------------------------------------------------------- |
43 | -function fix_oob_ui(player) | 43 | +local function fix_oob_ui(player) |
44 | if global.gui_position[player.index].x < 0 then | 44 | if global.gui_position[player.index].x < 0 then |
45 | global.gui_position[player.index].x = 0 | 45 | global.gui_position[player.index].x = 0 |
46 | end | 46 | end |
@@ -58,33 +58,40 @@ function fix_oob_ui(player) | @@ -58,33 +58,40 @@ function fix_oob_ui(player) | ||
58 | if global.gui_position[player.index].y + height > player.display_resolution.height then | 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 | 59 | global.gui_position[player.index].y = player.display_resolution.height - height |
60 | end | 60 | end |
61 | - --global.gui_position[player.index] | ||
62 | end | 61 | end |
63 | 62 | ||
64 | -- ---------------------------------------------------------------- | 63 | -- ---------------------------------------------------------------- |
65 | function show_calculator(player) | 64 | function show_calculator(player) |
66 | local root = get_gui_root(player) | 65 | local root = get_gui_root(player) |
67 | 66 | ||
67 | + if not global.recent_results then | ||
68 | + global.recent_results = {} | ||
69 | + if not global.recent_results[player.index] then | ||
70 | + global.recent_results[player.index] = {} | ||
71 | + end | ||
72 | + end | ||
73 | + | ||
68 | if not root.calcui then | 74 | if not root.calcui then |
69 | local calcui = root.add({ | 75 | local calcui = root.add({ |
70 | - type = "frame", | ||
71 | - name = "calcui", | 76 | + type = "frame", |
77 | + name = "calcui", | ||
72 | style = "dialog_frame", | 78 | style = "dialog_frame", |
73 | direction = "vertical" | 79 | direction = "vertical" |
74 | }) | 80 | }) |
75 | - | 81 | + |
76 | local flow = calcui.add({ | 82 | local flow = calcui.add({ |
77 | - type = "flow", | 83 | + type = "flow", |
78 | name = "calcui_flow" | 84 | name = "calcui_flow" |
79 | }) | 85 | }) |
80 | flow.style.horizontally_stretchable = "on" | 86 | flow.style.horizontally_stretchable = "on" |
81 | - | 87 | + |
82 | flow.add({ | 88 | flow.add({ |
83 | - type = "label", | ||
84 | - caption = {"calculator-ui.title"}, | 89 | + type = "label", |
90 | + name = "calcui_title", | ||
91 | + caption = {"calculator-ui.title"}, | ||
85 | style = "frame_title" | 92 | style = "frame_title" |
86 | }).drag_target = calcui | 93 | }).drag_target = calcui |
87 | - | 94 | + |
88 | local widget = flow.add({ | 95 | local widget = flow.add({ |
89 | type = "empty-widget", | 96 | type = "empty-widget", |
90 | style = "draggable_space_header", | 97 | style = "draggable_space_header", |
@@ -94,30 +101,30 @@ function show_calculator(player) | @@ -94,30 +101,30 @@ function show_calculator(player) | ||
94 | widget.style.horizontally_stretchable = "on" | 101 | widget.style.horizontally_stretchable = "on" |
95 | widget.style.minimal_width = 24 | 102 | widget.style.minimal_width = 24 |
96 | widget.style.natural_height = 24 | 103 | widget.style.natural_height = 24 |
97 | - | 104 | + |
98 | flow.add({ | 105 | flow.add({ |
99 | - type = "sprite-button", | ||
100 | - sprite = "utility/close_white", | ||
101 | - style = "frame_action_button", | 106 | + type = "sprite-button", |
107 | + sprite = "utility/close_white", | ||
108 | + style = "frame_action_button", | ||
102 | name = "calcui_close" | 109 | name = "calcui_close" |
103 | }) | 110 | }) |
104 | - | 111 | + |
105 | local table = calcui.add({ | 112 | local table = calcui.add({ |
106 | - type = "table", | ||
107 | - name = "calcui_table", | ||
108 | - column_count = "2", | 113 | + type = "table", |
114 | + name = "calcui_table", | ||
115 | + column_count = "2", | ||
109 | vertical_centering = "false" | 116 | vertical_centering = "false" |
110 | }) | 117 | }) |
111 | - | 118 | + |
112 | local col1 = table.add({ | 119 | local col1 = table.add({ |
113 | - type = "flow", | ||
114 | - name = "calcui_table_col1", | 120 | + type = "flow", |
121 | + name = "calcui_table_col1", | ||
115 | direction = "vertical" | 122 | direction = "vertical" |
116 | }) | 123 | }) |
117 | - | 124 | + |
118 | local display = col1.add({ | 125 | local display = col1.add({ |
119 | - type = "textfield", | ||
120 | - caption = "", | 126 | + type = "textfield", |
127 | + caption = "", | ||
121 | name = "calcui_display" | 128 | name = "calcui_display" |
122 | }) | 129 | }) |
123 | display.style.width = 212 | 130 | display.style.width = 212 |
@@ -125,7 +132,7 @@ function show_calculator(player) | @@ -125,7 +132,7 @@ function show_calculator(player) | ||
125 | local row1 = col1.add({type="flow", name="calcui_col1_row1", direction="horizontal"}) | 132 | local row1 = col1.add({type="flow", name="calcui_col1_row1", direction="horizontal"}) |
126 | row1.add({type="sprite-button", style="calcui_button_style_light", caption="CE", name="calcui_button_CE"}).sprite = "sprite_calcui_light" -- CE = Clear Entry (just this line) | 133 | row1.add({type="sprite-button", style="calcui_button_style_light", caption="CE", name="calcui_button_CE"}).sprite = "sprite_calcui_light" -- CE = Clear Entry (just this line) |
127 | row1.add({type="sprite-button", style="calcui_button_style_light", caption="C", name="calcui_button_C"}).sprite = "sprite_calcui_light" -- C = Clear (all, past results as well) | 134 | row1.add({type="sprite-button", style="calcui_button_style_light", caption="C", name="calcui_button_C"}).sprite = "sprite_calcui_light" -- C = Clear (all, past results as well) |
128 | - row1.add({type="sprite-button", style="calcui_button_style_light", caption="BS", name="calcui_button_BS"}).sprite = "sprite_calcui_light" | 135 | + row1.add({type="sprite-button", style="calcui_button_style_light", caption="", name="calcui_button_BS"}).sprite = "sprite_calcui_backspace" |
129 | row1.add({type="sprite-button", style="calcui_button_style_light", caption="/", name="calcui_button_DIV"}).sprite = "sprite_calcui_light" | 136 | row1.add({type="sprite-button", style="calcui_button_style_light", caption="/", name="calcui_button_DIV"}).sprite = "sprite_calcui_light" |
130 | 137 | ||
131 | local row2 = col1.add({type="flow", name="calcui_col1_row2", direction="horizontal"}) | 138 | local row2 = col1.add({type="flow", name="calcui_col1_row2", direction="horizontal"}) |
@@ -153,43 +160,54 @@ function show_calculator(player) | @@ -153,43 +160,54 @@ function show_calculator(player) | ||
153 | row5.add({type="sprite-button", style="calcui_button_style_red", caption="=", name="calcui_button_EQU"}).sprite = "sprite_calcui_red" | 160 | row5.add({type="sprite-button", style="calcui_button_style_red", caption="=", name="calcui_button_EQU"}).sprite = "sprite_calcui_red" |
154 | 161 | ||
155 | local col2 = table.add({ | 162 | local col2 = table.add({ |
156 | - type = "flow", | ||
157 | - name = "calcui_table_col2", | 163 | + type = "flow", |
164 | + name = "calcui_table_col2", | ||
158 | direction = "vertical" | 165 | direction = "vertical" |
159 | }) | 166 | }) |
160 | 167 | ||
161 | local result = col2.add({ | 168 | local result = col2.add({ |
162 | - type = "label", | ||
163 | - caption = "= ", | ||
164 | - name = "calcui_display_result" | 169 | + type = "flow", |
170 | + name = "calcui_result", | ||
171 | + direction = "horizontal" | ||
165 | }) | 172 | }) |
166 | - result.style.font = "default-large" | ||
167 | - | ||
168 | - local rant = col2.add({ | 173 | + |
174 | + result.add({ | ||
175 | + type = "label", | ||
176 | + caption = "=", | ||
177 | + name = "calcui_display_sign" | ||
178 | + }).style.font = "default-large" | ||
179 | + | ||
180 | + result.add({ | ||
181 | + type = "label", | ||
182 | + caption = "", | ||
183 | + name = "calcui_copy_display_result" | ||
184 | + }).style.font = "default-large" | ||
185 | + | ||
186 | + col2.add({ | ||
169 | type = "sprite", | 187 | type = "sprite", |
170 | name = "calcui_rant" | 188 | name = "calcui_rant" |
171 | }) | 189 | }) |
172 | - | 190 | + |
173 | col2.add({ | 191 | col2.add({ |
174 | - type = "line", | 192 | + type = "line", |
193 | + name = "calcui_line", | ||
175 | direction = "horizontal" | 194 | direction = "horizontal" |
176 | }) | 195 | }) |
177 | - | 196 | + |
178 | local scroll = col2.add({ | 197 | local scroll = col2.add({ |
179 | type = "scroll-pane", | 198 | type = "scroll-pane", |
180 | name = "calcui_scroll_pane" | 199 | name = "calcui_scroll_pane" |
181 | }) | 200 | }) |
182 | scroll.style.height = 252 | 201 | scroll.style.height = 252 |
183 | - | ||
184 | - local recents = scroll.add({ | ||
185 | - type = "table", | ||
186 | - caption = "", | ||
187 | - name = "calcui_result_table", | ||
188 | - column_count = "2" | ||
189 | - }) | ||
190 | - recents.style.column_alignments[1] = "right" | ||
191 | - | ||
192 | - | 202 | + |
203 | + scroll.add({ | ||
204 | + type = "table", | ||
205 | + caption = "", | ||
206 | + name = "calcui_result_table", | ||
207 | + column_count = "3" | ||
208 | + }).style.column_alignments[1] = "right" | ||
209 | + | ||
210 | + | ||
193 | -- use last saved location or center the gui | 211 | -- use last saved location or center the gui |
194 | if not global.gui_position then | 212 | if not global.gui_position then |
195 | global.gui_position = {} | 213 | global.gui_position = {} |
@@ -197,16 +215,19 @@ function show_calculator(player) | @@ -197,16 +215,19 @@ function show_calculator(player) | ||
197 | if global.gui_position[player.index] then | 215 | if global.gui_position[player.index] then |
198 | -- fix weird saved positions (out of reach) | 216 | -- fix weird saved positions (out of reach) |
199 | fix_oob_ui(player) | 217 | fix_oob_ui(player) |
200 | - | 218 | + |
201 | calcui.location = global.gui_position[player.index] | 219 | calcui.location = global.gui_position[player.index] |
202 | else | 220 | else |
203 | calcui.force_auto_center() | 221 | calcui.force_auto_center() |
204 | end | 222 | end |
223 | + | ||
224 | + -- focus on display | ||
225 | + display.focus() | ||
205 | end | 226 | end |
206 | end | 227 | end |
207 | 228 | ||
208 | -- ---------------------------------------------------------------- | 229 | -- ---------------------------------------------------------------- |
209 | -function hide_calculator(player) | 230 | +local function hide_calculator(player) |
210 | destroy_calculator(player) | 231 | destroy_calculator(player) |
211 | end | 232 | end |
212 | 233 | ||
@@ -227,36 +248,65 @@ function focus_on_input(player) | @@ -227,36 +248,65 @@ function focus_on_input(player) | ||
227 | end | 248 | end |
228 | 249 | ||
229 | -- ---------------------------------------------------------------- | 250 | -- ---------------------------------------------------------------- |
230 | -function clear_equation(player) | 251 | +local function clear_equation(player) |
231 | local root = get_gui_root(player) | 252 | local root = get_gui_root(player) |
232 | root.calcui.calcui_table.calcui_table_col1.calcui_display.text = "" | 253 | root.calcui.calcui_table.calcui_table_col1.calcui_display.text = "" |
233 | end | 254 | end |
234 | 255 | ||
235 | -- ---------------------------------------------------------------- | 256 | -- ---------------------------------------------------------------- |
236 | -function process_ce_key(player, button) | 257 | +local function process_ce_key(player, button) |
237 | local root = get_gui_root(player) | 258 | local root = get_gui_root(player) |
238 | clear_equation(player) | 259 | clear_equation(player) |
239 | - root.calcui.calcui_table.calcui_table_col2.calcui_display_result.caption = "=" | ||
240 | - root.calcui.calcui_table.calcui_table_col2.calcui_display_result.tooltip = "" | 260 | + root.calcui.calcui_table.calcui_table_col2.calcui_result.calcui_copy_display_result.caption = "" |
261 | + root.calcui.calcui_table.calcui_table_col2.calcui_result.calcui_copy_display_result.tooltip = "" | ||
241 | end | 262 | end |
242 | 263 | ||
243 | -- ---------------------------------------------------------------- | 264 | -- ---------------------------------------------------------------- |
244 | -function process_c_key(player, button) | 265 | +local function process_c_key(player, button) |
245 | local root = get_gui_root(player) | 266 | local root = get_gui_root(player) |
246 | process_ce_key(player, button) | 267 | process_ce_key(player, button) |
247 | root.calcui.calcui_table.calcui_table_col2.calcui_scroll_pane.calcui_result_table.clear() | 268 | root.calcui.calcui_table.calcui_table_col2.calcui_scroll_pane.calcui_result_table.clear() |
269 | + global.recent_results[player.index] = {} | ||
248 | end | 270 | end |
249 | 271 | ||
250 | -- ---------------------------------------------------------------- | 272 | -- ---------------------------------------------------------------- |
251 | -function process_backspace_key(player, button) | 273 | +local function process_backspace_key(player, button) |
252 | local root = get_gui_root(player) | 274 | local root = get_gui_root(player) |
253 | root.calcui.calcui_table.calcui_table_col1.calcui_display.text = string.sub(root.calcui.calcui_table.calcui_table_col1.calcui_display.text, 1, -2) | 275 | root.calcui.calcui_table.calcui_table_col1.calcui_display.text = string.sub(root.calcui.calcui_table.calcui_table_col1.calcui_display.text, 1, -2) |
254 | end | 276 | end |
255 | 277 | ||
256 | -- ---------------------------------------------------------------- | 278 | -- ---------------------------------------------------------------- |
257 | -function fix_equation(equation, root) | 279 | +local function draw_recent_table(player) |
280 | + local root = get_gui_root(player) | ||
281 | + | ||
282 | + -- drop old table | ||
283 | + root.calcui.calcui_table.calcui_table_col2.calcui_scroll_pane.calcui_result_table.clear() | ||
284 | + | ||
285 | + for i, result in ipairs(global.recent_results[player.index]) do | ||
286 | + root.calcui.calcui_table.calcui_table_col2.calcui_scroll_pane.calcui_result_table.add({ | ||
287 | + type = "label", | ||
288 | + name = "calcui_copy_equation_" .. i, | ||
289 | + caption = result["equation"], | ||
290 | + tooltip = {"calculator-ui.recent_tooltip"} | ||
291 | + }) | ||
292 | + root.calcui.calcui_table.calcui_table_col2.calcui_scroll_pane.calcui_result_table.add({ | ||
293 | + type = "label", | ||
294 | + name = "calcui_sign_" .. i, | ||
295 | + caption = "=" | ||
296 | + }) | ||
297 | + root.calcui.calcui_table.calcui_table_col2.calcui_scroll_pane.calcui_result_table.add({ | ||
298 | + type = "label", | ||
299 | + name = "calcui_copy_result_" .. i, | ||
300 | + caption = result["result"] | ||
301 | + }) | ||
302 | + end | ||
303 | + root.calcui.calcui_table.calcui_table_col2.calcui_scroll_pane.scroll_to_top() | ||
304 | +end | ||
305 | + | ||
306 | +-- ---------------------------------------------------------------- | ||
307 | +local function fix_equation(equation, root) | ||
258 | local result = equation | 308 | local result = equation |
259 | - local prev_result = root.calcui.calcui_table.calcui_table_col2.calcui_display_result.tooltip | 309 | + local prev_result = root.calcui.calcui_table.calcui_table_col2.calcui_result.calcui_copy_display_result.tooltip |
260 | 310 | ||
261 | 311 | ||
262 | -- 1. visible part | 312 | -- 1. visible part |
@@ -308,7 +358,7 @@ function fix_equation(equation, root) | @@ -308,7 +358,7 @@ function fix_equation(equation, root) | ||
308 | 358 | ||
309 | -- fix percentage | 359 | -- fix percentage |
310 | result = result:gsub("(%%)", "/100") | 360 | result = result:gsub("(%%)", "/100") |
311 | - | 361 | + |
312 | -- fix danish keyboard | 362 | -- fix danish keyboard |
313 | result = result:gsub(",", ".") | 363 | result = result:gsub(",", ".") |
314 | result = result:gsub(";", ",") | 364 | result = result:gsub(";", ",") |
@@ -321,17 +371,17 @@ end | @@ -321,17 +371,17 @@ end | ||
321 | function process_equal_key(player, button) | 371 | function process_equal_key(player, button) |
322 | local root = get_gui_root(player) | 372 | local root = get_gui_root(player) |
323 | local original_equation = root.calcui.calcui_table.calcui_table_col1.calcui_display.text; | 373 | local original_equation = root.calcui.calcui_table.calcui_table_col1.calcui_display.text; |
324 | - | 374 | + |
325 | equation, original_equation = fix_equation(original_equation, root) | 375 | equation, original_equation = fix_equation(original_equation, root) |
326 | - | 376 | + |
327 | -- just testing | 377 | -- just testing |
328 | --root.calcui.calcui_table.calcui_table_col1.calcui_display.text = equation | 378 | --root.calcui.calcui_table.calcui_table_col1.calcui_display.text = equation |
329 | - | 379 | + |
330 | if not (equation == nil or equation == "") then | 380 | if not (equation == nil or equation == "") then |
331 | local status, retval = pcall(function() | 381 | local status, retval = pcall(function() |
332 | return load("return " .. equation)() | 382 | return load("return " .. equation)() |
333 | end) | 383 | end) |
334 | - root.calcui.calcui_table.calcui_table_col2.calcui_display_result.tooltip = retval | 384 | + root.calcui.calcui_table.calcui_table_col2.calcui_result.calcui_copy_display_result.tooltip = retval |
335 | if not (retval == math.huge or retval ~= retval) then | 385 | if not (retval == math.huge or retval ~= retval) then |
336 | status, retval_show = pcall(function() | 386 | status, retval_show = pcall(function() |
337 | local result = string.format("%0." .. settings.get_player_settings(player)["calcui-decimal-places"].value .. "f", retval) | 387 | local result = string.format("%0." .. settings.get_player_settings(player)["calcui-decimal-places"].value .. "f", retval) |
@@ -352,31 +402,22 @@ function process_equal_key(player, button) | @@ -352,31 +402,22 @@ function process_equal_key(player, button) | ||
352 | else | 402 | else |
353 | if retval <= 0 then | 403 | if retval <= 0 then |
354 | show_think(player, true) | 404 | show_think(player, true) |
355 | - else | 405 | + else |
356 | show_rant(player, false) | 406 | show_rant(player, false) |
357 | end | 407 | end |
358 | end | 408 | end |
359 | - root.calcui.calcui_table.calcui_table_col2.calcui_display_result.caption = "= " .. retval_show | ||
360 | - | 409 | + root.calcui.calcui_table.calcui_table_col2.calcui_result.calcui_copy_display_result.caption = retval_show |
410 | + | ||
361 | -- only write in recent table if actually a result | 411 | -- only write in recent table if actually a result |
362 | if status then | 412 | if status then |
363 | - -- check last equation and only insert if not the same | ||
364 | - local item_size = #root.calcui.calcui_table.calcui_table_col2.calcui_scroll_pane.calcui_result_table.children | ||
365 | - | ||
366 | - if item_size == 0 or root.calcui.calcui_table.calcui_table_col2.calcui_scroll_pane.calcui_result_table.children[item_size-1].caption ~= original_equation then | ||
367 | - local recent_equation = root.calcui.calcui_table.calcui_table_col2.calcui_scroll_pane.calcui_result_table.add({ | ||
368 | - type = "label", | ||
369 | - name = "calcui_recent_equation_" .. item_size, | ||
370 | - caption = original_equation, | ||
371 | - tooltip = {"calculator-ui.recent_tooltip"} | ||
372 | - }) | ||
373 | - local recent_result = root.calcui.calcui_table.calcui_table_col2.calcui_scroll_pane.calcui_result_table.add({ | ||
374 | - type = "label", | ||
375 | - name = "calcui_recent_result_" .. item_size, | ||
376 | - caption = root.calcui.calcui_table.calcui_table_col2.calcui_display_result.caption | 413 | + -- check first equation and only insert if not the same |
414 | + if #global.recent_results[player.index] == 0 or global.recent_results[player.index][1]["equation"] ~= original_equation then | ||
415 | + table.insert(global.recent_results[player.index], 1, { | ||
416 | + equation = original_equation, | ||
417 | + result = retval_show | ||
377 | }) | 418 | }) |
378 | - root.calcui.calcui_table.calcui_table_col2.calcui_scroll_pane.scroll_to_bottom() | ||
379 | end | 419 | end |
420 | + draw_recent_table(player) | ||
380 | end | 421 | end |
381 | end | 422 | end |
382 | 423 | ||
@@ -386,7 +427,7 @@ function process_equal_key(player, button) | @@ -386,7 +427,7 @@ function process_equal_key(player, button) | ||
386 | end | 427 | end |
387 | 428 | ||
388 | -- ---------------------------------------------------------------- | 429 | -- ---------------------------------------------------------------- |
389 | -function display_addchar(player, char) | 430 | +local function display_addchar(player, char) |
390 | local root = get_gui_root(player) | 431 | local root = get_gui_root(player) |
391 | root.calcui.calcui_table.calcui_table_col1.calcui_display.text = root.calcui.calcui_table.calcui_table_col1.calcui_display.text .. char | 432 | root.calcui.calcui_table.calcui_table_col1.calcui_display.text = root.calcui.calcui_table.calcui_table_col1.calcui_display.text .. char |
392 | show_rant(player, false) | 433 | show_rant(player, false) |
@@ -428,10 +469,10 @@ function handle_calcui_click(event, player) | @@ -428,10 +469,10 @@ function handle_calcui_click(event, player) | ||
428 | local event_name = event.element.name | 469 | local event_name = event.element.name |
429 | local button_prefix = "calcui_button_" | 470 | local button_prefix = "calcui_button_" |
430 | local button_prefix_len = string.len(button_prefix) | 471 | local button_prefix_len = string.len(button_prefix) |
431 | - | ||
432 | - local recent_prefix = "calcui_recent_" | ||
433 | - local recent_prefix_len = string.len(recent_prefix); | ||
434 | - | 472 | + |
473 | + local copy_prefix = "calcui_copy_" | ||
474 | + local copy_prefix_len = string.len(copy_prefix); | ||
475 | + | ||
435 | -- calculator buttons | 476 | -- calculator buttons |
436 | if string.sub(event_name, 1, button_prefix_len) == button_prefix then | 477 | if string.sub(event_name, 1, button_prefix_len) == button_prefix then |
437 | show_rant(player, false) | 478 | show_rant(player, false) |
@@ -442,7 +483,7 @@ function handle_calcui_click(event, player) | @@ -442,7 +483,7 @@ function handle_calcui_click(event, player) | ||
442 | if dispatch_func then | 483 | if dispatch_func then |
443 | dispatch_func(player, button) | 484 | dispatch_func(player, button) |
444 | end | 485 | end |
445 | - | 486 | + |
446 | local addchar = button_addchar[button] | 487 | local addchar = button_addchar[button] |
447 | if addchar then | 488 | if addchar then |
448 | display_addchar(player, addchar) | 489 | display_addchar(player, addchar) |
@@ -450,15 +491,22 @@ function handle_calcui_click(event, player) | @@ -450,15 +491,22 @@ function handle_calcui_click(event, player) | ||
450 | -- close button | 491 | -- close button |
451 | elseif event_name == "calcui_close" then | 492 | elseif event_name == "calcui_close" then |
452 | hide_calculator(player) | 493 | hide_calculator(player) |
453 | - -- recent results | ||
454 | - elseif string.sub(event_name, 1, recent_prefix_len) == recent_prefix then | ||
455 | - if event.button == defines.mouse_button_type.left and | 494 | + -- copy results |
495 | + elseif string.sub(event_name, 1, copy_prefix_len) == copy_prefix then | ||
496 | + if event.button == defines.mouse_button_type.left and | ||
456 | event.shift == true then | 497 | event.shift == true then |
457 | - -- copy equation to display | 498 | + -- copy equation or result to display |
458 | local root = get_gui_root(player) | 499 | local root = get_gui_root(player) |
459 | - 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 | 500 | + if event_name == "calcui_copy_display_result" then |
501 | + root.calcui.calcui_table.calcui_table_col1.calcui_display.text = root.calcui.calcui_table.calcui_table_col2.calcui_result.calcui_copy_display_result.caption | ||
502 | + else | ||
503 | + 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 | ||
504 | + end | ||
460 | focus_on_input(player) | 505 | focus_on_input(player) |
461 | end | 506 | end |
507 | + -- if else focus on focus on display | ||
508 | + else | ||
509 | + focus_on_input(player) | ||
462 | end | 510 | end |
463 | end | 511 | end |
464 | 512 | ||
@@ -477,7 +525,6 @@ end | @@ -477,7 +525,6 @@ end | ||
477 | -- ---------------------------------------------------------------- | 525 | -- ---------------------------------------------------------------- |
478 | function calcui_on_gui_location_changed(event) | 526 | function calcui_on_gui_location_changed(event) |
479 | if event.element.name == "calcui" then | 527 | if event.element.name == "calcui" then |
480 | - local root = get_gui_root(game.players[event.player_index]) | ||
481 | if not global.gui_position then | 528 | if not global.gui_position then |
482 | global.gui_position = {} | 529 | global.gui_position = {} |
483 | end | 530 | end |
control.lua
@@ -27,17 +27,6 @@ function debug_log(f, str) | @@ -27,17 +27,6 @@ function debug_log(f, str) | ||
27 | end | 27 | end |
28 | 28 | ||
29 | -- ---------------------------------------------------------------- | 29 | -- ---------------------------------------------------------------- |
30 | -local function get_gui_root(player) | ||
31 | - return player.gui.screen | ||
32 | -end | ||
33 | - | ||
34 | --- ---------------------------------------------------------------- | ||
35 | -function destroy_calcui_gui(player) | ||
36 | - local root = get_gui_root(player) | ||
37 | - root.calcui_gui_top.destroy() | ||
38 | -end | ||
39 | - | ||
40 | --- ---------------------------------------------------------------- | ||
41 | local function shortcut(event) | 30 | local function shortcut(event) |
42 | if event.prototype_name == "calcui_4func" then | 31 | if event.prototype_name == "calcui_4func" then |
43 | local player = game.players[event.player_index] | 32 | local player = game.players[event.player_index] |
@@ -52,8 +41,8 @@ local function on_gui_click(event) | @@ -52,8 +41,8 @@ local function on_gui_click(event) | ||
52 | local event_name = event.element.name | 41 | local event_name = event.element.name |
53 | debug_print("event_name " .. event_name) | 42 | debug_print("event_name " .. event_name) |
54 | local player = game.players[event.player_index] | 43 | local player = game.players[event.player_index] |
55 | - | ||
56 | - local calcui_prefix = "calcui_" | 44 | + |
45 | + local calcui_prefix = "calcui" | ||
57 | local possible_marcalc_prefix = string.sub( event_name, 1, string.len(calcui_prefix)) | 46 | local possible_marcalc_prefix = string.sub( event_name, 1, string.len(calcui_prefix)) |
58 | if possible_marcalc_prefix == calcui_prefix then | 47 | if possible_marcalc_prefix == calcui_prefix then |
59 | handle_calcui_click(event, player) | 48 | handle_calcui_click(event, player) |
graphics/backspace.png
0 → 100644
653 Bytes
settings.lua
@@ -6,13 +6,11 @@ data:extend({ | @@ -6,13 +6,11 @@ data:extend({ | ||
6 | maximum_value = 10, | 6 | maximum_value = 10, |
7 | name = "calcui-decimal-places", | 7 | name = "calcui-decimal-places", |
8 | setting_type = "runtime-per-user", | 8 | setting_type = "runtime-per-user", |
9 | - default_value = true | ||
10 | }, | 9 | }, |
11 | { | 10 | { |
12 | type = "bool-setting", | 11 | type = "bool-setting", |
13 | - default_value = 0, | 12 | + default_value = false, |
14 | name = "calcui-clear-on-calc", | 13 | name = "calcui-clear-on-calc", |
15 | setting_type = "runtime-per-user", | 14 | setting_type = "runtime-per-user", |
16 | - default_value = false | ||
17 | } | 15 | } |
18 | }) | 16 | }) |
19 | \ No newline at end of file | 17 | \ No newline at end of file |