POC for health panels in MP
This commit is contained in:
@@ -29,6 +29,8 @@ function ModDataHandler:new(username, isResetForced)
|
||||
TOC_DEBUG.print("tocData in ModDataHandler for " .. username .. " is nil, creating it now")
|
||||
self:setup(key)
|
||||
end
|
||||
-- Transmit it to the server
|
||||
ModData.transmit(key)
|
||||
|
||||
ModDataHandler.instances[username] = o
|
||||
|
||||
@@ -59,8 +61,7 @@ function ModDataHandler:setup(key)
|
||||
-- Add it to global mod data
|
||||
ModData.add(key, self.tocData)
|
||||
|
||||
-- Transmit it to the server
|
||||
ModData.transmit(key)
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -169,12 +170,26 @@ function ModDataHandler:setLimbParams(limbName, ampStatus, cicatrizationTime)
|
||||
end
|
||||
|
||||
|
||||
--* Global Mod Data Apply *--
|
||||
--* Global Mod Data Handling *--
|
||||
|
||||
function ModDataHandler:apply()
|
||||
ModData.transmit(CommandsData.GetKey(self.username))
|
||||
end
|
||||
|
||||
|
||||
function ModDataHandler.ReceiveData(key, table)
|
||||
TOC_DEBUG.print("receive data for " .. key)
|
||||
if table == {} or table == nil then
|
||||
TOC_DEBUG.print("table is nil... returning")
|
||||
return
|
||||
end
|
||||
ModData.add(key, table) -- Add it to the client mod data (not sure)
|
||||
local username = key:sub(5)
|
||||
ModDataHandler.GetInstance(username)
|
||||
end
|
||||
Events.OnReceiveGlobalModData.Add(ModDataHandler.ReceiveData)
|
||||
|
||||
|
||||
---@param username string?
|
||||
---@return ModDataHandler
|
||||
function ModDataHandler.GetInstance(username)
|
||||
|
||||
@@ -18,7 +18,7 @@ local PlayerHandler = {}
|
||||
PlayerHandler.amputatedLimbs = {}
|
||||
|
||||
|
||||
---Setup the Player Handler and modData
|
||||
---Setup the Player Handler and modData, only for local client
|
||||
---@param playerObj IsoPlayer
|
||||
---@param isForced boolean?
|
||||
function PlayerHandler.InitializePlayer(playerObj, isForced)
|
||||
@@ -27,15 +27,9 @@ function PlayerHandler.InitializePlayer(playerObj, isForced)
|
||||
TOC_DEBUG.print("initializing " .. username)
|
||||
local modDataHandler = ModDataHandler:new(username, isForced)
|
||||
PlayerHandler.playerObj = playerObj
|
||||
-- Calculate amputated limbs at startup
|
||||
PlayerHandler.amputatedLimbs[username] = {}
|
||||
|
||||
for i=1, #StaticData.LIMBS_STRINGS do
|
||||
local limbName = StaticData.LIMBS_STRINGS[i]
|
||||
if modDataHandler:getIsCut(limbName) then
|
||||
PlayerHandler.AddLocalAmputatedLimb(username, limbName)
|
||||
end
|
||||
end
|
||||
-- Calculate amputated limbs at startup
|
||||
PlayerHandler.CacheAmputatedLimbs(username)
|
||||
|
||||
-- Since isForced is used to reset an existing player data, we're gonna clean their ISHealthPanel table too
|
||||
if isForced then
|
||||
@@ -60,8 +54,23 @@ function PlayerHandler.ManageTraits(playerObj)
|
||||
end
|
||||
end
|
||||
|
||||
---Cycle through all the limbs and caches the ones that the player cut off
|
||||
---@param username string
|
||||
function PlayerHandler.CacheAmputatedLimbs(username)
|
||||
PlayerHandler.amputatedLimbs[username] = {}
|
||||
local modDataHandler = ModDataHandler.GetInstance(username)
|
||||
for i=1, #StaticData.LIMBS_STRINGS do
|
||||
local limbName = StaticData.LIMBS_STRINGS[i]
|
||||
if modDataHandler:getIsCut(limbName) then
|
||||
PlayerHandler.AddLocalAmputatedLimb(username, limbName)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
---Cache the currently amputated limbs
|
||||
---@param limbName string
|
||||
---@private
|
||||
function PlayerHandler.AddLocalAmputatedLimb(username, limbName)
|
||||
TOC_DEBUG.print("added " .. limbName .. " to known amputated limbs for " .. username)
|
||||
table.insert(PlayerHandler.amputatedLimbs[username], limbName) -- TODO This should be player specific, not generic
|
||||
|
||||
@@ -2,7 +2,6 @@ local PlayerHandler = require("TOC/Handlers/PlayerHandler")
|
||||
local StaticData = require("TOC/StaticData")
|
||||
local CommonMethods = require("TOC/CommonMethods")
|
||||
local ModDataHandler = require("TOC/Handlers/ModDataHandler")
|
||||
local CommandsData = require("TOC/CommandsData")
|
||||
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
local CutLimbHandler = require("TOC/UI/CutLimbInteractions")
|
||||
@@ -48,15 +47,12 @@ end
|
||||
function ISHealthPanel:setHighestAmputation()
|
||||
|
||||
--TOC_DEBUG.print("setHighestAmputation for " .. self.tocUsername)
|
||||
|
||||
if self.otherPlayer ~= nil then
|
||||
self.tocUsername = self.otherPlayer:getUsername()
|
||||
else
|
||||
self.tocUsername = self.character:getUsername()
|
||||
end
|
||||
|
||||
-- character is always the patient.
|
||||
self.tocUsername = self.character:getUsername()
|
||||
|
||||
if PlayerHandler.amputatedLimbs == nil or PlayerHandler.amputatedLimbs[self.tocUsername] == nil then
|
||||
TOC_DEBUG.print("PlayerHandler.amputatedLimbs is still nil or wasn't initialized for that player")
|
||||
TOC_DEBUG.print("PlayerHandler.amputatedLimbs is still nil or wasn't initialized for " .. self.tocUsername)
|
||||
return
|
||||
end
|
||||
local amputatedLimbs = PlayerHandler.amputatedLimbs[self.tocUsername]
|
||||
@@ -111,6 +107,8 @@ local og_ISHealthPanel_render = ISHealthPanel.render
|
||||
function ISHealthPanel:render()
|
||||
og_ISHealthPanel_render(self)
|
||||
|
||||
--print("Rendering ISHealthPanel")
|
||||
|
||||
|
||||
if self.highestAmputations ~= nil and self.highestAmputations[self.tocUsername] ~= nil then
|
||||
-- Left Texture
|
||||
@@ -134,4 +132,45 @@ local og_ISCharacterInfoWindow_render = ISCharacterInfoWindow.prerender
|
||||
function ISCharacterInfoWindow:prerender()
|
||||
og_ISCharacterInfoWindow_render(self)
|
||||
self.backgroundColor.a = 1
|
||||
end
|
||||
|
||||
-- We need to override this to force the alpha to 1 for the Medical Check in particular
|
||||
local og_ISHealthPanel_prerender = ISHealthPanel.prerender
|
||||
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
|
||||
local overrideBackgroundColor = true
|
||||
local og_ISUIElement_wrapInCollapsableWindow = ISUIElement.wrapInCollapsableWindow
|
||||
function ISUIElement:wrapInCollapsableWindow(title, resizable, subClass)
|
||||
local panel = og_ISUIElement_wrapInCollapsableWindow(self, title, resizable, subClass)
|
||||
|
||||
if overrideBackgroundColor then
|
||||
TOC_DEBUG.print("Overriding color for panel - " .. title)
|
||||
self.backgroundColor.a = 1
|
||||
panel.backgroundColor.a = 1
|
||||
end
|
||||
|
||||
return panel
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- This is run when a player is trying the Medical Check action on another player
|
||||
local og_ISMedicalCheckAction_perform = ISMedicalCheckAction.perform
|
||||
function ISMedicalCheckAction:perform()
|
||||
local username = self.otherPlayer:getUsername()
|
||||
TOC_DEBUG.print("creating instance for " .. username )
|
||||
ModDataHandler.GetInstance(username)
|
||||
|
||||
-- We need to recalculate them here before we can create the highest amputations point
|
||||
PlayerHandler.CacheAmputatedLimbs(username)
|
||||
og_ISMedicalCheckAction_perform(self)
|
||||
end
|
||||
Reference in New Issue
Block a user