diff --git a/src/GlobalState.lua b/src/GlobalState.lua index e854e58..12dab5e 100644 --- a/src/GlobalState.lua +++ b/src/GlobalState.lua @@ -141,6 +141,12 @@ function M.inner_setup() global.mod.mine_queue = {} end + -- used to configure the preferred fuels for an entity + -- key=entity name, val={ preferred=name, blocked={ name=true }} + if global.mod.fuel_config == nil then + global.mod.fuel_config = {} + end + -- scan prototypes to see if we need to rescan all surfaces local name_service_map = M.scan_prototypes() if true or not tables_have_same_keys(name_service_map, global.name_service_map) then @@ -405,6 +411,7 @@ function M.remove_old_ui() end end end + end ------------------------------------------------------------------------------- @@ -1207,23 +1214,25 @@ function M.auto_network_chest(entity) return requests, provides end +------------------------------------------------------------------------------- + function M.get_fuel_table() if global.fuel_table == nil then local fuels = {} -- array { name=name, val=energy per stack, cat=category } - for _, prot in pairs(game.item_prototypes) do - local fc = prot.fuel_category - if fc ~= nil then - local value = prot.fuel_value - -- HACK: make processed-fuel preferrible to nearly everything, coke not wanted - if prot.name == 'processed-fuel' then - value = value * 100 - elseif prot.name == 'coke' then - value = value / 10 - end - --table.insert(fuels, { name=prot.name, val=prot.stack_size * prot.fuel_value, cat=fc }) - table.insert(fuels, { name=prot.name, val=value, cat=fc }) + for _, prot in pairs(game.item_prototypes) do + local fc = prot.fuel_category + if fc ~= nil and not prot.has_flag("hidden") then + local value = prot.fuel_value + -- HACK: make processed-fuel preferrible to nearly everything, coke not wanted + if prot.name == 'processed-fuel' then + value = value * 100 + elseif prot.name == 'coke' then + value = value / 10 end + --table.insert(fuels, { name=prot.name, val=prot.stack_size * prot.fuel_value, cat=fc }) + table.insert(fuels, { name=prot.name, val=value, cat=fc }) end + end table.sort(fuels, function (a, b) return a.val > b.val end) print(string.format("fuel table: %s", serpent.line(fuels))) @@ -1232,7 +1241,29 @@ function M.get_fuel_table() return global.fuel_table end +function M.fuel_config_get(entity_name) + return global.mod.fuel_config[entity_name] or {} +end + +function M.fuel_config_set(entity_name, config) + -- fuel config has 2 members: preferred:string, blocked:{name=true} + global.mod.fuel_config[entity_name] = config +end + function M.get_best_available_fuel(entity) + local config = M.fuel_config_get(entity.name) + + -- check for the preferred fuel first + local fuel_name = config.preferred + if fuel_name ~= nil then + -- TODO: verify that the fuel is still valid + local n_avail = M.get_item_count(fuel_name) + if n_avail > 0 then + -- clog("FUEL: %s preferred fuel %s and we have %s", entity.name, fuel_name, n_avail) + return fuel_name, n_avail + end + end + --clog("called get best fuel on %s", entity.name) local bprot = entity.prototype.burner_prototype if bprot ~= nil then @@ -1241,7 +1272,7 @@ function M.get_best_available_fuel(entity) local ff = M.get_fuel_table() --clog(" fuel tab: %s", serpent.line(ff)) for _, fuel in ipairs(ff) do - if fct[fuel.cat] ~= nil then + if fct[fuel.cat] ~= nil and config[fuel.name] ~= true then local n_avail = M.get_item_count(fuel.name) if n_avail > 0 then --clog("FUEL: %s can use %s and we have %s", entity.name, fuel.name, n_avail) @@ -1448,12 +1479,14 @@ function M.scan_prototypes() } if true or settings.global["item-network-service-assemblers"].value then - clog("Adding 'assembling-machine' to the list") + -- clog("Adding 'assembling-machine' to the list") type_to_service["assembling-machine"] = "assembling-machine" end for _, prot in pairs(game.entity_prototypes) do - if prot.type == "logistic-container" then + if prot.has_flag("hidden") or not prot.has_flag("player-creation") then + -- not ading it + elseif prot.type == "logistic-container" then --if prot.logistic_mode == "requester" or prot.logistic_mode == "buffer" or prot.logistic_mode == "storage" then name_to_service[prot.name] = "logistic-chest-" .. prot.logistic_mode --elseif prot.logistic_mode == "active-provider" then @@ -1501,6 +1534,32 @@ function M.scan_surfaces() clog("[%s] item-network: Scanning complete", game.tick) end +--[[ +Determine the recipe name based on ore based on the inputs, last_recipe or info.ore_name +]] +function M.furnace_get_ore_recipe(ore_name) + local o2fr = global.ore_to_furnce_recipe + if o2fr == nil then + o2fr = {} + global.ore_to_furnce_recipe = o2fr + + -- for a recipe to be valid for a furnace, it must be a "smelting" and have one ingredient. + -- assume assembbles will be used for anything else + for _, recipe in pairs(game.recipe_prototypes) do + if recipe.category == 'smelting' and #recipe.ingredients == 1 then + local ing = recipe.ingredients[1] + print(string.format("FURNACE RECIPE %s => %s %s", recipe.name, ing.name, ing.amount)) + o2fr[ing.name] = recipe.name + end + end + print(serpent.line(o2fr)) + end + local recipe_name = o2fr[ore_name] + if recipe_name ~= nil then + return game.recipe_prototypes[recipe_name] + end +end + ------------------------------------------------------------------------------- -- not sure this belongs here... diff --git a/src/GuiManager.lua b/src/GuiManager.lua index 5af0c30..2c9537c 100644 --- a/src/GuiManager.lua +++ b/src/GuiManager.lua @@ -8,9 +8,15 @@ local GlobalState = require "src.GlobalState" local clog = require("src.log_console").log local GuiManager = {} + +local GuiManager__metatable = { + __index = GuiManager +} +script.register_metatable("GuiManager", GuiManager__metatable) + function GuiManager.new(name) local self = { name=name } - return setmetatable(self, { __index = GuiManager }) + return setmetatable(self, GuiManager__metatable) end function GuiManager:get(player_index) diff --git a/src/NetworkViewUi.lua b/src/NetworkViewUi.lua index 0a7252d..3240720 100644 --- a/src/NetworkViewUi.lua +++ b/src/NetworkViewUi.lua @@ -6,6 +6,7 @@ local UiNetworkItems = require "src.UiNetworkItems" local UiNetworkFluid = require "src.UiNetworkFluid" local UiNetworkLimits = require "src.UiNetworkLimits" local UiNetworkShortages = require "src.UiNetworkShortages" +local UiNetworkFuels = require "src.UiNetworkFuels" local clog = require("src.log_console").log local M = {} @@ -173,6 +174,7 @@ function M.open_main_frame(player_index) add_tab("Fluids", UiNetworkFluid) add_tab("Shortages", UiNetworkShortages) add_tab("Limits", UiNetworkLimits) + add_tab("Fuels", UiNetworkFuels) -- select "items" (not really needed, as that is the default) tabbed_pane.selected_tab_index = 1 diff --git a/src/NetworkViewUi_test.lua b/src/NetworkViewUi_test.lua index f92ee2f..4a2c632 100644 --- a/src/NetworkViewUi_test.lua +++ b/src/NetworkViewUi_test.lua @@ -745,9 +745,6 @@ local function update_player_selected(player) end end - if ent.name == "entity-ghost" then - end - if false then -- need 'pipe-connectable' entity local nn = ent.neighbours if nn ~= nil then diff --git a/src/ServiceEntity.lua b/src/ServiceEntity.lua index 994b0c4..32a1591 100644 --- a/src/ServiceEntity.lua +++ b/src/ServiceEntity.lua @@ -69,46 +69,78 @@ local promote_fuel = { coal = 'processed-fuel', } + +local function service_refuel_empty(entity, inv) + local fuel_name, n_avail = GlobalState.get_best_available_fuel(entity) + if fuel_name == nil or n_avail == nil then + return + end + --sclog("best fuel for %s is %s and we have %s", entity.name, fuel_name, n_avail) + if n_avail > 0 then + local prot = game.item_prototypes[fuel_name] + local n_add = (#inv * prot.stack_size) -- - 12 + transfer_item_to_inv(entity, inv, fuel_name, math.min(n_avail, n_add)) + end + return +end + --[[ Add fuel to the entity. If empty, we pick the best available fuel and add that. -If non-empty, we top off the current fuel. + - preferred + - not blocked + + If non-empty, we check to make sure the current fuel is not blocked. + If blocked, we remove it. + If not preferred and we have the preferred fuel, then remove the fuel. Ideally, the amount of fuel would be enough for 3 * service period ticks. ]] local function service_refuel(entity, inv) - if inv.is_empty() then - local fuel_name, n_avail = GlobalState.get_best_available_fuel(entity) - if fuel_name == nil or n_avail == nil then - return + local cfg = GlobalState.fuel_config_get(entity.name) + local preferred = cfg.preferred + + -- See if we need to purge non-preferred fuel + local purge = false + if preferred ~= nil then + local n_avail = GlobalState.get_item_count(preferred) + if n_avail > 5 then + purge = true end - --sclog("best fuel for %s is %s and we have %s", entity.name, fuel_name, n_avail) - if n_avail > 0 then - local prot = game.item_prototypes[fuel_name] - local n_add = (#inv * prot.stack_size) -- - 12 - transfer_item_to_inv(entity, inv, fuel_name, math.min(n_avail, n_add)) + end + + -- remove unwanted fuel + local contents = inv.get_contents() + for fuel, count in pairs(contents) do + -- if blocked or we are purging and the fuel isn't preferred + if cfg[fuel] == true or (purge and fuel ~= preferred) then + local n_taken = inv.remove({name=fuel, count=count}) + if n_taken > 0 then + GlobalState.increment_item_count(fuel, n_taken) + if n_taken == count then + contents[fuel] = nil + else + contents[fuel] = count - n_taken + end + end end + end + + -- We might have just removed all fuel + if next(contents) == nil then + service_refuel_empty(entity, inv) return - else - -- try to top off the fuel(s) - for fuel, _ in ipairs(inv.get_contents()) do - local fuel_prot = game.item_prototypes[fuel] - if fuel_prot ~= nil then - local n_need = inv.get_insertable_count(fuel) - 12 - -- start requesting when fuel is below 1/2 stack - if n_need > fuel_prot.stack_size / 2 then - local promo = promote_fuel[fuel] - if promo ~= nil then - local fcnt = GlobalState.get_item_count(promo) - if fcnt > 10 then - GlobalState.items_inv_to_net(inv) - transfer_item_to_inv(entity, inv, promo, math.min(fcnt, 20)) - return - end - end - transfer_item_to_inv(entity, inv, fuel, n_need) - end + end + + -- try to top off existing fuel(s) + for fuel, count in pairs(contents) do + local fuel_prot = game.item_prototypes[fuel] + if fuel_prot ~= nil then + local n_need = inv.get_insertable_count(fuel) - 12 + -- start requesting when fuel is below 1/2 stack + if n_need > fuel_prot.stack_size / 2 then + transfer_item_to_inv(entity, inv, fuel, n_need) end end end @@ -457,6 +489,17 @@ local function assembling_machine_clone(dst_info, src_info) assembling_machine_paste(dst_info, src_info.entity) end +local ore_to_furnce_recipe + +--[[ +Determine the recipe name based on ore based on the inputs, last_recipe or info.ore_name +]] +function M.furnace_get_ore_recipe(ore_name) + local recipe_name = GlobalState.furnace_get_ore_recipe(ore_name) + -- go with whatever was last configured (inputs and outputs are empty) + return info.ore_name +end + -- determine the ore based on the inputs, last_recipe or info.ore_name function M.furnace_get_ore(info) local entity = info.entity @@ -481,6 +524,41 @@ function M.furnace_get_ore(info) return info.ore_name end +--[[ + Get the required refill level. +]] +function M.furnace_get_ore_count(info) + if info.ore_name == nil then + return nil + end + local recipe = GlobalState.furnace_get_ore_recipe(info.ore_name) + if recipe == nil then + return nil + end + + local rtime = recipe.energy / info.entity.crafting_speed -- time to finish one recipe + local svc_ticks = info.service_tick_delta or (10 * 60) -- assume 60 seconds on first service + local mult = math.ceil(svc_ticks / (rtime * 60)) + + local ing = recipe.ingredients[1] + --print(string.format("Furnace: name=%s amount=%s mult=%s", ing.name, ing.amount, mult)) + return ing.amount * mult +end + +--[[ +This services a furnace. + - adds fuel + - removes burnt results + - removes output + - adds ore + +NOTE that we can't get the current recipe. +Determining the ore to add: + - same ore(s) as is currently present in the input + - record in info.ore_name + - use info.ore_name + - check the output +]] function M.furnace_update(info) local entity = info.entity @@ -525,7 +603,14 @@ function M.furnace_update(info) end if info.ore_name ~= nil then - transfer_item_to_inv_max(entity, inv_src, info.ore_name) + local ore_count = M.furnace_get_ore_count(info) + if ore_count ~= nil then + --print(string.format("ore level: %s %s", info.ore_name, ore_count)) + transfer_item_to_inv_level(entity, inv_src, info.ore_name, ore_count) + else + --print(string.format("ore max: %s", info.ore_name)) + transfer_item_to_inv_max(entity, inv_src, info.ore_name) + end end return GlobalState.UPDATE_STATUS.UPDATE_PRI_MAX end @@ -625,7 +710,10 @@ function M.lab_service(info) return end + -- try to load each lib_input at a minimum level + -- clog("lab inputs: %s", serpent.line(entity.prototype.lab_inputs)) for _, item in ipairs(entity.prototype.lab_inputs) do + -- want to check force.technologies, but that is not accurate transfer_item_to_inv_level(entity, inv, item, 10) end diff --git a/src/UiCharacterInventory.lua b/src/UiCharacterInventory.lua index 3dc0ca0..82285cb 100644 --- a/src/UiCharacterInventory.lua +++ b/src/UiCharacterInventory.lua @@ -42,6 +42,11 @@ local item_utils = require("src.item_utils") local M = {} local CharInv = {} +local CharInv__metatable = { + __index = CharInv +} +script.register_metatable("CharInv", CharInv__metatable) + local function gui_get(player_index) return GlobalState.get_ui_state(player_index).UiCharacterInventory end @@ -57,7 +62,7 @@ function M.create(parent, player) } -- set index so we can call self:refresh() or M.refresh(self) - setmetatable(self, { __index = CharInv }) + setmetatable(self, CharInv__metatable) --[[ GuiElement Layout: diff --git a/src/UiChestInventory.lua b/src/UiChestInventory.lua index d1673e5..bbf1fbe 100644 --- a/src/UiChestInventory.lua +++ b/src/UiChestInventory.lua @@ -48,6 +48,11 @@ local item_utils = require("src.item_utils") local M = {} local ChestInv = {} +local ChestInv__metatable = { + __index = ChestInv +} +script.register_metatable("ChestInv", ChestInv__metatable) + local function gui_get(player_index) return GlobalState.get_ui_state(player_index).UiChestInventory end @@ -64,7 +69,7 @@ function M.create(parent, player, entity) } -- set index so we can call self:refresh() or M.refresh(self) - setmetatable(self, { __index = ChestInv }) + setmetatable(self, ChestInv__metatable) --[[ GuiElement Layout: diff --git a/src/UiConstants.lua b/src/UiConstants.lua index c6d608f..f43dbb9 100644 --- a/src/UiConstants.lua +++ b/src/UiConstants.lua @@ -77,4 +77,7 @@ M.NT_CONFIRM_EVENT = "2aeb6458481cb17d443e0743858eec78" M.NT_CANCEL_EVENT = "ccd188f96dbd5d80ead57ac11f2a4315" M.NT_BTN_AUTO = "item_network.tank.btn_auto" +M.NETFUEL_SELECT_ITEM = "item_network.fuel.preferred_select" +M.NETFUEL_BLOCK_ITEM = "item_network.fuel.blocked_select" + return M diff --git a/src/UiNetworkFluid.lua b/src/UiNetworkFluid.lua index 55d9d85..cac069c 100644 --- a/src/UiNetworkFluid.lua +++ b/src/UiNetworkFluid.lua @@ -24,6 +24,9 @@ local M = {} local NetInv = {} +local NetFluid__metatable = { __index = NetInv } +script.register_metatable("NetFluid", NetFluid__metatable) + local function gui_get(player_index) return GlobalState.get_ui_state(player_index).UiNetworkFluid end @@ -40,7 +43,7 @@ function M.create(parent, player) } -- set index so we can call self:refresh() or M.refresh(self) - setmetatable(self, { __index = NetInv }) + setmetatable(self, NetFluid__metatable) local vert_flow = parent.add({ type = "flow", diff --git a/src/UiNetworkFuels.lua b/src/UiNetworkFuels.lua new file mode 100644 index 0000000..d061186 --- /dev/null +++ b/src/UiNetworkFuels.lua @@ -0,0 +1,269 @@ +--[[ +Allows configuration of allowable fuels. +]] +local GlobalState = require "src.GlobalState" +local UiConstants = require "src.UiConstants" +local Gui = require('__stdlib__/stdlib/event/gui') +local item_utils = require "src.item_utils" +local clog = require("src.log_console").log + +-- M is the module that supplies 'create()' +local M = {} + +local NetFuels = {} + +local NetFuels__metatable = { __index = NetFuels } +script.register_metatable("NetFuels", NetFuels__metatable) + +local function gui_get(player_index) + return GlobalState.get_ui_state(player_index).UiNetworkFuels +end + +local function gui_set(player_index, value) + GlobalState.get_ui_state(player_index).UiNetworkFuels = value +end + +function M.create(parent, player, show_title) + local self = { + player = player, + elems = {}, + use_group = false, + } + + -- set index so we can call self:refresh() or M.refresh(self) + -- FIXME: need to restore mettables + setmetatable(self, NetFuels__metatable) + + local vert_flow = parent.add({ + type = "flow", + direction = "vertical", + }) + self.frame = vert_flow + + local inv_frame = vert_flow.add({ + type = "frame", + style = "character_inventory_frame", + --style = "inventory_frame", + }) + local scroll_pane = inv_frame.add({ + type = "scroll-pane", + style = "character_inventory_scroll_pane", + --style = "entity_inventory_scroll_pane", + }) -- 424, 728 or 400,712 + scroll_pane.style.width = 424 + + --[[ + local hdr = scroll_pane.add({ + type = "flow", + direction = "horizontal", + }) + hdr.style.size = { 400, 28 } + + self.elems.title = hdr.add({ + type = "label", + caption = "Network Fuels", + style = "inventory_label", + }) + local hdr_spacer = hdr.add({ type = "empty-widget" }) + hdr_spacer.style.horizontally_stretchable = true + ]] + local item_table = scroll_pane.add({ + type = "table", + name = "item_table", + style = "slot_table", + column_count = 3 + }) + item_table.style.horizontal_spacing = 12 + self.elems.item_table = item_table + + gui_set(player.index, self) + + -- populate the table + NetFuels.refresh(self) + + return self +end + +function NetFuels.destroy(self) + if self.frame ~= nil then + self.frame.destroy() -- destroy the GUI + self.frame = nil + end + gui_set(self.player.index, nil) +end + +local function get_list_of_items() + local fuel_items = {} + local fuel_tab = GlobalState.get_fuel_table() + + for name, prot in pairs(game.entity_prototypes) do + local fct = prot.burner_prototype + if fct ~= nil then + local fuel_rec = {} + for _, fuel in ipairs(fuel_tab) do + if fct.fuel_categories[fuel.cat] ~= nil then + table.insert(fuel_rec, fuel) + end + end + if #fuel_rec > 0 then + fuel_items[name] = fuel_rec + end + end + end + + for name, ii in pairs(fuel_items) do + print(string.format("fuel for %s [%s]", name, #ii)) + for _, xx in ipairs(ii) do + print(string.format(" - %s", serpent.line(xx))) + end + end + + return fuel_items +end + +-- TODO: move to GlobalState so it can be viewed via gvv? +local fuel_filters = {} + +local function get_fuel_filter_for_entity(name) + -- the filter never changes, so cache it + local filt = fuel_filters[name] + if filt ~= nil then + return filt + end + + filt = {} + local bprot = game.entity_prototypes[name].burner_prototype + if bprot ~= nil then + for cat, _ in pairs(bprot.fuel_categories) do + local nv = { filter = "fuel-category", ["fuel-category"] = cat } + if #filt > 0 then + nv.mode = "or" + end + table.insert(filt, nv) + end + end + fuel_filters[name] = filt + return filt +end + +--[[ + The table has three columns. + 1. the item to service. + 2. the preferred fuel + 3. row of forbidden fuels. +]] +function NetFuels:refresh() + local item_table = self.elems.item_table + item_table.clear() + + -- first row + item_table.add({ + type = "label", + caption = "Entity", + }) + item_table.add({ + type = "label", + caption = "Best", + }) + item_table.add({ + type = "label", + caption = "Forbidden Fuels (red)", + }) + + -- add the items + local items = get_list_of_items() + for name, fuel_list in pairs(items) do + -- make sure it is something we service + if global.name_service_map[name] ~= nil then + local cfg = GlobalState.fuel_config_get(name) + + -- put the entity button down + local ent_elem = item_table.add({ + type = "choose-elem-button", + elem_type = "entity", + }) + ent_elem.elem_value = name + ent_elem.locked = true + + -- add the preferred fuel selector + local f_elem = item_table.add({ + type = "choose-elem-button", + elem_type = "item", + name=string.format("%s:%s", UiConstants.NETFUEL_SELECT_ITEM, name), + tags = { name = name }, + }) + if cfg.preferred ~= nil then + f_elem.elem_value = cfg.preferred + end + f_elem.elem_filters = get_fuel_filter_for_entity(name) + + -- add the forbidden fuel list + local hflow = item_table.add({ type="flow", direction = "horizontal" }) + local cnt = 1 + for _, fuel in ipairs(fuel_list) do + local style = nil + if cfg[fuel.name] == true then + style = "red_slot_button" + -- style = "yellow_slot_button" + end + local fuel_elem = hflow.add({ + name = string.format("%s:%s", UiConstants.NETFUEL_BLOCK_ITEM, cnt), + type = "choose-elem-button", + style = style, + elem_type = "item", + tags = { name = name, fuel = fuel.name }, + }) + fuel_elem.elem_value = fuel.name + fuel_elem.locked = true + cnt = cnt + 1 + end + end + end +end + +------------------------------------------------------------------------------ +-- Event handling below + +-- the item selection change. refresh the current limit text box +local function on_fuel_item_elem_changed(event) + local self = gui_get(event.player_index) + if self ~= nil then + local name = event.element.tags.name + if name ~= nil then + local cfg = GlobalState.fuel_config_get(name) + local fuel = event.element.elem_value + cfg.preferred = fuel + if fuel ~= nil then + cfg[fuel] = nil + end + GlobalState.fuel_config_set(name, cfg) + NetFuels.refresh(self) + end + end +end + +-- toggles whether a fuel is blocked +local function on_fuel_blocked(event) + local self = gui_get(event.player_index) + if self ~= nil then + local tags = event.element.tags + local name = tags.name + local fuel = tags.fuel + if name ~= nil and fuel ~= nil then + local cfg = GlobalState.fuel_config_get(name) + -- toggle whether the fuel is blocked + if cfg[fuel] ~= true then + cfg[fuel] = true + else + cfg[fuel] = nil + end + GlobalState.fuel_config_set(name, cfg) + NetFuels.refresh(self) + end + end +end + +Gui.on_elem_changed(UiConstants.NETFUEL_SELECT_ITEM, on_fuel_item_elem_changed) +Gui.on_click(UiConstants.NETFUEL_BLOCK_ITEM, on_fuel_blocked) + +return M diff --git a/src/UiNetworkItems.lua b/src/UiNetworkItems.lua index b7ae325..b278369 100644 --- a/src/UiNetworkItems.lua +++ b/src/UiNetworkItems.lua @@ -38,6 +38,9 @@ local M = {} local NetInv = {} +local NetItems__metatable = { __index = NetInv } +script.register_metatable("NetItems", NetItems__metatable) + local function gui_get(player_index) return GlobalState.get_ui_state(player_index).UiNetworkItems end @@ -46,6 +49,14 @@ local function gui_set(player_index, value) GlobalState.get_ui_state(player_index).UiNetworkItems = value end +function NetInv:get_item_tooltip(item_name, item_count) + if self.read_only == true then + return item_utils.get_item_plain_tooltip(item_name, item_count) + else + return item_utils.get_item_inventory_tooltip(item_name, item_count) + end +end + function M.create(parent, player, args) args = args or {} local self = { @@ -58,15 +69,15 @@ function M.create(parent, player, args) if args.read_only == true then self.id_item = UiConstants.NETITEM_ITEM_RO self.id_slot = UiConstants.NETITEM_SLOT_RO - self.get_item_tooltip = item_utils.get_item_plain_tooltip + --self.get_item_tooltip = item_utils.get_item_plain_tooltip else self.id_item = UiConstants.NETITEM_ITEM self.id_slot = UiConstants.NETITEM_SLOT - self.get_item_tooltip = item_utils.get_item_inventory_tooltip + --self.get_item_tooltip = item_utils.get_item_inventory_tooltip end -- set index so we can call self:refresh() or M.refresh(self) - setmetatable(self, { __index = NetInv }) + setmetatable(self, NetItems__metatable) local vert_flow = parent.add({ type = "flow", @@ -154,7 +165,7 @@ local function get_sprite_button_def(self, item, event_name) local name if item.temp == nil then name = string.format("%s:%s", self.id_item, item.item) - tooltip = self.get_item_tooltip(item.item, item.count) + tooltip = self:get_item_tooltip(item.item, item.count) tags = { item = item.item } sprite_path = "item/" .. item.item else @@ -329,7 +340,7 @@ local function NetInv_click_slot(self, event) GlobalState.set_item_count(item_name, network_count - n_moved) local count = GlobalState.get_item_count(item_name) element.number = count - element.tooltip = self.get_item_tooltip(item_name, count) + element.tooltip = self:get_item_tooltip(item_name, count) something_changed = true end end diff --git a/src/UiNetworkLimits.lua b/src/UiNetworkLimits.lua index 6201d54..4501428 100644 --- a/src/UiNetworkLimits.lua +++ b/src/UiNetworkLimits.lua @@ -25,6 +25,9 @@ local M = {} local NetLim = {} +local NetLimit__metatable = { __index = NetLim } +script.register_metatable("NetLimit", NetLimit__metatable) + local function gui_get(player_index) return GlobalState.get_ui_state(player_index).UiNetworkLimits end @@ -41,7 +44,7 @@ function M.create(parent, player, show_title) } -- set index so we can call self:refresh() or M.refresh(self) - setmetatable(self, { __index = NetLim }) + setmetatable(self, NetLimit__metatable) local vert_flow = parent.add({ type = "flow", diff --git a/src/UiNetworkShortages.lua b/src/UiNetworkShortages.lua index a6827dc..9c0e59b 100644 --- a/src/UiNetworkShortages.lua +++ b/src/UiNetworkShortages.lua @@ -23,6 +23,9 @@ local M = {} local NetLimits = {} +local NetShortage__metatable = { __index = NetLimits } +script.register_metatable("NetShortage", NetShortage__metatable) + local function gui_get(player_index) return GlobalState.get_ui_state(player_index).UiNetworkShortages end @@ -38,7 +41,7 @@ function M.create(parent, player) } -- set index so we can call self:refresh() or M.refresh(self) - setmetatable(self, { __index = NetLimits }) + setmetatable(self, NetShortage__metatable) local vert_flow = parent.add({ type = "flow",