Commit 3371d41359808085e71eb7d4e56e30c93da20eda

Authored by Stefan Wichmann
1 parent 7b916f12

New setting for closing the UI by pressing the shortcut

calculator.lua
@@ -257,19 +257,26 @@ local function hide_calculator(player) @@ -257,19 +257,26 @@ local function hide_calculator(player)
257 end 257 end
258 258
259 -- ---------------------------------------------------------------- 259 -- ----------------------------------------------------------------
260 -function toggle_calculator(player) 260 +function focus_on_input(player)
261 local root = get_gui_root(player) 261 local root = get_gui_root(player)
262 - if root and root.calcui then  
263 - hide_calculator(player)  
264 - else  
265 - show_calculator(player)  
266 - end 262 + root.calcui.calcui_table.calcui_table_col1.calcui_display.focus()
267 end 263 end
268 264
269 -- ---------------------------------------------------------------- 265 -- ----------------------------------------------------------------
270 -function focus_on_input(player) 266 +function toggle_calculator(player, extended_mode)
  267 + extended_mode = extended_mode or false
  268 +
271 local root = get_gui_root(player) 269 local root = get_gui_root(player)
272 - root.calcui.calcui_table.calcui_table_col1.calcui_display.focus() 270 + if root and root.calcui then
  271 + -- root.calcui.calcui_table.calcui_table_col1.calcui_display.in_focus()? FIXME not possible with current api
  272 + if extended_mode and not settings.get_player_settings(player)["calcui-shortcut-close"].value then
  273 + focus_on_input(player)
  274 + else
  275 + hide_calculator(player)
  276 + end
  277 + else
  278 + show_calculator(player)
  279 + end
273 end 280 end
274 281
275 -- ---------------------------------------------------------------- 282 -- ----------------------------------------------------------------
changelog.txt
1 --------------------------------------------------------------------------------------------------- 1 ---------------------------------------------------------------------------------------------------
  2 +Version: 1.1.1
  3 +Date: 2020-11-28
  4 + Features:
  5 + - Introduces a new setting to define the behavior of the shortcut. When enabled (Default:
  6 + false) it will close the UI by pressing the shortcut. Default-behavior is still the same:
  7 + focus on the input-field.
  8 +---------------------------------------------------------------------------------------------------
2 Version: 1.1.0 9 Version: 1.1.0
3 Date: 2020-11-24 10 Date: 2020-11-24
4 - Changes: 11 + Info:
5 - Updated the version for Factorio 1.1 Experimental Branch 12 - Updated the version for Factorio 1.1 Experimental Branch
6 --------------------------------------------------------------------------------------------------- 13 ---------------------------------------------------------------------------------------------------
7 Version: 0.18.7 14 Version: 0.18.7
8 Date: 2020-06-25 15 Date: 2020-06-25
9 - Changed: 16 + Changes:
10 - Updated the thumbnail on the mods page 17 - Updated the thumbnail on the mods page
11 - Fixed:  
12 - - Fixed UI style for 0.18.33 update 18 + Bugfixes:
  19 + - Bugfixes UI style for 0.18.33 update
13 --------------------------------------------------------------------------------------------------- 20 ---------------------------------------------------------------------------------------------------
14 Version: 0.18.6 21 Version: 0.18.6
15 Date: 2020-06-11 22 Date: 2020-06-11
16 - Fixed:  
17 - - Percentage calculations fixed; big thanks to GWulf for raising the issue and also providing the fix for it <3 23 + Bugfixes:
  24 + - Percentage calculations Bugfixes; big thanks to GWulf for raising the issue and also
  25 + providing the fix for it <3
18 26
19 --------------------------------------------------------------------------------------------------- 27 ---------------------------------------------------------------------------------------------------
20 Version: 0.18.5 28 Version: 0.18.5
21 Date: 2020-06-08 29 Date: 2020-06-08
22 - General:  
23 - - Added some fancy sound effects and a special [Nilaus](https://www.youtube.com/c/Nilaus) mode.  
24 - Added:  
25 - - Added sound effects to the calculator whenever a result may be not the desired one (has be enabled in the settings)  
26 - Changed:  
27 - - Emotes will no longer be displayed at default, "Nilaus mode" has to be enabled for the emotes to appear again  
28 - Fixed: 30 + Info:
  31 + - Features some fancy sound effects and a special [Nilaus](https://www.youtube.com/c/Nilaus)
  32 + mode.
  33 + Features:
  34 + - Features sound effects to the calculator whenever a result may be not the desired one (has be
  35 + enabled in the settings)
  36 + Changes:
  37 + - Emotes will no longer be displayed at default, "Nilaus mode" has to be enabled for the emotes
  38 + to appear again
  39 + Bugfixes:
29 - Recent results weren't properly cleared in 0.18.4 40 - Recent results weren't properly cleared in 0.18.4
30 - Misc: 41 + Other:
31 - Some code rework, not too fancy stuff 42 - Some code rework, not too fancy stuff
32 43
33 --------------------------------------------------------------------------------------------------- 44 ---------------------------------------------------------------------------------------------------
34 Version: 0.18.4 45 Version: 0.18.4
35 Date: 2020-06-07 46 Date: 2020-06-07
36 - General: 47 + Info:
37 - Based on user feedback updated the mod 48 - Based on user feedback updated the mod
38 - Added:  
39 - - Added the possibility to copy the results (from recent and also the current) to the display  
40 - Changed: 49 + Features:
  50 + - Features the possibility to copy the results (from recent and also the current) to the
  51 + display
  52 + Changes:
41 - Window now remember last location when opened 53 - Window now remember last location when opened
42 - - Updated the BS button (it's backspace people...) so it now has a nice icon instead of the letters 54 + - Updated the BS button (it's backspace people...) so it now has a nice icon instead of the
  55 + letters
43 - Recent results now add to the top, instead of the bottom 56 - Recent results now add to the top, instead of the bottom
44 - When calculator is opened it focues on the display for entering the equation 57 - When calculator is opened it focues on the display for entering the equation
45 - You can click pretty much anywhere now and it focues on the display for entering the equation 58 - You can click pretty much anywhere now and it focues on the display for entering the equation
46 - Fixed:  
47 - - 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).  
48 - - When window is moved out of boundaries, when reopened, it will correct itself to be fully in sight again. 59 + Bugfixes:
  60 + - On multiplayer session the window would lag behind while dragging, because the location would
  61 + be saved on server. This isn't going to happen anymore, hopefully (not tested yet).
  62 + - When window is moved out of boundaries, when reopened, it will correct itself to be fully in
  63 + sight again.
49 - Settings had weird default values (were set 2 times) 64 - Settings had weird default values (were set 2 times)
50 65
51 --------------------------------------------------------------------------------------------------- 66 ---------------------------------------------------------------------------------------------------
52 Version: 0.18.3 67 Version: 0.18.3
53 Date: 2020-06-07 68 Date: 2020-06-07
54 - General: 69 + Info:
55 - A small visual overhaul of the mod 70 - A small visual overhaul of the mod
56 - Added:  
57 - - 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.  
58 - Changed: 71 + Features:
  72 + - Features the possibility to "calculate further" (especially usefull when setting "Clear
  73 + equation on calculation" is set). When the equation doesn't start with a number, character or
  74 + parenthesis (so it assumes it starts with a math symbol) it will take the previous result and
  75 + prepend it to the current equation.
  76 + Changes:
59 - Updated the UI a bit to match it in color a bit more to the Windows calculator 77 - Updated the UI a bit to match it in color a bit more to the Windows calculator
60 - Updated also the icon on the shortcut to better distinguish it 78 - Updated also the icon on the shortcut to better distinguish it
61 79
62 --------------------------------------------------------------------------------------------------- 80 ---------------------------------------------------------------------------------------------------
63 Version: 0.18.2 81 Version: 0.18.2
64 Date: 2020-06-06 82 Date: 2020-06-06
65 - General: 83 + Info:
66 - Based on user feedback updated the mod 84 - Based on user feedback updated the mod
67 - Added: 85 + Features:
68 - new easter egg :-) 86 - new easter egg :-)
69 - - added more math.lib functions 87 + - Features more math.lib functions
70 - atan2() -> math.atan2() 88 - atan2() -> math.atan2()
71 - cosh() -> math.cosh() 89 - cosh() -> math.cosh()
72 - sinh() -> math.sinh() 90 - sinh() -> math.sinh()
@@ -76,32 +94,39 @@ Date: 2020-06-06 @@ -76,32 +94,39 @@ Date: 2020-06-06
76 - frexp() -> math.frexp() 94 - frexp() -> math.frexp()
77 - ldexp() -> math.ldexp() 95 - ldexp() -> math.ldexp()
78 - pow() -> math.pow() 96 - pow() -> math.pow()
79 - Fixed:  
80 - - Interpreting ";" as "," in the equation, because of the fix in 0.18.1, so that math functions with more than 1 parameter work. They have to use ";" as a separator for inputs  
81 - - Fixed sqrt(-1) equaling "na" because of the rounding fix from 0.18.1. It does now show "NaN" again 97 + Bugfixes:
  98 + - Interpreting ";" as "," in the equation, because of the fix in 0.18.1, so that math functions
  99 + with more than 1 parameter work. They have to use ";" as a separator for inputs
  100 + - Bugfixes sqrt(-1) equaling "na" because of the rounding fix from 0.18.1. It does now show
  101 + "NaN" again
82 102
83 --------------------------------------------------------------------------------------------------- 103 ---------------------------------------------------------------------------------------------------
84 Version: 0.18.1 104 Version: 0.18.1
85 Date: 2020-06-06 105 Date: 2020-06-06
86 - General: 106 + Info:
87 - Based on user feedback updated the mod 107 - Based on user feedback updated the mod
88 - Added:  
89 - - Shortcut for opening the calculator and automatically focus on the input (Default: Ctrl+Shift+C)  
90 - Fixed: 108 + Features:
  109 + - Shortcut for opening the calculator and automatically focus on the input (Default:
  110 + Ctrl+Shift+C)
  111 + Bugfixes:
91 - Rounding removed 0 at the end, will now stand as it should. So 2.0000001 -> 2.00 112 - Rounding removed 0 at the end, will now stand as it should. So 2.0000001 -> 2.00
92 - - Interpreting "," as "." in the equation, because of some European countries do have a weird keyboard layout 113 + - Interpreting "," as "." in the equation, because of some European countries do have a weird
  114 + keyboard layout
93 115
94 --------------------------------------------------------------------------------------------------- 116 ---------------------------------------------------------------------------------------------------
95 Version: 0.18.0 117 Version: 0.18.0
96 Date: 2020-06-06 118 Date: 2020-06-06
97 - General: 119 + Info:
98 - Initial Release of the mod 120 - Initial Release of the mod
99 - Compatible with Factorio >0.18.0; tested on 0.18.30 121 - Compatible with Factorio >0.18.0; tested on 0.18.30
100 - - Based on the 4-Function Calculator found in the [Max Rate Calculator](https://mods.factorio.com/mod/MaxRateCalculator) mod by [Theanderblast](https://mods.factorio.com/user/theanderblast)  
101 - Added: 122 + - Based on the 4-Function Calculator found in the
  123 + [Max Rate Calculator](https://mods.factorio.com/mod/MaxRateCalculator) mod by
  124 + [Theanderblast](https://mods.factorio.com/user/theanderblast)
  125 + Features:
102 - History of recent calculations 126 - History of recent calculations
103 - Possibility to copy recent calculations to the current one (with shift+left-click) 127 - Possibility to copy recent calculations to the current one (with shift+left-click)
104 - - Substitutes some functions & "constants" of the Lua [math-lib](http://lua-users.org/wiki/MathLibraryTutorial) 128 + - Substitutes some functions & "constants" of the Lua
  129 + [math-lib](http://lua-users.org/wiki/MathLibraryTutorial)
105 - abs() -> math.abs() 130 - abs() -> math.abs()
106 - acos() -> math.acos() 131 - acos() -> math.acos()
107 - asin() -> math.asin() 132 - asin() -> math.asin()
@@ -123,12 +148,13 @@ Date: 2020-06-06 @@ -123,12 +148,13 @@ Date: 2020-06-06
123 - pi -> math.pi 148 - pi -> math.pi
124 - Allows the use of "%" (percent sign) in the calculation 149 - Allows the use of "%" (percent sign) in the calculation
125 - A little easter egg :-) 150 - A little easter egg :-)
126 - - Setting for number of decimal places in result (Default: 2). Exact value will be displayed in the tooltip 151 + - Setting for number of decimal places in result (Default: 2). Exact value will be displayed in
  152 + the tooltip
127 - Setting if triggering the calculation should clear the current equation (Default: no) 153 - Setting if triggering the calculation should clear the current equation (Default: no)
128 - Changed: 154 + Changes:
129 - Made the buttons slightly bigger, so that it's better readable on streams. 155 - Made the buttons slightly bigger, so that it's better readable on streams.
130 - Allows to make "complex" calculations with parentheses 156 - Allows to make "complex" calculations with parentheses
131 - Allows pretty much all characters in the equation field 157 - Allows pretty much all characters in the equation field
132 - but the "=" (equal sign) will trigger the calculation 158 - but the "=" (equal sign) will trigger the calculation
133 - Removed: 159 + Ease of use:
134 - Got rid of the memory functions - but introduced the list of recent calculations instead 160 - Got rid of the memory functions - but introduced the list of recent calculations instead
135 \ No newline at end of file 161 \ No newline at end of file
control.lua
@@ -77,8 +77,7 @@ end @@ -77,8 +77,7 @@ end
77 -- ---------------------------------------------------------------- 77 -- ----------------------------------------------------------------
78 local function on_hotkey_main(event) 78 local function on_hotkey_main(event)
79 local player = game.players[event.player_index] 79 local player = game.players[event.player_index]
80 - show_calculator(player)  
81 - focus_on_input(player) 80 + toggle_calculator(player, true)
82 end 81 end
83 82
84 -- ---------------------------------------------------------------- 83 -- ----------------------------------------------------------------
info.json
1 { 1 {
2 "name": "calculator-ui", 2 "name": "calculator-ui",
3 - "version": "1.1.0", 3 + "version": "1.1.1",
4 "title": "Calculator UI", 4 "title": "Calculator UI",
5 "author": "Wichu", 5 "author": "Wichu",
6 "factorio_version": "1.1", 6 "factorio_version": "1.1",
locale/en/config.cfg
@@ -7,12 +7,14 @@ calcui_hotkey=Focus on input @@ -7,12 +7,14 @@ calcui_hotkey=Focus on input
7 [mod-setting-name] 7 [mod-setting-name]
8 calcui-decimal-places=Decimal places 8 calcui-decimal-places=Decimal places
9 calcui-clear-on-calc=Clear equation on calculation 9 calcui-clear-on-calc=Clear equation on calculation
  10 +calcui-shortcut-close=Close with Shortcut
10 calcui-nilaus-mode=Nilaus mode 11 calcui-nilaus-mode=Nilaus mode
11 calcui-sfx=Sound effects 12 calcui-sfx=Sound effects
12 13
13 [mod-settings-description] 14 [mod-settings-description]
14 calcui-decimal-places=Number of decimal places in the result 15 calcui-decimal-places=Number of decimal places in the result
15 calcui-clear-on-calc=Should trigger the calculation delete the equation? 16 calcui-clear-on-calc=Should trigger the calculation delete the equation?
  17 +calcui-shortcut-close=Whether the UI should close as well by pressing the shortcut (when true), or focus on the inputfield when already open (when false)
16 calcui-nilaus-mode=With Nilaus mode enabled some special easter eggs appear 18 calcui-nilaus-mode=With Nilaus mode enabled some special easter eggs appear
17 calcui-sfx=When enabled sound effects will be played on strange results 19 calcui-sfx=When enabled sound effects will be played on strange results
18 20
settings.lua
@@ -16,6 +16,12 @@ data:extend({ @@ -16,6 +16,12 @@ data:extend({
16 { 16 {
17 type = "bool-setting", 17 type = "bool-setting",
18 default_value = false, 18 default_value = false,
  19 + name = "calcui-shortcut-close",
  20 + setting_type = "runtime-per-user"
  21 + },
  22 + {
  23 + type = "bool-setting",
  24 + default_value = false,
19 name = "calcui-nilaus-mode", 25 name = "calcui-nilaus-mode",
20 setting_type = "runtime-per-user" 26 setting_type = "runtime-per-user"
21 }, 27 },