Added New Mods and Profiles Folders

This is a complete rebuild of the modpack, with all new mods and updates for 1.5.3 of Anomaly.
This commit is contained in:
2025-01-14 05:07:53 -05:00
parent 85c665b107
commit 376b4b9689
21217 changed files with 546254 additions and 0 deletions
@@ -0,0 +1,55 @@
--[[
Functionality for digital clock furniture
Author: HarukaSai (visit us at: https://discord.com/invite/efp)
19-06-2023
]]
function init(obj)
obj:bind_object(haru_placeable_digital_clock_wrapper(obj).binder)
end
--------------------------------------------------------------------------------
-- Class "placeable_digital_clock_binder"
--------------------------------------------------------------------------------
class "haru_placeable_digital_clock_wrapper" (bind_hf_base.hf_binder_wrapper)
-- Class constructor
function haru_placeable_digital_clock_wrapper:__init(obj) super(obj)
end
-- Class update
function haru_placeable_digital_clock_wrapper:update(delta)
bind_hf_base.hf_binder_wrapper.update(self, delta)
local curr_time = game.get_game_time()
if (self.previous_time == nil) then self.previous_time = curr_time end
if not (curr_time:diffSec(self.previous_time) > 1) then
return
end
self.previous_time = curr_time
local time = {
h = string.format("%02d", tostring(level.get_time_hours())),
m = string.format("%02d", tostring(level.get_time_minutes()))
}
for k, v in pairs(time) do
local i = 1
v:gsub(".", function(c)
self:set_digit_visible({k, i}, c)
i = i + 1
end)
end
end
function haru_placeable_digital_clock_wrapper:set_digit_visible(pos, digit)
for i = 0, 9 do
self.object:set_bone_visible(
string.format("digit_%s_%s_%s", pos[1], pos[2], i),
i == tonumber(digit),
false, false
)
end
end
@@ -0,0 +1,64 @@
--[[
Functionality and interactivity for table fan furniture
Author: HarukaSai (visit us at: https://discord.com/invite/efp)
Credits: Aoldri
19-06-2023
]]
function toggle_fan(obj_id)
local section = alife_object(obj_id):section_name()
local is_on = hf_obj_manager.get_data(obj_id).is_on
hf_obj_manager.update_data(obj_id, {is_on = (not is_on)})
end
function init(obj)
obj:bind_object(haru_placeable_fan_wrapper(obj).binder)
end
--------------------------------------------------------------------------------
-- Class "placeable_digital_clock_binder"
--------------------------------------------------------------------------------
class "haru_placeable_fan_wrapper" (bind_hf_base.hf_binder_wrapper)
-- Class constructor
function haru_placeable_fan_wrapper:__init(obj) super(obj)
self.first_update = true
self.snd_switch = sound_object([[efp_props\fan_switch]])
self.snd_idle = sound_object([[efp_props\fan_idle]])
end
-- Class update
function haru_placeable_fan_wrapper:update(delta)
bind_hf_base.hf_binder_wrapper.update(self, delta)
local is_on = hf_obj_manager.get_data(self.object:id()).is_on
if (self.last_state ~= is_on) or self.first_update then
self.object:play_cycle(is_on and "fan_movement" or "fan_static")
if (not self.first_update) then
self.snd_switch:play_no_feedback(self.object, sound_object.s3d, 0, self.object:position(), 0.5, random_float(0.9, 1.1))
end
if is_on then
if (not self.snd_idle:playing()) then
self.snd_idle:play_at_pos(self.object, self.object:position(), 0, sound_object.s3d + sound_object.looped)
self.snd_idle.volume = self.first_update and 0.5 or 0
self.snd_idle_max = time_global() + (not self.first_update and 2000 or 0)
end
else
if self.snd_idle:playing() then
self.snd_idle:stop()
end
end
end
if self.snd_idle:playing() and (self.snd_idle_max > time_global()) then
self.snd_idle.volume = 0.5 - (self.snd_idle_max - time_global()) / 2000
end
self.last_state = is_on
self.first_update = false
end
@@ -0,0 +1,139 @@
--[[
Functionality for specialized storage boxes
Author: HarukaSai (visit us at: https://discord.gg/efp)
19-06-2023
]]
-- no real way to tell apart canned food, so we just have a table with them
canned_food = {
["beans"] = true,
["chili"] = true,
["conserva"] = true,
["corn"] = true,
["tomato"] = true,
["tushonka"] = true
}
storage_types = {
["ammo"] = function(obj)
return IsAmmo(obj)
end,
["meds"] = function(obj)
return SYS_GetParam(0, obj:section(), "kind") == "i_medical"
end,
["canned_food"] = function(obj)
local sec = obj:section()
return canned_food[sec] or false
end
}
-- Wrapper for CreateTimeEvent that checks if object exists
function CreateSafeObjEvent(obj, ev_id, act_id, timer, f, ...)
local id = obj:id()
CreateTimeEvent(ev_id, act_id, timer, function(...)
if level.object_by_id(id) then
return f(obj, ...)
end
return true
end, ...)
end
local check_ids = {
[EDDListType.iActorBag] = true,
[EDDListType.iActorBelt] = true,
[EDDListType.iActorTrade] = true,
[EDDListType.iActorSlot] = true
}
function actor_on_item_before_move(flags, npc_id, obj, mode, bag_id)
if not (check_ids[bag_id] and obj and mode == "loot") then return end
local box = get_object_by_id(npc_id)
if (not box) then return end
local specialized_storage = SYS_GetParam(0, box:section(), "specialized_storage")
if (not storage_types[specialized_storage]) or storage_types[specialized_storage](obj) then
return
end
flags.ret_value = false
end
local levels = {
[0] = 0,
[1] = 1,
[2] = 2,
[3] = 2,
[4] = 3,
}
function update_display(box)
local items = 0
box:iterate_inventory_box(function(box)
items = items + 1
end, box)
local level = levels[clamp(math.floor(items/12), 0, 4)] or 0
for i = 1, 3 do
local ev_id = string.format("update_tuna_box_bone_%s_%s", box:id(), i)
CreateSafeObjEvent(box, ev_id, ev_id, i/25, function()
box:set_bone_visible("tuna_" .. i, level >= i, false, false)
return true
end)
end
end
function update_tuna_box(box)
local id = box:id()
ResetTimeEvent("update_tuna_box" .. id, "update_tuna_box" .. id, 0.1)
CreateSafeObjEvent(box, "update_tuna_box" .. id, "update_tuna_box" .. id, 0.1, function()
update_display(box)
return true
end, id)
end
function is_tuna_box(box)
return box:section() == "placeable_cans_tuna"
end
function actor_on_item_take_from_box(box, item)
if (not is_tuna_box(box)) then
return
end
update_tuna_box(box)
end
function actor_on_item_put_in_box(box, item)
if (not is_tuna_box(box)) then
return
end
update_tuna_box(box)
end
binder_update = bind_physic_object.generic_physics_binder.update
bind_physic_object.generic_physics_binder.update = function(self, delta)
binder_update(self, delta)
if is_tuna_box(self.object) and (not self.tuna_box_updated) then
update_display(self.object)
self.tuna_box_updated = true
end
end
function on_game_start()
RegisterScriptCallback("actor_on_item_take_from_box", actor_on_item_take_from_box)
RegisterScriptCallback("actor_on_item_put_in_box", actor_on_item_put_in_box)
RegisterScriptCallback("ActorMenu_on_item_before_move", actor_on_item_before_move)
end
@@ -0,0 +1,185 @@
--[[
Full rewrite of Rotten Meat addon by HarukaSai for EFP (visit at: https://discord.com/invite/stalker-efp)
Created: 13-11-2022
Credits for original addon: Arszi
Features:
- Rewritten logic
- Refrigiration
- MCM configuration
]]
local mcm_id = "meat_spoiling"
local expiration_time = nil
local expiration_table = {}
local ini_meat = ini_file_ex("plugins\\meat_spoiling_settings.ltx")
meats = utils_data.collect_section(ini_meat.ini, "meats", true)
local function t2c(t)
if not t then return nil end
local ct = game.CTime()
ct:set(t.Y,t.M,t.D,t.h,t.m,t.s,t.ms)
return ct
end
local function c2t(ct)
if not ct then return nil end
local Y, M, D, h, m, s, ms = 0, 0, 0, 0, 0, 0, 0
Y, M, D, h, m, s, ms = ct:get(Y, M, D, h, m, s, ms)
return { Y=Y, M=M, D=D, h=h, m=m, s=s, ms=ms }
end
local previous_time = nil
function actor_on_update()
local curr_time = game.get_game_time()
if (previous_time == nil) then previous_time = curr_time end
if not (curr_time:diffSec(previous_time) > 1) then
return
end
previous_time = curr_time
tick_expiration()
end
function actor_on_item_take(item)
local id = item:id()
local sec = item:section()
if not (meats[sec] and (not expiration_table[id])) then
return
end
expiration_table[id] = {
duration = string.match(sec, "meat_") and expiration_time.cooked or expiration_time.raw,
last_update = c2t(game.get_game_time())
}
end
function actor_on_item_use(obj)
if (obj and expiration_table[obj:id()]) then
expiration_table[obj:id()] = nil
end
end
function get_meat_is_frozen(se_obj)
if (not se_obj) then return false end
local se_parent = se_obj.parent_id and se_obj.parent_id < 65535 and alife_object(se_obj.parent_id)
if (not se_parent) or (se_parent:section_name() ~= "placeable_fridge") then
return false
end
return true
end
function tick_expiration()
local curr_time = game.get_game_time()
for id, data in pairs(expiration_table) do
repeat
local se_obj = alife_object(id)
if (not se_obj) or (not meats[se_obj:section_name()]) then
expiration_table[id] = nil
do break end
end
if (not get_meat_is_frozen(se_obj)) then
data.duration = data.duration - curr_time:diffSec(t2c(data.last_update))
end
data.last_update = c2t(curr_time)
if (data.duration <= 0) then
expire_food(se_obj)
expiration_table[id] = nil
end
until true
end
end
function expire_food(se_obj)
if (not se_obj.parent_id) or se_obj.parent_id >= 65535 then
alife_release(se_obj)
return
end
local se_parent = alife_object(se_obj.parent_id)
alife_release(se_obj)
if se_parent and (IsInvbox(se_parent) or se_parent.id == AC_ID) then
alife_create_item("rotten_meat", se_parent)
end
end
function save_state(m_data)
m_data.expiration_table = expiration_table
end
function load_state(m_data)
expiration_table = m_data.expiration_table or {}
end
function on_option_change()
expiration_time = {
raw = ui_mcm and ui_mcm.get(mcm_id .. "/expiration_hours_raw") * 60 * 60 or 48 * 60 * 60,
cooked = ui_mcm and ui_mcm.get(mcm_id .. "/expiration_hours_cooked") * 60 * 60 or 120 * 60 * 60
}
end
local clr_frozen = GetARGB(40,0,197,255)
function get_meat_is_frozen_cell(cell)
local se_obj = cell.ID and expiration_table[cell.ID] and alife_object(cell.ID)
if get_meat_is_frozen(se_obj) then
return true
end
end
function on_game_start()
RegisterScriptCallback("actor_on_item_use", actor_on_item_use)
RegisterScriptCallback("save_state",save_state)
RegisterScriptCallback("load_state",load_state)
RegisterScriptCallback("actor_on_item_take",actor_on_item_take)
RegisterScriptCallback("actor_on_update", actor_on_update)
RegisterScriptCallback("on_option_change", on_option_change)
rax_persistent_highlight.register("frozen_meat", function(cell)
return get_meat_is_frozen_cell(cell) and clr_frozen or false
end)
local anchor_x = function(axis, margin, w)
return (axis.w - w) - margin
end
local anchor_y = function(axis, margin, h)
return margin
end
rax_icon_layers.register("frozen_meat", function(cell, obj, sec)
if get_meat_is_frozen_cell(cell) then
local axis = utils_xml.get_item_axis(sec)
return {
texture = "ui_icon_freeze",
x = anchor_x(axis, 2, 13),
y = anchor_y(axis, 2, 13),
w = 13,
h = 13
}
end
end)
on_option_change()
end
@@ -0,0 +1,13 @@
local mcm_id = "meat_spoiling"
function on_mcm_load()
local options = {
id = mcm_id, sh = true,
gr = {
{ id = mcm_id , type = "slide" , link = "ui_options_slider_player", text = "ui_mcm_menu_" .. mcm_id, size = {512, 50}, spacing = 20},
{ id = "expiration_hours_raw", type = "input", val = 2, def = 48, min = 24, max = 144},
{ id = "expiration_hours_cooked", type = "input", val = 2, def = 120, min = 24, max = 360},
}
}
return options
end
@@ -0,0 +1,191 @@
--[[
Dynamic Icon Layers for anomaly inventory. Used by SortingPlus and other mods by RavenAscendant.
4JUL2021
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
Author: RavenAscendant
--]]
function pr(txt, ...)
-- printf("RAXPH: "..txt, ...)
end
local iconor = aaa_rax_icon_override_mcm and true or false
local icon_override = iconor and aaa_rax_icon_override_mcm.icon_override
local ratio = utils_xml.screen_ratio()
local icon_layers = {}
--functor will be passed cell, obj and section
--functor should return table with the same info as an item section icon layer. {icon_layer = "tch_upgr_ico", icon_layer_x = 0, icon_layer_y = 1, icon_layer_scale = 0.75}
--functor can alternitivly return texture name/file, cords and dimesions {texture = "xxy.dds", x = 0, y = 0, w = 10, h = 10}
function register(name, functor)
if not name then return end -- need all three params and field really needs to be a string
if not icon_layers[name] then
icon_layers[name] = {}
end
table.insert(icon_layers[name], functor)
end
function refresh(mode) --safer way to refresh inventory, mode == 1 refreshes sorting.
local inventory = GetActorMenu()
inventory:UnHighlight_All()
if mode == 1 then
local sort = nil
for i=1,#inventory.sort_btn do
if inventory.sort_btn[i]:GetCheck() then
sort = i
end
end
inventory:On_Sort(sort or 1,false)
else
inventory:UpdateItems()
end
end
--add layers to what gets updated
local base_update = utils_ui.UICellItem.Update
function utils_ui.UICellItem:Update(obj)
obj = obj or (self.ID and level.object_by_id(self.ID))
if (self.showcase == 0) and (not obj) then
self:ResetToChild()
return false
end
local sec = self.section
local xml = self:GetXML()
if obj then
local clsid = obj:clsid()
self:Add_Layers(xml, obj, sec, clsid)
end
return base_update(self, obj)
end
local base_layers = utils_ui.UICellItem.Add_Layers
function utils_ui.UICellItem:Add_Layers(xml, obj, sec, clsid)
base_layers(self, xml, obj, sec, clsid)
local ii = 1
while ((iconor and icon_override:section_exist(sec) and icon_override:r_string_ex(sec,(ii).."icon_layer")) or SYS_GetParam(0, sec, (ii).."icon_layer") ~= nil) do --get ii up to next avail layer.
ii = ii + 1
end
if (not self.layer) then
self.layer = {}
end
for key, name in pairs(icon_layers) do
for _, functor in pairs(name) do
if (not self.layer[ii]) then
if (not xml) then
xml = self:GetXML()
end
self.layer[ii] = xml:InitStatic(self.path .. ":" .. self.cx .. ":pic", self.ico)
end
local tbl = functor and functor(self, obj, sec)
if tbl then
if tbl.icon_layer then
add_icon_layer(self, self.layer[ii], self.ico, sec, tbl)
ii = ii + 1
end
if tbl.texture then
add_texture_layer(self,self.layer[ii], self.ico, sec, tbl)
ii = ii + 1
end
end
end
end
end
function add_icon_layer(self,ele, base, sec_m, tbl)
local sec_l = tbl.icon_layer
local grid_size = self.grid_size
local x = tbl.icon_layer_x or 0
local y = tbl.icon_layer_y or 0
local axis = utils_xml.get_item_axis(sec_l, grid_size)
local w = axis.w
local h = axis.h
local scale = tbl.icon_layer_scale or 1
local scale_pos = scale * (grid_size/50)
local rot = ele:GetHeading() > 0
local x_s = x * ratio * scale_pos
local y_s = y * scale_pos
local w_s = w * ratio * scale
local h_s = h * scale
local w_off = (w_s/2)
local h_off = (h_s/2)
if rot then
-- despite rotation, movement for x and y stays normal!
-- Move start pos to match the one for rotated base icon
local w_b, h_b = base:GetWidth(), base:GetHeight()
local x_st = (w_b/2) - (h_b/2)
local y_st = h_b + x_st
-- On 90 rotation, x and y are inverted, y axis goes negative simulate normal x movement
x_s = x_st + (y * ratio * scale_pos)
y_s = y_st - (x * scale_pos)
w_s = w * scale
h_s = h * scale
w_off = (h_s - h_s *ratio/2)
h_off = -w_s/2
end
ele:InitTexture( utils_xml.get_icons_texture(sec_l) )
ele:SetTextureRect(Frect():set( utils_xml.get_item_axis(sec_l, nil, true) ))
ele:SetStretchTexture(true)
ele:SetWndPos(vector2():set( x_s + w_off , y_s + h_off ))
ele:SetWndSize(vector2():set( w_s , h_s ))
ele:Show(true)
end
function add_texture_layer(self,ele, base, sec_m, tbl)
local grid_size = self.grid_size
local x = tbl.x or 0
local y = tbl.y or 0
local w = tbl.w
local h = tbl.h
local scale = 1
local scale_pos = scale * (grid_size/50)
local rot = ele:GetHeading() > 0
local x_s = x * ratio * scale_pos
local y_s = y * scale_pos
local w_s = w * ratio * scale
local h_s = h * scale
local w_off = (w_s/2)
local h_off = (h_s/2)
if rot then
-- despite rotation, movement for x and y stays normal!
-- Move start pos to match the one for rotated base icon
local w_b, h_b = base:GetWidth(), base:GetHeight()
local x_st = (w_b/2) - (h_b/2)
local y_st = h_b + x_st
-- On 90 rotation, x and y are inverted, y axis goes negative simulate normal x movement
x_s = x_st + (y * ratio * scale_pos)
y_s = y_st - (x * scale_pos)
w_s = w * scale
h_s = h * scale
w_off = (h_s - h_s *ratio/2)
h_off = -w_s/2
end
ele:InitTexture( tbl.texture )
ele:SetStretchTexture(true)
ele:SetWndPos(vector2():set( x_s + w_off , y_s + h_off ))
ele:SetWndSize(vector2():set( w_s , h_s ))
ele:Show(true)
end
@@ -0,0 +1,68 @@
--[[
Persitant Highlights for anomaly inventory. Used by SortingPlus and other mods by RavenAscendant.
24FEB2021
Updated 19Jun21 improved compatablity.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
Author: RavenAscendant
--]]
function pr(txt, ...)
-- printf("RAXPH: "..txt, ...)
end
local persistent_highlights = {}
--functor should return an ARGB for the highlight color. recomend low alpha values. name is mostly for aplhabetical priority. will not conflict. there is no unregister, just retun nil if you don't want to use.
function register(name, functor)
if not name then return end -- need all three params and field really needs to be a string
if not persistent_highlights[name] then
persistent_highlights[name] = {}
end
table.insert(persistent_highlights[name], functor)
end
function utils_ui.UICellItem:GetPersistantHighlight()
local clr = nil
for key, name in pairs(persistent_highlights) do
for _, functor in pairs(name) do
clr = functor and functor(self) or clr
pr(key .. ":" .. tostring(clr) .. ":" .. tostring(self.section))
end
end
return clr
end
local base_highlight = utils_ui.UICellItem.Highlight
function utils_ui.UICellItem:Highlight(state, clr_id, main_clr)
if state and (not self:IsShown()) and (not self.manual) then return end
persistant_highlight = self:GetPersistantHighlight()
if (not state) and persistant_highlight then
color = main_clr and change_alpha(persistant_highlight, 255) or persistant_highlight -- if main_clr set the alpha to max for reasons.
self.hl:Show(persistant_highlight or state) -- show if we have a persistant highlight or state is true, else hide.
self.hl:SetTextureColor(color)
else
base_highlight(self, state, clr_id, main_clr)
end
end
clr_cache = {}
function change_alpha(clr, a)
if not clr and a ~= nil then return end
if not clr_cache[clr .. "_" .. a] then
b = bit.band(clr, 255)
g = bit.band(bit.rshift(clr, 8), 255)
r = bit.band(bit.rshift(clr, 16), 255)
clr_cache[clr .. "_" .. a] = GetARGB(a, r, g, b)
end
return clr_cache[clr .. "_" .. a]
end
@@ -0,0 +1,276 @@
--[[
Interactivity for stove furniture
Author: HarukaSai (visit us at: https://discord.com/invite/efp)
Credits: Aoldri
19-06-2023
]]
local function use_container(id,pid)
local box = id and level.object_by_id(id)
if (box) then
--level.map_add_object_spot(id, "ui_pda2_actor_box_location", "st_ui_pda_actor_box") -- debug
curBoxID = pid
hide_hud_inventory()
box:use(db.actor)
return true -- destroy timed event
end
return false -- repeat timed event
end
-- called from item section in items.ltx
function access_inventory(obj)
local id = obj:id()
local m_data = alife_storage_manager.get_state()
local se_inv_box = m_data.stove_stashes and m_data.stove_stashes[id] and alife_object(m_data.stove_stashes[id])
if not (se_inv_box) then
-- position under map
local pos = vec_set(obj:position())
pos.y = pos.y - 50
-- create inventory_box_s
se_inv_box = alife_create(SYS_GetParam(0, obj:section(), "integrated_storage"),pos,obj:level_vertex_id(),obj:game_vertex_id())
end
if (se_inv_box) then
-- shouldn't be possible but very safe incase some sort of save corruption
if not (IsInvbox(nil,se_inv_box:clsid())) then
if m_data.stove_stashes then
m_data.stove_stashes[id] = nil
end
return
end
-- force strictly online
alife():set_switch_online(se_inv_box.id,true)
alife():set_switch_offline(se_inv_box.id,false)
-- Save container
if not (m_data.stove_stashes) then
m_data.stove_stashes = {}
end
m_data.stove_stashes[id] = se_inv_box.id
-- Object will come online next update so wait
CreateTimeEvent(id,"container",0,use_container,se_inv_box.id,id)
end
end
local ratio = utils_xml.screen_ratio()
GUI = nil -- instance, don't touch
class "UICookStove" (CUIScriptWnd)
function UICookStove:__init() super()
self:InitControls()
self:InitCallbacks()
end
function UICookStove:__finalize()
GUI = nil
end
function UICookStove:InitControls()
self:SetWndRect(Frect():set(0,0,1024,768))
self.wide = (device().width/device().height) > (1024/768 + 0.01)
self:SetAutoDelete(true)
local xml = CScriptXmlInit()
-- xml:ParseFile("ui_sleep_dialog.xml")
xml:ParseFile("ui_furniture_stove_dialog.xml")
self.back = xml:InitFrame("background", self)
self.icon = xml:InitStatic("icon", self.back)
self.icon_temp = xml:InitStatic("icon", self.back)
self.icon:SetWndSize(vector2():set( self.icon:GetWidth(), self.icon:GetWidth() / ratio ))
--self.btn_pickup = xml:Init3tButton("btn_pickup", self.back)
--self:Register(self.btn_pickup, "btn_pickup")
self.btn_close = xml:Init3tButton("btn_close", self.back)
self:Register(self.btn_close, "btn_close")
self.btn_access_stash = xml:Init3tButton("btn_access_stash", self.back)
self:Register(self.btn_access_stash, "btn_access_stash")
self.btn_use_stove = xml:Init3tButton("btn_use_stove", self.back)
self:Register(self.btn_use_stove, "btn_use_stove")
end
function UICookStove:AccessStash()
local obj = get_object_by_id(self.obj_id)
access_inventory(obj)
self:Close()
end
function UICookStove:GetStashObj()
local m_data = alife_storage_manager.get_state()
local se_inv_box = m_data.stove_stashes and m_data.stove_stashes[self.obj_id] and alife_object(m_data.stove_stashes[self.obj_id])
local stash_id = nil
if (se_inv_box) then
-- shouldn't be possible but very safe incase some sort of save corruption
if not (IsInvbox(nil,se_inv_box:clsid())) then
if m_data.stove_stashes then
m_data.stove_stashes[self.obj_id] = nil
end
return
end
-- force strictly online
alife():set_switch_online(se_inv_box.id,true)
alife():set_switch_offline(se_inv_box.id,false)
-- Save container
if not (m_data.stove_stashes) then
m_data.stove_stashes = {}
end
m_data.stove_stashes[self.obj_id] = se_inv_box.id
stash_id = se_inv_box.id
end
-- Object will come online next update so wait
CreateTimeEvent(self.obj_id,"move_stash",0,self.GiveStashToActor,self,stash_id)
end
function UICookStove:Pickup()
local obj = get_object_by_id(self.obj_id)
alife_create_item(self.section.item, db.actor)
local m_data = alife_storage_manager.get_state()
if m_data.stove_stashes then
local id = m_data.stove_stashes[self.obj_id]
local stash_obj = get_object_by_id(id)
if stash_obj then
stash_obj:iterate_inventory_box( function(temp, obj)
stash_obj:transfer_item(obj, db.actor)
end, stash_obj)
end
alife_release_id(id)
end
alife_release(obj)
self:Close()
end
function UICookStove:UseCook()
self:GetStashObj()
end
local item_ids = {}
local stash_obj_id = nil
function return_items()
if stash_obj_id == nil then return end
local stash_obj = get_object_by_id(stash_obj_id)
if stash_obj == nil then return end
for i, id in ipairs(item_ids) do
local item_obj = get_object_by_id(id)
if item_obj then
db.actor:transfer_item(item_obj, stash_obj)
end
end
end
function GUI_on_hide(name)
if name == "UICook" then
return_items()
UnregisterScriptCallback("GUI_on_hide", GUI_on_hide)
end
end
function UICookStove:GiveStashToActor(id)
local items = {}
if id then
local stash_obj = get_object_by_id(id)
stash_obj:iterate_inventory_box( function(temp, obj)
table.insert(items, obj:id())
stash_obj:transfer_item(obj, db.actor)
end, stash_obj)
end
item_ids = items
stash_obj_id = id
RegisterScriptCallback("GUI_on_hide", GUI_on_hide)
CreateTimeEvent(self.obj_id,"open_stove",0.1,self.OpenCookUI,self)
return true
end
function UICookStove:OpenCookUI()
local obj = get_object_by_id(self.obj_id)
local cook_ui = item_cooking.start(obj, "fieldcooker")
self:Close()
return true
end
function UICookStove:InitCallbacks()
self:AddCallback("btn_access_stash", ui_events.BUTTON_CLICKED, self.AccessStash, self)
--self:AddCallback("btn_pickup", ui_events.BUTTON_CLICKED, self.Pickup, self)
self:AddCallback("btn_use_stove", ui_events.BUTTON_CLICKED, self.UseCook, self)
self:AddCallback("btn_close", ui_events.BUTTON_CLICKED, self.Close, self)
end
function UICookStove:Initialize()
local obj = get_object_by_id(self.obj_id)
self.section = {}
self.section.placeable = obj:section() or "placeable_stove1"
self.section.item = SYS_GetParam(0, self.section.placeable, "item_section", "prop_stove2")
utils_xml.set_icon(self.section.item, false, self.icon_temp, self.icon)
self.btn_access_stash:Enable(SYS_GetParam(0, self.section.placeable, "integrated_storage") and true or false)
end
function UICookStove:TestAndShow(obj_id)
self.obj_id = obj_id
self:Initialize()
self:ShowDialog(true)
Register_UI("UICookStove","ui_furniture_stove")
end
function UICookStove:Update()
CUIScriptWnd.Update(self)
end
function UICookStove:OnTrackButton()
end
function UICookStove:OnKeyboard(dik, keyboard_action)
local res = CUIScriptWnd.OnKeyboard(self,dik,keyboard_action)
if (res == false) then
local bind = dik_to_bind(dik)
if keyboard_action == ui_events.WINDOW_KEY_PRESSED then
if dik == DIK_keys.DIK_ESCAPE then
self:Close()
end
end
end
return res
end
function UICookStove:Close()
if (self:IsShown()) then
self:HideDialog()
end
Unregister_UI("UICookStove")
end
function start_dialog(obj_id)
if (GUI == nil) then
GUI = UICookStove()
end
GUI:TestAndShow(obj_id)
end