Simplifield health panel logic

This commit is contained in:
ZioPao
2024-01-08 16:09:10 +01:00
parent c35454807d
commit d3722c1171
2 changed files with 170 additions and 213 deletions

View File

@@ -407,8 +407,6 @@ end
---A recreation of the original method, but with amputations in mind ---A recreation of the original method, but with amputations in mind
---@param dcInst DataController ---@param dcInst DataController
function ISEquipWeaponAction:performWithAmputation(dcInst) function ISEquipWeaponAction:performWithAmputation(dcInst)
-- TODO Simplify this
local hand = nil local hand = nil
local otherHand = nil local otherHand = nil
local getMethodFirst = nil local getMethodFirst = nil

View File

@@ -14,258 +14,217 @@ function SetHealthPanelTOC()
isReady = true isReady = true
end end
--function OverrideHealthPanelForTOC()
-- We're overriding ISHealthPanel to add custom textures to the body panel. -- We're overriding ISHealthPanel to add custom textures to the body panel.
-- By doing so we can show the player which limbs have been cut without having to use another menu -- By doing so we can show the player which limbs have been cut without having to use another menu
-- We can show prosthesis too this way -- We can show prosthesis too this way
-- We also manage the drag'n drop of items on the body to let the players use the saw this way too -- We also manage the drag'n drop of items on the body to let the players use the saw this way too
---@diagnostic disable: duplicate-set-field ---@diagnostic disable: duplicate-set-field
--ISHealthBodyPartPanel = ISBodyPartPanel:derive("ISHealthBodyPartPanel") --ISHealthBodyPartPanel = ISBodyPartPanel:derive("ISHealthBodyPartPanel")
--* Handling drag n drop of the saw *-- --* Handling drag n drop of the saw *--
local og_ISHealthPanel_dropItemsOnBodyPart = ISHealthPanel.dropItemsOnBodyPart local og_ISHealthPanel_dropItemsOnBodyPart = ISHealthPanel.dropItemsOnBodyPart
function ISHealthPanel:dropItemsOnBodyPart(bodyPart, items) function ISHealthPanel:dropItemsOnBodyPart(bodyPart, items)
og_ISHealthPanel_dropItemsOnBodyPart(self, bodyPart, items) og_ISHealthPanel_dropItemsOnBodyPart(self, bodyPart, items)
TOC_DEBUG.print("override to dropItemsOnBodyPart running")
local cutLimbHandler = CutLimbHandler:new(self, bodyPart)
for _,item in ipairs(items) do
cutLimbHandler:checkItem(item)
end
if cutLimbHandler:dropItems(items) then
return
end
TOC_DEBUG.print("override to dropItemsOnBodyPart running")
local cutLimbHandler = CutLimbHandler:new(self, bodyPart)
for _,item in ipairs(items) do
cutLimbHandler:checkItem(item)
end
if cutLimbHandler:dropItems(items) then
return
end end
local og_ISHealthPanel_doBodyPartContextMenu = ISHealthPanel.doBodyPartContextMenu end
function ISHealthPanel:doBodyPartContextMenu(bodyPart, x, y)
og_ISHealthPanel_doBodyPartContextMenu(self, bodyPart, x, y)
local playerNum = self.otherPlayer and self.otherPlayer:getPlayerNum() or self.character:getPlayerNum()
-- To not recreate it but reuse the one that has been created in the original method local og_ISHealthPanel_doBodyPartContextMenu = ISHealthPanel.doBodyPartContextMenu
local context = getPlayerContextMenu(playerNum) function ISHealthPanel:doBodyPartContextMenu(bodyPart, x, y)
og_ISHealthPanel_doBodyPartContextMenu(self, bodyPart, x, y)
local playerNum = self.otherPlayer and self.otherPlayer:getPlayerNum() or self.character:getPlayerNum()
local cutLimbHandler = CutLimbHandler:new(self, bodyPart) -- To not recreate it but reuse the one that has been created in the original method
self:checkItems({cutLimbHandler}) local context = getPlayerContextMenu(playerNum)
cutLimbHandler:addToMenu(context)
local woundCleaningHandler = WoundCleaningHandler:new(self, bodyPart, self.character:getUsername()) local cutLimbHandler = CutLimbHandler:new(self, bodyPart)
self:checkItems({woundCleaningHandler}) self:checkItems({cutLimbHandler})
woundCleaningHandler:addToMenu(context) cutLimbHandler:addToMenu(context)
local woundCleaningHandler = WoundCleaningHandler:new(self, bodyPart, self.character:getUsername())
self:checkItems({woundCleaningHandler})
woundCleaningHandler:addToMenu(context)
end
--* Modifications and additional methods to handle visible amputation on the health menu *--
---Get a value between 1 and 0.1 for the cicatrization time
---@param cicTime integer
---@return integer
local function GetColorFromCicatrizationTime(cicTime, limbName)
local defaultTime = StaticData.LIMBS_CICATRIZATION_TIME_IND_NUM[limbName]
local delta = cicTime/defaultTime
return math.max(0.15, math.min(delta, 1))
end
---Try to draw the highest amputation in the health panel, based on the cicatrization time
---@param side string L or R
---@param username string
function ISHealthPanel:tryDrawHighestAmputation(highestAmputations, side, username)
local redColor
local texture
if TOC_DEBUG.enableHealthPanelDebug then
redColor = 1
texture = getTexture("media/ui/test_pattern.png")
else
if highestAmputations[side] == nil then return end
local limbName = highestAmputations[side]
--TOC_DEBUG.print("Drawing " .. tostring(limbName) .. " for " .. username)
local cicTime = DataController.GetInstance(username):getCicatrizationTime(limbName)
redColor = GetColorFromCicatrizationTime(cicTime, limbName)
local sexPl = self.character:isFemale() and "Female" or "Male"
texture = StaticData.HEALTH_PANEL_TEXTURES[sexPl][limbName]
end end
self:drawTexture(texture, self.healthPanel.x, self.healthPanel.y, 1, redColor, 0, 0)
end
--* Modifications and additional methods to handle visible amputation on the health menu *-- local og_ISHealthPanel_render = ISHealthPanel.render
function ISHealthPanel:render()
og_ISHealthPanel_render(self)
local username = self.character:getUsername()
local highestAmputations = CachedDataHandler.GetHighestAmputatedLimbs(username)
local og_ISHealthPanel_initialise = ISHealthPanel.initialise if highestAmputations ~= nil then
function ISHealthPanel:initialise() -- Left Texture
if self.character:isFemale() then self:tryDrawHighestAmputation(highestAmputations, "L", username)
self.sexPl = "Female"
else
self.sexPl = "Male"
end
local username = self.character:getUsername() -- Right Texture
if username ~= "Bob" then self:tryDrawHighestAmputation(highestAmputations, "R", username)
--CachedDataHandler.CalculateHighestAmputatedLimbs(username)
self.highestAmputations = CachedDataHandler.GetHighestAmputatedLimbs(username)
end
og_ISHealthPanel_initialise(self)
end end
end
local og_ISHealthPanel_setOtherPlayer = ISHealthPanel.setOtherPlayer -- We need to override this to force the alpha to 1
---@param playerObj IsoPlayer local og_ISCharacterInfoWindow_render = ISCharacterInfoWindow.prerender
function ISHealthPanel:setOtherPlayer(playerObj) function ISCharacterInfoWindow:prerender()
og_ISHealthPanel_setOtherPlayer(self, playerObj) og_ISCharacterInfoWindow_render(self)
--CachedDataHandler.CalculateAmputatedLimbs(self.character:getUsername()) self.backgroundColor.a = 1
end end
---Get a value between 1 and 0.1 for the cicatrization time -- We need to override this to force the alpha to 1 for the Medical Check in particular
---@param cicTime integer local og_ISHealthPanel_prerender = ISHealthPanel.prerender
---@return integer function ISHealthPanel:prerender()
local function GetColorFromCicatrizationTime(cicTime, limbName) og_ISHealthPanel_prerender(self)
local defaultTime = StaticData.LIMBS_CICATRIZATION_TIME_IND_NUM[limbName] self.backgroundColor.a = 1
local delta = cicTime/defaultTime end
return math.max(0.15, math.min(delta, 1))
end
---Try to draw the highest amputation in the health panel, based on the cicatrization time --- The medical check wrap the health panel into this. We need to override its color
---@param side string L or R local overrideBackgroundColor = true
---@param username string local og_ISUIElement_wrapInCollapsableWindow = ISUIElement.wrapInCollapsableWindow
function ISHealthPanel:tryDrawHighestAmputation(highestAmputations, side, username) ---@param title string
local redColor ---@param resizable any
local texture ---@param subClass any
---@return any
function ISUIElement:wrapInCollapsableWindow(title, resizable, subClass)
local panel = og_ISUIElement_wrapInCollapsableWindow(self, title, resizable, subClass)
if TOC_DEBUG.enableHealthPanelDebug then if overrideBackgroundColor then
redColor = 1 TOC_DEBUG.print("Overriding color for panel - " .. title)
texture = getTexture("media/ui/test_pattern.png")
else
if highestAmputations[side] == nil then return end
local limbName = highestAmputations[side]
--TOC_DEBUG.print("Drawing " .. tostring(limbName) .. " for " .. username)
local cicTime = DataController.GetInstance(username):getCicatrizationTime(limbName)
redColor = GetColorFromCicatrizationTime(cicTime, limbName)
local sexPl
if self.character:isFemale() then
sexPl = "Female"
else
sexPl = "Male"
end
texture = StaticData.HEALTH_PANEL_TEXTURES[sexPl][limbName]
end
self:drawTexture(texture, self.healthPanel.x, self.healthPanel.y, 1, redColor, 0, 0)
end
local og_ISHealthPanel_render = ISHealthPanel.render
function ISHealthPanel:render()
og_ISHealthPanel_render(self)
local username = self.character:getUsername()
--CachedDataHandler.CalculateHighestAmputatedLimbs(username)
local highestAmputations = CachedDataHandler.GetHighestAmputatedLimbs(username)
-- TODO Client should send update to other client somehow
if highestAmputations ~= nil then
-- Left Texture
self:tryDrawHighestAmputation(highestAmputations, "L", username)
-- Right Texture
self:tryDrawHighestAmputation(highestAmputations, "R", username)
-- else
-- -- Request caching data
-- TOC_DEBUG.print("highest amputated limbs was nil, calculating and getting it now for " .. username)
-- CachedDataHandler.CalculateHighestAmputatedLimbs(username)
end
end
-- We need to override this to force the alpha to 1
local og_ISCharacterInfoWindow_render = ISCharacterInfoWindow.prerender
function ISCharacterInfoWindow:prerender()
og_ISCharacterInfoWindow_render(self)
self.backgroundColor.a = 1 self.backgroundColor.a = 1
panel.backgroundColor.a = 1
end end
-- We need to override this to force the alpha to 1 for the Medical Check in particular return panel
local og_ISHealthPanel_prerender = ISHealthPanel.prerender end
function ISHealthPanel:prerender()
og_ISHealthPanel_prerender(self)
self.backgroundColor.a = 1
end
--- The medical check wrap the health panel into this. We need to override its color -- This is run when a player is trying the Medical Check action on another player
local overrideBackgroundColor = true local og_ISMedicalCheckAction_perform = ISMedicalCheckAction.perform
local og_ISUIElement_wrapInCollapsableWindow = ISUIElement.wrapInCollapsableWindow function ISMedicalCheckAction:perform()
---@param title string local username = self.otherPlayer:getUsername()
---@param resizable any TOC_DEBUG.print("Medical Action on " .. username )
---@param subClass any
---@return any
function ISUIElement:wrapInCollapsableWindow(title, resizable, subClass)
local panel = og_ISUIElement_wrapInCollapsableWindow(self, title, resizable, subClass)
if overrideBackgroundColor then -- We need to recalculate them here before we can create the highest amputations point
TOC_DEBUG.print("Overriding color for panel - " .. title) CachedDataHandler.CalculateAmputatedLimbs(username)
self.backgroundColor.a = 1 og_ISMedicalCheckAction_perform(self)
panel.backgroundColor.a = 1 end
end
return panel local og_ISHealthBodyPartListBox_doDrawItem = ISHealthBodyPartListBox.doDrawItem
end function ISHealthBodyPartListBox:doDrawItem(y, item, alt)
y = og_ISHealthBodyPartListBox_doDrawItem(self, y, item, alt)
y = y - 5
local x = 15
local fontHgt = getTextManager():getFontHeight(UIFont.Small)
-- This is run when a player is trying the Medical Check action on another player local username = self.parent.character:getUsername()
local og_ISMedicalCheckAction_perform = ISMedicalCheckAction.perform --local amputatedLimbs = CachedDataHandler.GetIndexedAmputatedLimbs(username)
function ISMedicalCheckAction:perform()
local username = self.otherPlayer:getUsername()
TOC_DEBUG.print("Medical Action on " .. username )
-- We need to recalculate them here before we can create the highest amputations point ---@type BodyPart
CachedDataHandler.CalculateAmputatedLimbs(username) local bodyPart = item.item.bodyPart
og_ISMedicalCheckAction_perform(self)
end
local og_ISHealthBodyPartListBox_doDrawItem = ISHealthBodyPartListBox.doDrawItem local bodyPartTypeStr = BodyPartType.ToString(bodyPart:getType())
function ISHealthBodyPartListBox:doDrawItem(y, item, alt) local limbName = StaticData.LIMBS_IND_STR[bodyPartTypeStr]
y = og_ISHealthBodyPartListBox_doDrawItem(self, y, item, alt) if limbName then
y = y - 5 local dcInst = DataController.GetInstance(username)
local x = 15 if dcInst:getIsCut(limbName) and dcInst:getIsVisible(limbName) then
local fontHgt = getTextManager():getFontHeight(UIFont.Small) if dcInst:getIsCicatrized(limbName) then
if dcInst:getIsCauterized(limbName) then
local username = self.parent.character:getUsername() self:drawText("- " .. getText("IGUI_HealthPanel_Cauterized"), x, y, 0.58, 0.75, 0.28, 1, UIFont.Small)
--local amputatedLimbs = CachedDataHandler.GetIndexedAmputatedLimbs(username)
---@type BodyPart
local bodyPart = item.item.bodyPart
local bodyPartTypeStr = BodyPartType.ToString(bodyPart:getType())
local limbName = StaticData.LIMBS_IND_STR[bodyPartTypeStr]
if limbName then
local dcInst = DataController.GetInstance(username)
if dcInst:getIsCut(limbName) and dcInst:getIsVisible(limbName) then
if dcInst:getIsCicatrized(limbName) then
if dcInst:getIsCauterized(limbName) then
self:drawText("- " .. getText("IGUI_HealthPanel_Cauterized"), x, y, 0.58, 0.75, 0.28, 1, UIFont.Small)
else
self:drawText("- " .. getText("IGUI_HealthPanel_Cicatrized"), x, y, 0.28, 0.89, 0.28, 1, UIFont.Small)
end
else else
local cicaTime = dcInst:getCicatrizationTime(limbName) self:drawText("- " .. getText("IGUI_HealthPanel_Cicatrized"), x, y, 0.28, 0.89, 0.28, 1, UIFont.Small)
-- Show it in percentage
local maxCicaTime = StaticData.LIMBS_CICATRIZATION_TIME_IND_NUM[limbName]
local percentage = (1 - cicaTime/maxCicaTime) * 100
self:drawText("- " .. getText("IGUI_HealthPanel_Cicatrization") .. string.format(" %.2f", percentage) .. "%", x, y, 0.89, 0.28, 0.28, 1, UIFont.Small)
y = y + fontHgt
local scaledDirtyness = math.floor(dcInst:getWoundDirtyness(limbName) * 100)
self:drawText("- " .. getText("IGUI_HealthPanel_WoundDirtyness") .. string.format(" %d", scaledDirtyness) .. "%", x, y, 0.89, 0.28, 0.28, 1, UIFont.Small)
end end
else
local cicaTime = dcInst:getCicatrizationTime(limbName)
-- Show it in percentage
local maxCicaTime = StaticData.LIMBS_CICATRIZATION_TIME_IND_NUM[limbName]
local percentage = (1 - cicaTime/maxCicaTime) * 100
self:drawText("- " .. getText("IGUI_HealthPanel_Cicatrization") .. string.format(" %.2f", percentage) .. "%", x, y, 0.89, 0.28, 0.28, 1, UIFont.Small)
y = y + fontHgt y = y + fontHgt
local scaledDirtyness = math.floor(dcInst:getWoundDirtyness(limbName) * 100)
self:drawText("- " .. getText("IGUI_HealthPanel_WoundDirtyness") .. string.format(" %d", scaledDirtyness) .. "%", x, y, 0.89, 0.28, 0.28, 1, UIFont.Small)
end end
y = y + fontHgt
end end
y = y + 5
return y
end end
local og_ISHealthPanel_getDamagedParts = ISHealthPanel.getDamagedParts y = y + 5
function ISHealthPanel:getDamagedParts() return y
-- TODO Overriding it is a lot easier, but ew end
if isReady then local og_ISHealthPanel_getDamagedParts = ISHealthPanel.getDamagedParts
function ISHealthPanel:getDamagedParts()
-- TODO Overriding it is a lot easier, but ew
local result = {} if isReady then
local bodyParts = self:getPatient():getBodyDamage():getBodyParts()
if isClient() and not self:getPatient():isLocalPlayer() then
bodyParts = self:getPatient():getBodyDamageRemote():getBodyParts()
end
local patientUsername = self:getPatient():getUsername() local result = {}
local mdh = DataController.GetInstance(patientUsername) local bodyParts = self:getPatient():getBodyDamage():getBodyParts()
for i=1,bodyParts:size() do if isClient() and not self:getPatient():isLocalPlayer() then
local bodyPart = bodyParts:get(i-1) bodyParts = self:getPatient():getBodyDamageRemote():getBodyParts()
local bodyPartTypeStr = BodyPartType.ToString(bodyPart:getType())
local limbName = StaticData.LIMBS_IND_STR[bodyPartTypeStr]
if ISHealthPanel.cheat or bodyPart:HasInjury() or bodyPart:bandaged() or bodyPart:stitched() or bodyPart:getSplintFactor() > 0 or bodyPart:getAdditionalPain() > 10 or bodyPart:getStiffness() > 5 or (mdh:getIsCut(limbName) and mdh:getIsVisible(limbName)) then
table.insert(result, bodyPart)
end
end
return result
else
return og_ISHealthPanel_getDamagedParts(self)
end end
end
--end local patientUsername = self:getPatient():getUsername()
local mdh = DataController.GetInstance(patientUsername)
for i=1,bodyParts:size() do
local bodyPart = bodyParts:get(i-1)
local bodyPartTypeStr = BodyPartType.ToString(bodyPart:getType())
local limbName = StaticData.LIMBS_IND_STR[bodyPartTypeStr]
if ISHealthPanel.cheat or bodyPart:HasInjury() or bodyPart:bandaged() or bodyPart:stitched() or bodyPart:getSplintFactor() > 0 or bodyPart:getAdditionalPain() > 10 or bodyPart:getStiffness() > 5 or (mdh:getIsCut(limbName) and mdh:getIsVisible(limbName)) then
table.insert(result, bodyPart)
end
end
return result
else
return og_ISHealthPanel_getDamagedParts(self)
end
end