Skip to content

Commit

Permalink
added hotkeys to toggle pause for autotrash/requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Choumiko committed Jul 6, 2016
1 parent 4d62e35 commit daf8022
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 64 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PACKAGE_NAME := AutoTrash
VERSION_STRING := 0.0.56
VERSION_STRING := 0.1.0

OUTPUT_NAME := $(PACKAGE_NAME)_$(VERSION_STRING)
OUTPUT_DIR := build/$(OUTPUT_NAME)
Expand Down Expand Up @@ -36,7 +36,7 @@ clean:
rm -rf build/

verify:
luacheck . --exclude-files factorio_mods/ --exclude-files build/ --exclude-files data*.lua --exclude-files prototypes/ -d -a --globals game global remote serpent bit32 defines script table string data
luacheck . --exclude-files factorio_mods/ --exclude-files build/ --exclude-files data*.lua --exclude-files prototypes/ -d -a --globals game global remote serpent bit32 defines script table string data log

install_mod:
if [ -L factorio_mods ] ; \
Expand Down
60 changes: 40 additions & 20 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,36 @@ function unpause_requests(player)
end
end

function toggle_autotrash_pause(player, element)
global.active[player.index] = not global.active[player.index]
local mainButton = player.gui.top[GUI.mainFlow][GUI.mainButton]
if global.active[player.index] then
mainButton.style = "auto-trash-button"
if element then
element.caption = {"auto-trash-config-button-pause"}
end
else
mainButton.style = "auto-trash-button-paused"
if element then
element.caption = {"auto-trash-config-button-unpause"}
end
end
gui_close(player)
end

function toggle_autotrash_pause_requests(player)
global["logistics-active"][player.index] = not global["logistics-active"][player.index]
local mainButton = player.gui.top[GUI.mainFlow][GUI.logisticsButton]
if global["logistics-active"][player.index] then
mainButton.style = "auto-trash-logistics-button"
unpause_requests(player)
else
mainButton.style = "auto-trash-logistics-button-paused"
pause_requests(player)
end
gui_close(player)
end

script.on_event(defines.events.on_gui_click, function(event)
local status, err = pcall(function()
local element = event.element
Expand Down Expand Up @@ -427,29 +457,11 @@ script.on_event(defines.events.on_gui_click, function(event)
elseif element.name == "auto-trash-clear-all" or element.name == "auto-trash-logistics-clear-all" then
gui_clear_all(player)
elseif element.name == "auto-trash-pause" then
global.active[player_index] = not global.active[player_index]
local mainButton = player.gui.top[GUI.mainFlow][GUI.mainButton]
if global.active[player_index] then
mainButton.style = "auto-trash-button"
element.caption = {"auto-trash-config-button-pause"}
else
mainButton.style = "auto-trash-button-paused"
element.caption = {"auto-trash-config-button-unpause"}
end
toggle_autotrash_pause(player)
elseif element.name == "auto-trash-logistics-button" then
gui_open_logistics_frame(player)
elseif element.name == "auto-trash-logistics-pause" then
global["logistics-active"][player_index] = not global["logistics-active"][player_index]
local mainButton = player.gui.top[GUI.mainFlow][GUI.logisticsButton]
if global["logistics-active"][player_index] then
mainButton.style = "auto-trash-logistics-button"
element.caption = {"auto-trash-config-button-pause"}
unpause_requests(player)
else
mainButton.style = "auto-trash-logistics-button-paused"
element.caption = {"auto-trash-config-button-unpause"}
pause_requests(player)
end
toggle_autotrash_pause_requests(player)
elseif element.name == "auto-trash-logistics-storage-store" then
gui_store(player)
elseif element.name == "auto-trash-above-requested" then
Expand Down Expand Up @@ -495,6 +507,14 @@ script.on_event(defines.events.on_research_finished, function(event)
end
end)

script.on_event("autotrash_pause", function(event)
toggle_autotrash_pause(game.players[event.player_index])
end)

script.on_event("autotrash_pause_requests", function(event)
toggle_autotrash_pause_requests(game.players[event.player_index])
end)

function debugDump(var, force)
if false or force then
for _, player in pairs(game.players) do
Expand Down
15 changes: 15 additions & 0 deletions data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,18 @@ data.raw["gui-style"].default["auto-trash-logistics-button-paused"] =
}
}
}

data:extend({
{
type = "custom-input",
name = "autotrash_pause",
key_sequence = "SHIFT + p",
consuming = "none"
},
{
type = "custom-input",
name = "autotrash_pause_requests",
key_sequence = "SHIFT + o",
consuming = "none"
}
})
39 changes: 21 additions & 18 deletions gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,15 @@ function gui_open_frame(player)
name = "auto-trash-config-frame",
direction = "vertical"
}

--local sprite_button =
-- frame.add{
-- type = "sprite-button",
-- --sprite = "item/iron-ore",
-- style = "auto-trash-sprite-button",
-- name = "spritetest"
-- }




--local sprite_button =
-- frame.add{
-- type = "sprite-button",
-- --sprite = "item/iron-ore",
-- style = "auto-trash-sprite-button",
-- name = "spritetest"
-- }

local error_label = frame.add{
type = "label",
caption = "---",
Expand Down Expand Up @@ -389,13 +387,23 @@ function gui_open_logistics_frame(player, redraw)
end
end

function gui_close(player)
local frame = player.gui.left[GUI.configFrame] or player.gui.left[GUI.logisticsConfigFrame]
local storage_frame = player.gui.left[GUI.logisticsStorageFrame]
if frame then
frame.destroy()
end
if storage_frame then
storage_frame.destroy()
end
end

function gui_save_changes(player)
-- Saving changes consists in:
-- 1. copying config-tmp to config
-- 2. removing config-tmp
-- 3. closing the frame
local frame = player.gui.left[GUI.configFrame] or player.gui.left[GUI.logisticsConfigFrame]
local storage_frame = player.gui.left[GUI.logisticsStorageFrame]

local key = player.gui.left[GUI.configFrame] and "" or "logistics-"

Expand Down Expand Up @@ -427,12 +435,7 @@ function gui_save_changes(player)
remote.call("YARM", "show_expando", player.index)
end
--saveVar(global, "saved")
if frame then
frame.destroy()
end
if storage_frame then
storage_frame.destroy()
end
gui_close(player)
end

function gui_clear_all(player)
Expand Down
4 changes: 4 additions & 0 deletions locale/de/de.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ auto-trash-item-already-set=Dieser Gegenstand ist bereits gewählt!
auto-trash-item-is-same=Derselbe Gegenstand kann nicht zweimal in der gleichen Spalte vorkommen!
auto-trash-item-no-entity = Kein Gegenstand gewählt!
auto-trash-above-requested = Auto-Abtransport wenn Anzahl größer als Anforderung

[controls]
autotrash_pause = Pausiere Auto-Abtransport
autotrash_pause_requests = Pausiere Anforderungen
50 changes: 27 additions & 23 deletions locale/en/en.cfg
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
auto-trash-config-frame-title=Auto Trash configuration
auto-trash-logistics-config-frame-title=Logistics configuration
auto-trash-config-header-1=Item:
auto-trash-config-header-2=Amount:
auto-trash-config-button-apply=Save
auto-trash-config-button-clear-all=Clear all
auto-trash-config-button-pause = Pause
auto-trash-config-button-unpause = Unpause
auto-trash-storage-frame-title=Store / restore ruleset
auto-trash-storage-name-label=Name
auto-trash-storage-store=store
auto-trash-storage-restore=restore
auto-trash-storage-remove=remove
auto-trash-storage-name-not-set=You must enter a name!
auto-trash-storage-name-in-use=This name is already used!
auto-trash-storage-too-long=Too many entries in storage!
auto-trash-item-not-set=not set
auto-trash-item-empty=Click the button with an item in your hand!
auto-trash-item-not-valid=This item is not valid!
auto-trash-item-already-set=This item is already set!
auto-trash-item-is-same=You can't set the same item twice in one row!
auto-trash-item-no-entity = Entity is not set!
auto-trash-above-requested = Autotrash above logistics requests
auto-trash-config-frame-title=Auto Trash configuration
auto-trash-logistics-config-frame-title=Logistics configuration
auto-trash-config-header-1=Item:
auto-trash-config-header-2=Amount:
auto-trash-config-button-apply=Save
auto-trash-config-button-clear-all=Clear all
auto-trash-config-button-pause = Pause
auto-trash-config-button-unpause = Unpause
auto-trash-storage-frame-title=Store / restore ruleset
auto-trash-storage-name-label=Name
auto-trash-storage-store=store
auto-trash-storage-restore=restore
auto-trash-storage-remove=remove
auto-trash-storage-name-not-set=You must enter a name!
auto-trash-storage-name-in-use=This name is already used!
auto-trash-storage-too-long=Too many entries in storage!
auto-trash-item-not-set=not set
auto-trash-item-empty=Click the button with an item in your hand!
auto-trash-item-not-valid=This item is not valid!
auto-trash-item-already-set=This item is already set!
auto-trash-item-is-same=You can't set the same item twice in one row!
auto-trash-item-no-entity = Entity is not set!
auto-trash-above-requested = Autotrash above logistics requests
[controls]
autotrash_pause = Pause Autotrash
autotrash_pause_requests = Pause Requests
6 changes: 5 additions & 1 deletion locale/he/he.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ auto-trash-item-not-valid=!ליבק אל טירפ
auto-trash-item-already-set=!עבקנ רבכ טירפ
auto-trash-item-is-same=!תופיצרב םיימעפ טירפ ותוא תא עובקל ןתינ אל
auto-trash-item-no-entity =!העבקנ אל תושיי
auto-trash-above-requested = תושקב לעמש המ קורז
auto-trash-above-requested = תושקב לעמש המ קורז

[controls]
autotrash_pause = Pause Autotrash
autotrash_pause_requests = Pause Requests

0 comments on commit daf8022

Please sign in to comment.