Re-added context menus for saws
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
local BaseHandler = require("UI/TOC_HealthPanelBaseHandler")
|
||||
local CutLimbAction = require("TimedActions/TOC_CutLimbAction")
|
||||
|
||||
---@class CutLimbHandler
|
||||
---@field panel any
|
||||
---@field bodyPart any
|
||||
local CutLimbHandler = BaseHandler:derive("CutLimbHandler")
|
||||
|
||||
|
||||
---Creates new CutLimbHandler
|
||||
---@param panel any
|
||||
---@param bodyPart any
|
||||
---@return CutLimbHandler
|
||||
function CutLimbHandler:new(panel, bodyPart)
|
||||
local o = BaseHandler.new(self, panel, bodyPart)
|
||||
o.items.ITEMS = {}
|
||||
return o
|
||||
end
|
||||
|
||||
function CutLimbHandler:checkItem(item)
|
||||
local itemType = item:getType()
|
||||
if itemType == "Saw" or itemType == "GardenSaw" or itemType == "Chainsaw" then
|
||||
self:addItem(self.items.ITEMS, item)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function CutLimbHandler:addToMenu(context)
|
||||
local types = self:getAllItemTypes(self.items.ITEMS)
|
||||
if #types > 0 then
|
||||
context:addOption(getText("ContextMenu_Amputate"), self, self.onMenuOptionSelected)
|
||||
end
|
||||
end
|
||||
|
||||
function CutLimbHandler:dropItems(items)
|
||||
local types = self:getAllItemTypes(items)
|
||||
if #self.items.ITEMS > 0 and #types == 1 then
|
||||
self:onMenuOptionSelected(types[1])
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function CutLimbHandler:isValid(itemType)
|
||||
return self:getItemOfType(self.items.ITEMS, itemType)
|
||||
end
|
||||
|
||||
function CutLimbHandler:perform(previousAction, itemType)
|
||||
print("perform cutlimbhandler")
|
||||
local item = self:getItemOfType(self.items.ITEMS, itemType)
|
||||
previousAction = self:toPlayerInventory(item, previousAction)
|
||||
|
||||
local action = CutLimbAction:new(self:getPatient(), self:getDoctor(), self.bodyPart)
|
||||
ISTimedActionQueue.addAfter(previousAction, action)
|
||||
end
|
||||
|
||||
return CutLimbHandler
|
||||
104
media/lua/client/UI/TOC_CutLimbInteractions.lua
Normal file
104
media/lua/client/UI/TOC_CutLimbInteractions.lua
Normal file
@@ -0,0 +1,104 @@
|
||||
local BaseHandler = require("UI/TOC_HealthPanelBaseHandler")
|
||||
local CutLimbAction = require("TimedActions/TOC_CutLimbAction")
|
||||
local StaticData = require("TOC_StaticData")
|
||||
local ModDataHandler = require("Handlers/TOC_ModDataHandler")
|
||||
|
||||
---------------------
|
||||
|
||||
|
||||
---comment
|
||||
---@param itemName string
|
||||
local function CheckIfSaw(itemName)
|
||||
return itemName == "Saw" or itemName == "GardenSaw" or itemName == "Chainsaw"
|
||||
end
|
||||
|
||||
local function PerformAction(limbName, surgeon, patient)
|
||||
ISTimedActionQueue.add(CutLimbAction:new(surgeon, patient, limbName))
|
||||
end
|
||||
|
||||
local function AddInventoryAmputationOptions(surgeonNum, context)
|
||||
local surgeonObj = getSpecificPlayer(surgeonNum)
|
||||
local option = context:addOption(getText("ContextMenu_Amputate"), nil)
|
||||
local subMenu = context:getNew(context)
|
||||
context:addSubMenu(option, subMenu)
|
||||
for i=1, #StaticData.LIMBS_STRINGS do
|
||||
local limbName = StaticData.LIMBS_STRINGS[i]
|
||||
if not ModDataHandler.GetInstance():getIsCut(limbName) then
|
||||
local limbTranslatedName = getText("ContextMenu_Limb_" .. limbName)
|
||||
subMenu:addOption(limbTranslatedName, limbName, PerformAction, surgeonObj, surgeonObj) -- TODO Should be patient, not surgeon
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function AddInventoryAmputationMenu(player, context, items)
|
||||
local item = items[1]
|
||||
if CheckIfSaw(item.name) then
|
||||
AddInventoryAmputationOptions(player, context)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Events.OnFillInventoryObjectContextMenu.Add(AddInventoryAmputationMenu)
|
||||
|
||||
-------------------------------------
|
||||
|
||||
---@class CutLimbHandler : BaseHandler
|
||||
local CutLimbHandler = BaseHandler:derive("CutLimbHandler")
|
||||
|
||||
|
||||
---Creates new CutLimbHandler
|
||||
---@param panel any
|
||||
---@param bodyPart any
|
||||
---@return CutLimbHandler
|
||||
function CutLimbHandler:new(panel, bodyPart)
|
||||
local o = BaseHandler.new(self, panel, bodyPart)
|
||||
o.items.ITEMS = {}
|
||||
return o
|
||||
end
|
||||
|
||||
function CutLimbHandler:checkItem(item)
|
||||
local itemType = item:getType()
|
||||
if CheckIfSaw(itemType) then
|
||||
self:addItem(self.items.ITEMS, item)
|
||||
end
|
||||
end
|
||||
|
||||
function CutLimbHandler:addToMenu(context)
|
||||
--local types = self:getAllItemTypes(self.items.ITEMS)
|
||||
--if #types > 0 then
|
||||
local option = context:addOption(getText("ContextMenu_Amputate"), nil)
|
||||
local subMenu = context:getNew(context)
|
||||
context:addSubMenu(option, subMenu)
|
||||
for i=1, #StaticData.LIMBS_STRINGS do
|
||||
local limbName = StaticData.LIMBS_STRINGS[i]
|
||||
if not ModDataHandler.GetInstance():getIsCut(limbName) then
|
||||
local limbTranslatedName = getText("ContextMenu_Limb_" .. limbName)
|
||||
subMenu:addOption(limbTranslatedName, self.onMenuOptionSelected, nil)
|
||||
end
|
||||
end
|
||||
--end
|
||||
end
|
||||
|
||||
function CutLimbHandler:dropItems(items)
|
||||
local types = self:getAllItemTypes(items)
|
||||
if #self.items.ITEMS > 0 and #types == 1 then
|
||||
self:onMenuOptionSelected(types[1])
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function CutLimbHandler:isValid(itemType)
|
||||
return self:getItemOfType(self.items.ITEMS, itemType)
|
||||
end
|
||||
|
||||
function CutLimbHandler:perform(previousAction, itemType)
|
||||
print("perform cutlimbhandler")
|
||||
local item = self:getItemOfType(self.items.ITEMS, itemType)
|
||||
previousAction = self:toPlayerInventory(item, previousAction)
|
||||
|
||||
local action = CutLimbAction:new(self:getPatient(), self:getDoctor(), self.bodyPart)
|
||||
ISTimedActionQueue.addAfter(previousAction, action)
|
||||
end
|
||||
|
||||
return CutLimbHandler
|
||||
@@ -3,7 +3,7 @@ local StaticData = require("TOC_StaticData")
|
||||
local CommonMethods = require("TOC_Common")
|
||||
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
local CutLimbHandler = require("UI/TOC_CutLimbHandler")
|
||||
local CutLimbHandler = require("UI/TOC_CutLimbInteractions")
|
||||
|
||||
-- TODO Use this to replace the sprites once a limb is cut
|
||||
ISHealthBodyPartPanel = ISBodyPartPanel:derive("ISHealthBodyPartPanel")
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
-- Had to cop and paste this stuff from the base game since this is a local only class. Kinda shit, but eh
|
||||
|
||||
---@class BaseHandler : ISBaseObject
|
||||
---@field panel ISUIElement
|
||||
---@field bodyPart BodyPart
|
||||
---@field items table
|
||||
local BaseHandler = ISBaseObject:derive("BaseHandler")
|
||||
|
||||
function BaseHandler:new(panel, bodyPart)
|
||||
|
||||
Reference in New Issue
Block a user