Skip to content

Commit

Permalink
Added Rules for production machine list
Browse files Browse the repository at this point in the history
Added Rules for production machine list
Fixed Not Multiplayer Compatible
Fixed module limitation
  • Loading branch information
Helfima committed Mar 8, 2018
1 parent 72e28ab commit 9bcdabd
Show file tree
Hide file tree
Showing 16 changed files with 732 additions and 98 deletions.
2 changes: 2 additions & 0 deletions controller/Controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require "edition.RecipeEdition"
require "edition.ProductEdition"
require "edition.ResourceEdition"
require "edition.EnergyEdition"
require "edition.RuleEdition"
require "selector.EntitySelector"
require "selector.RecipeSelector"
require "selector.TechnologySelector"
Expand Down Expand Up @@ -65,6 +66,7 @@ function Controller.init()
table.insert(controllers, ResourceEdition:new(main_panel))
table.insert(controllers, ProductEdition:new(main_panel))
table.insert(controllers, EnergyEdition:new(main_panel))
table.insert(controllers, RuleEdition:new(main_panel))
table.insert(controllers, PinPanel:new(main_panel))
table.insert(controllers, StatusPanel:new(main_panel))
table.insert(controllers, TechnologySelector:new(main_panel))
Expand Down
68 changes: 66 additions & 2 deletions core/ElementGui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,56 @@ function ElementGui.addGuiButton(parent, action, key, style, caption, tooltip)
return button
end

-------------------------------------------------------------------------------
-- Add a choose element button
--
-- @function [parent=#ElementGui] addGuiChooseButton
--
-- @param #LuaGuiElement parent container for element
-- @param #string action action name
-- @param #string key unique id
-- @param #string elem_type "item", "tile", "entity", or "signal"
-- @param #string default
-- @param #string style style of button
-- @param #string caption container for element
-- @param #string tooltip displayed text
--
-- @return #LuaGuiElement the LuaGuiElement added
--
function ElementGui.addGuiChooseButton(parent, action, key, elem_type, default, style, caption, tooltip)
Logging:trace(ElementGui.classname, "addGuiButton", parent, action, key, elem_type, default, style, caption, tooltip)
local options = {}
options.type = "choose-elem-button"
if key ~= nil then
options.name = action..key
else
options.name = action
end
options.elem_type = elem_type
options[elem_type] = default
options.style = style
options.caption = caption
options.tooltip = tooltip

local button = nil
local ok , err = pcall(function()
button = parent.add(options)
end)
if not ok then
Logging:trace(ElementGui.classname, "addGuiButton", action, key, style, err)
options.style = "helmod_button_default"
if (type(caption) == "boolean") then
Logging:error(ElementGui.classname, "addGuiButton - caption is a boolean")
elseif caption ~= nil then
options.caption = caption
else
options.caption = key
end
button = parent.add(options)
end
return button
end

-------------------------------------------------------------------------------
-- Add a radio-button element
--
Expand Down Expand Up @@ -1102,7 +1152,7 @@ end
function ElementGui.getStyleSizes()
Logging:trace(ElementGui.classname, "getStyleSizes()")
local width, height = ElementGui.getDisplaySizes()

local style_sizes = {}
if type(width) == "number" and type(height) == "number" then
local width_recipe_column_1 = 220
Expand All @@ -1118,7 +1168,7 @@ function ElementGui.getStyleSizes()
local ratio_v = 0.75
local width_main = math.ceil(width*ratio_h)
local height_main = math.ceil(height*ratio_v)

style_sizes.main = {}
style_sizes.main.width = width_main
style_sizes.main.height = height_main
Expand Down Expand Up @@ -1208,4 +1258,18 @@ function ElementGui.setStyle(element, style, property)
end
end

-------------------------------------------------------------------------------
-- Get dropdown selection
--
-- @function [parent=#ElementGui] getDropdownSelection
--
-- @param #LuaGuiElement element
--
function ElementGui.getDropdownSelection(element)
Logging:trace(ElementGui.classname, "getDropdownSelection(element)", element)
if element.selected_index == 0 then return nil end
if #element.items == 0 then return nil end
return element.items[element.selected_index]
end

return ElementGui
91 changes: 58 additions & 33 deletions core/Event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ local Event = {
--
function Event.start()
Logging:trace(Event.classname, "start()")

script.on_init(Event.onInit)
script.on_load(Event.onLoad)
script.on_configuration_changed(Event.onConfigurationChanged)
Expand All @@ -30,7 +30,7 @@ function Event.start()
Event.pcallEvent("on_runtime_mod_setting_changed", defines.events.on_runtime_mod_setting_changed, Event.onRuntimeModSettingChanged)
Event.pcallEvent("on_console_command", defines.events.on_console_command, Event.onConsoleCommand)
--Event.pcallEvent("on_gui_closed", defines.events.on_gui_closed, Event.onGuiClosed)

-- event hotkey
Event.pcallEvent("helmod-input-valid", "helmod-input-valid", Event.onCustomInput)
Event.pcallEvent("helmod-close", "helmod-close", Event.onCustomInput)
Expand All @@ -48,9 +48,11 @@ end
--
function Event.onCustomInput(event)
Logging:trace(Event.classname, "onCustomInput(event)", event)
Player.load(event)
local new_event = {name=event.input_name, player_index = event.player_index}
Controller.parseEvent(new_event, "hotkey")
if event ~= nil and event.player_index ~= nil then
Player.load(event)
local new_event = {name=event.input_name, player_index = event.player_index}
Controller.parseEvent(new_event, "hotkey")
end
end

-------------------------------------------------------------------------------
Expand Down Expand Up @@ -81,6 +83,7 @@ end
--
function Event.onInit(event)
Logging:trace(Event.classname, "onInit(event)", event)
Command.start()
end

-------------------------------------------------------------------------------
Expand All @@ -104,8 +107,10 @@ end
--
function Event.onConsoleCommand(event)
Logging:trace(Event.classname, "onConsoleCommand(event)", event)
Player.load(event)
Command.parse(event)
if event ~= nil and event.player_index ~= nil then
Player.load(event)
Command.parse(event)
end
end

-------------------------------------------------------------------------------
Expand All @@ -119,8 +124,10 @@ end
--
function Event.onGuiClosed(event)
Logging:trace(Event.classname, "onGuiClosed(event)", event)
Player.load(event)
Controller.onGuiClosed(event)
if event ~= nil and event.player_index ~= nil then
Player.load(event)
Controller.onGuiClosed(event)
end
end

-------------------------------------------------------------------------------
Expand Down Expand Up @@ -163,8 +170,10 @@ end
--
function Event.onTick(event)
Logging:trace(Event.classname, "onTick(event)", event)
Player.load(event)
Controller.onTick(event)
if event ~= nil and event.player_index ~= nil then
Player.load(event)
Controller.onTick(event)
end
end

-------------------------------------------------------------------------------
Expand All @@ -176,13 +185,15 @@ end
--
function Event.onGuiClick(event)
Logging:trace(Event.classname, "onGuiClick(event)", event)
Player.load(event)
local allowed = true
if event.element ~= nil and event.element.valid and (event.element.type == "drop-down" or event.element.type == "checkbox" or event.element.type == "radiobutton") then
allowed = false
end
if allowed then
Controller.onGuiClick(event)
if event ~= nil and event.player_index ~= nil then
Player.load(event)
local allowed = true
if event.element ~= nil and event.element.valid and (event.element.type == "drop-down" or event.element.type == "checkbox" or event.element.type == "radiobutton") then
allowed = false
end
if allowed then
Controller.onGuiClick(event)
end
end
end

Expand All @@ -195,8 +206,10 @@ end
--
function Event.onGuiTextChanged(event)
Logging:trace(Event.classname, "onGuiTextChanged(event)", event)
Player.load(event)
Controller.parseEvent(event)
if event ~= nil and event.player_index ~= nil then
Player.load(event)
Controller.parseEvent(event)
end
end

-------------------------------------------------------------------------------
Expand All @@ -208,8 +221,10 @@ end
--
function Event.onGuiHotkey(event)
Logging:trace(Event.classname, "onGuiHotkey(event)", event)
Player.load(event)
Controller.parseEvent(event, "hotkey")
if event ~= nil and event.player_index ~= nil then
Player.load(event)
Controller.parseEvent(event, "hotkey")
end
end

-------------------------------------------------------------------------------
Expand All @@ -221,8 +236,10 @@ end
--
function Event.onGuiSelectionStateChanged(event)
Logging:trace(Event.classname, "onGuiSelectionStateChanged(event)", event)
Player.load(event)
Controller.parseEvent(event, "dropdown")
if event ~= nil and event.player_index ~= nil then
Player.load(event)
Controller.parseEvent(event, "dropdown")
end
end

-------------------------------------------------------------------------------
Expand All @@ -234,8 +251,10 @@ end
--
function Event.onGuiCheckedStateChanged(event)
Logging:trace(Event.classname, "onGuiCheckedStateChanged(event)", event)
Player.load(event)
Controller.parseEvent(event, "checked")
if event ~= nil and event.player_index ~= nil then
Player.load(event)
Controller.parseEvent(event, "checked")
end
end

-------------------------------------------------------------------------------
Expand All @@ -247,8 +266,10 @@ end
--
function Event.onRuntimeModSettingChanged(event)
Logging:trace(Event.classname, "onRuntimeModSettingChanged(event)", event)
Player.load(event)
Controller.parseEvent(event, "settings")
if event ~= nil and event.player_index ~= nil then
Player.load(event)
Controller.parseEvent(event, "settings")
end
end

-------------------------------------------------------------------------------
Expand All @@ -261,8 +282,10 @@ end
function Event.onPlayerCreated(event)
--log("Event.onPlayerCreated(event)")
Logging:trace(Event.classname, "onPlayerCreated(event)", event)
local player = Player.load(event).native()
Controller.bindController(player)
if event ~= nil and event.player_index ~= nil then
local player = Player.load(event).native()
Controller.bindController(player)
end
end

-------------------------------------------------------------------------------
Expand All @@ -275,8 +298,10 @@ end
function Event.onPlayerJoinedGame(event)
--log("Event.onPlayerJoinedGame(event)")
Logging:trace(Event.classname, "onPlayerJoinedGame(event)", event)
local player = Player.load(event).native()
Controller.bindController(player)
if event ~= nil and event.player_index ~= nil then
local player = Player.load(event).native()
Controller.bindController(player)
end
end

return Event
return Event
38 changes: 36 additions & 2 deletions core/ModelBuilder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,23 @@ function ModelBuilder.removePower(power_id)
end
end

-------------------------------------------------------------------------------
-- Remove a rule
--
-- @function [parent=#ModelBuilder] removeRule
--
-- @param #number power_id
--
function ModelBuilder.removeRule(rule_id)
Logging:trace(ModelBuilder.classname, "removeRule()", rule_id)
if global.rules ~= nil then
Logging:debug(ModelBuilder.classname, "before remove rule", global.rules)
table.remove(global.rules,rule_id)
Model.reIndexList(global.rules)
Logging:debug(ModelBuilder.classname, "after remove rule", global.rules)
end
end

-------------------------------------------------------------------------------
-- Update a object
--
Expand Down Expand Up @@ -663,7 +680,24 @@ function ModelBuilder.upProductionList(list, index, step)
end
end



-------------------------------------------------------------------------------
-- Add rule
--
-- @function [parent=#ModelBuilder] addRule
--
-- @param #string mod
-- @param #string name
-- @param #string category
-- @param #string type
-- @param #string value
-- @param #string excluded
-- @param #string index
--
function ModelBuilder.addRule(mod, name, category, type, value, excluded, index)
Logging:debug(ModelBuilder.classname, "addRule()", mod, name, category, type, value, excluded, index)
local rule = Model.newRule(mod, name, category, type, value, excluded, #Model.getRules())
local rules = Model.getRules()
table.insert(rules, rule)
end

return ModelBuilder
7 changes: 6 additions & 1 deletion core/defines.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ helmod_table_style = {
default = "helmod_table_default",
panel = "helmod_table_panel",
list = "helmod_table_list",
tab = "helmod_table_tab"
tab = "helmod_table_tab",
rule = "helmod_table_rule"
}

helmod_rule_manes = {"production-crafting"}
helmod_rule_categories = {"standard", "crafting-handonly", "extraction-machine", "energy", "technology"}
helmod_rule_types = {"entity-name", "entity-type", "entity-group", "entity-subgroup"}

helmod_icons = {}
helmod_icons["unknown-assembling-machine"]="__helmod__/graphics/icons/unknown-assembling-machine.png"
helmod_icons["default-assembling-machine"]="__helmod__/graphics/icons/unknown-assembling-machine.png"
Expand Down
Loading

0 comments on commit 9bcdabd

Please sign in to comment.