Commit 1eefa09083430f20f5028a10a22f393b15dbf604
1 parent
ad9f5b12
visual overhaul in version 0.18.3
Showing
8 changed files
with
91 additions
and
65 deletions
CHANGELOG.md
... | ... | @@ -6,8 +6,20 @@ 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.3] - 2020-06-07 | |
10 | +### General | |
11 | +A small visual overhaul of the mod | |
12 | +### Added | |
13 | +- Added the possibility to "calculate further" (especially usefull when setting "Clear equation on calculation" is set). When the equation doesn't start with a number, character or parenthesis (so it assumes it starts with a math symbol) it will take the previous result and prepend it to the current equation. | |
14 | + | |
15 | +### Changed | |
16 | +- Updated the UI a bit to match it in color a bit more to the Windows calculator | |
17 | +- Updated also the icon on the shortcut to better distinguish it | |
18 | + | |
9 | 19 | ## [0.18.2] - 2020-06-06 |
20 | +### General | |
10 | 21 | Based on user feedback updated the mod |
22 | + | |
11 | 23 | ### Added |
12 | 24 | - new easter egg :-) |
13 | 25 | - added more math.lib functions |
... | ... | @@ -26,7 +38,9 @@ Based on user feedback updated the mod |
26 | 38 | - Fixed sqrt(-1) equaling "na" because of the rounding fix from 0.18.1. It does now show "NaN" again |
27 | 39 | |
28 | 40 | ## [0.18.1] - 2020-06-06 |
41 | +### General | |
29 | 42 | Based on user feedback updated the mod |
43 | + | |
30 | 44 | ### Added |
31 | 45 | - Shortcut for opening the calculator and automatically focus on the input (Default: Ctrl+Shift+C) |
32 | 46 | ... | ... |
calcui-styles.lua
... | ... | @@ -2,21 +2,9 @@ |
2 | 2 | |
3 | 3 | local default_gui = data.raw["gui-style"].default |
4 | 4 | |
5 | -default_gui.calcui_sprite_obj_style = { | |
6 | - type = "button_style", | |
7 | - -- parent="button_style", | |
8 | - top_padding = 0, | |
9 | - right_padding = 0, | |
10 | - bottom_padding = 0, | |
11 | - left_padding = 0, | |
12 | - height = 32, | |
13 | - width = 32, | |
14 | - scalable = false | |
15 | -} | |
16 | - | |
17 | 5 | default_gui.calcui_button_style = { |
18 | 6 | type = "button_style", |
19 | - -- parent="button_style", | |
7 | + parent = "icon_button", | |
20 | 8 | top_padding = 0, |
21 | 9 | right_padding = 0, |
22 | 10 | bottom_padding = 0, |
... | ... | @@ -25,33 +13,20 @@ default_gui.calcui_button_style = { |
25 | 13 | width = 50, |
26 | 14 | scalable = false |
27 | 15 | } |
28 | - | |
29 | -default_gui.calcui_textfield_style = { | |
30 | - type = "textbox_style", | |
31 | - width = 212 | |
16 | +default_gui.calcui_button_style_red = { | |
17 | + type = "button_style", | |
18 | + parent = "calcui_button_style", | |
19 | + sprite = "sprite_calcui_red" | |
32 | 20 | } |
33 | - | |
34 | -default_gui.calcui_table_style = { | |
35 | - type = "table_style", | |
36 | - horizontal_spacing = 5, | |
37 | - vertical_spacing = 1, | |
38 | - resize_row_to_width = false, | |
39 | - resize_to_row_height = false, | |
21 | +default_gui.calcui_button_style_light = { | |
22 | + type = "button_style", | |
23 | + parent = "calcui_button_style", | |
24 | + sprite = "sprite_calcui_light" | |
40 | 25 | } |
41 | - | |
42 | -default_gui.calcui_scroll_pane_style = { | |
43 | - type = "scroll_pane_style", | |
44 | - -- parent="scroll_pane_style", | |
45 | - -- flow_style = | |
46 | - -- { | |
47 | - -- type = "flow_style", | |
48 | - -- parent = "flow_style" | |
49 | - -- }, | |
50 | - resize_row_to_width = true, | |
51 | - resize_to_row_height = false, | |
52 | - minimal_height=128, | |
53 | - maximal_height=400, | |
54 | - max_on_row = 1, | |
26 | +default_gui.calcui_button_style_dark = { | |
27 | + type = "button_style", | |
28 | + parent = "calcui_button_style", | |
29 | + sprite = "sprite_calcui_dark" | |
55 | 30 | } |
56 | 31 | |
57 | 32 | data:extend({ |
... | ... | @@ -75,5 +50,26 @@ data:extend({ |
75 | 50 | filename = "__calculator-ui__/graphics/calculator.png", |
76 | 51 | width = 64, |
77 | 52 | height = 64 |
53 | + }, | |
54 | + { | |
55 | + type = "sprite", | |
56 | + name = "sprite_calcui_red", | |
57 | + filename = "__calculator-ui__/graphics/red.png", | |
58 | + width = 50, | |
59 | + height = 50 | |
60 | + }, | |
61 | + { | |
62 | + type = "sprite", | |
63 | + name = "sprite_calcui_light", | |
64 | + filename = "__calculator-ui__/graphics/light.png", | |
65 | + width = 50, | |
66 | + height = 50 | |
67 | + }, | |
68 | + { | |
69 | + type = "sprite", | |
70 | + name = "sprite_calcui_dark", | |
71 | + filename = "__calculator-ui__/graphics/dark.png", | |
72 | + width = 50, | |
73 | + height = 50 | |
78 | 74 | } |
79 | 75 | }) |
80 | 76 | \ No newline at end of file | ... | ... |
calculator.lua
... | ... | @@ -95,41 +95,42 @@ function show_calculator(player) |
95 | 95 | |
96 | 96 | local display = col1.add({ |
97 | 97 | type = "textfield", |
98 | - style = "calcui_textfield_style", | |
99 | 98 | caption = "", |
100 | 99 | name = "calcui_display" |
101 | 100 | }) |
101 | + display.style.width = 212 | |
102 | 102 | |
103 | 103 | local row1 = col1.add({type="flow", name="calcui_col1_row1", direction="horizontal"}) |
104 | - row1.add({type="button", style="calcui_button_style", caption="CE", name="calcui_button_CE"}) -- CE = Clear Entry (just this line) | |
105 | - row1.add({type="button", style="calcui_button_style", caption="C", name="calcui_button_C"}) -- C = Clear (all, past results as well) | |
106 | - row1.add({type="button", style="calcui_button_style", caption="BS", name="calcui_button_BS"}) | |
107 | - row1.add({type="button", style="calcui_button_style", caption="/", name="calcui_button_DIV"}) | |
104 | + 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) | |
105 | + 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) | |
106 | + row1.add({type="sprite-button", style="calcui_button_style_light", caption="BS", name="calcui_button_BS"}).sprite = "sprite_calcui_light" | |
107 | + row1.add({type="sprite-button", style="calcui_button_style_light", caption="/", name="calcui_button_DIV"}).sprite = "sprite_calcui_light" | |
108 | 108 | |
109 | 109 | local row2 = col1.add({type="flow", name="calcui_col1_row2", direction="horizontal"}) |
110 | - row2.add({type="button", style="calcui_button_style", caption="7", name="calcui_button_7"}) | |
111 | - row2.add({type="button", style="calcui_button_style", caption="8", name="calcui_button_8"}) | |
112 | - row2.add({type="button", style="calcui_button_style", caption="9", name="calcui_button_9"}) | |
113 | - row2.add({type="button", style="calcui_button_style", caption="*", name="calcui_button_MUL"}) | |
110 | + row2.add({type="sprite-button", style="calcui_button_style_dark", caption="7", name="calcui_button_7"}).sprite = "sprite_calcui_dark" | |
111 | + row2.add({type="sprite-button", style="calcui_button_style_dark", caption="8", name="calcui_button_8"}).sprite = "sprite_calcui_dark" | |
112 | + row2.add({type="sprite-button", style="calcui_button_style_dark", caption="9", name="calcui_button_9"}).sprite = "sprite_calcui_dark" | |
113 | + row2.add({type="sprite-button", style="calcui_button_style_light", caption="*", name="calcui_button_MUL"}).sprite = "sprite_calcui_light" | |
114 | 114 | |
115 | 115 | local row3 = col1.add({type="flow", name="calcui_col1_row3", direction="horizontal"}) |
116 | - row3.add({type="button", style="calcui_button_style", caption="4", name="calcui_button_4"}) | |
117 | - row3.add({type="button", style="calcui_button_style", caption="5", name="calcui_button_5"}) | |
118 | - row3.add({type="button", style="calcui_button_style", caption="6", name="calcui_button_6"}) | |
119 | - row3.add({type="button", style="calcui_button_style", caption="-", name="calcui_button_SUB"}) | |
116 | + row3.add({type="sprite-button", style="calcui_button_style_dark", caption="4", name="calcui_button_4"}).sprite = "sprite_calcui_dark" | |
117 | + row3.add({type="sprite-button", style="calcui_button_style_dark", caption="5", name="calcui_button_5"}).sprite = "sprite_calcui_dark" | |
118 | + row3.add({type="sprite-button", style="calcui_button_style_dark", caption="6", name="calcui_button_6"}).sprite = "sprite_calcui_dark" | |
119 | + row3.add({type="sprite-button", style="calcui_button_style_light", caption="-", name="calcui_button_SUB"}).sprite = "sprite_calcui_light" | |
120 | 120 | |
121 | 121 | local row4 = col1.add({type="flow", name="calcui_col1_row4", direction="horizontal"}) |
122 | - row4.add({type="button", style="calcui_button_style", caption="1", name="calcui_button_1"}) | |
123 | - row4.add({type="button", style="calcui_button_style", caption="2", name="calcui_button_2"}) | |
124 | - row4.add({type="button", style="calcui_button_style", caption="3", name="calcui_button_3"}) | |
125 | - row4.add({type="button", style="calcui_button_style", caption="+", name="calcui_button_ADD"}) | |
122 | + row4.add({type="sprite-button", style="calcui_button_style_dark", caption="1", name="calcui_button_1"}).sprite = "sprite_calcui_dark" | |
123 | + row4.add({type="sprite-button", style="calcui_button_style_dark", caption="2", name="calcui_button_2"}).sprite = "sprite_calcui_dark" | |
124 | + row4.add({type="sprite-button", style="calcui_button_style_dark", caption="3", name="calcui_button_3"}).sprite = "sprite_calcui_dark" | |
125 | + row4.add({type="sprite-button", style="calcui_button_style_light", caption="+", name="calcui_button_ADD"}).sprite = "sprite_calcui_light" | |
126 | 126 | |
127 | 127 | local row5 = col1.add({type="flow", name="calcui_col1_row5", direction="horizontal"}) |
128 | - row5.add({type="button", style="calcui_button_style", caption="%", name="calcui_button_PERC"}) | |
129 | - row5.add({type="button", style="calcui_button_style", caption="0", name="calcui_button_0"}) | |
130 | - row5.add({type="button", style="calcui_button_style", caption=".", name="calcui_button_DOT"}) | |
131 | - row5.add({type="button", style="calcui_button_style", caption="=", name="calcui_button_EQU"}) | |
128 | + row5.add({type="sprite-button", style="calcui_button_style_light", caption="%", name="calcui_button_PERC"}).sprite = "sprite_calcui_light" | |
129 | + row5.add({type="sprite-button", style="calcui_button_style_dark", caption="0", name="calcui_button_0"}).sprite = "sprite_calcui_dark" | |
130 | + 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" | |
132 | 132 | |
133 | + --.sprite = "sprite_calcui_dark" | |
133 | 134 | |
134 | 135 | local col2 = table.add({ |
135 | 136 | type = "flow", |
... | ... | @@ -206,6 +207,7 @@ function process_ce_key(player, button) |
206 | 207 | local root = get_gui_root(player) |
207 | 208 | clear_equation(player) |
208 | 209 | root.calcui.calcui_table.calcui_table_col2.calcui_display_result.caption = "=" |
210 | + root.calcui.calcui_table.calcui_table_col2.calcui_display_result.tooltip = "" | |
209 | 211 | end |
210 | 212 | |
211 | 213 | -- ---------------------------------------------------------------- |
... | ... | @@ -222,9 +224,23 @@ function process_backspace_key(player, button) |
222 | 224 | end |
223 | 225 | |
224 | 226 | -- ---------------------------------------------------------------- |
225 | -function fix_equation(equation) | |
227 | +function fix_equation(equation, root) | |
226 | 228 | local result = equation |
227 | - | |
229 | + local prev_result = root.calcui.calcui_table.calcui_table_col2.calcui_display_result.tooltip | |
230 | + | |
231 | + | |
232 | + -- 1. visible part | |
233 | + -- if equation does not start with a number or char, use the previous result (if available) and put it in front | |
234 | + if not (string.match(result:sub(1, 1), "[^%w%(%)]") == nil) and prev_result then | |
235 | + result = prev_result .. result | |
236 | + end | |
237 | + | |
238 | + -- remove "math." | |
239 | + result = result:gsub("math.", "") | |
240 | + local new_equation = result | |
241 | + | |
242 | + | |
243 | + -- 2. invisible part | |
228 | 244 | -- fix math library shortcuts |
229 | 245 | local math_lib = { |
230 | 246 | ["abs"] = "math.abs", |
... | ... | @@ -267,16 +283,16 @@ function fix_equation(equation) |
267 | 283 | result = result:gsub(",", ".") |
268 | 284 | result = result:gsub(";", ",") |
269 | 285 | |
270 | - return result | |
286 | + | |
287 | + return result, new_equation | |
271 | 288 | end |
272 | 289 | |
273 | 290 | -- ---------------------------------------------------------------- |
274 | 291 | function process_equal_key(player, button) |
275 | 292 | local root = get_gui_root(player) |
276 | - | |
277 | 293 | local original_equation = root.calcui.calcui_table.calcui_table_col1.calcui_display.text; |
278 | 294 | |
279 | - equation = fix_equation(original_equation) | |
295 | + equation, original_equation = fix_equation(original_equation, root) | |
280 | 296 | |
281 | 297 | -- just testing |
282 | 298 | --root.calcui.calcui_table.calcui_table_col1.calcui_display.text = equation | ... | ... |
graphics/calculator.png
graphics/dark.png
0 โ 100644
190 Bytes
graphics/light.png
0 โ 100644
189 Bytes
graphics/red.png
0 โ 100644
182 Bytes