This commit is contained in:
ZioPao
2023-11-12 05:53:26 +01:00
parent 3443198edb
commit 3d963a2ad6
4 changed files with 27 additions and 11 deletions

View File

@@ -7,4 +7,10 @@ function CommonMethods.GetSide(name)
if string.find(name, "_L") then return "L" else return "R" end if string.find(name, "_L") then return "L" else return "R" end
end end
---comment
---@param bodyPart BodyPart
function CommonMethods.GetLimbNameFromBodyPart(bodyPart)
local bodyPartType = bodyPart:getType()
end
return CommonMethods return CommonMethods

View File

@@ -28,21 +28,21 @@ local function AddInventoryAmputationOptions(surgeonNum, context)
local option = context:addOption(getText("ContextMenu_Amputate"), nil) local option = context:addOption(getText("ContextMenu_Amputate"), nil)
local subMenu = context:getNew(context) local subMenu = context:getNew(context)
context:addSubMenu(option, subMenu) context:addSubMenu(option, subMenu)
for i=1, #StaticData.LIMBS_STRINGS do for i = 1, #StaticData.LIMBS_STRINGS do
local limbName = StaticData.LIMBS_STRINGS[i] local limbName = StaticData.LIMBS_STRINGS[i]
if not ModDataHandler.GetInstance():getIsCut(limbName) then if not ModDataHandler.GetInstance():getIsCut(limbName) then
local limbTranslatedName = getText("ContextMenu_Limb_" .. limbName) local limbTranslatedName = getText("ContextMenu_Limb_" .. limbName)
subMenu:addOption(limbTranslatedName, limbName, PerformAction, surgeonObj, surgeonObj) -- TODO Should be patient, not surgeon subMenu:addOption(limbTranslatedName, limbName, PerformAction, surgeonObj, surgeonObj) -- TODO Should be patient, not surgeon
end end
end end
end end
---Handler for OnFillInventoryObjectContextMenu ---Handler for OnFillInventoryObjectContextMenu
---@param player number ---@param player number
---@param context ISUIElement ---@param context ISContextMenu
---@param items table ---@param items table
local function AddInventoryAmputationMenu(player, context, items) local function AddInventoryAmputationMenu(player, context, items)
local item = items[1] -- Selected item local item = items[1] -- Selected item
if CheckIfSaw(item.name) then if CheckIfSaw(item.name) then
AddInventoryAmputationOptions(player, context) AddInventoryAmputationOptions(player, context)
end end
@@ -58,8 +58,8 @@ local CutLimbHandler = BaseHandler:derive("CutLimbHandler")
---Creates new CutLimbHandler ---Creates new CutLimbHandler
---@param panel any ---@param panel ISUIElement
---@param bodyPart any ---@param bodyPart BodyPart
---@return CutLimbHandler ---@return CutLimbHandler
function CutLimbHandler:new(panel, bodyPart) function CutLimbHandler:new(panel, bodyPart)
local o = BaseHandler.new(self, panel, bodyPart) local o = BaseHandler.new(self, panel, bodyPart)
@@ -67,6 +67,7 @@ function CutLimbHandler:new(panel, bodyPart)
return o return o
end end
---@param item InventoryItem
function CutLimbHandler:checkItem(item) function CutLimbHandler:checkItem(item)
local itemType = item:getType() local itemType = item:getType()
if CheckIfSaw(itemType) then if CheckIfSaw(itemType) then
@@ -74,13 +75,14 @@ function CutLimbHandler:checkItem(item)
end end
end end
---@param context ISContextMenu
function CutLimbHandler:addToMenu(context) function CutLimbHandler:addToMenu(context)
--local types = self:getAllItemTypes(self.items.ITEMS) --local types = self:getAllItemTypes(self.items.ITEMS)
--if #types > 0 then --if #types > 0 then
local option = context:addOption(getText("ContextMenu_Amputate"), nil) local option = context:addOption(getText("ContextMenu_Amputate"), nil)
local subMenu = context:getNew(context) local subMenu = context:getNew(context)
context:addSubMenu(option, subMenu) context:addSubMenu(option, subMenu)
for i=1, #StaticData.LIMBS_STRINGS do for i = 1, #StaticData.LIMBS_STRINGS do
local limbName = StaticData.LIMBS_STRINGS[i] local limbName = StaticData.LIMBS_STRINGS[i]
if not ModDataHandler.GetInstance():getIsCut(limbName) then if not ModDataHandler.GetInstance():getIsCut(limbName) then
local limbTranslatedName = getText("ContextMenu_Limb_" .. limbName) local limbTranslatedName = getText("ContextMenu_Limb_" .. limbName)
@@ -108,7 +110,8 @@ function CutLimbHandler:perform(previousAction, itemType)
local item = self:getItemOfType(self.items.ITEMS, itemType) local item = self:getItemOfType(self.items.ITEMS, itemType)
previousAction = self:toPlayerInventory(item, previousAction) previousAction = self:toPlayerInventory(item, previousAction)
local action = CutLimbAction:new(self:getPatient(), self:getDoctor(), self.bodyPart) local limbName = BodyPartType.getDisplayName(self.bodyPart:getType()) -- TODO Test this
local action = CutLimbAction:new(self:getPatient(), self:getDoctor(), limbName)
ISTimedActionQueue.addAfter(previousAction, action) ISTimedActionQueue.addAfter(previousAction, action)
end end

View File

@@ -79,10 +79,13 @@ function ISHealthPanel:initialise()
end end
local og_ISHealthPanel_setOtherPlayer = ISHealthPanel.setOtherPlayer local og_ISHealthPanel_setOtherPlayer = ISHealthPanel.setOtherPlayer
---comment
---@param playerObj IsoPlayer ---@param playerObj IsoPlayer
function ISHealthPanel:setOtherPlayer(playerObj) function ISHealthPanel:setOtherPlayer(playerObj)
og_ISHealthPanel_setOtherPlayer(self, playerObj) og_ISHealthPanel_setOtherPlayer(self, playerObj)
-- Since setOtherPlayer may be run after initialise (or always), we need to recheck it after.
self:setHighestAmputation() self:setHighestAmputation()
end end

View File

@@ -6,6 +6,9 @@
---@field items table ---@field items table
local BaseHandler = ISBaseObject:derive("BaseHandler") local BaseHandler = ISBaseObject:derive("BaseHandler")
---@param panel ISUIElement
---@param bodyPart BodyPart
---@return table
function BaseHandler:new(panel, bodyPart) function BaseHandler:new(panel, bodyPart)
local o = {} local o = {}
setmetatable(o, self) setmetatable(o, self)
@@ -52,7 +55,8 @@ function BaseHandler:checkContainerItems(container, childContainers)
table.insert(childContainers, item:getInventory()) table.insert(childContainers, item:getInventory())
end end
else else
self:checkItem(item) ---@diagnostic disable-next-line: undefined-field
self:checkItem(item) -- This is in inherited classes, we never use this class by itself
end end
end end
end end