From 1eefa09083430f20f5028a10a22f393b15dbf604 Mon Sep 17 00:00:00 2001 From: Wichu Date: Sun, 7 Jun 2020 19:24:39 +0200 Subject: [PATCH] visual overhaul in version 0.18.3 --- CHANGELOG.md | 14 ++++++++++++++ calcui-styles.lua | 72 ++++++++++++++++++++++++++++++++++-------------------------------------- calculator.lua | 68 ++++++++++++++++++++++++++++++++++++++++++-------------------------- graphics/calculator.png | Bin 387 -> 0 bytes graphics/dark.png | Bin 0 -> 190 bytes graphics/light.png | Bin 0 -> 189 bytes graphics/red.png | Bin 0 -> 182 bytes info.json | 2 +- 8 files changed, 91 insertions(+), 65 deletions(-) create mode 100644 graphics/dark.png create mode 100644 graphics/light.png create mode 100644 graphics/red.png diff --git a/CHANGELOG.md b/CHANGELOG.md index f6b42be..aa92e67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,20 @@ and this project adheres to the versioning of Factorio, so 0.18.x will be at lea ## [Released] +## [0.18.3] - 2020-06-07 +### General +A small visual overhaul of the mod +### Added +- 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. + +### Changed +- Updated the UI a bit to match it in color a bit more to the Windows calculator +- Updated also the icon on the shortcut to better distinguish it + ## [0.18.2] - 2020-06-06 +### General Based on user feedback updated the mod + ### Added - new easter egg :-) - added more math.lib functions @@ -26,7 +38,9 @@ Based on user feedback updated the mod - Fixed sqrt(-1) equaling "na" because of the rounding fix from 0.18.1. It does now show "NaN" again ## [0.18.1] - 2020-06-06 +### General Based on user feedback updated the mod + ### Added - Shortcut for opening the calculator and automatically focus on the input (Default: Ctrl+Shift+C) diff --git a/calcui-styles.lua b/calcui-styles.lua index 9111c3c..970889e 100644 --- a/calcui-styles.lua +++ b/calcui-styles.lua @@ -2,21 +2,9 @@ local default_gui = data.raw["gui-style"].default -default_gui.calcui_sprite_obj_style = { - type = "button_style", - -- parent="button_style", - top_padding = 0, - right_padding = 0, - bottom_padding = 0, - left_padding = 0, - height = 32, - width = 32, - scalable = false -} - default_gui.calcui_button_style = { type = "button_style", - -- parent="button_style", + parent = "icon_button", top_padding = 0, right_padding = 0, bottom_padding = 0, @@ -25,33 +13,20 @@ default_gui.calcui_button_style = { width = 50, scalable = false } - -default_gui.calcui_textfield_style = { - type = "textbox_style", - width = 212 +default_gui.calcui_button_style_red = { + type = "button_style", + parent = "calcui_button_style", + sprite = "sprite_calcui_red" } - -default_gui.calcui_table_style = { - type = "table_style", - horizontal_spacing = 5, - vertical_spacing = 1, - resize_row_to_width = false, - resize_to_row_height = false, +default_gui.calcui_button_style_light = { + type = "button_style", + parent = "calcui_button_style", + sprite = "sprite_calcui_light" } - -default_gui.calcui_scroll_pane_style = { - type = "scroll_pane_style", - -- parent="scroll_pane_style", - -- flow_style = - -- { - -- type = "flow_style", - -- parent = "flow_style" - -- }, - resize_row_to_width = true, - resize_to_row_height = false, - minimal_height=128, - maximal_height=400, - max_on_row = 1, +default_gui.calcui_button_style_dark = { + type = "button_style", + parent = "calcui_button_style", + sprite = "sprite_calcui_dark" } data:extend({ @@ -75,5 +50,26 @@ data:extend({ filename = "__calculator-ui__/graphics/calculator.png", width = 64, height = 64 + }, + { + type = "sprite", + name = "sprite_calcui_red", + filename = "__calculator-ui__/graphics/red.png", + width = 50, + height = 50 + }, + { + type = "sprite", + name = "sprite_calcui_light", + filename = "__calculator-ui__/graphics/light.png", + width = 50, + height = 50 + }, + { + type = "sprite", + name = "sprite_calcui_dark", + filename = "__calculator-ui__/graphics/dark.png", + width = 50, + height = 50 } }) \ No newline at end of file diff --git a/calculator.lua b/calculator.lua index 34448dc..1940ac1 100644 --- a/calculator.lua +++ b/calculator.lua @@ -95,41 +95,42 @@ function show_calculator(player) local display = col1.add({ type = "textfield", - style = "calcui_textfield_style", caption = "", name = "calcui_display" }) + display.style.width = 212 local row1 = col1.add({type="flow", name="calcui_col1_row1", direction="horizontal"}) - row1.add({type="button", style="calcui_button_style", caption="CE", name="calcui_button_CE"}) -- CE = Clear Entry (just this line) - row1.add({type="button", style="calcui_button_style", caption="C", name="calcui_button_C"}) -- C = Clear (all, past results as well) - row1.add({type="button", style="calcui_button_style", caption="BS", name="calcui_button_BS"}) - row1.add({type="button", style="calcui_button_style", caption="/", name="calcui_button_DIV"}) + 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) + 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) + row1.add({type="sprite-button", style="calcui_button_style_light", caption="BS", name="calcui_button_BS"}).sprite = "sprite_calcui_light" + row1.add({type="sprite-button", style="calcui_button_style_light", caption="/", name="calcui_button_DIV"}).sprite = "sprite_calcui_light" local row2 = col1.add({type="flow", name="calcui_col1_row2", direction="horizontal"}) - row2.add({type="button", style="calcui_button_style", caption="7", name="calcui_button_7"}) - row2.add({type="button", style="calcui_button_style", caption="8", name="calcui_button_8"}) - row2.add({type="button", style="calcui_button_style", caption="9", name="calcui_button_9"}) - row2.add({type="button", style="calcui_button_style", caption="*", name="calcui_button_MUL"}) + row2.add({type="sprite-button", style="calcui_button_style_dark", caption="7", name="calcui_button_7"}).sprite = "sprite_calcui_dark" + row2.add({type="sprite-button", style="calcui_button_style_dark", caption="8", name="calcui_button_8"}).sprite = "sprite_calcui_dark" + row2.add({type="sprite-button", style="calcui_button_style_dark", caption="9", name="calcui_button_9"}).sprite = "sprite_calcui_dark" + row2.add({type="sprite-button", style="calcui_button_style_light", caption="*", name="calcui_button_MUL"}).sprite = "sprite_calcui_light" local row3 = col1.add({type="flow", name="calcui_col1_row3", direction="horizontal"}) - row3.add({type="button", style="calcui_button_style", caption="4", name="calcui_button_4"}) - row3.add({type="button", style="calcui_button_style", caption="5", name="calcui_button_5"}) - row3.add({type="button", style="calcui_button_style", caption="6", name="calcui_button_6"}) - row3.add({type="button", style="calcui_button_style", caption="-", name="calcui_button_SUB"}) + row3.add({type="sprite-button", style="calcui_button_style_dark", caption="4", name="calcui_button_4"}).sprite = "sprite_calcui_dark" + row3.add({type="sprite-button", style="calcui_button_style_dark", caption="5", name="calcui_button_5"}).sprite = "sprite_calcui_dark" + row3.add({type="sprite-button", style="calcui_button_style_dark", caption="6", name="calcui_button_6"}).sprite = "sprite_calcui_dark" + row3.add({type="sprite-button", style="calcui_button_style_light", caption="-", name="calcui_button_SUB"}).sprite = "sprite_calcui_light" local row4 = col1.add({type="flow", name="calcui_col1_row4", direction="horizontal"}) - row4.add({type="button", style="calcui_button_style", caption="1", name="calcui_button_1"}) - row4.add({type="button", style="calcui_button_style", caption="2", name="calcui_button_2"}) - row4.add({type="button", style="calcui_button_style", caption="3", name="calcui_button_3"}) - row4.add({type="button", style="calcui_button_style", caption="+", name="calcui_button_ADD"}) + row4.add({type="sprite-button", style="calcui_button_style_dark", caption="1", name="calcui_button_1"}).sprite = "sprite_calcui_dark" + row4.add({type="sprite-button", style="calcui_button_style_dark", caption="2", name="calcui_button_2"}).sprite = "sprite_calcui_dark" + row4.add({type="sprite-button", style="calcui_button_style_dark", caption="3", name="calcui_button_3"}).sprite = "sprite_calcui_dark" + row4.add({type="sprite-button", style="calcui_button_style_light", caption="+", name="calcui_button_ADD"}).sprite = "sprite_calcui_light" local row5 = col1.add({type="flow", name="calcui_col1_row5", direction="horizontal"}) - row5.add({type="button", style="calcui_button_style", caption="%", name="calcui_button_PERC"}) - row5.add({type="button", style="calcui_button_style", caption="0", name="calcui_button_0"}) - row5.add({type="button", style="calcui_button_style", caption=".", name="calcui_button_DOT"}) - row5.add({type="button", style="calcui_button_style", caption="=", name="calcui_button_EQU"}) + row5.add({type="sprite-button", style="calcui_button_style_light", caption="%", name="calcui_button_PERC"}).sprite = "sprite_calcui_light" + row5.add({type="sprite-button", style="calcui_button_style_dark", caption="0", name="calcui_button_0"}).sprite = "sprite_calcui_dark" + 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", @@ -206,6 +207,7 @@ function process_ce_key(player, button) local root = get_gui_root(player) clear_equation(player) root.calcui.calcui_table.calcui_table_col2.calcui_display_result.caption = "=" + root.calcui.calcui_table.calcui_table_col2.calcui_display_result.tooltip = "" end -- ---------------------------------------------------------------- @@ -222,9 +224,23 @@ function process_backspace_key(player, button) end -- ---------------------------------------------------------------- -function fix_equation(equation) +function fix_equation(equation, root) local result = equation - + local prev_result = root.calcui.calcui_table.calcui_table_col2.calcui_display_result.tooltip + + + -- 1. visible part + -- if equation does not start with a number or char, use the previous result (if available) and put it in front + if not (string.match(result:sub(1, 1), "[^%w%(%)]") == nil) and prev_result then + result = prev_result .. result + end + + -- remove "math." + result = result:gsub("math.", "") + local new_equation = result + + + -- 2. invisible part -- fix math library shortcuts local math_lib = { ["abs"] = "math.abs", @@ -267,16 +283,16 @@ function fix_equation(equation) result = result:gsub(",", ".") result = result:gsub(";", ",") - return result + + return result, new_equation end -- ---------------------------------------------------------------- function process_equal_key(player, button) local root = get_gui_root(player) - local original_equation = root.calcui.calcui_table.calcui_table_col1.calcui_display.text; - equation = fix_equation(original_equation) + equation, original_equation = fix_equation(original_equation, root) -- just testing --root.calcui.calcui_table.calcui_table_col1.calcui_display.text = equation diff --git a/graphics/calculator.png b/graphics/calculator.png index d95b768..81404df 100644 Binary files a/graphics/calculator.png and b/graphics/calculator.png differ diff --git a/graphics/dark.png b/graphics/dark.png new file mode 100644 index 0000000..beaa0f2 Binary files /dev/null and b/graphics/dark.png differ diff --git a/graphics/light.png b/graphics/light.png new file mode 100644 index 0000000..2cfefad Binary files /dev/null and b/graphics/light.png differ diff --git a/graphics/red.png b/graphics/red.png new file mode 100644 index 0000000..1de6ebb Binary files /dev/null and b/graphics/red.png differ diff --git a/info.json b/info.json index e6e7215..1672cd0 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "calculator-ui", - "version": "0.18.2", + "version": "0.18.3", "title": "Calculator UI", "author": "Wichu", "factorio_version": "0.18", -- libgit2 0.22.2