Refreshing UI working

This commit is contained in:
Pao
2023-01-23 03:52:51 +01:00
parent bb408e3667
commit 6b39ff83fd
7 changed files with 96 additions and 86 deletions

View File

@@ -43,6 +43,7 @@
"ISDropItemAction",
"BloodBodyPartType",
"ISInventoryPane",
"ModData"
"ModData",
"isDebugEnabled"
]
}

View File

@@ -193,32 +193,24 @@ Commands["AcceptResetEverything"] = function(arg)
end
-- Base stuff
Commands["GivePlayerData"] = function(arg)
local surgeon_id = arg[1]
local patient = getPlayerByOnlineID(arg[2])
local toc_data = patient:getModData().TOC
sendClientCommand(patient, "TOC", "SendPlayerData", { surgeon_id, toc_data })
end
Commands["SendTocData"] = function(arg)
print("Sending TOC data")
-- Cut Limb stuff
Commands["AcceptDamageOtherPlayer"] = function(arg)
local patient_id = arg[1]
local patient = getPlayerByOnlineID(arg[1])
MP_other_player_toc_data = arg[2]
local part_name = arg[2]
TocDamagePlayerDuringAmputation(patient, part_name)
end
-- Base stuff
local function OnTocServerCommand(module, command, args)
if module == 'TOC' then
print("OnTocServerCommand " .. command)
print("TOC: On Toc Server Command " .. command)
if Commands[command] then
print("Found command, executing it now")
args = args or {}

View File

@@ -89,6 +89,19 @@ function TocGetSawInInventory(surgeon)
return item
end
function TocDamagePlayerDuringAmputation(patient, part_name)
local body_part_type = TocGetBodyPartTypeFromPartName(part_name)
local body_damage = patient:getBodyDamage()
local body_damage_part = body_damage:getBodyPart(body_part_type)
body_damage_part:setBleeding(true)
body_damage_part:setCut(true)
body_damage_part:setBleedingTime(ZombRand(10, 20))
end
-- OperateLimb
function SetBodyPartsStatusAfterOperation(player, limbs_data, part_name, use_oven)
--for _, v in ipairs(GetBodyParts()) do

View File

@@ -138,7 +138,7 @@ local function OnClickTocMainUI(button, args)
desc_ui:open()
desc_ui:setPositionPixel(main_ui:getRight(), main_ui:getY())
SetupTocDescUI(main_ui.surgeon, main_ui.patient, args.limbs_data, args.part_name) -- surgeon is generic.
SetupTocDescUI(main_ui.surgeon, main_ui.patient, main_ui.limbs_data, args.part_name) -- surgeon is generic.
end
@@ -360,12 +360,8 @@ function SetupTocMainUI(surgeon, patient, limbs_data)
main_ui.patient = patient
if limbs_data then
main_ui["b11"]:addArg("limbs_data", limbs_data)
main_ui["b12"]:addArg("limbs_data", limbs_data)
main_ui["b21"]:addArg("limbs_data", limbs_data)
main_ui["b22"]:addArg("limbs_data", limbs_data)
main_ui["b31"]:addArg("limbs_data", limbs_data)
main_ui["b32"]:addArg("limbs_data", limbs_data)
main_ui.limbs_data = limbs_data
main_ui["b11"]:setPath(GetImageName("Right_UpperArm", limbs_data))
main_ui["b12"]:setPath(GetImageName("Left_UpperArm", limbs_data))
@@ -534,45 +530,28 @@ local ISHealthPanel_render = ISHealthPanel.render
-- Add button to health panel
TocTempTable = {
TempPatient = nil,
TempSurgeon = nil
}
function ISNewHealthPanel.onClick_TOC(button)
local surgeon = button.otherPlayer
local patient = button.character
TocTempTable.patient = patient
TocTempTable.surgeon = surgeon
-- MP Handling
if surgeon then
if surgeon == patient then
SetupTocMainUI(surgeon, surgeon, surgeon:getModData().TOC.Limbs)
Events.OnTick.Add(TocRefreshPlayerMenu)
else
-- MP stuff, try to get the other player data and display it on the surgeon display
print("TOC: Checking part_data for " .. patient:getUsername())
if ModData.get("TOC_PLAYER_DATA")[patient:getUsername()] ~= nil then
local other_player_part_data = ModData.get("TOC_PLAYER_DATA")[patient:getUsername()]
SetupTocMainUI(surgeon, patient, other_player_part_data[1])
end
--sendClientCommand(surgeon, "TOC", "GetPlayerData", { surgeon:getOnlineID(), patient:getOnlineID() })
--TocTempTable.TempPatient = patient
--TocTempTable.TempSurgeon = surgeon
-- Wait for ack
--Events.OnTick.Add(TocWaitForOnlinePlayerData)
Events.OnTick.Add(TocRefreshOtherPlayerMenu) -- MP stuff, try to get the other player data and display it on the surgeon display
end
else
-- This is when surgeon doesnt exist for some reason.
SetupTocMainUI(patient, patient, patient:getModData().TOC.Limbs)
-- SP Handling
Events.OnTick.Add(TocRefreshPlayerMenu)
end
main_ui:toggle()
@@ -580,28 +559,54 @@ function ISNewHealthPanel.onClick_TOC(button)
end
function TocWaitForOnlinePlayerData(numberTicks)
if MP_other_player_toc_data ~= nil then
SetupTocMainUI(TocTempTable.TempSurgeon, TocTempTable.TempPatient, MP_other_player_toc_data)
TocTempTable.TempSurgeon = nil
TocTempTable.TempPatient = nil
MP_other_player_toc_data = nil
Events.OnTick.Remove(TocWaitForOnlinePlayerData)
TocTempTable = {patient = nil, surgeon = nil}
function TocRefreshPlayerMenu(_)
if main_ui:getIsVisible() == false then
Events.OnTick.Remove(TocRefreshPlayerMenu)
TocTempTable.patient = nil
TocTempTable.surgeon = nil
else
local limbs_data = TocTempTable.patient:getModData().TOC.Limbs
SetupTocMainUI(TocTempTable.patient, TocTempTable.patient, limbs_data)
end
end
function TocRefreshOtherPlayerMenu(_)
if main_ui:getIsVisible() == false then
Events.OnTick.Remove(TocRefreshOtherPlayerMenu)
TocTempTable.patient = nil
TocTempTable.surgeon = nil
else
if ModData.get("TOC_PLAYER_DATA")[TocTempTable.patient:getUsername()] ~= nil then
local other_player_part_data = ModData.get("TOC_PLAYER_DATA")[TocTempTable.patient:getUsername()]
SetupTocMainUI(TocTempTable.surgeon, TocTempTable.patient, other_player_part_data[1])
end
end
end
function ISHealthPanel:createChildren()
ISHealthPanel_createChildren(self)
--self.fitness:setWidth(self.fitness:getWidth() / 1.5)
self.fitness:setWidth(self.fitness:getWidth() / 1.2)
self.TOCButton = ISButton:new(self.fitness:getRight() + 25, self.healthPanel.y, 70, 20, "The Only Cure", self,
self.TOCButton = ISButton:new(self.fitness:getRight() + 10, self.healthPanel.y, 70, 20, "The Only Cure", self,
ISNewHealthPanel.onClick_TOC)
--self.TOCButton:setImage(getTexture("media/ui/TOC/iconForMenu.png"))
self.TOCButton.anchorTop = false

View File

@@ -161,6 +161,7 @@ function TheOnlyCure.UpdateEveryOneMinute()
-- Updates toc data in a global way, basically player:transmitModData but it works
-- Sends only Limbs since the other stuff is mostly static
if toc_data ~= nil then
-- TODO make it so that we dont send it constantly
sendClientCommand(player, 'TOC', 'ChangePlayerState', { toc_data.Limbs } )
end

View File

@@ -41,17 +41,13 @@ function ISCutLimb:start()
end
if self.patient == self.surgeon then
TocDamagePlayerDuringAmputation(self.patient, self.part_name)
else
sendClientCommand(self.surgeon, "TOC", "AskDamageOtherPlayer", {self.patient:getOnlineID(), self.part_name})
end
-- TODO this doesn't work when doing it on another player
local body_part_type = TocGetBodyPartTypeFromPartName(self.part_name)
local body_damage = self.patient:getBodyDamage()
local body_damage_part = body_damage:getBodyPart(body_part_type)
body_damage_part:setBleeding(true)
body_damage_part:setCut(true)
body_damage_part:setBleedingTime(ZombRand(10, 20))

View File

@@ -5,28 +5,26 @@
local TOC_Commands = {}
--TODO how does this work
TOC_Commands["SendServer"] = function(player, arg)
local otherPlayer = getPlayerByOnlineID(arg["To"])
print("The Only Cure Command: ", arg['command'])
sendServerCommand(otherPlayer, "TOC", arg["command"], arg)
end
-- To make the UI Work
TOC_Commands["GetPlayerData"] = function(_, arg)
local surgeon_id = arg[1]
local patient_id = arg[2]
local patient = getPlayerByOnlineID(arg[2])
sendServerCommand(patient, "TOC", "GivePlayerData", { surgeon_id, patient_id })
-- Cut Limb stuff
TOC_Commands["AskDamageOtherPlayer"] = function(_, arg)
local patient = getPlayerByOnlineID(arg[1])
local patient_id = arg[1]
local part_name = arg[2]
sendServerCommand(patient, "TOC", "AcceptDamageOtherPlayer", {patient_id, part_name})
end
TOC_Commands["SendPlayerData"] = function(_, arg)
local surgeon = getPlayerByOnlineID(arg[1])
local surgeon_id = arg[1]
local toc_data = arg[2]
sendServerCommand(surgeon, "TOC", "SendTocData", { surgeon_id, toc_data })
end
@@ -40,6 +38,9 @@ TOC_Commands["AskToResetEverything"] = function(_, arg)
end
------ Global Mod Data -----------
function TOC_OnInitGlobalModData()
@@ -49,6 +50,7 @@ end
Events.OnInitGlobalModData.Add(TOC_OnInitGlobalModData)
TOC_Commands.OnClientCommand = function(module, command, playerObj, args)
if module == 'TOC' and TOC_Commands[command] then
TOC_Commands[command](playerObj, args)
end