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,20 +14,19 @@ 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") TOC_DEBUG.print("override to dropItemsOnBodyPart running")
@@ -39,10 +38,10 @@ end
return return
end end
end end
local og_ISHealthPanel_doBodyPartContextMenu = ISHealthPanel.doBodyPartContextMenu local og_ISHealthPanel_doBodyPartContextMenu = ISHealthPanel.doBodyPartContextMenu
function ISHealthPanel:doBodyPartContextMenu(bodyPart, x, y) function ISHealthPanel:doBodyPartContextMenu(bodyPart, x, y)
og_ISHealthPanel_doBodyPartContextMenu(self, bodyPart, x, y) og_ISHealthPanel_doBodyPartContextMenu(self, bodyPart, x, y)
local playerNum = self.otherPlayer and self.otherPlayer:getPlayerNum() or self.character:getPlayerNum() local playerNum = self.otherPlayer and self.otherPlayer:getPlayerNum() or self.character:getPlayerNum()
@@ -56,48 +55,24 @@ end
local woundCleaningHandler = WoundCleaningHandler:new(self, bodyPart, self.character:getUsername()) local woundCleaningHandler = WoundCleaningHandler:new(self, bodyPart, self.character:getUsername())
self:checkItems({woundCleaningHandler}) self:checkItems({woundCleaningHandler})
woundCleaningHandler:addToMenu(context) woundCleaningHandler:addToMenu(context)
end end
--* Modifications and additional methods to handle visible amputation on the health menu *-- --* Modifications and additional methods to handle visible amputation on the health menu *--
local og_ISHealthPanel_initialise = ISHealthPanel.initialise ---Get a value between 1 and 0.1 for the cicatrization time
function ISHealthPanel:initialise() ---@param cicTime integer
if self.character:isFemale() then ---@return integer
self.sexPl = "Female" local function GetColorFromCicatrizationTime(cicTime, limbName)
else
self.sexPl = "Male"
end
local username = self.character:getUsername()
if username ~= "Bob" then
--CachedDataHandler.CalculateHighestAmputatedLimbs(username)
self.highestAmputations = CachedDataHandler.GetHighestAmputatedLimbs(username)
end
og_ISHealthPanel_initialise(self)
end
local og_ISHealthPanel_setOtherPlayer = ISHealthPanel.setOtherPlayer
---@param playerObj IsoPlayer
function ISHealthPanel:setOtherPlayer(playerObj)
og_ISHealthPanel_setOtherPlayer(self, playerObj)
--CachedDataHandler.CalculateAmputatedLimbs(self.character:getUsername())
end
---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 defaultTime = StaticData.LIMBS_CICATRIZATION_TIME_IND_NUM[limbName]
local delta = cicTime/defaultTime local delta = cicTime/defaultTime
return math.max(0.15, math.min(delta, 1)) return math.max(0.15, math.min(delta, 1))
end end
---Try to draw the highest amputation in the health panel, based on the cicatrization time ---Try to draw the highest amputation in the health panel, based on the cicatrization time
---@param side string L or R ---@param side string L or R
---@param username string ---@param username string
function ISHealthPanel:tryDrawHighestAmputation(highestAmputations, side, username) function ISHealthPanel:tryDrawHighestAmputation(highestAmputations, side, username)
local redColor local redColor
local texture local texture
@@ -112,64 +87,50 @@ end
local cicTime = DataController.GetInstance(username):getCicatrizationTime(limbName) local cicTime = DataController.GetInstance(username):getCicatrizationTime(limbName)
redColor = GetColorFromCicatrizationTime(cicTime, limbName) redColor = GetColorFromCicatrizationTime(cicTime, limbName)
local sexPl local sexPl = self.character:isFemale() and "Female" or "Male"
if self.character:isFemale() then
sexPl = "Female"
else
sexPl = "Male"
end
texture = StaticData.HEALTH_PANEL_TEXTURES[sexPl][limbName] texture = StaticData.HEALTH_PANEL_TEXTURES[sexPl][limbName]
end end
self:drawTexture(texture, self.healthPanel.x, self.healthPanel.y, 1, redColor, 0, 0) self:drawTexture(texture, self.healthPanel.x, self.healthPanel.y, 1, redColor, 0, 0)
end end
local og_ISHealthPanel_render = ISHealthPanel.render local og_ISHealthPanel_render = ISHealthPanel.render
function ISHealthPanel:render() function ISHealthPanel:render()
og_ISHealthPanel_render(self) og_ISHealthPanel_render(self)
local username = self.character:getUsername() local username = self.character:getUsername()
--CachedDataHandler.CalculateHighestAmputatedLimbs(username)
local highestAmputations = CachedDataHandler.GetHighestAmputatedLimbs(username) local highestAmputations = CachedDataHandler.GetHighestAmputatedLimbs(username)
-- TODO Client should send update to other client somehow
if highestAmputations ~= nil then if highestAmputations ~= nil then
-- Left Texture -- Left Texture
self:tryDrawHighestAmputation(highestAmputations, "L", username) self:tryDrawHighestAmputation(highestAmputations, "L", username)
-- Right Texture -- Right Texture
self:tryDrawHighestAmputation(highestAmputations, "R", username) 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 end
end
-- We need to override this to force the alpha to 1 -- We need to override this to force the alpha to 1
local og_ISCharacterInfoWindow_render = ISCharacterInfoWindow.prerender local og_ISCharacterInfoWindow_render = ISCharacterInfoWindow.prerender
function ISCharacterInfoWindow:prerender() function ISCharacterInfoWindow:prerender()
og_ISCharacterInfoWindow_render(self) og_ISCharacterInfoWindow_render(self)
self.backgroundColor.a = 1 self.backgroundColor.a = 1
end end
-- We need to override this to force the alpha to 1 for the Medical Check in particular -- We need to override this to force the alpha to 1 for the Medical Check in particular
local og_ISHealthPanel_prerender = ISHealthPanel.prerender local og_ISHealthPanel_prerender = ISHealthPanel.prerender
function ISHealthPanel:prerender() function ISHealthPanel:prerender()
og_ISHealthPanel_prerender(self) og_ISHealthPanel_prerender(self)
self.backgroundColor.a = 1 self.backgroundColor.a = 1
end end
--- The medical check wrap the health panel into this. We need to override its color --- The medical check wrap the health panel into this. We need to override its color
local overrideBackgroundColor = true local overrideBackgroundColor = true
local og_ISUIElement_wrapInCollapsableWindow = ISUIElement.wrapInCollapsableWindow local og_ISUIElement_wrapInCollapsableWindow = ISUIElement.wrapInCollapsableWindow
---@param title string ---@param title string
---@param resizable any ---@param resizable any
---@param subClass any ---@param subClass any
---@return any ---@return any
function ISUIElement:wrapInCollapsableWindow(title, resizable, subClass) function ISUIElement:wrapInCollapsableWindow(title, resizable, subClass)
local panel = og_ISUIElement_wrapInCollapsableWindow(self, title, resizable, subClass) local panel = og_ISUIElement_wrapInCollapsableWindow(self, title, resizable, subClass)
if overrideBackgroundColor then if overrideBackgroundColor then
@@ -179,21 +140,21 @@ end
end end
return panel return panel
end end
-- This is run when a player is trying the Medical Check action on another player -- This is run when a player is trying the Medical Check action on another player
local og_ISMedicalCheckAction_perform = ISMedicalCheckAction.perform local og_ISMedicalCheckAction_perform = ISMedicalCheckAction.perform
function ISMedicalCheckAction:perform() function ISMedicalCheckAction:perform()
local username = self.otherPlayer:getUsername() local username = self.otherPlayer:getUsername()
TOC_DEBUG.print("Medical Action on " .. username ) TOC_DEBUG.print("Medical Action on " .. username )
-- We need to recalculate them here before we can create the highest amputations point -- We need to recalculate them here before we can create the highest amputations point
CachedDataHandler.CalculateAmputatedLimbs(username) CachedDataHandler.CalculateAmputatedLimbs(username)
og_ISMedicalCheckAction_perform(self) og_ISMedicalCheckAction_perform(self)
end end
local og_ISHealthBodyPartListBox_doDrawItem = ISHealthBodyPartListBox.doDrawItem local og_ISHealthBodyPartListBox_doDrawItem = ISHealthBodyPartListBox.doDrawItem
function ISHealthBodyPartListBox:doDrawItem(y, item, alt) function ISHealthBodyPartListBox:doDrawItem(y, item, alt)
y = og_ISHealthBodyPartListBox_doDrawItem(self, y, item, alt) y = og_ISHealthBodyPartListBox_doDrawItem(self, y, item, alt)
y = y - 5 y = y - 5
local x = 15 local x = 15
@@ -236,10 +197,10 @@ end
y = y + 5 y = y + 5
return y return y
end end
local og_ISHealthPanel_getDamagedParts = ISHealthPanel.getDamagedParts local og_ISHealthPanel_getDamagedParts = ISHealthPanel.getDamagedParts
function ISHealthPanel:getDamagedParts() function ISHealthPanel:getDamagedParts()
-- TODO Overriding it is a lot easier, but ew -- TODO Overriding it is a lot easier, but ew
if isReady then if isReady then
@@ -266,6 +227,4 @@ end
else else
return og_ISHealthPanel_getDamagedParts(self) return og_ISHealthPanel_getDamagedParts(self)
end end
end end
--end