Fixed TOC UI not working in MP

This commit is contained in:
Pao
2023-01-14 18:40:08 +01:00
parent 53e8d7456d
commit 3ce154079a
7 changed files with 241 additions and 123 deletions

15
.vscode/settings.json vendored
View File

@@ -17,6 +17,19 @@
"getPlayerInventory",
"sendServerCommand",
"TraitFactory",
"ISWorldObjectContextMenu"
"ISWorldObjectContextMenu",
"getCell",
"getSpecificPlayer",
"_",
"NewUI",
"getTextManager",
"isClient",
"ISHealthPanel",
"ModOptions",
"ISNewHealthPanel",
"ISButton",
"getCore",
"ProfessionFactory",
"BaseGameCharacterDetails"
]
}

View File

@@ -0,0 +1,18 @@
-- VARIOUS CHECKS --
if TheOnlyCure == nil then
TheOnlyCure = {}
end
function TheOnlyCure.CheckIfCanBeCut(toc_data, part_name)
return not toc_data[part_name].is_cut
end
function TheOnlyCure.CheckIfCanBeOperated(toc_data, part_name)
return toc_data[part_name].is_operated == false and toc_data[part_name].is_amputation_shown
end

View File

@@ -29,9 +29,10 @@ function TryToToResetEverythingOtherPlayer(_, patient, surgeon)
sendClientCommand(surgeon, "TOC", "AskToResetEverything", {patient:getOnlineID()})
end
--TODO Make the name more unique
function TryActionOnOtherPlayerLocal(_, part_name, action, surgeon, patient)
function TryTheOnlyCureActionOnAnotherPlayer(_, part_name, action, surgeon, patient)
-- TODO add checks so that we don't show these menus if a player has already beeen operated or amputated
-- TODO at this point surgeon doesnt do anything. We'll fix this later
local ui = GetConfirmUIMP()
if not ui then
MakeConfirmUIMP()
@@ -94,83 +95,38 @@ TocContextMenus = {}
TocContextMenus.CreateMenus = function(player, context, worldObjects, test)
local clickedPlayersTable = {} --todo awful workaround
local clickedPlayer = nil
local clicked_players_table = {}
local clicked_player = nil
local player_obj = getSpecificPlayer(player)
local local_player = getSpecificPlayer(player)
--local players = getOnlinePlayers()
for k,v in ipairs(worldObjects) do
-- help detecting a player by checking nearby squares
-- help detecting a player by checking nearby squares
for x=v:getSquare():getX()-1,v:getSquare():getX()+1 do
for y=v:getSquare():getY()-1,v:getSquare():getY()+1 do
local sq = getCell():getGridSquare(x,y,v:getSquare():getZ());
local sq = getCell():getGridSquare(x,y,v:getSquare():getZ())
if sq then
for i=0,sq:getMovingObjects():size()-1 do
local o = sq:getMovingObjects():get(i)
if instanceof(o, "IsoPlayer") then
clickedPlayer = o
clicked_player = o
if clickedPlayersTable[clickedPlayer:getUsername()] == nil then
clickedPlayersTable[clickedPlayer:getUsername()] = true
if clicked_players_table[clicked_player:getUsername()] == nil then
-- FIXME this is to prevent context menu spamming. Find a better way
clicked_players_table[clicked_player:getUsername()] = true
local rootOption = context:addOption("The Only Cure on " .. clickedPlayer:getUsername())
local rootMenu = context:getNew(context)
local cutOption = rootMenu:addOption("Cut");
local operateOption = rootMenu:addOption("Operate");
local cutMenu = context:getNew(context);
local operateMenu = context:getNew(context);
local root_option = context:addOption("The Only Cure on " .. clicked_player:getUsername())
local root_menu = context:getNew(context)
local cut_menu = TocContextMenus.CreateNewMenu("Cut", context, root_menu)
local operate_menu = TocContextMenus.CreateNewMenu("Operate", context, root_menu)
local cheat_menu = TocContextMenus.CreateCheatMenu(context, root_menu, local_player, clicked_player)
context:addSubMenu(root_option, root_menu)
-- admin stuff
if player_obj:getAccessLevel() == "Admin" then
local cheat_option = rootMenu:addOption("Cheat")
local cheat_menu = context:getNew(context)
context:addSubMenu(cheat_option, cheat_menu)
if clickedPlayer == player_obj then
cheat_menu:addOption("Reset TOC for me", worldObjects, ResetEverything)
else
cheat_menu:addOption("Reset TOC for " .. clickedPlayer:getUsername(), worldObjects, TryToToResetEverythingOtherPlayer, clickedPlayer, player_obj)
end
end
context:addSubMenu(rootOption, rootMenu);
context:addSubMenu(cutOption, cutMenu);
context:addSubMenu(operateOption, operateMenu);
-- todo add checks so that we don't show these menus if a player has already beeen operated or amputated
local player_toc_data = getPlayer():getModData().TOC
for k_part, v_part in ipairs(GetBodyParts()) do
--todo right now it doesnt check for a saw.
if clickedPlayer == player_obj then
if player_toc_data[v_part].is_cut == false then
cutMenu:addOption(getText('UI_ContextMenu_' .. v_part), worldObjects, CutLocal, player_obj, player_obj, v_part)
elseif player_toc_data[v_part].is_operated == false and player_toc_data[v_part].is_amputation_shown then
operateMenu:addOption(getText('UI_ContextMenu_' .. v_part), worldObjects, OperateLocal, player_obj, player_obj, v_part)
end
else
--TODO Make it so cut limbs do not appear in the Cut Menu
--if clickedPlayer.getModData().TOC[v_part].is_cut == false then
cutMenu:addOption(getText('UI_ContextMenu_' .. v_part), worldObjects, TryActionOnOtherPlayerLocal, v_part, "Cut", player_obj, clickedPlayer)
--elseif clickedPlayer.getModData().TOC[v_part].is_operated == false then
operateMenu:addOption(getText('UI_ContextMenu_' .. v_part), worldObjects, TryActionOnOtherPlayerLocal, v_part, "Operate", player_obj, clickedPlayer);
--end
end
end
TocContextMenus.FillCutAndOperateMenus(local_player, clicked_player, worldObjects, cut_menu, operate_menu)
--TocContextMenus.FillCheatMenu(context, cheat_menu)
break
end
@@ -238,6 +194,70 @@ end
TocContextMenus.CreateNewMenu = function(name, context, root_menu)
local new_option = root_menu:addOption(name)
local new_menu = context:getNew(context)
context:addSubMenu(new_option, new_menu)
return new_menu
end
TocContextMenus.FillCutAndOperateMenus = function(local_player, clicked_player, world_objects, cut_menu, operate_menu)
local local_toc_data = local_player:getModData().TOC
for _, v in ipairs(GetBodyParts()) do
if local_player == clicked_player then -- Local player
if TheOnlyCure.CheckIfCanBeCut(local_toc_data, v) then
cut_menu:addOption(getText('UI_ContextMenu_' .. v), _, CutLocal, local_player, local_player, v)
elseif TheOnlyCure.CheckIfCanBeOperated(local_toc_data, v) then
operate_menu:addOption(getText('UI_ContextMenu_' .. v), _, OperateLocal, local_player, local_player, v)
end
else -- Another player
cut_menu:addOption(getText('UI_ContextMenu_' .. v), world_objects, TryTheOnlyCureActionOnAnotherPlayer, v, "Cut", local_player, clicked_player)
operate_menu:addOption(getText('UI_ContextMenu_' .. v), world_objects, TryTheOnlyCureActionOnAnotherPlayer, v, "Operate", local_player, clicked_player)
end
end
end
TocContextMenus.CreateCheatMenu = function(context, root_menu, local_player, clicked_player)
if local_player:getAccessLevel() == "Admin" then
local cheat_menu = TocContextMenus.CreateNewMenu("Cheat", context, root_menu)
if clicked_player == local_player then
cheat_menu:addOption("Reset TOC for me", _, ResetEverything)
else
cheat_menu:addOption("Reset TOC for " .. clicked_player:getUsername(), _, TryToToResetEverythingOtherPlayer, clicked_player, local_player)
end
return cheat_menu
end
end
TocContextMenus.FillCheatMenus = function(context, cheat_menu)
if cheat_menu then
local cheat_cut_and_fix_menu = TocContextMenus.CreateNewMenu("Cut and Fix", context, cheat_menu)
end
end
Events.OnFillWorldObjectContextMenu.Add(TocContextMenus.CreateOperateWithOvenMenu) -- this is probably too much
Events.OnFillWorldObjectContextMenu.Add(TocContextMenus.CreateMenus)

View File

@@ -82,6 +82,7 @@ end
if name == "LeftArm" then return "ArmLeft_Prot" end
end
-- TODO ew
function find_itemWorn_TOC(partName)
local wornItems = getPlayer():getWornItems();
for i=1,wornItems:size()-1 do -- Maybe wornItems:size()-1
@@ -256,10 +257,10 @@ local function setConfirmUI(action)
confirmUI:open()
if action == "Cut" then
if isPlayerHaveBandage() and isPlayerHavePainkiller() then
confirmUI["text2"]:setText("You have bandage and painkiller");
confirmUI["text2"]:setText("You have a bandage and some painkillers");
confirmUI["text2"]:setColor(1, 0, 1, 0);
else
confirmUI["text2"]:setText("You miss bandage or painkiller");
confirmUI["text2"]:setText("You do not have a bandage or painkillers");
confirmUI["text2"]:setColor(1, 1, 0, 0);
end
@@ -329,25 +330,65 @@ function SetConfirmUIMP(action, isBitten, userName, partName)
end
local function setImageMainUI(toc_data)
mainUI["b11"]:setPath(getImageName("RightArm", toc_data));
mainUI["b12"]:setPath(getImageName("LeftArm", toc_data));
mainUI["b21"]:setPath(getImageName("RightForearm", toc_data));
mainUI["b22"]:setPath(getImageName("LeftForearm", toc_data));
if toc_data then
mainUI["b11"]:setPath(getImageName("RightArm", toc_data))
mainUI["b12"]:setPath(getImageName("LeftArm", toc_data))
mainUI["b21"]:setPath(getImageName("RightForearm", toc_data))
mainUI["b22"]:setPath(getImageName("LeftForearm", toc_data))
mainUI["b31"]:setPath(getImageName("RightHand", toc_data))
mainUI["b32"]:setPath(getImageName("LeftHand", toc_data))
end
mainUI["b31"]:setPath(getImageName("RightHand", toc_data));
mainUI["b32"]:setPath(getImageName("LeftHand", toc_data));
end
local function ConfirmPress(button, args)
-- For both SP and MP
local surgeon, patient
if confirmUI.actionAct == "Cut" then
if args.option == "yes" then
ISTimedActionQueue.add(ISCutLimb:new(patient, surgeon, descUI.partNameAct))
else
surgeon:Say("Nevermind")
end
end
if confirmUI.actionAct == "Operate" then
end
end
-- Functions for button of UIs
local function confirmPress(button, args)
local player = getPlayer();
local player = getPlayer()
if confirmUI.actionAct == "Cut" then
if args.option == "yes" then
ISTimedActionQueue.add(ISCutLimb:new(player, player, descUI.partNameAct))
-- TODO this is wrong!
if args.patient ~= args.surgeon then
TryTheOnlyCureActionOnAnotherPlayer(_, descUI.partNameAct, "Cut", args.surgeon, args.patient)
else
ISTimedActionQueue.add(ISCutLimb:new(args.patient, args.surgeon, descUI.partNameAct))
end
else
getPlayer():Say("Never mind");
getPlayer():Say("Nevermind");
end
end
if confirmUI.actionAct == "Operate" then
@@ -355,7 +396,7 @@ local function confirmPress(button, args)
local playerInv = player:getInventory();
local item = playerInv:getItemFromType('TOC.Real_surgeon_kit') or playerInv:getItemFromType('TOC.Surgeon_kit') or playerInv:getItemFromType('TOC.Improvised_surgeon_kit');
if item then
ISTimedActionQueue.add(ISOperateArm:new(player, player, item, descUI.partNameAct, false));
ISTimedActionQueue.add(ISOperateLimb:new(patient, surgeon, item, descUI.partNameAct, false));
else
player:Say("I need a kit");
end
@@ -382,7 +423,7 @@ local function confirmPressMP(button, args)
local item = playerInv:getItemFromType('TOC.Real_surgeon_kit') or playerInv:getItemFromType('TOC.Surgeon_kit') or playerInv:getItemFromType('TOC.Improvised_surgeon_kit');
if item then
getPlayer():Say("Don't move! Ok?");
ISTimedActionQueue.add(ISOperateArm:new(confirmUIMP.patient, player, item, confirmUIMP.partNameAct, false));
ISTimedActionQueue.add(ISOperateLimb:new(confirmUIMP.patient, player, item, confirmUIMP.partNameAct, false));
else
player:Say("I need a kit");
end
@@ -428,21 +469,45 @@ local function descPress(button, args)
end
mainUI:close();
elseif args.option == "Unequip" then
ISTimedActionQueue.add(ISUninstallProthesis:new(player, find_itemWorn_TOC(descUI.partNameAct), player:getBodyDamage():getBodyPart(TOC_getBodyPart(descUI.partNameAct))));
ISTimedActionQueue.add(ISUninstallProsthesis:new(player, find_itemWorn_TOC(descUI.partNameAct), player:getBodyDamage():getBodyPart(TOC_getBodyPart(descUI.partNameAct))));
mainUI:close();
end
end
-- Make the UIS
local function SetCorrectArgsMainUI(toc_data)
local function SetCorrectArgsMainUI(surgeon, patient, toc_data)
-- TODO Make it less shitty
mainUI["b11"]:addArg("toc_data", toc_data)
mainUI["b12"]:addArg("toc_data", toc_data)
mainUI["b21"]:addArg("toc_data", toc_data)
mainUI["b22"]:addArg("toc_data", toc_data)
mainUI["b31"]:addArg("toc_data", toc_data)
mainUI["b32"]:addArg("toc_data", toc_data)
if toc_data then
mainUI["b11"]:addArg("surgeon", surgeon)
mainUI["b11"]:addArg("patient", patient)
mainUI["b11"]:addArg("toc_data", toc_data)
mainUI["b12"]:addArg("toc_data", toc_data)
mainUI["b12"]:addArg("patient", patient)
mainUI["b12"]:addArg("surgeon", surgeon)
mainUI["b21"]:addArg("toc_data", toc_data)
mainUI["b21"]:addArg("patient", patient)
mainUI["b21"]:addArg("surgeon", surgeon)
mainUI["b22"]:addArg("toc_data", toc_data)
mainUI["b22"]:addArg("patient", patient)
mainUI["b22"]:addArg("surgeon", surgeon)
mainUI["b31"]:addArg("toc_data", toc_data)
mainUI["b31"]:addArg("patient", patient)
mainUI["b31"]:addArg("surgeon", surgeon)
mainUI["b32"]:addArg("toc_data", toc_data)
mainUI["b32"]:addArg("patient", patient)
mainUI["b32"]:addArg("surgeon", surgeon)
end
end
@@ -525,9 +590,9 @@ local function makeDescUI()
descUI:saveLayout();
end
local function makeConfirmUI()
local function makeConfirmUI(surgeon, patient)
confirmUI = NewUI();
confirmUI:isSubUIOf(descUI);
confirmUI:isSubUIOf(descUI)
confirmUI:addText("text1", "Are you sure ?", "Title", "Center");
confirmUI:setLineHeightPixel(getTextManager():getFontHeight(confirmUI.text1.font) + 10)
@@ -545,6 +610,8 @@ local function makeConfirmUI()
confirmUI:addEmpty();
confirmUI:addButton("b1", "Yes", confirmPress);
confirmUI.b1:addArg("option", "yes");
confirmUI:addEmpty();
confirmUI:addButton("b2", "No", confirmPress);
confirmUI:addEmpty();
@@ -597,9 +664,9 @@ function OnCreateTheOnlyCureUI()
-- how do we pass the correct player here?
--print(self.character)
makeMainUI();
makeDescUI();
makeConfirmUI();
makeMainUI()
makeDescUI()
makeConfirmUI()
if isClient() then MakeConfirmUIMP() end
mainUI:close()
@@ -612,53 +679,46 @@ Events.OnCreateUI.Add(OnCreateTheOnlyCureUI)
function ISNewHealthPanel.onClick_TOC(button)
-- TODO only visuals work, right now you're gonna cut your own limbs
-- button.character is patient
-- button.otherPlayer is surgeon
if button.otherPlayer then
if button.otherPlayer then
if button.character ~= button.otherPlayer then
sendClientCommand(button.otherPlayer, "TOC", "GetPlayerData", {button.otherPlayer:getOnlineID(), button.character:getOnlineID()})
if MP_other_player_toc_data == nil then
print("MP_other_player_toc_data is still nil")
else
SetCorrectArgsMainUI(MP_other_player_toc_data) --other player is the surgeon
end
SetCorrectArgsMainUI(button.otherPlayer, button.character, MP_other_player_toc_data) --other player is the surgeon
setImageMainUI(MP_other_player_toc_data)
SetCorrectConfirmUI(button.otherPlayer, button.character)
else
SetCorrectArgsMainUI(getPlayer():getModData().TOC) --myself?
SetCorrectArgsMainUI(getPlayer():getModData().TOC) --myself
setImageMainUI(getPlayer():getModData().TOC)
-- TODO this is wrong, we're still checking for the other player... probably?
end
else
SetCorrectArgsMainUI(getPlayer():getModData().TOC) --myself?
SetCorrectArgsMainUI(getPlayer():getModData().TOC) --myself
setImageMainUI(getPlayer():getModData().TOC)
SetCorrectConfirmUI(getPlayer(), getPlayer()) -- TODO just for test
end
mainUI:toggle()
mainUI:setInCenterOfScreen()
end
if button.otherPlayer then
if button.character ~= button.otherPlayer then
sendClientCommand(button.otherPlayer, "TOC", "GetPlayerData", {button.otherPlayer:getOnlineID(), button.character:getOnlineID()})
setImageMainUI(MP_other_player_toc_data)
else
setImageMainUI(getPlayer():getModData().TOC)
end
else
setImageMainUI(getPlayer():getModData().TOC)
end
function SetCorrectConfirmUI(surgeon, patient)
confirmUI.b1:addArg("surgeon", surgeon)
confirmUI.b1:addArg("patient", patient)
end
local ISHealthPanel_createChildren = ISHealthPanel.createChildren
function ISHealthPanel:createChildren()

View File

@@ -2,7 +2,16 @@ if not TheOnlyCure then
TheOnlyCure = {}
end
-- TODO this is gonna break a lot of stuff, don't do this you ass
-- GLOBAL STRINGS
-- TODO Unify Context Menus check with TOC Menu UI
Left = "Left"
Right = "Right"
@@ -116,10 +125,6 @@ function TheOnlyCure.DeclareTraits()
TraitFactory.setMutualExclusive("amputee2", "amputee3")
end
-- ModOptions implement it you cuck
-----------------------------------------------------------------------
function TheOnlyCure.CutLimb(part_name, surgeon_factor, bandage_table, painkiller_table)

View File

@@ -32,6 +32,8 @@ function ISCutLimb:start()
end
-- TODO this doesn't work when doing it online
local body_part_type = TheOnlyCure.GetBodyPartTypeFromBodyPart(self.part_name)
local body_damage = self.patient:getBodyDamage()
local body_damage_part = body_damage:getBodyPart(body_part_type)

View File

@@ -30,7 +30,7 @@ function GetAcceptingProsthesisBodyParts()
end
-- TODO ew
function find_clothName_TOC(bodyPart)
if bodyPart:getType() == BodyPartType.Hand_R then return "TOC.ArmRight_noHand"
elseif bodyPart:getType() == BodyPartType.ForeArm_R then return "TOC.ArmRight_noForearm"