Skip to content

Commit

Permalink
Make # of config slots changeable (max of 80)
Browse files Browse the repository at this point in the history
command: /c remote.call("at","setConfigSize", size1, size2)
  • Loading branch information
Choumiko committed Mar 20, 2016
1 parent fdf327e commit a7a314c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 41 deletions.
38 changes: 34 additions & 4 deletions control.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
require "defines"
require "util"

MAX_CONFIG_SIZE = 10
MAX_CONFIG_SIZES = {
["character-logistic-trash-slots-1"] = 10,
["character-logistic-trash-slots-2"] = 30
}
MAX_STORAGE_SIZE = 6

require "gui"
Expand Down Expand Up @@ -52,7 +55,11 @@ local function init_force(force)
init_global()
end
if not global.configSize[force.name] then
global.configSize[force.name] = force.technologies["character-logistic-trash-slots-2"].researched and 30 or MAX_CONFIG_SIZE
if force.technologies["character-logistic-trash-slots-2"].researched then
global.configSize[force.name] = MAX_CONFIG_SIZES["character-logistic-trash-slots-2"]
else
global.configSize[force.name] = MAX_CONFIG_SIZES["character-logistic-trash-slots-1"]
end
end
end

Expand Down Expand Up @@ -225,9 +232,10 @@ function on_tick(event)
end
end
end
local configSize = global.configSize[player.force.name]
local already_trashed = {}
for i, item in pairs(global.config[player.name]) do
if item and item.name ~= "" then
if item and item.name ~= "" and i <= configSize then
already_trashed[item.name] = item.count
local count = player.get_item_count(item.name)
local requested = requests[item.name] and requests[item.name] or 0
Expand Down Expand Up @@ -470,7 +478,7 @@ script.on_event(defines.events.on_research_finished, function(event)
return
end
if event.research.name == "character-logistic-trash-slots-2" then
global.configSize[event.research.force.name] = 30
global.configSize[event.research.force.name] = MAX_CONFIG_SIZES["character-logistic-trash-slots-2"]
end
end)

Expand Down Expand Up @@ -503,5 +511,27 @@ remote.add_interface("at",
init_global()
init_forces()
init_players()
end,

setConfigSize = function(size1, size2)
local s1 = size1 and size1 or MAX_CONFIG_SIZES["character-logistic-trash-slots-1"]
local s2 = size2 and size2 or MAX_CONFIG_SIZES["character-logistic-trash-slots-2"]
if s1 > s2 then
s1, s2 = s2, s1
end
--check max size (to avoid gui hanging out of the game
s1 = s1 > 80 and 80 or s1
s2 = s2 > 80 and 80 or s2
--update all forces
if not global.configSize then
init_global()
end
for i, force in pairs(game.forces) do
if force.technologies["character-logistic-trash-slots-2"].researched then
global.configSize[force.name] = s2
else
global.configSize[force.name] = s1
end
end
end
})
48 changes: 11 additions & 37 deletions gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ function gui_open_frame(player)
-- Temporary config lives as long as the frame is open, so it has to be created
-- every time the frame is opened.
global["config-tmp"][player.name] = {}

local configSize = global.configSize[player.force.name]
-- We need to copy all items from normal config to temporary config.
local i = 0
for i = 1, global.configSize[player.force.name] do
for i = 1, configSize do
if i > #global["config"][player.name] then
global["config-tmp"][player.name][i] = { name = "", count = 0 }
else
Expand All @@ -124,60 +124,34 @@ function gui_open_frame(player)
name = "auto-trash-error-label"
}
error_label.style.minimal_width = 200
local colspan = global.configSize[player.force.name] > 10 and 9 or 6
local colspan = configSize > 10 and 9 or 6
colspan = configSize > 54 and 12 or colspan
local ruleset_grid = frame.add{
type = "table",
colspan = colspan,
name = "auto-trash-ruleset-grid"
}
ruleset_grid.add{
type = "label",
name = "auto-trash-grid-header-1",
caption = {"auto-trash-config-header-1"}
}
ruleset_grid.add{
type = "label",
name = "auto-trash-grid-header-2",
caption = {"auto-trash-config-header-2"}
}

ruleset_grid.add{
type = "label",
caption = ""
}

ruleset_grid.add{
type = "label",
name = "auto-trash-grid-header-3",
caption = {"auto-trash-config-header-1"}
}
ruleset_grid.add{
type = "label",
name = "auto-trash-grid-header-4",
caption = {"auto-trash-config-header-2"}
}
ruleset_grid.add{
type = "label",
caption = ""
}
if colspan == 9 then
local j = 1
for i=1,colspan/3 do
ruleset_grid.add{
type = "label",
name = "auto-trash-grid-header-5",
name = "auto-trash-grid-header-"..j,
caption = {"auto-trash-config-header-1"}
}
j = j+1
ruleset_grid.add{
type = "label",
name = "auto-trash-grid-header-6",
name = "auto-trash-grid-header-"..j,
caption = {"auto-trash-config-header-2"}
}
j=j+1
ruleset_grid.add{
type = "label",
caption = ""
}
end

for i = 1, global.configSize[player.force.name] do
for i = 1, configSize do
local style = global["config-tmp"][player.name][i].name or "style"
style = style == "" and "style" or style
ruleset_grid.add{
Expand Down

0 comments on commit a7a314c

Please sign in to comment.