Commit 9d6691a6ce97f4a4ff880399073f150adbbd7b49
1 parent
3371d413
Updated to Factorio 2.0
Showing
12 changed files
with
336 additions
and
97 deletions
.vscode/launch.json
| ... | ... | @@ -8,9 +8,8 @@ |
| 8 | 8 | "type": "factoriomod", |
| 9 | 9 | "request": "launch", |
| 10 | 10 | "name": "Factorio Mod Debug", |
| 11 | - "modsPath": "C:/Program Files/Factorio/mods", | |
| 12 | - "configPath": "C:/Program Files/Factorio/config/config.ini", | |
| 13 | - "factorioPath": "C:/Program Files/Factorio/bin/x64/factorio.exe" | |
| 11 | + "modsPath": "C:\\Users\\stefa\\AppData\\Roaming\\Factorio\\mods", | |
| 12 | + "disableExtraMods": false | |
| 14 | 13 | // "hookSettings": true, |
| 15 | 14 | // "hookData": true |
| 16 | 15 | } | ... | ... |
.vscode/settings.json
0 → 100644
| 1 | +{ | |
| 2 | + "factorio.versions": [ | |
| 3 | + { | |
| 4 | + "name": "2.0", | |
| 5 | + "factorioPath": "C:\\Program Files\\Factorio\\bin\\x64\\factorio.exe", | |
| 6 | + "active": true | |
| 7 | + }, | |
| 8 | + { | |
| 9 | + "name": "Steam", | |
| 10 | + "factorioPath": "d:\\SteamLibrary\\steamapps\\common\\Factorio\\bin\\x64\\factorio.exe" | |
| 11 | + } | |
| 12 | + ], | |
| 13 | + "Lua.workspace.userThirdParty": [ | |
| 14 | + "c:\\Users\\stefa\\AppData\\Roaming\\Code\\User\\workspaceStorage\\35847ccd64cb986037e0824286320fb8\\justarandomgeek.factoriomod-debug\\sumneko-3rd" | |
| 15 | + ], | |
| 16 | + "Lua.workspace.checkThirdParty": "ApplyInMemory" | |
| 17 | +} | |
| 0 | 18 | \ No newline at end of file | ... | ... |
calcui-hotkey.lua
calcui-prototypes.lua
| ... | ... | @@ -7,13 +7,9 @@ data:extend({ |
| 7 | 7 | order = "b[blueprints]-h[calculator-ui]", |
| 8 | 8 | action = "lua", |
| 9 | 9 | toggleable = true, |
| 10 | - icon = | |
| 11 | - { | |
| 12 | - filename = "__calculator-ui__/graphics/calculator.png", | |
| 13 | - priority = "extra-high-no-scale", | |
| 14 | - size = 64, | |
| 15 | - scale = 1, | |
| 16 | - flags = {"icon"} | |
| 17 | - } | |
| 10 | + icon = "__calculator-ui__/graphics/calculator.png", | |
| 11 | + icon_size = 64, | |
| 12 | + small_icon = "__calculator-ui__/graphics/calculator.png", | |
| 13 | + small_icon_size = 64 | |
| 18 | 14 | } |
| 19 | -}) | |
| 20 | 15 | \ No newline at end of file |
| 16 | +}) | ... | ... |
calculator.lua
| ... | ... | @@ -11,7 +11,7 @@ local nilaus_rant = { "calcui_nilaus_ugghhhh", "utility/cannot_build" } |
| 11 | 11 | -- ---------------------------------------------------------------- |
| 12 | 12 | local function play_sfx(player, sfx) |
| 13 | 13 | if settings.get_player_settings(player)["calcui-sfx"].value then |
| 14 | - player.play_sound{ | |
| 14 | + player.play_sound { | |
| 15 | 15 | path = sfx, |
| 16 | 16 | volume_modifier = 1.0 |
| 17 | 17 | } |
| ... | ... | @@ -61,28 +61,28 @@ local function destroy_calculator(player) |
| 61 | 61 | local root = get_gui_root(player) |
| 62 | 62 | if root.calcui then |
| 63 | 63 | root.calcui.destroy() |
| 64 | - global.recent_results[player.index] = {} | |
| 64 | + storage.recent_results[player.index] = {} | |
| 65 | 65 | end |
| 66 | 66 | end |
| 67 | 67 | |
| 68 | 68 | -- ---------------------------------------------------------------- |
| 69 | 69 | local function fix_oob_ui(player) |
| 70 | - if global.gui_position[player.index].x < 0 then | |
| 71 | - global.gui_position[player.index].x = 0 | |
| 70 | + if storage.gui_position[player.index].x < 0 then | |
| 71 | + storage.gui_position[player.index].x = 0 | |
| 72 | 72 | end |
| 73 | - if global.gui_position[player.index].y < 0 then | |
| 74 | - global.gui_position[player.index].y = 0 | |
| 73 | + if storage.gui_position[player.index].y < 0 then | |
| 74 | + storage.gui_position[player.index].y = 0 | |
| 75 | 75 | end |
| 76 | 76 | |
| 77 | 77 | -- TODO fixed box size, because there is no API call for that |
| 78 | 78 | local width = 255 |
| 79 | 79 | local height = 350 |
| 80 | 80 | |
| 81 | - if global.gui_position[player.index].x + width > player.display_resolution.width then | |
| 82 | - global.gui_position[player.index].x = player.display_resolution.width - width | |
| 81 | + if storage.gui_position[player.index].x + width > player.display_resolution.width then | |
| 82 | + storage.gui_position[player.index].x = player.display_resolution.width - width | |
| 83 | 83 | end |
| 84 | - if global.gui_position[player.index].y + height > player.display_resolution.height then | |
| 85 | - global.gui_position[player.index].y = player.display_resolution.height - height | |
| 84 | + if storage.gui_position[player.index].y + height > player.display_resolution.height then | |
| 85 | + storage.gui_position[player.index].y = player.display_resolution.height - height | |
| 86 | 86 | end |
| 87 | 87 | end |
| 88 | 88 | |
| ... | ... | @@ -90,11 +90,11 @@ end |
| 90 | 90 | function show_calculator(player) |
| 91 | 91 | local root = get_gui_root(player) |
| 92 | 92 | |
| 93 | - if not global.recent_results then | |
| 94 | - global.recent_results = {} | |
| 93 | + if not storage.recent_results then | |
| 94 | + storage.recent_results = {} | |
| 95 | 95 | end |
| 96 | - if not global.recent_results[player.index] then | |
| 97 | - global.recent_results[player.index] = {} | |
| 96 | + if not storage.recent_results[player.index] then | |
| 97 | + storage.recent_results[player.index] = {} | |
| 98 | 98 | end |
| 99 | 99 | |
| 100 | 100 | if not root.calcui then |
| ... | ... | @@ -108,12 +108,12 @@ function show_calculator(player) |
| 108 | 108 | type = "flow", |
| 109 | 109 | name = "calcui_flow" |
| 110 | 110 | }) |
| 111 | - flow.style.horizontally_stretchable = "on" | |
| 111 | + flow.style.horizontally_stretchable = true | |
| 112 | 112 | |
| 113 | 113 | flow.add({ |
| 114 | 114 | type = "label", |
| 115 | 115 | name = "calcui_title", |
| 116 | - caption = {"calculator-ui.title"}, | |
| 116 | + caption = { "calculator-ui.title" }, | |
| 117 | 117 | style = "frame_title" |
| 118 | 118 | }).drag_target = calcui |
| 119 | 119 | |
| ... | ... | @@ -123,13 +123,13 @@ function show_calculator(player) |
| 123 | 123 | name = "calcui_drag" |
| 124 | 124 | }) |
| 125 | 125 | widget.drag_target = calcui |
| 126 | - widget.style.horizontally_stretchable = "on" | |
| 126 | + widget.style.horizontally_stretchable = true | |
| 127 | 127 | widget.style.minimal_width = 24 |
| 128 | 128 | widget.style.natural_height = 24 |
| 129 | 129 | |
| 130 | 130 | flow.add({ |
| 131 | 131 | type = "sprite-button", |
| 132 | - sprite = "utility/close_white", | |
| 132 | + sprite = "utility/close", | |
| 133 | 133 | style = "frame_action_button", |
| 134 | 134 | name = "calcui_close" |
| 135 | 135 | }) |
| ... | ... | @@ -154,35 +154,61 @@ function show_calculator(player) |
| 154 | 154 | }) |
| 155 | 155 | display.style.width = 212 |
| 156 | 156 | |
| 157 | - local row1 = col1.add({type="flow", name="calcui_col1_row1", direction="horizontal"}) | |
| 158 | - 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) | |
| 159 | - 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) | |
| 160 | - row1.add({type="sprite-button", style="calcui_button_style_light", caption="", name="calcui_button_BS"}).sprite = "sprite_calcui_backspace" | |
| 161 | - row1.add({type="sprite-button", style="calcui_button_style_light", caption="/", name="calcui_button_DIV"}).sprite = "sprite_calcui_light" | |
| 162 | - | |
| 163 | - local row2 = col1.add({type="flow", name="calcui_col1_row2", direction="horizontal"}) | |
| 164 | - row2.add({type="sprite-button", style="calcui_button_style_dark", caption="7", name="calcui_button_7"}).sprite = "sprite_calcui_dark" | |
| 165 | - row2.add({type="sprite-button", style="calcui_button_style_dark", caption="8", name="calcui_button_8"}).sprite = "sprite_calcui_dark" | |
| 166 | - row2.add({type="sprite-button", style="calcui_button_style_dark", caption="9", name="calcui_button_9"}).sprite = "sprite_calcui_dark" | |
| 167 | - row2.add({type="sprite-button", style="calcui_button_style_light", caption="*", name="calcui_button_MUL"}).sprite = "sprite_calcui_light" | |
| 168 | - | |
| 169 | - local row3 = col1.add({type="flow", name="calcui_col1_row3", direction="horizontal"}) | |
| 170 | - row3.add({type="sprite-button", style="calcui_button_style_dark", caption="4", name="calcui_button_4"}).sprite = "sprite_calcui_dark" | |
| 171 | - row3.add({type="sprite-button", style="calcui_button_style_dark", caption="5", name="calcui_button_5"}).sprite = "sprite_calcui_dark" | |
| 172 | - row3.add({type="sprite-button", style="calcui_button_style_dark", caption="6", name="calcui_button_6"}).sprite = "sprite_calcui_dark" | |
| 173 | - row3.add({type="sprite-button", style="calcui_button_style_light", caption="-", name="calcui_button_SUB"}).sprite = "sprite_calcui_light" | |
| 174 | - | |
| 175 | - local row4 = col1.add({type="flow", name="calcui_col1_row4", direction="horizontal"}) | |
| 176 | - row4.add({type="sprite-button", style="calcui_button_style_dark", caption="1", name="calcui_button_1"}).sprite = "sprite_calcui_dark" | |
| 177 | - row4.add({type="sprite-button", style="calcui_button_style_dark", caption="2", name="calcui_button_2"}).sprite = "sprite_calcui_dark" | |
| 178 | - row4.add({type="sprite-button", style="calcui_button_style_dark", caption="3", name="calcui_button_3"}).sprite = "sprite_calcui_dark" | |
| 179 | - row4.add({type="sprite-button", style="calcui_button_style_light", caption="+", name="calcui_button_ADD"}).sprite = "sprite_calcui_light" | |
| 180 | - | |
| 181 | - local row5 = col1.add({type="flow", name="calcui_col1_row5", direction="horizontal"}) | |
| 182 | - row5.add({type="sprite-button", style="calcui_button_style_light", caption="%", name="calcui_button_PERC"}).sprite = "sprite_calcui_light" | |
| 183 | - row5.add({type="sprite-button", style="calcui_button_style_dark", caption="0", name="calcui_button_0"}).sprite = "sprite_calcui_dark" | |
| 184 | - row5.add({type="sprite-button", style="calcui_button_style_dark", caption=".", name="calcui_button_DOT"}).sprite = "sprite_calcui_dark" | |
| 185 | - row5.add({type="sprite-button", style="calcui_button_style_red", caption="=", name="calcui_button_EQU"}).sprite = "sprite_calcui_red" | |
| 157 | + local row1 = col1.add({ type = "flow", name = "calcui_col1_row1", direction = "horizontal" }) | |
| 158 | + row1.add({ | |
| 159 | + type = "sprite-button", | |
| 160 | + style = "calcui_button_style_light", | |
| 161 | + caption = "CE", | |
| 162 | + tooltip = { "calculator-ui.button_CE" }, | |
| 163 | + name = | |
| 164 | + "calcui_button_CE" | |
| 165 | + }) --.sprite = "sprite_calcui_light" -- CE = Clear Entry (just this line) | |
| 166 | + row1.add({ type = "sprite-button", style = "calcui_button_style_light", caption = "C", tooltip = { "calculator-ui.button_C" }, name = "calcui_button_C" }).sprite = | |
| 167 | + "sprite_calcui_light" -- C = Clear (all, past results as well) | |
| 168 | + row1.add({ type = "sprite-button", style = "calcui_button_style_light", caption = "", tooltip = { "calculator-ui.button_BS" }, name = "calcui_button_BS" }).sprite = | |
| 169 | + "sprite_calcui_backspace" | |
| 170 | + row1.add({ type = "sprite-button", style = "calcui_button_style_light", caption = "/", tooltip = { "calculator-ui.button_DIV" }, name = "calcui_button_DIV" }).sprite = | |
| 171 | + "sprite_calcui_light" | |
| 172 | + | |
| 173 | + local row2 = col1.add({ type = "flow", name = "calcui_col1_row2", direction = "horizontal" }) | |
| 174 | + row2.add({ type = "sprite-button", style = "calcui_button_style_dark", caption = "7", tooltip = { "calculator-ui.button_7" }, name = "calcui_button_7" }).sprite = | |
| 175 | + "sprite_calcui_dark" | |
| 176 | + row2.add({ type = "sprite-button", style = "calcui_button_style_dark", caption = "8", tooltip = { "calculator-ui.button_8" }, name = "calcui_button_8" }).sprite = | |
| 177 | + "sprite_calcui_dark" | |
| 178 | + row2.add({ type = "sprite-button", style = "calcui_button_style_dark", caption = "9", tooltip = { "calculator-ui.button_9" }, name = "calcui_button_9" }).sprite = | |
| 179 | + "sprite_calcui_dark" | |
| 180 | + row2.add({ type = "sprite-button", style = "calcui_button_style_light", caption = "*", tooltip = { "calculator-ui.button_MUL" }, name = "calcui_button_MUL" }).sprite = | |
| 181 | + "sprite_calcui_light" | |
| 182 | + | |
| 183 | + local row3 = col1.add({ type = "flow", name = "calcui_col1_row3", direction = "horizontal" }) | |
| 184 | + row3.add({ type = "sprite-button", style = "calcui_button_style_dark", caption = "4", tooltip = { "calculator-ui.button_4" }, name = "calcui_button_4" }).sprite = | |
| 185 | + "sprite_calcui_dark" | |
| 186 | + row3.add({ type = "sprite-button", style = "calcui_button_style_dark", caption = "5", tooltip = { "calculator-ui.button_5" }, name = "calcui_button_5" }).sprite = | |
| 187 | + "sprite_calcui_dark" | |
| 188 | + row3.add({ type = "sprite-button", style = "calcui_button_style_dark", caption = "6", tooltip = { "calculator-ui.button_6" }, name = "calcui_button_6" }).sprite = | |
| 189 | + "sprite_calcui_dark" | |
| 190 | + row3.add({ type = "sprite-button", style = "calcui_button_style_light", caption = "-", tooltip = { "calculator-ui.button_SUB" }, name = "calcui_button_SUB" }).sprite = | |
| 191 | + "sprite_calcui_light" | |
| 192 | + | |
| 193 | + local row4 = col1.add({ type = "flow", name = "calcui_col1_row4", direction = "horizontal" }) | |
| 194 | + row4.add({ type = "sprite-button", style = "calcui_button_style_dark", caption = "1", tooltip = { "calculator-ui.button_1" }, name = "calcui_button_1" }).sprite = | |
| 195 | + "sprite_calcui_dark" | |
| 196 | + row4.add({ type = "sprite-button", style = "calcui_button_style_dark", caption = "2", tooltip = { "calculator-ui.button_2" }, name = "calcui_button_2" }).sprite = | |
| 197 | + "sprite_calcui_dark" | |
| 198 | + row4.add({ type = "sprite-button", style = "calcui_button_style_dark", caption = "3", tooltip = { "calculator-ui.button_3" }, name = "calcui_button_3" }).sprite = | |
| 199 | + "sprite_calcui_dark" | |
| 200 | + row4.add({ type = "sprite-button", style = "calcui_button_style_light", caption = "+", tooltip = { "calculator-ui.button_ADD" }, name = "calcui_button_ADD" }).sprite = | |
| 201 | + "sprite_calcui_light" | |
| 202 | + | |
| 203 | + local row5 = col1.add({ type = "flow", name = "calcui_col1_row5", direction = "horizontal" }) | |
| 204 | + row5.add({ type = "sprite-button", style = "calcui_button_style_light", caption = "%", tooltip = { "calculator-ui.button_PERC" }, name = "calcui_button_PERC" }).sprite = | |
| 205 | + "sprite_calcui_light" | |
| 206 | + row5.add({ type = "sprite-button", style = "calcui_button_style_dark", caption = "0", tooltip = { "calculator-ui.button_0" }, name = "calcui_button_0" }).sprite = | |
| 207 | + "sprite_calcui_dark" | |
| 208 | + row5.add({ type = "sprite-button", style = "calcui_button_style_dark", caption = ".", tooltip = { "calculator-ui.button_DOT" }, name = "calcui_button_DOT" }).sprite = | |
| 209 | + "sprite_calcui_dark" | |
| 210 | + row5.add({ type = "sprite-button", style = "calcui_button_style_red", caption = "=", tooltip = { "calculator-ui.button_EQU" }, name = "calcui_button_EQU" }).sprite = | |
| 211 | + "sprite_calcui_red" | |
| 186 | 212 | |
| 187 | 213 | local col2 = table.add({ |
| 188 | 214 | type = "flow", |
| ... | ... | @@ -234,14 +260,14 @@ function show_calculator(player) |
| 234 | 260 | |
| 235 | 261 | |
| 236 | 262 | -- use last saved location or center the gui |
| 237 | - if not global.gui_position then | |
| 238 | - global.gui_position = {} | |
| 263 | + if not storage.gui_position then | |
| 264 | + storage.gui_position = {} | |
| 239 | 265 | end |
| 240 | - if global.gui_position[player.index] then | |
| 266 | + if storage.gui_position[player.index] then | |
| 241 | 267 | -- fix weird saved positions (out of reach) |
| 242 | 268 | fix_oob_ui(player) |
| 243 | 269 | |
| 244 | - calcui.location = global.gui_position[player.index] | |
| 270 | + calcui.location = storage.gui_position[player.index] | |
| 245 | 271 | else |
| 246 | 272 | calcui.force_auto_center() |
| 247 | 273 | end |
| ... | ... | @@ -299,7 +325,7 @@ local function process_c_key(player, button) |
| 299 | 325 | local root = get_gui_root(player) |
| 300 | 326 | process_ce_key(player, button) |
| 301 | 327 | root.calcui.calcui_table.calcui_table_col2.calcui_scroll_pane.calcui_result_table.clear() |
| 302 | - global.recent_results[player.index] = {} | |
| 328 | + storage.recent_results[player.index] = {} | |
| 303 | 329 | end |
| 304 | 330 | |
| 305 | 331 | -- ---------------------------------------------------------------- |
| ... | ... | @@ -318,12 +344,12 @@ local function draw_recent_table(player) |
| 318 | 344 | -- drop old table |
| 319 | 345 | recent.calcui_result_table.clear() |
| 320 | 346 | |
| 321 | - for i, result in ipairs(global.recent_results[player.index]) do | |
| 347 | + for i, result in ipairs(storage.recent_results[player.index]) do | |
| 322 | 348 | recent.calcui_result_table.add({ |
| 323 | 349 | type = "label", |
| 324 | 350 | name = "calcui_copy_equation_" .. i, |
| 325 | 351 | caption = result["equation"], |
| 326 | - tooltip = {"calculator-ui.recent_tooltip"} | |
| 352 | + tooltip = { "calculator-ui.recent_tooltip" } | |
| 327 | 353 | }) |
| 328 | 354 | recent.calcui_result_table.add({ |
| 329 | 355 | type = "label", |
| ... | ... | @@ -394,11 +420,11 @@ local function fix_equation(equation, root) |
| 394 | 420 | |
| 395 | 421 | -- fix percentage |
| 396 | 422 | -- complex equations like "20+10%" = 22, before it was 20.1 -- big thanks to GWulf |
| 397 | - result = result:gsub("(%d+)(.)(%d+)%%", function (base, sign, perc) | |
| 423 | + result = result:gsub("(%d+)(.)(%d+)%%", function(base, sign, perc) | |
| 398 | 424 | if sign == "+" then |
| 399 | 425 | return base .. "*1." .. perc |
| 400 | 426 | elseif sign == "-" then |
| 401 | - return base .. "*(1-0." ..perc .. ")" | |
| 427 | + return base .. "*(1-0." .. perc .. ")" | |
| 402 | 428 | elseif sign == "*" then |
| 403 | 429 | return "(" .. base .. "/100)*" .. perc |
| 404 | 430 | elseif sign == "/" then |
| ... | ... | @@ -412,11 +438,26 @@ local function fix_equation(equation, root) |
| 412 | 438 | result = result:gsub(",", ".") |
| 413 | 439 | result = result:gsub(";", ",") |
| 414 | 440 | |
| 441 | + -- remove thousand separators | |
| 442 | + result = result:gsub("'", ""); | |
| 415 | 443 | |
| 416 | 444 | return result, new_equation |
| 417 | 445 | end |
| 418 | 446 | |
| 419 | 447 | -- ---------------------------------------------------------------- |
| 448 | +function add_thousand_separator(result) | |
| 449 | + local left, num, right = string.match(result, '^([^%d]*%d)(%d*)(.-)$') | |
| 450 | + num = num:reverse():gsub("(%d%d%d)", "%1'"):reverse() | |
| 451 | + return left .. num .. right | |
| 452 | +end | |
| 453 | + | |
| 454 | +-- ---------------------------------------------------------------- | |
| 455 | +function is_scientific_notation(result) | |
| 456 | + -- Check if the number is in scientific notation | |
| 457 | + return string.match(result, "^[-+]?%d*%.?%d+e[-+]?%d+$") | |
| 458 | +end | |
| 459 | + | |
| 460 | +-- ---------------------------------------------------------------- | |
| 420 | 461 | function process_equal_key(player, button) |
| 421 | 462 | local root = get_gui_root(player) |
| 422 | 463 | local original_equation = root.calcui.calcui_table.calcui_table_col1.calcui_display.text; |
| ... | ... | @@ -431,12 +472,34 @@ function process_equal_key(player, button) |
| 431 | 472 | return load("return " .. equation)() |
| 432 | 473 | end) |
| 433 | 474 | root.calcui.calcui_table.calcui_table_col2.calcui_result.calcui_copy_display_result.tooltip = retval |
| 475 | + | |
| 434 | 476 | if not (retval == math.huge or retval ~= retval) then |
| 435 | 477 | status, retval_show = pcall(function() |
| 436 | - local result = string.format("%0." .. settings.get_player_settings(player)["calcui-decimal-places"].value .. "f", retval) | |
| 437 | - if result:len() > tostring(retval):len() then | |
| 438 | - result = retval | |
| 478 | + -- Check if the result is in scientific notation | |
| 479 | + if is_scientific_notation(retval) then | |
| 480 | + return retval | |
| 439 | 481 | end |
| 482 | + | |
| 483 | + local result = string.format( | |
| 484 | + "%0." .. settings.get_player_settings(player)["calcui-decimal-places"].value .. "f", retval) | |
| 485 | + | |
| 486 | + | |
| 487 | + -- Add thousand separators | |
| 488 | + result = add_thousand_separator(result) | |
| 489 | + | |
| 490 | + -- Check if extra decimal places need to be removed | |
| 491 | + local trimmed_result = tostring(retval) | |
| 492 | + if string.find(trimmed_result, '%.') then | |
| 493 | + local int, frac = trimmed_result:match("(%d+)%.(%d+)") | |
| 494 | + if frac then | |
| 495 | + local truncated_result = int .. | |
| 496 | + "." .. frac:sub(1, settings.get_player_settings(player)["calcui-decimal-places"].value) | |
| 497 | + result = add_thousand_separator(truncated_result) | |
| 498 | + end | |
| 499 | + else | |
| 500 | + result = add_thousand_separator(trimmed_result) | |
| 501 | + end | |
| 502 | + | |
| 440 | 503 | return result |
| 441 | 504 | end) |
| 442 | 505 | else |
| ... | ... | @@ -460,8 +523,8 @@ function process_equal_key(player, button) |
| 460 | 523 | -- only write in recent table if actually a result |
| 461 | 524 | if status then |
| 462 | 525 | -- check first equation and only insert if not the same |
| 463 | - if #global.recent_results[player.index] == 0 or global.recent_results[player.index][1]["equation"] ~= original_equation then | |
| 464 | - table.insert(global.recent_results[player.index], 1, { | |
| 526 | + if #storage.recent_results[player.index] == 0 or storage.recent_results[player.index][1]["equation"] ~= original_equation then | |
| 527 | + table.insert(storage.recent_results[player.index], 1, { | |
| 465 | 528 | equation = original_equation, |
| 466 | 529 | result = retval_show |
| 467 | 530 | }) |
| ... | ... | @@ -527,7 +590,7 @@ function handle_calcui_click(event, player) |
| 527 | 590 | if string.sub(event_name, 1, button_prefix_len) == button_prefix then |
| 528 | 591 | show_rant(player, false) |
| 529 | 592 | |
| 530 | - button = string.sub(event_name, button_prefix_len + 1 ) | |
| 593 | + button = string.sub(event_name, button_prefix_len + 1) | |
| 531 | 594 | debug_print("handle_calcui_click button " .. button) |
| 532 | 595 | local dispatch_func = button_dispatch[button] |
| 533 | 596 | if dispatch_func then |
| ... | ... | @@ -538,23 +601,25 @@ function handle_calcui_click(event, player) |
| 538 | 601 | if addchar then |
| 539 | 602 | display_addchar(player, addchar) |
| 540 | 603 | end |
| 541 | - -- close button | |
| 604 | + -- close button | |
| 542 | 605 | elseif event_name == "calcui_close" then |
| 543 | 606 | hide_calculator(player) |
| 544 | - -- copy results | |
| 607 | + -- copy results | |
| 545 | 608 | elseif string.sub(event_name, 1, copy_prefix_len) == copy_prefix then |
| 546 | 609 | if event.button == defines.mouse_button_type.left and |
| 547 | - event.shift == true then | |
| 610 | + event.shift == true then | |
| 548 | 611 | -- copy equation or result to display |
| 549 | 612 | local root = get_gui_root(player) |
| 550 | 613 | if event_name == "calcui_copy_display_result" then |
| 551 | - root.calcui.calcui_table.calcui_table_col1.calcui_display.text = root.calcui.calcui_table.calcui_table_col2.calcui_result.calcui_copy_display_result.caption | |
| 614 | + root.calcui.calcui_table.calcui_table_col1.calcui_display.text = root.calcui.calcui_table | |
| 615 | + .calcui_table_col2.calcui_result.calcui_copy_display_result.caption | |
| 552 | 616 | else |
| 553 | - 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 | |
| 617 | + root.calcui.calcui_table.calcui_table_col1.calcui_display.text = root.calcui.calcui_table | |
| 618 | + .calcui_table_col2.calcui_scroll_pane.calcui_result_table[event_name].caption | |
| 554 | 619 | end |
| 555 | 620 | end |
| 556 | 621 | focus_on_input(player) |
| 557 | - -- if else focus on focus on display | |
| 622 | + -- if else focus on focus on display | |
| 558 | 623 | else |
| 559 | 624 | focus_on_input(player) |
| 560 | 625 | end |
| ... | ... | @@ -566,7 +631,8 @@ function calcui_on_gui_text_changed(event) |
| 566 | 631 | local player = game.players[event.player_index] |
| 567 | 632 | local root = get_gui_root(player) |
| 568 | 633 | if string.find(root.calcui.calcui_table.calcui_table_col1.calcui_display.text, "=") then |
| 569 | - root.calcui.calcui_table.calcui_table_col1.calcui_display.text = root.calcui.calcui_table.calcui_table_col1.calcui_display.text:gsub("=", "") | |
| 634 | + root.calcui.calcui_table.calcui_table_col1.calcui_display.text = root.calcui.calcui_table.calcui_table_col1 | |
| 635 | + .calcui_display.text:gsub("=", "") | |
| 570 | 636 | process_equal_key(player) |
| 571 | 637 | end |
| 572 | 638 | end |
| ... | ... | @@ -575,9 +641,9 @@ end |
| 575 | 641 | -- ---------------------------------------------------------------- |
| 576 | 642 | function calcui_on_gui_location_changed(event) |
| 577 | 643 | if event.element.name == "calcui" then |
| 578 | - if not global.gui_position then | |
| 579 | - global.gui_position = {} | |
| 644 | + if not storage.gui_position then | |
| 645 | + storage.gui_position = {} | |
| 580 | 646 | end |
| 581 | - global.gui_position[event.player_index] = event.element.location | |
| 647 | + storage.gui_position[event.player_index] = event.element.location | |
| 582 | 648 | end |
| 583 | -end | |
| 584 | 649 | \ No newline at end of file |
| 650 | +end | ... | ... |
changelog.txt
| 1 | 1 | --------------------------------------------------------------------------------------------------- |
| 2 | +Version: 2.0.0 | |
| 3 | +Date: 2024-10-29 | |
| 4 | + Info: | |
| 5 | + - Updated the version for Factorio 2.0 | |
| 6 | + Features: | |
| 7 | + - Added thousand seperators for big numbers, to make it more readable | |
| 8 | + - Also is now able to display scientific notation correctly (like 1.69e+42) | |
| 9 | + - Added translations for French, Spanish and German (Thanks to ChatGPT, Feedback is welcome if | |
| 10 | + something is not sounding correct) | |
| 11 | +--------------------------------------------------------------------------------------------------- | |
| 2 | 12 | Version: 1.1.1 |
| 3 | 13 | Date: 2020-11-28 |
| 4 | 14 | Features: | ... | ... |
control.lua
| ... | ... | @@ -13,7 +13,7 @@ end |
| 13 | 13 | |
| 14 | 14 | -- ---------------------------------------------------------------- |
| 15 | 15 | function debug_print(str) |
| 16 | - if global.marc_debug then | |
| 16 | + if storage.marc_debug then | |
| 17 | 17 | game.print(str) |
| 18 | 18 | end |
| 19 | 19 | end |
| ... | ... | @@ -21,7 +21,7 @@ end |
| 21 | 21 | function __FUNC__() return debug.getinfo(2, 'n').name end |
| 22 | 22 | |
| 23 | 23 | function debug_log(f, str) |
| 24 | - if global.marc_debug then | |
| 24 | + if storage.marc_debug then | |
| 25 | 25 | game.print(f .. ": " .. str) |
| 26 | 26 | end |
| 27 | 27 | end |
| ... | ... | @@ -62,11 +62,11 @@ end |
| 62 | 62 | -- ---------------------------------------------------------------- |
| 63 | 63 | local function on_calcui_command(event) |
| 64 | 64 | if event.parameter == "debug" then |
| 65 | - global.calcui_debug = true | |
| 65 | + storage.calcui_debug = true | |
| 66 | 66 | debug_print("calcui debugging is on") |
| 67 | 67 | elseif event.parameter == "nodebug" then |
| 68 | 68 | debug_print("calcui debugging is off") |
| 69 | - global.calcui_debug = false | |
| 69 | + storage.calcui_debug = false | |
| 70 | 70 | elseif event.parameter == nil then |
| 71 | 71 | game.players[event.player_index].print("please add a parameter") |
| 72 | 72 | else | ... | ... |
info.json
| 1 | 1 | { |
| 2 | 2 | "name": "calculator-ui", |
| 3 | - "version": "1.1.1", | |
| 3 | + "version": "2.0.0", | |
| 4 | 4 | "title": "Calculator UI", |
| 5 | 5 | "author": "Wichu", |
| 6 | - "factorio_version": "1.1", | |
| 7 | - "dependencies": ["base >= 1.1.0"], | |
| 6 | + "factorio_version": "2.0", | |
| 7 | + "dependencies": [ | |
| 8 | + "base >= 2.0.13" | |
| 9 | + ], | |
| 8 | 10 | "description": "This mod adds a calculator with advanced controls to the UI." |
| 9 | 11 | } |
| 10 | 12 | \ No newline at end of file | ... | ... |
locale/de/config.cfg
0 → 100644
| 1 | +[shortcut-name] | |
| 2 | +calcui_4func=Taschenrechner | |
| 3 | + | |
| 4 | +[controls] | |
| 5 | +calcui_hotkey=Fokus auf die Eingabe / Öffnen/Schliessen des Taschenrechners (je nach Eintstellung) | |
| 6 | + | |
| 7 | +[mod-setting-name] | |
| 8 | +calcui-decimal-places=Nachkommastellen | |
| 9 | +calcui-clear-on-calc=Gleichung nach Berechnung löschen | |
| 10 | +calcui-shortcut-close=Mit Shortcut schliessen | |
| 11 | +calcui-nilaus-mode=Nilaus-Modus | |
| 12 | +calcui-sfx=Soundeffekte | |
| 13 | + | |
| 14 | +[mod-settings-description] | |
| 15 | +calcui-decimal-places=Anzahl der Nachkommastellen im Ergebnis | |
| 16 | +calcui-clear-on-calc=Soll die Berechnung die Gleichung löschen? | |
| 17 | +calcui-shortcut-close=Soll das Fenster beim Drücken des Shortcuts geschlossen werden (wahr), oder soll das Eingabefeld fokussiert werden, wenn es bereits geöffnet ist (falsch)? | |
| 18 | +calcui-nilaus-mode=Bei aktiviertem Nilaus-Modus erscheinen einige spezielle Easter Eggs | |
| 19 | +calcui-sfx=Wenn aktiviert, werden bei ungewöhnlichen Ergebnissen Soundeffekte abgespielt | |
| 20 | + | |
| 21 | +[calculator-ui] | |
| 22 | +title=Taschenrechner | |
| 23 | +recent_tooltip=Drücke Umschalt+Linksklick, um es in die aktuelle Gleichung zu kopieren | |
| 24 | +button_CE=Eingabe löschen | |
| 25 | +button_C=Löschen | |
| 26 | +button_BS=Rücktaste | |
| 27 | +button_DIV=Division | |
| 28 | +button_7=7 | |
| 29 | +button_8=8 | |
| 30 | +button_9=9 | |
| 31 | +button_MUL=Multiplikation | |
| 32 | +button_4=4 | |
| 33 | +button_5=5 | |
| 34 | +button_6=6 | |
| 35 | +button_SUB=Subtraktion | |
| 36 | +button_1=1 | |
| 37 | +button_2=2 | |
| 38 | +button_3=3 | |
| 39 | +button_ADD=Addition | |
| 40 | +button_PERC=Prozent | |
| 41 | +button_0=0 | |
| 42 | +button_DOT=Komma | |
| 43 | +button_EQU=Gleich | |
| 0 | 44 | \ No newline at end of file | ... | ... |
locale/en/config.cfg
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | calcui_4func=Calculator |
| 3 | 3 | |
| 4 | 4 | [controls] |
| 5 | -calcui_hotkey=Focus on input | |
| 5 | +calcui_hotkey=Focus on input / Open/Close the calculator (Depending on setting) | |
| 6 | 6 | |
| 7 | 7 | [mod-setting-name] |
| 8 | 8 | calcui-decimal-places=Decimal places |
| ... | ... | @@ -13,11 +13,31 @@ calcui-sfx=Sound effects |
| 13 | 13 | |
| 14 | 14 | [mod-settings-description] |
| 15 | 15 | calcui-decimal-places=Number of decimal places in the result |
| 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-clear-on-calc=Should the calculation trigger the equation to be deleted? | |
| 17 | +calcui-shortcut-close=Should the UI close when the shortcut is pressed (true), or focus on the input field if already open (false)? | |
| 18 | 18 | calcui-nilaus-mode=With Nilaus mode enabled some special easter eggs appear |
| 19 | 19 | calcui-sfx=When enabled sound effects will be played on strange results |
| 20 | 20 | |
| 21 | 21 | [calculator-ui] |
| 22 | 22 | title=Calculator |
| 23 | -recent_tooltip=Press shift+left-click to copy it to current equation | |
| 24 | 23 | \ No newline at end of file |
| 24 | +recent_tooltip=Press shift+left-click to copy it to current equation | |
| 25 | +button_CE=Clear Entry | |
| 26 | +button_C=Clear | |
| 27 | +button_BS=Backspace | |
| 28 | +button_DIV=Division | |
| 29 | +button_7=7 | |
| 30 | +button_8=8 | |
| 31 | +button_9=9 | |
| 32 | +button_MUL=Multiplication | |
| 33 | +button_4=4 | |
| 34 | +button_5=5 | |
| 35 | +button_6=6 | |
| 36 | +button_SUB=Subtraction | |
| 37 | +button_1=1 | |
| 38 | +button_2=2 | |
| 39 | +button_3=3 | |
| 40 | +button_ADD=Addition | |
| 41 | +button_PERC=Percentage | |
| 42 | +button_0=0 | |
| 43 | +button_DOT=Decimal point | |
| 44 | +button_EQU=Equals | |
| 25 | 45 | \ No newline at end of file | ... | ... |
locale/es/config.cfg
0 → 100644
| 1 | +[shortcut-name] | |
| 2 | +calcui_4func=Calculadora | |
| 3 | + | |
| 4 | +[controls] | |
| 5 | +calcui_hotkey=Enfocar en la entrada / Abrir/Cerrar la calculadora (según la configuración) | |
| 6 | + | |
| 7 | +[mod-setting-name] | |
| 8 | +calcui-decimal-places=Lugares decimales | |
| 9 | +calcui-clear-on-calc=Limpiar la ecuación tras el cálculo | |
| 10 | +calcui-shortcut-close=Cerrar con atajo | |
| 11 | +calcui-nilaus-mode=Modo Nilaus | |
| 12 | +calcui-sfx=Efectos de sonido | |
| 13 | + | |
| 14 | +[mod-settings-description] | |
| 15 | +calcui-decimal-places=Número de lugares decimales en el resultado | |
| 16 | +calcui-clear-on-calc=¿Debe el cálculo borrar la ecuación? | |
| 17 | +calcui-shortcut-close=¿Debe la interfaz cerrarse al presionar el atajo (verdadero), o enfocar el campo de entrada si ya está abierto (falso)? | |
| 18 | +calcui-nilaus-mode=Con el modo Nilaus activado, aparecen algunos Easter Eggs especiales | |
| 19 | +calcui-sfx=Cuando está activado, se reproducen efectos de sonido en resultados extraños | |
| 20 | + | |
| 21 | +[calculator-ui] | |
| 22 | +title=Calculadora | |
| 23 | +recent_tooltip=Presiona shift+clic izquierdo para copiar en la ecuación actual | |
| 24 | +button_CE=Borrar entrada | |
| 25 | +button_C=Borrar | |
| 26 | +button_BS=Retroceso | |
| 27 | +button_DIV=División | |
| 28 | +button_7=7 | |
| 29 | +button_8=8 | |
| 30 | +button_9=9 | |
| 31 | +button_MUL=Multiplicación | |
| 32 | +button_4=4 | |
| 33 | +button_5=5 | |
| 34 | +button_6=6 | |
| 35 | +button_SUB=Sustracción | |
| 36 | +button_1=1 | |
| 37 | +button_2=2 | |
| 38 | +button_3=3 | |
| 39 | +button_ADD=Adición | |
| 40 | +button_PERC=Porcentaje | |
| 41 | +button_0=0 | |
| 42 | +button_DOT=Punto decimal | |
| 43 | +button_EQU=Igual | |
| 0 | 44 | \ No newline at end of file | ... | ... |
locale/fr/config.cfg
0 → 100644
| 1 | +[shortcut-name] | |
| 2 | +calcui_4func=Calculatrice | |
| 3 | + | |
| 4 | +[controls] | |
| 5 | +calcui_hotkey=Focus sur l'entrée / Ouvrir/Fermer la calculatrice (selon les paramètres) | |
| 6 | + | |
| 7 | +[mod-setting-name] | |
| 8 | +calcui-decimal-places=Décimales | |
| 9 | +calcui-clear-on-calc=Effacer l'équation après le calcul | |
| 10 | +calcui-shortcut-close=Fermer avec le raccourci | |
| 11 | +calcui-nilaus-mode=Mode Nilaus | |
| 12 | +calcui-sfx=Effets sonores | |
| 13 | + | |
| 14 | +[mod-settings-description] | |
| 15 | +calcui-decimal-places=Nombre de décimales dans le résultat | |
| 16 | +calcui-clear-on-calc=La calculatrice doit-elle effacer l'équation après le calcul? | |
| 17 | +calcui-shortcut-close=La fenêtre doit-elle se fermer lors de l'utilisation du raccourci (vrai), ou se focaliser sur le champ de saisie si déjà ouvert (faux) ? | |
| 18 | +calcui-nilaus-mode=Avec le mode Nilaus activé, quelques easter eggs spéciaux apparaissent | |
| 19 | +calcui-sfx=Si activé, des effets sonores seront joués pour des résultats étranges | |
| 20 | + | |
| 21 | +[calculator-ui] | |
| 22 | +title=Calculatrice | |
| 23 | +recent_tooltip=Appuyez sur shift+clic gauche pour copier dans l'équation actuelle | |
| 24 | +button_CE=Effacer l'entrée | |
| 25 | +button_C=Effacer | |
| 26 | +button_BS=Retour arrière | |
| 27 | +button_DIV=Division | |
| 28 | +button_7=7 | |
| 29 | +button_8=8 | |
| 30 | +button_9=9 | |
| 31 | +button_MUL=Multiplication | |
| 32 | +button_4=4 | |
| 33 | +button_5=5 | |
| 34 | +button_6=6 | |
| 35 | +button_SUB=Soustraction | |
| 36 | +button_1=1 | |
| 37 | +button_2=2 | |
| 38 | +button_3=3 | |
| 39 | +button_ADD=Addition | |
| 40 | +button_PERC=Pourcentage | |
| 41 | +button_0=0 | |
| 42 | +button_DOT=Virgule | |
| 43 | +button_EQU=Égal | |
| 0 | 44 | \ No newline at end of file | ... | ... |