From 3371d41359808085e71eb7d4e56e30c93da20eda Mon Sep 17 00:00:00 2001 From: Wichu Date: Sat, 28 Nov 2020 12:59:54 +0100 Subject: [PATCH] New setting for closing the UI by pressing the shortcut --- calculator.lua | 23 +++++++++++++++-------- changelog.txt | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------- control.lua | 3 +-- info.json | 2 +- locale/en/config.cfg | 2 ++ settings.lua | 6 ++++++ 6 files changed, 95 insertions(+), 55 deletions(-) diff --git a/calculator.lua b/calculator.lua index 58c59f8..1f1baa1 100644 --- a/calculator.lua +++ b/calculator.lua @@ -257,19 +257,26 @@ local function hide_calculator(player) end -- ---------------------------------------------------------------- -function toggle_calculator(player) +function focus_on_input(player) local root = get_gui_root(player) - if root and root.calcui then - hide_calculator(player) - else - show_calculator(player) - end + root.calcui.calcui_table.calcui_table_col1.calcui_display.focus() end -- ---------------------------------------------------------------- -function focus_on_input(player) +function toggle_calculator(player, extended_mode) + extended_mode = extended_mode or false + local root = get_gui_root(player) - root.calcui.calcui_table.calcui_table_col1.calcui_display.focus() + if root and root.calcui then + -- root.calcui.calcui_table.calcui_table_col1.calcui_display.in_focus()? FIXME not possible with current api + if extended_mode and not settings.get_player_settings(player)["calcui-shortcut-close"].value then + focus_on_input(player) + else + hide_calculator(player) + end + else + show_calculator(player) + end end -- ---------------------------------------------------------------- diff --git a/changelog.txt b/changelog.txt index 5ea5662..b2c7ca9 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,72 +1,90 @@ --------------------------------------------------------------------------------------------------- +Version: 1.1.1 +Date: 2020-11-28 + Features: + - Introduces a new setting to define the behavior of the shortcut. When enabled (Default: + false) it will close the UI by pressing the shortcut. Default-behavior is still the same: + focus on the input-field. +--------------------------------------------------------------------------------------------------- Version: 1.1.0 Date: 2020-11-24 - Changes: + Info: - Updated the version for Factorio 1.1 Experimental Branch --------------------------------------------------------------------------------------------------- Version: 0.18.7 Date: 2020-06-25 - Changed: + Changes: - Updated the thumbnail on the mods page - Fixed: - - Fixed UI style for 0.18.33 update + Bugfixes: + - Bugfixes UI style for 0.18.33 update --------------------------------------------------------------------------------------------------- Version: 0.18.6 Date: 2020-06-11 - Fixed: - - Percentage calculations fixed; big thanks to GWulf for raising the issue and also providing the fix for it <3 + Bugfixes: + - Percentage calculations Bugfixes; big thanks to GWulf for raising the issue and also + providing the fix for it <3 --------------------------------------------------------------------------------------------------- Version: 0.18.5 Date: 2020-06-08 - General: - - Added some fancy sound effects and a special [Nilaus](https://www.youtube.com/c/Nilaus) mode. - Added: - - Added sound effects to the calculator whenever a result may be not the desired one (has be enabled in the settings) - Changed: - - Emotes will no longer be displayed at default, "Nilaus mode" has to be enabled for the emotes to appear again - Fixed: + Info: + - Features some fancy sound effects and a special [Nilaus](https://www.youtube.com/c/Nilaus) + mode. + Features: + - Features sound effects to the calculator whenever a result may be not the desired one (has be + enabled in the settings) + Changes: + - Emotes will no longer be displayed at default, "Nilaus mode" has to be enabled for the emotes + to appear again + Bugfixes: - Recent results weren't properly cleared in 0.18.4 - Misc: + Other: - Some code rework, not too fancy stuff --------------------------------------------------------------------------------------------------- Version: 0.18.4 Date: 2020-06-07 - General: + Info: - Based on user feedback updated the mod - Added: - - Added the possibility to copy the results (from recent and also the current) to the display - Changed: + Features: + - Features the possibility to copy the results (from recent and also the current) to the + display + Changes: - Window now remember last location when opened - - Updated the BS button (it's backspace people...) so it now has a nice icon instead of the letters + - Updated the BS button (it's backspace people...) so it now has a nice icon instead of the + letters - Recent results now add to the top, instead of the bottom - When calculator is opened it focues on the display for entering the equation - You can click pretty much anywhere now and it focues on the display for entering the equation - Fixed: - - 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). - - When window is moved out of boundaries, when reopened, it will correct itself to be fully in sight again. + Bugfixes: + - 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). + - When window is moved out of boundaries, when reopened, it will correct itself to be fully in + sight again. - Settings had weird default values (were set 2 times) --------------------------------------------------------------------------------------------------- Version: 0.18.3 Date: 2020-06-07 - General: + Info: - 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: + Features: + - Features 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. + Changes: - 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 --------------------------------------------------------------------------------------------------- Version: 0.18.2 Date: 2020-06-06 - General: + Info: - Based on user feedback updated the mod - Added: + Features: - new easter egg :-) - - added more math.lib functions + - Features more math.lib functions - atan2() -> math.atan2() - cosh() -> math.cosh() - sinh() -> math.sinh() @@ -76,32 +94,39 @@ Date: 2020-06-06 - frexp() -> math.frexp() - ldexp() -> math.ldexp() - pow() -> math.pow() - Fixed: - - 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 - - Fixed sqrt(-1) equaling "na" because of the rounding fix from 0.18.1. It does now show "NaN" again + Bugfixes: + - 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 + - Bugfixes sqrt(-1) equaling "na" because of the rounding fix from 0.18.1. It does now show + "NaN" again --------------------------------------------------------------------------------------------------- Version: 0.18.1 Date: 2020-06-06 - General: + Info: - Based on user feedback updated the mod - Added: - - Shortcut for opening the calculator and automatically focus on the input (Default: Ctrl+Shift+C) - Fixed: + Features: + - Shortcut for opening the calculator and automatically focus on the input (Default: + Ctrl+Shift+C) + Bugfixes: - Rounding removed 0 at the end, will now stand as it should. So 2.0000001 -> 2.00 - - Interpreting "," as "." in the equation, because of some European countries do have a weird keyboard layout + - Interpreting "," as "." in the equation, because of some European countries do have a weird + keyboard layout --------------------------------------------------------------------------------------------------- Version: 0.18.0 Date: 2020-06-06 - General: + Info: - Initial Release of the mod - Compatible with Factorio >0.18.0; tested on 0.18.30 - - 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) - Added: + - 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) + Features: - History of recent calculations - Possibility to copy recent calculations to the current one (with shift+left-click) - - Substitutes some functions & "constants" of the Lua [math-lib](http://lua-users.org/wiki/MathLibraryTutorial) + - Substitutes some functions & "constants" of the Lua + [math-lib](http://lua-users.org/wiki/MathLibraryTutorial) - abs() -> math.abs() - acos() -> math.acos() - asin() -> math.asin() @@ -123,12 +148,13 @@ Date: 2020-06-06 - pi -> math.pi - Allows the use of "%" (percent sign) in the calculation - A little easter egg :-) - - Setting for number of decimal places in result (Default: 2). Exact value will be displayed in the tooltip + - Setting for number of decimal places in result (Default: 2). Exact value will be displayed in + the tooltip - Setting if triggering the calculation should clear the current equation (Default: no) - Changed: + Changes: - Made the buttons slightly bigger, so that it's better readable on streams. - Allows to make "complex" calculations with parentheses - Allows pretty much all characters in the equation field - but the "=" (equal sign) will trigger the calculation - Removed: + Ease of use: - Got rid of the memory functions - but introduced the list of recent calculations instead \ No newline at end of file diff --git a/control.lua b/control.lua index bbd0af4..229e6ab 100644 --- a/control.lua +++ b/control.lua @@ -77,8 +77,7 @@ end -- ---------------------------------------------------------------- local function on_hotkey_main(event) local player = game.players[event.player_index] - show_calculator(player) - focus_on_input(player) + toggle_calculator(player, true) end -- ---------------------------------------------------------------- diff --git a/info.json b/info.json index 1df3c2c..131d14e 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "calculator-ui", - "version": "1.1.0", + "version": "1.1.1", "title": "Calculator UI", "author": "Wichu", "factorio_version": "1.1", diff --git a/locale/en/config.cfg b/locale/en/config.cfg index 0c496fa..9b5c330 100644 --- a/locale/en/config.cfg +++ b/locale/en/config.cfg @@ -7,12 +7,14 @@ calcui_hotkey=Focus on input [mod-setting-name] calcui-decimal-places=Decimal places calcui-clear-on-calc=Clear equation on calculation +calcui-shortcut-close=Close with Shortcut calcui-nilaus-mode=Nilaus mode calcui-sfx=Sound effects [mod-settings-description] calcui-decimal-places=Number of decimal places in the result calcui-clear-on-calc=Should trigger the calculation delete the equation? +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) calcui-nilaus-mode=With Nilaus mode enabled some special easter eggs appear calcui-sfx=When enabled sound effects will be played on strange results diff --git a/settings.lua b/settings.lua index 36dac8e..c304915 100644 --- a/settings.lua +++ b/settings.lua @@ -16,6 +16,12 @@ data:extend({ { type = "bool-setting", default_value = false, + name = "calcui-shortcut-close", + setting_type = "runtime-per-user" + }, + { + type = "bool-setting", + default_value = false, name = "calcui-nilaus-mode", setting_type = "runtime-per-user" }, -- libgit2 0.22.2