From 00b1b78cb37e9b104471524916e50f44894f3d90 Mon Sep 17 00:00:00 2001 From: ZioPao Date: Fri, 22 Mar 2024 15:52:34 +0100 Subject: [PATCH] Fixed update when Health Panel is open for remote pl --- .../client/TOC/Controllers/DataController.lua | 3 ++ media/lua/client/TOC/UI/HealthPanel.lua | 30 ++++++++++++++----- media/lua/server/TOC/DebugCommands.lua | 1 + media/lua/server/TOC/ServerDataHandler.lua | 2 ++ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/media/lua/client/TOC/Controllers/DataController.lua b/media/lua/client/TOC/Controllers/DataController.lua index 5e6880b..0a7817a 100644 --- a/media/lua/client/TOC/Controllers/DataController.lua +++ b/media/lua/client/TOC/Controllers/DataController.lua @@ -1,3 +1,5 @@ +if isServer() then return end + local CommandsData = require("TOC/CommandsData") local StaticData = require("TOC/StaticData") ---------------- @@ -346,6 +348,7 @@ function DataController:apply() ModData.transmit(CommandsData.GetKey(self.username)) end + ---Online only, Global Mod Data doesn't trigger this in SP ---@param key any ---@param data any diff --git a/media/lua/client/TOC/UI/HealthPanel.lua b/media/lua/client/TOC/UI/HealthPanel.lua index 1c79456..ee3b1c2 100644 --- a/media/lua/client/TOC/UI/HealthPanel.lua +++ b/media/lua/client/TOC/UI/HealthPanel.lua @@ -1,4 +1,5 @@ local StaticData = require("TOC/StaticData") +local CommandsData = require("TOC/CommandsData") local DataController = require("TOC/Controllers/DataController") local CachedDataHandler = require("TOC/Handlers/CachedDataHandler") @@ -7,7 +8,6 @@ local WoundCleaningInteractionHandler = require("TOC/UI/Interactions/WoundCleani ------------------------ - local isReady = false function SetHealthPanelTOC() @@ -125,14 +125,27 @@ function ISHealthPanel:render() self:tryDrawAmputation(highestAmputations, "R", username) self:tryDrawProsthesis(highestAmputations, "R", username) end - - - - - - end + +local og_ISHealthPanel_update = ISHealthPanel.update +function ISHealthPanel:update() + og_ISHealthPanel_update(self) + -- TODO Listen for changes on other player side instead of looping this + + if self.character then + local locPlUsername = getPlayer():getUsername() + local remPlUsername = self.character:getUsername() + if locPlUsername ~= remPlUsername and self:isReallyVisible() then + -- Request update for TOC DATA? + local key = CommandsData.GetKey(remPlUsername) + ModData.request(key) + end + end +end + + + -- We need to override this to force the alpha to 1 local og_ISCharacterInfoWindow_render = ISCharacterInfoWindow.prerender function ISCharacterInfoWindow:prerender() @@ -192,6 +205,9 @@ function ISHealthBodyPartListBox:doDrawItem(y, item, alt) local bodyPartTypeStr = BodyPartType.ToString(bodyPart:getType()) local limbName = StaticData.LIMBS_IND_STR[bodyPartTypeStr] + + + -- We should cache a lot of other stuff to have this working with CacheDataHandler :( if limbName then local dcInst = DataController.GetInstance(username) if dcInst:getIsCut(limbName) and dcInst:getIsVisible(limbName) then diff --git a/media/lua/server/TOC/DebugCommands.lua b/media/lua/server/TOC/DebugCommands.lua index cca0244..a501f92 100644 --- a/media/lua/server/TOC/DebugCommands.lua +++ b/media/lua/server/TOC/DebugCommands.lua @@ -29,3 +29,4 @@ local function OnClientDebugCommand(module, command, playerObj, args) end Events.OnClientCommand.Add(OnClientDebugCommand) + diff --git a/media/lua/server/TOC/ServerDataHandler.lua b/media/lua/server/TOC/ServerDataHandler.lua index 0975c26..aa5db52 100644 --- a/media/lua/server/TOC/ServerDataHandler.lua +++ b/media/lua/server/TOC/ServerDataHandler.lua @@ -21,6 +21,8 @@ function ServerDataHandler.AddTable(key, table) if not luautils.stringStarts(key, StaticData.MOD_NAME .. "_") then return end TOC_DEBUG.print("Received TOC ModData: " .. tostring(key)) + TOC_DEBUG.printTable(table) + ModData.add(key, table) -- Add it to the server mod data ServerDataHandler.modData[key] = table end