Re-added context menus for saws

This commit is contained in:
ZioPao
2023-11-11 02:58:51 +01:00
parent e8d4a37fdc
commit 9459360948
9 changed files with 130 additions and 72 deletions

View File

@@ -86,6 +86,8 @@ function AmputationHandler:execute(damagePlayer)
-- Add it to the list of cut limbs
PlayerHandler.AddLocalAmputatedLimb(self.limbName)
-- Set the highest amputation and caches them.
ISHealthPanel.GetHighestAmputation()
end
---Deletes the instance

View File

@@ -155,8 +155,7 @@ function ModDataHandler:setCutLimb(limbName, isOperated, isCicatrized, isCauteri
-- Set that a limb has been cut, to activate some functions without having to loop through the parts
self:setIsAnyLimbCut(true)
-- Set the highest amputation and caches them.
ISHealthPanel.GetHighestAmputation()
end

View File

@@ -7,12 +7,12 @@ local PlayerHandler = require("Handlers/TOC_PlayerHandler")
local ProsthesisHandler = {}
---Cache the correct texture for the Health Panel for the currently equipped prosthesis
function ProsthesisHandler.SetHealthPanelTexture()
-- TODO do it
end
---comment
---Check if a prosthesis is equippable. It depends whether the player has a cut limb or not on that specific side. There's an exception for Upper arm, obviously
---@param bodyLocation string
---@return boolean
function ProsthesisHandler.CheckIfEquippable(bodyLocation)
@@ -33,9 +33,6 @@ end
--* Overrides *--
function ISWearClothing:isValid()
local bodyLocation = self.item:getBodyLocation()
if not string.contains(bodyLocation, "TOC_ArmProst") then
@@ -45,7 +42,6 @@ function ISWearClothing:isValid()
end
end
local og_ISClothingExtraAction_isValid = ISClothingExtraAction.isValid
function ISClothingExtraAction:isValid()
local bodyLocation = self.item:getBodyLocation()

View File

@@ -4,9 +4,9 @@ local AmputationHandler = require("Handlers/TOC_AmputationHandler")
-----------------------------
---@class CutLimbAction
---@class CutLimbAction : ISBaseTimedAction
---@field patient IsoPlayer
---@field surgeon IsoPlayer
---@field character IsoPlayer
---@field limbName string
local CutLimbAction = ISBaseTimedAction:derive("CutLimbAction")
@@ -15,18 +15,21 @@ local CutLimbAction = ISBaseTimedAction:derive("CutLimbAction")
---@param surgeon IsoPlayer
---@param limbName string
---@return CutLimbAction
function CutLimbAction:new(patient, surgeon, limbName)
function CutLimbAction:new(surgeon, patient, limbName)
local o = {}
setmetatable(o, self)
self.__index = self
-- We need to follow ISBaseTimedAction. self.character is gonna be the surgeon
o.character = surgeon
o.patient = patient
o.surgeon = surgeon
o.limbName = limbName
o.stopOnWalk = true
o.stopOnRun = true
if o.surgeon:isTimedActionInstant() then o.maxTime = 1 end
o.maxTime = 100
if o.character:isTimedActionInstant() then o.maxTime = 1 end
return o
end
@@ -37,7 +40,7 @@ function CutLimbAction:isValid()
end
function CutLimbAction:start()
if self.patient == self.surgeon then
if self.patient == self.character then
-- Self
self.handler = AmputationHandler:new(self.limbName)
self.handler:damageDuringAmputation()

View File

@@ -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

View 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

View File

@@ -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")

View File

@@ -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)

View File

@@ -1,5 +1,12 @@
ContextMenu_EN = {
ContextMenu_Amputate = "Amputate",
ContextMenu_Limb_Hand_L = "Left Hand",
ContextMenu_Limb_ForeArm_L = "Left forearm",
ContextMenu_Limb_UpperArm_L = "Left UpperArm"
ContextMenu_Limb_Hand_R = "Right Hand",
ContextMenu_Limb_ForeArm_R = "Right forearm",
ContextMenu_Limb_UpperArm_R = "Right UpperArm"
ContextMenu_InstallProstRight = "Install prosthesis on right arm",