From cab538cfbfa1b3b7c7a64bfcd156f1b6fd059f71 Mon Sep 17 00:00:00 2001 From: Zenon Seth Date: Mon, 6 Nov 2023 00:13:49 +0000 Subject: [PATCH] Added on/off Demander Toggle; Added network renaming; code cleanup --- ROADMAP.md | 24 +++++++ api/controller.lua | 50 +++++++++++++- api/demander.lua | 29 +++++++-- logic/demander.lua | 6 +- logic/inv_list_picker.lua | 49 -------------- logic/logic.lua | 1 - logic/network_logic.lua | 23 +++++-- logic/processing_queue.lua | 68 ++++---------------- textures/logistica_basic_demander_front.png | Bin 2346 -> 2244 bytes textures/logistica_basic_demander_side.png | Bin 2345 -> 2294 bytes textures/logistica_icon_off.png | Bin 0 -> 1964 bytes textures/logistica_icon_on.png | Bin 0 -> 2257 bytes util/common.lua | 27 +++++++- util/ui.lua | 44 ++++++++++++- util/ui_logic.lua | 23 +++++++ util/util.lua | 1 + 16 files changed, 220 insertions(+), 125 deletions(-) create mode 100644 ROADMAP.md delete mode 100644 logic/inv_list_picker.lua create mode 100644 textures/logistica_icon_off.png create mode 100644 textures/logistica_icon_on.png create mode 100644 util/ui_logic.lua diff --git a/ROADMAP.md b/ROADMAP.md new file mode 100644 index 0000000..048d102 --- /dev/null +++ b/ROADMAP.md @@ -0,0 +1,24 @@ +Missing Features: +- Supplier implementation +- Item Storage implementation +- On/Off state of demander and supplier +- Storage Access Point +- Crafting recipes + +High Priority: +- Rework demanders to be run from controller and to have priority +- Remote Storage Access Point +- Crafting Supplier +- Ability to name storages +- Machine Upgrades + +Medium Priority +- Wirelss Network Extender +- Ability to add entity display on storages +- Rework all node textures; make new textures 32x32 +- Rework all UI icons to be.. 48x48? 64x64? something else? +- Direct pipeworks compatibility +- Direct tubelib compatibility + +Low Priority: +- Improve node sounds diff --git a/api/controller.lua b/api/controller.lua index 9f0c19d..f5d6a14 100644 --- a/api/controller.lua +++ b/api/controller.lua @@ -1,9 +1,50 @@ +local SET_BUTTON = "logsetbtn" +local NAME_FIELD = "namef" +local FORMSPEC_NAME = "logconren" +local controllerForms = {} + +local function get_controller_formspec(pos) + local name = logistica.get_network_name_or_nil(pos) or "" + return "formspec_version[6]" .. + "size[10.5,2]" .. + logistica.ui.background.. + "field[2.5,0.6;3,0.8;"..NAME_FIELD..";Network Name;"..name.."]" .. + "button[5.6,0.6;3,0.8;"..SET_BUTTON..";Set]" +end + +local function show_controller_formspec(pos, playerName) + local pInfo = {} + pInfo.position = pos + controllerForms[playerName] = pInfo + minetest.show_formspec(playerName, FORMSPEC_NAME, get_controller_formspec(pos)) +end + +local function on_controller_receive_fields(player, formname, fields) + if formname ~= FORMSPEC_NAME then return end + local playerName = player:get_player_name() + minetest.chat_send_all("rec: "..logistica.ttos(fields)) + if fields.quit and not fields.key_enter_field then + controllerForms[playerName] = nil + elseif (fields[SET_BUTTON] or fields.key_enter_field) and fields[NAME_FIELD] then + local pos = controllerForms[playerName].position + local newNetworkName = fields[NAME_FIELD] + logistica.rename_network(minetest.hash_node_position(pos), newNetworkName) + local meta = minetest.get_meta(pos) + meta:set_string("infotext", "Controller of Network: "..newNetworkName) + meta:set_string("name", newNetworkName) + end + return true +end + +-- registration stuff +minetest.register_on_player_receive_fields(on_controller_receive_fields) --[[ The definition table will get the fololwing fields overriden (and currently originals are not called): - on_construct - after_destruct - on_timer + - on_rightclick The definition must also provide a `logistica_controller` table. This table should contains: { @@ -46,11 +87,15 @@ function logistica.register_controller(simpleName, def, tier) def.after_destruct = after_destruct def.on_timer = on_timer def.drop = controller_name + def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + if clicker and clicker:is_player() then + show_controller_formspec(pos, clicker:get_player_name()) + end + end minetest.register_node(controller_name, def) - local def_disabled = {} - for k, v in pairs(def) do def_disabled[k] = v end + local def_disabled = table.copy(def) local tiles_disabled = {} for k, v in pairs(def.tiles) do tiles_disabled[k] = v.."^logistica_disabled.png" end def_disabled.tiles = tiles_disabled @@ -58,6 +103,7 @@ function logistica.register_controller(simpleName, def, tier) def_disabled.on_construct = nil def_disabled.after_desctruct = nil def_disabled.on_timer = nil + def_disabled.on_rightclick = nil minetest.register_node(controller_name.."_disabled", def_disabled) end diff --git a/api/demander.lua b/api/demander.lua index 9121df4..c750677 100644 --- a/api/demander.lua +++ b/api/demander.lua @@ -1,22 +1,33 @@ local NUM_DEMAND_SLOTS = 4 -- maybe at some point make this a param, but why? local PUSH_LIST_PICKER = "push_pick" +local ON_OFF_BUTTON = "on_off_btn" local FORMSPEC_NAME = "logistica_demander" local demanderForms = {} + + local function get_demander_formspec(pos) local posForm = "nodemeta:"..pos.x..","..pos.y..","..pos.z local pushPos = logistica.get_demander_target(pos) local meta = minetest.get_meta(pos) local selectedList = meta:get_string("demtarlist") + local isOn = logistica.is_machine_on(pos) return "formspec_version[4]" .. "size[10.6,7]" .. logistica.ui.background.. - logistica.get_push_list_dropdown(PUSH_LIST_PICKER, 8.5, 0.7, pushPos, selectedList).. + logistica.ui.push_list_picker(PUSH_LIST_PICKER, 7.5, 0.7, pushPos, selectedList).. + logistica.ui.on_off_btn(isOn, 9.5, 0.5, ON_OFF_BUTTON).. "list["..posForm..";filter;0.5,0.5;"..NUM_DEMAND_SLOTS..",1;0]".. - "list[current_player;main;0.5,2;8,4;0]" - + "list[current_player;main;0.5,2;8,4;0]" +end + +local function show_demander_formspec(playerName, pos) + local pInfo = {} + pInfo.position = pos + demanderForms[playerName] = pInfo + minetest.show_formspec(playerName, FORMSPEC_NAME, get_demander_formspec(pos)) end local function on_player_receive_fields(player, formname, fields) @@ -26,6 +37,13 @@ local function on_player_receive_fields(player, formname, fields) if not demanderForms[playerName] then return false end if fields.quit then demanderForms[playerName] = nil + elseif fields[ON_OFF_BUTTON] then + local pos = demanderForms[playerName].position + if not pos then return false end + if logistica.toggle_machine_on_off(pos) then + logistica.start_demander_timer(pos, 1) + end + show_demander_formspec(player:get_player_name(), pos) elseif fields[PUSH_LIST_PICKER] then local selected = fields[PUSH_LIST_PICKER] if logistica.is_allowed_push_list(selected) then @@ -47,10 +65,7 @@ end local function on_demander_rightclick(pos, node, clicker, itemstack, pointed_thing) if not clicker or not clicker:is_player() then return end - local pInfo = {} - pInfo.position = pos - demanderForms[clicker:get_player_name()] = pInfo - minetest.show_formspec(clicker:get_player_name(), FORMSPEC_NAME, get_demander_formspec(pos)) + show_demander_formspec(clicker:get_player_name(), pos) end local function after_place_demander(pos, placer, itemstack, numDemandSlots) diff --git a/logic/demander.lua b/logic/demander.lua index 8e52ff7..3484f5e 100644 --- a/logic/demander.lua +++ b/logic/demander.lua @@ -127,12 +127,14 @@ end function logistica.start_demander_timer(pos, duration) if duration == nil then duration = TIMER_DURATION_SHORT end logistica.start_node_timer(pos, duration) + logistica.set_logistica_node_infotext(pos, true) end function logistica.on_demander_timer(pos, elapsed) local network = logistica.get_network_or_nil(pos) - if not network then - return false -- this will get restarted once the demander is added to a network + if not network or not logistica.is_machine_on(pos) then + logistica.set_logistica_node_infotext(pos, false) + return false end take_demanded_items_from_network(pos, network) return true diff --git a/logic/inv_list_picker.lua b/logic/inv_list_picker.lua deleted file mode 100644 index 0e982d9..0000000 --- a/logic/inv_list_picker.lua +++ /dev/null @@ -1,49 +0,0 @@ -local ALLOWED_PULL_LISTS = {} -ALLOWED_PULL_LISTS["main"] = true -ALLOWED_PULL_LISTS["src"] = true -ALLOWED_PULL_LISTS["dst"] = true -ALLOWED_PULL_LISTS["output"] = true -ALLOWED_PULL_LISTS["fuel"] = true - -local ALLOWED_PUSH_LISTS = {} -ALLOWED_PUSH_LISTS["main"] = true -ALLOWED_PUSH_LISTS["src"] = true -ALLOWED_PUSH_LISTS["fuel"] = true -ALLOWED_PUSH_LISTS["input"] = true -ALLOWED_PUSH_LISTS["shift"] = true - --- returns a string of comma separated lists we're allowed to push to at the given pushToPos -local function get_lists(pushToPos, allowedLists) - logistica.load_position(pushToPos) - local availableLists = minetest.get_meta(pushToPos):get_inventory():get_lists() - local pushLists = {} - for name, _ in pairs(availableLists) do - if allowedLists[name] then - table.insert(pushLists, name) - end - end - return pushLists -end - -local function list_dropdown(name, itemTable, x, y, default) - local defaultIndex = 0 - for i, v in ipairs(itemTable) do if default == v then defaultIndex = i end end - local items = table.concat(itemTable, ",") - return "dropdown["..x..","..y..";2,0.6;"..name..";"..items..";"..defaultIndex..";false]" -end - -function logistica.get_pull_list_dropdown(name, x, y, pullFromPos, default) - return list_dropdown(name, get_lists(pullFromPos, ALLOWED_PULL_LISTS), x, y, default) -end - -function logistica.get_push_list_dropdown(name, x, y, pushToPos, default) - return list_dropdown(name, get_lists(pushToPos, ALLOWED_PUSH_LISTS), x, y, default) -end - -function logistica.is_allowed_pull_list(listName) - return ALLOWED_PULL_LISTS[listName] == true -end - -function logistica.is_allowed_push_list(listName) - return ALLOWED_PUSH_LISTS[listName] == true -end diff --git a/logic/logic.lua b/logic/logic.lua index 892539c..c456337 100644 --- a/logic/logic.lua +++ b/logic/logic.lua @@ -1,6 +1,5 @@ local path = logistica.MODPATH .. "/logic" dofile(path .. "/processing_queue.lua") -dofile(path .. "/inv_list_picker.lua") dofile(path .. "/groups.lua") dofile(path .. "/network_logic.lua") dofile(path .. "/controller.lua") diff --git a/logic/network_logic.lua b/logic/network_logic.lua index d3471e7..e6add3b 100644 --- a/logic/network_logic.lua +++ b/logic/network_logic.lua @@ -4,7 +4,7 @@ local STATUS_OK = 0 local CREATE_NETWORK_STATUS_FAIL_OTHER_NETWORK = -1 local CREATE_NETWORK_STATUS_TOO_MANY_NODES = -2 -logistica.networks = networks +-- logistica.networks = networks local p2h = minetest.hash_node_position local h2p = minetest.get_position_from_hash @@ -44,6 +44,12 @@ function logistica.get_network_name_or_nil(pos) if not network then return nil else return network.name end end +function logistica.rename_network(networkId, newName) + local network = networks[networkId] + if not network then return false end + network.name = newName + return true +end function logistica.get_network_id_or_nil(pos) local network = logistica.get_network_or_nil(pos) @@ -187,13 +193,15 @@ local function recursive_scan_for_nodes_for_controller(network, positionHashes, else return recursive_scan_for_nodes_for_controller(network, connections, numScanned) end end -local function create_network(controllerPosition) +local function create_network(controllerPosition, oldNetworkName) local node = minetest.get_node(controllerPosition) if not node.name:find("_controller") or not node.name:find("logistica:") then return false end local meta = minetest.get_meta(controllerPosition) local controllerHash = p2h(controllerPosition) local network = {} - local networkName = logistica.get_network_name_for(controllerPosition) + local nameFromMeta = meta:get_string("name") + if nameFromMeta == "" then nameFromMeta = nil end + local networkName = oldNetworkName or nameFromMeta or logistica.get_network_name_for(controllerPosition) networks[controllerHash] = network meta:set_string("infotext", "Controller of Network: "..networkName) network.controller = controllerHash @@ -227,14 +235,15 @@ end -- worker functions for cable/machine/controllers ---------------------------------------------------------------- -local function rescan_network(networkName) - local network = networks[networkName] +local function rescan_network(networkId) + local network = networks[networkId] if not network then return false end if not network.controller then return false end local conHash = network.controller local controllerPosition = h2p(conHash) - clear_network(networkName) - create_network(controllerPosition) + local oldNetworkName = network.name + clear_network(networkId) + create_network(controllerPosition, oldNetworkName) end local function find_cable_connections(pos, node) diff --git a/logic/processing_queue.lua b/logic/processing_queue.lua index faba88c..6cde570 100644 --- a/logic/processing_queue.lua +++ b/logic/processing_queue.lua @@ -1,62 +1,20 @@ +local ProQ = {} +ProQ.__index = ProQ -logistica.proq = {} - -local function get_meta(pos) - logistica.load_position(pos) - return minetest.get_meta(pos) +function ProQ.new() + local self = setmetatable({}, ProQ) + self.queue = {} + return self end -local QUEUE_KEY = "log_proq" -local DELIM = "|" - --- listOfPositions must be a list (naturally numbered table) of position vectors -local function save_queue(meta, listOfPositions) - local tableOfStrings = {} - for _,v in ipairs(listOfPositions) do - table.insert(tableOfStrings, vector.to_string(v)) - end - local singleString = table.concat(tableOfStrings, DELIM) - meta:set_string(singleString) +-- the : syntax here causes a "self" arg to be implicitly added before any other args +function ProQ:add_pos(newval) + self.value = newval end --- listOfPositions must be a list (naturally numbered table) of position vectors -function logistica.proq.add(pos, listOfPositions) - local meta = get_meta(pos) - local positions = logistica.proq.get_all(pos) - for _, v in ipairs(listOfPositions) do - table.insert(positions, v) - end - save_queue(meta, positions) +function ProQ:get_value() + return self.value end --- returns a table of up to the next N positions -function logistica.proq.pop_next(pos, count) - local meta = get_meta(pos) - local positions = logistica.proq.get_all(pos) - local ret = {} - local rem = {} - for i, v in ipairs(positions) do - if (i <= count) then - table.insert(ret, v) - else - table.insert(rem, v) - end - end - save_queue(meta, rem) - return ret -end - -function logistica.proq.get_all(pos) - local meta = get_meta(pos) - if not meta:contains(QUEUE_KEY) then return {} end - local compressedString = meta:get_string(QUEUE_KEY) - local positionStrings = string.split(compressedString, DELIM, false) - local positions = {} - for _, v in ipairs(positionStrings) do - local vector = vector.from_string(v) - if vector then - table.insert(positions, vector) - end - end - return positions -end +local instance = ProQ.new() +-- do stuff with instance... \ No newline at end of file diff --git a/textures/logistica_basic_demander_front.png b/textures/logistica_basic_demander_front.png index b94585aa477bd7be8735da07ba5400706789f8bd..65aa8250bf02807cb467901554b15c4c97867a09 100644 GIT binary patch delta 486 zcmVyU8@ zM2>*KvMhnuJ3I5b2!^$&po5mWtA9S7oxObX{_=nW8WIR(LJ>i)4hR9r@3yb>?dP=w zC_vz2{Joz~#s?vma$%0jY1uC&SJ?J_KIrAcZ4W6!5`U|Ma54qZ!Y7Y5)!ln_cXtZe z$Y2&55Hu?_Mq15GRV|d+HcA6VLL#Ip-_8pdJ40b%z+UXR+t7O*mI6Y`ri_qj5>k5C zfmtqGvf*NTe!t?|50_rb#!z5LpvzC6JhU+`1AKmd4xE1ZG(O%)1d_P=bBD=w`TLNE%uog=o^;3uqDde$(8+ zhTKiNtOO=|eeyb$?TD~#*;vTfat_Nd$>W&F0$J-(Y?s{JfO)ApQjj~j%YzYtKtx2- z5x8}pe&|rpac)G1=`gRx2E4L~`9}nn#7bwo{x9|Y*^ASVo17xWfHsc7O1VX)oZ%)n c{BisGFRh^g;;6rQp8x;=07*qoM6N<$g4cuIIRF3v delta 589 zcmV-T0^K10)AAI65&oIx@5A0~G-WF*rIgIXW_v1qEsZ z)y&+PvvUQd0e}5TL_t(2kwubUOPog(ho9e>ck}MbVxiw9-=L6hup%{9D<-K;FwjD& zH@T6tPzt4gY-_TKX7%IrCNbo~K%k{X!Ge&4WZj+l^ zhlB(InNUQKO9q5CH`Z&I27|fHAAbb}2z;@>en07VJAWaj#Rb>sd+Tcr@Mb)A3EMuu zhaeZ9z0DytA*p_DKu=#DO(BB*Ok1*ZF4@_cVr&G6sSOB{33a1sQ>RJeQnnxb*0gD+ z*Ut3Ye!rcaZD&7dN2B3~v)#7WTFDw^T3N`1V5HgnI$=+~rVa1?>!{eR(;ho!`+ZY#fNpB322qdw! zwKcfD+*B*4r|t zIw_?TDaCl2Gfc&I8+RL^h4I4)|kh~G{;00000NkvXXu0mjfbF3XC diff --git a/textures/logistica_basic_demander_side.png b/textures/logistica_basic_demander_side.png index 4b168c68dc95a5b52edcb9f8c449e3968039bd15..2232faa0871b530224094b9028b8ff0f9cb00ad6 100644 GIT binary patch delta 539 zcmV+$0_6Rv67~_Ww*v?=GdeXmIx{qrzXKx(GBY|gI65;lv+4sB0SGcPIyE>tGc=P1 z1!)9jNb{_-a|NXVf5}NiK~yM_MUpXY6hRP0->>fRF2)i8XCWp*<_7CSfDjf0SRe$* z!UR|b9Kcz~d;k&>5+o#$5Qv4qUb8zp)BOp?yHwCYSL^?(-%pdt4glPL{wg7XKqeFs zlv)5G0C|7!t|pV6{Wotx0RpeivqiTxZbJ0c6|<@g%-Ys9e{6ewAC&6lc?l_pBnAgz zef<2RhX}SdN42<=T3lSH#zuhXZ9tGr);O}2Oj~OT<(x*!28@J6NVWRB>%rI&iU>Wu zf7^Cn>!Ryt%kFgEPG|F9XY=XV;?MbF)^-%9szhY}Ezcg_0or+2Wy8z8-Svu(4qm&j zHiim@JiG?3e_q)%t_FC2eHYk1IT~LcNd%IZ&gPiB7CSv%NLnRwQT?JfRJ%f|GQ{J< zuX(6kbeLCcJ0Q^CMAgB zt0E$&$SE}`r4%Ve+m`~pSjrg~LA&e*V*?)8#9R=8B{9&cHQswK4hM|G5jB7krAGaq du{n5f?;i(%12|niSGfQH002ovPDHLkV1m8p>}mi2 delta 591 zcmV-V0AK~yM_m6A(OQ&9kfXU@5|6vN*W!lNyHQ0OiG8AE%4(ucjR z3;iu7Zj5nZOiYvwsRrod+{YOgME1;Lb~BkwKJM=B;U(g?+XV@L1|XpS{;|25<&|HQIT# zBWm7w8Pm^J|Z5yrA@nn!n2i3-CJSZ$OgUli~LP%RO z{QCP&0?Cp!aU6HMktN?=^g5l6HRht%dvo3e;Iaace*k{^@iXuN07)Qb$-7GB7(kLt zs@1xrB$*sms{{p!GNrtfiFPXtw!^R-Hd-f1GO=M$t2d|9u?>RbdTTzNdT-<{iomR> zl=6aP1S7K1KAntiwn}09^lUP|DV2i#YUBNEoDyq_pTFN0kOw4)5C9PX`1BA6KqQ}_ d6km$>6+hIXC5}%mQ6vBW002ovPDHLkV1j871;+pY diff --git a/textures/logistica_icon_off.png b/textures/logistica_icon_off.png new file mode 100644 index 0000000000000000000000000000000000000000..7257033f86152b975e86d8ce5f41cfcbd12db596 GIT binary patch literal 1964 zcmaJ?eM}Q)7(aDPR-@Yj8{OvgID&()_S!?pC7!#65F$uGiRvA+H;f+Q8Om2S!HoJY`nKua-vEzm{- zA&4W0xgZ*%=sF;wwZO*)N$mFbKVT@!kXV(`sdI*`z|WS{3!tLDtdg#;qfHD}U{RT) z1SALmi9(|RE+`UF5>t2y_+LK8F;r2J>PXD(bfH#W0H{%G)ao#c3N;IimngRt4H`p< z#Qc&JB5*tsiD)CaT3+zsdXve7>kPQTpn)11F&31ls3s_8$P{r78xU!M4M{8?L}gB@ zmJdrLhCv)1BxmR$?oe3Z6lR9T0S5vgD2cdUtH(#`gD5*3O;8*x7c3kuBT!wJpf0iA zXQ<1_DD{w^mw3_7hlYYma4`grGKA$G+ayYb#!_}VpRXPWB%~oq_NB0JgH1??>4^ie zG8O`OIS~1L3v-G4S8UwF7>Ug^;3M34#)O9YKq%2U zc?JfTs{}U;IjmNfzZ?g2K9fVQkRW}_siWzZRNHF~{9 zXRI{n34?*q=fAIzDvEGy7)qj^qblEf)XdO?#7Z1cr1%^Za#CE1iySLoeuATdJ`#&+ z7~rMCoP=4}pxiZHh*h&R9~8~FJTn|SNTf(ln9O*B8#9d1=_E>6Q8pjpxdJRn^sI~? ziYgb1plG=tBo-2QCQJiHNfzc1M@8N%MJNFj`e0NfR_OJzuyZlgB@YP-2UDlbPqc{m z0c0DqjQGebowYU0WlNU=}`}W2k*}RI&m%lldHT6LD5%BM=O&6|S9GLCsJQ21x zw^UDjJihaUCmYMGI(;;0`SPv<7uGM|YB_W5pF?fe?p%*qUUp}AGPj?LrEkLh+uHk$ zX-sDMdySdv502khbZNf5Pt}vsQ?V>CM+89VuAT^t27@Uae^wSHw)~czODxeH}$z12Y@ffa438g&r&2ocD$* zYFpHL!_l1m(+0!7-J2i%cd?2z{+_cSa(~<7DxGkVz@>GYn41w(^vGQGbYW{?$z(5n}n~%Z<*4brVb-z6MrrBpFP#FD(9`s!V5+u|Kt(^xthF~ iK&s}ORYl!d&?AC4eY5&wE6k^1D2T&eX6u|=v+{qV#-m;U literal 0 HcmV?d00001 diff --git a/textures/logistica_icon_on.png b/textures/logistica_icon_on.png new file mode 100644 index 0000000000000000000000000000000000000000..7507f6e5479d56b2db5ae487b507d34443b3a7bb GIT binary patch literal 2257 zcmaJ@c~BE)6kn`bn^rA?R~6kZLSd9_4gzIO!jS|?Y0@YtNvng)?k3riWMg(?5|ldi zKoA|Ub)dEu#OY|Qh}A0fpjZ{9;CM}I9d(q!YC)%HE4D~c?6(Ob)Z>p$^1k1DzjuA_ zZHf%~StA8+2p|X=sZCSQ0pBqHj2I3+*}S}a5Hu{6&NOmH-MbjU*o8RBmp~DDFlL{nDrW5I$D#}Wy<+-SgJbfmSmrEp&NTO08_hNv+ zPH{Nwwc8vl=2akmUJU%^k5L5nt8lpr#HcgCD#k^@GNDW;LX-kn?jp_D9Cd1+F_099 zmE)Wkih4XAp+_oYTozQEkdT0iB&b9Z12ke-pM%4_F%CAIrwDMUDVA{2PL5_AFwcqS zFm6tPAOMH^$VsA~+v#@M{LCbQQZ~v?IXD&-3&rR_eacHeiN?Y9l?xOO!6ef6{iJ?HFg7I4;V)3-?>#Ih35=sT8|9Y*bC7J~0#ZP<(fsAd zY`DXsK)f*|Wyak$4pGt$zH5xjmrWClgO#KF%-HBYBER&QNsbP3BL@-cbXXeA^5z3P zXHbgh7){06o}KskZyt^{mFtH0w~LvIS=llk}V)A1(Iww)1Y%c*uW17 z3u~LBTnPo%=X7M;GIr>!Gfusj44qz8J0}BakHne}W0il06QVy^YU10S^ zDgQVQK|vqWp!rWV9fG3PyVswYehi=7n0>j>jD)TZD?35QW?Z}W?eVC|wb93@p4;V@ ze!tu`Q(M#Q))Wc;S2_Lj_?VXnI=%{{N|+9iwlBQ|JAd8YIw~S0eMF^TN$i2mf9~AgnEoKgb+92jGIzZJs@{3Dh8x?s!`Ng^ zz$~EY6;Mrc z$$2IfQ4~8-;8ibJe@j~weeP4qp6ZPcA6?E;$l9mR_1v%OZ4zD0+l;?jUtI8)&pM%H z*1{z#ixK$iH0Zq8F6Ca^j~6LT@tq&LBRR#_;+TJ?Uu@X9J+!VOi4DE9>qx!f zmdRK7+mgcSlUWOn+@5l;xx4K6)IEvT5z*H>3c)+<6=#}>g`ihM_$LVZeA5Kbp|7;+ zxws)6qO&U(=TtjBAfWlsQjt>TW@q8ZS%F1_bgATGCa6b zxPP-@M$x|`hi|PkIHmNgY-{y2dgdxB5^DG5|C^k2q81`I zsMC0xyTxH2{yqHks`Qr8rFZWLv_Hd@8zU2?#~b5&R3?fj&)&&aF!gIUOn85OW!*gH ztP7j}&%@m}pw0uYl}tI^+1(D_jk_53>LSyolYjL(nf8Re=T4ofUBR~M=Z_M7QA?Z* zQvRSw`g!Q7+K}dyAy+Em&+Thz&~GHVJ}XH6zHQz3{kbVa<~2{l+eZZVtS)ed>*Ln6 z^%#TW$Br@nWNFf0o)&VVVT>iL+>-mjZl5pziz7*UO3xHX9{zsqURz0)`=+40 z;!M&zv2UK0jZ~F9N*XitrLrlBtvyW_s+KpO5FUQS`AX9}TivqQQl!K?X+`^$Bl_#H hbzQTo4N;+Mrmrd3p_;kwqmTK2B3g}JU6ZnK`F|mnK 0 +end + +-- toggles the state and returns the new state (true for on, false for off) +function logistica.toggle_machine_on_off(pos) + local meta = minetest.get_meta(pos) + local newState = (meta:get_int(META_ON_OFF_KEY) + 1) % 2 + meta:set_int(META_ON_OFF_KEY, newState) + return newState > 0 +end + +-- isOn is optional +function logistica.set_logistica_node_infotext(pos, isOn) + if isOn == nil then isOn = logistica.is_machine_on(pos) end + logistica.load_position(pos) + local meta = minetest.get_meta(pos) + local node = minetest.get_node(pos) + local text = minetest.registered_nodes[node.name].description.. + "\n"..(isOn and "Running" or "Stopped") + meta:set_string("infotext", text) +end diff --git a/util/ui.lua b/util/ui.lua index 9c763be..8c681ee 100644 --- a/util/ui.lua +++ b/util/ui.lua @@ -1,3 +1,45 @@ logistica.ui = {} -logistica.ui.background = "no_prepend[]bgcolor[#0000]background9[0,0;1,1;logistica_formspec_background.png;true;8]" \ No newline at end of file +logistica.ui.background = "no_prepend[]bgcolor[#0000]background9[0,0;1,1;logistica_formspec_background.png;true;8]" + +-- returns a string of comma separated lists we're allowed to push to at the given pushToPos +local function get_lists(pushToPos, allowedLists) + logistica.load_position(pushToPos) + local availableLists = minetest.get_meta(pushToPos):get_inventory():get_lists() + local pushLists = {} + for name, _ in pairs(availableLists) do + if allowedLists[name] then + table.insert(pushLists, name) + end + end + return pushLists +end + + +local function list_dropdown(name, itemTable, x, y, default) + local defaultIndex = 0 + for i, v in ipairs(itemTable) do if default == v then defaultIndex = i end end + local items = table.concat(itemTable, ",") + return "dropdown["..x..","..y..";2,0.6;"..name..";"..items..";"..defaultIndex..";false]" +end + +-------------------------------- +-- public functions +-------------------------------- + +function logistica.ui.on_off_btn(isOn, x, y, name, w, h) + if not w or not h then + w = 1; h = 1 + end + local texture = (isOn and "logistica_icon_on.png" or "logistica_icon_off.png") + return "image_button["..x..","..y..";"..w..","..h..";".. + ""..texture..";"..name..";;false;false;"..texture.."]" +end + +function logistica.ui.pull_list_picker(name, x, y, pullFromPos, default) + return list_dropdown(name, get_lists(pullFromPos, logistica.ALLOWED_PULL_LISTS), x, y, default) +end + +function logistica.ui.push_list_picker(name, x, y, pushToPos, default) + return list_dropdown(name, get_lists(pushToPos, logistica.ALLOWED_PUSH_LISTS), x, y, default) +end diff --git a/util/ui_logic.lua b/util/ui_logic.lua new file mode 100644 index 0000000..7cc1d05 --- /dev/null +++ b/util/ui_logic.lua @@ -0,0 +1,23 @@ +logistica.ALLOWED_PULL_LISTS = {} +local allowedPull = logistica.ALLOWED_PULL_LISTS +allowedPull["main"] = true +allowedPull["src"] = true +allowedPull["dst"] = true +allowedPull["output"] = true +allowedPull["fuel"] = true + +logistica.ALLOWED_PUSH_LISTS = {} +local allowedPush = logistica.ALLOWED_PUSH_LISTS +allowedPush["main"] = true +allowedPush["src"] = true +allowedPush["fuel"] = true +allowedPush["input"] = true +allowedPush["shift"] = true + +function logistica.is_allowed_pull_list(listName) + return allowedPull[listName] == true +end + +function logistica.is_allowed_push_list(listName) + return allowedPush[listName] == true +end \ No newline at end of file diff --git a/util/util.lua b/util/util.lua index e00756d..2f248c7 100644 --- a/util/util.lua +++ b/util/util.lua @@ -3,4 +3,5 @@ local path = logistica.MODPATH.."/util" dofile(path.."/common.lua") dofile(path.."/rotations.lua") dofile(path.."/hud.lua") +dofile(path.."/ui_logic.lua") dofile(path.."/ui.lua")