Rewrote all the UI (except for some mp stuff)

This commit is contained in:
Pao
2023-01-15 00:43:25 +01:00
parent 12fd5e0b3c
commit 483d163f43
3 changed files with 32 additions and 806 deletions

View File

@@ -30,12 +30,14 @@ function TryToToResetEverythingOtherPlayer(_, patient, surgeon)
end end
function TryTheOnlyCureActionOnAnotherPlayer(_, part_name, action, surgeon, patient) -- TODO Rename this
function TryTocAction(_, 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 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 -- TODO at this point surgeon doesnt do anything. We'll fix this later
local ui = GetConfirmUIMP() local ui = GetConfirmUIMP()
if not ui then if not ui then
MakeConfirmUIMP() CreateTocConfirmUIMP()
ui = GetConfirmUIMP() ui = GetConfirmUIMP()
end end
@@ -213,15 +215,17 @@ TocContextMenus.FillCutAndOperateMenus = function(local_player, clicked_player,
if local_player == clicked_player then -- Local player if local_player == clicked_player then -- Local player
if TheOnlyCure.CheckIfCanBeCut(local_toc_data, v) then if TheOnlyCure.CheckIfCanBeCut(local_toc_data, v) then
cut_menu:addOption(getText('UI_ContextMenu_' .. v), _, TocCutLocal, local_player, local_player, v) cut_menu:addOption(getText('UI_ContextMenu_' .. v), _, TryTocAction, v, "Cut", local_player, local_player)
--cut_menu:addOption(getText('UI_ContextMenu_' .. v), _, TocCutLocal, local_player, local_player, v)
elseif TheOnlyCure.CheckIfCanBeOperated(local_toc_data, v) then elseif TheOnlyCure.CheckIfCanBeOperated(local_toc_data, v) then
operate_menu:addOption(getText('UI_ContextMenu_' .. v), _, TocOperateLocal, local_player, local_player, v) operate_menu:addOption(getText('UI_ContextMenu_' .. v), _, TryTocAction, v, "Operate", local_player, local_player)
end end
else -- Another player else -- Another player
-- TODO add way to prevent cutting already cut parts -- TODO add way to prevent cutting already cut parts
cut_menu:addOption(getText('UI_ContextMenu_' .. v), world_objects, TryTheOnlyCureActionOnAnotherPlayer, v, "Cut", local_player, clicked_player) cut_menu:addOption(getText('UI_ContextMenu_' .. v), world_objects, TryTocAction, v, "Cut", local_player, clicked_player)
operate_menu:addOption(getText('UI_ContextMenu_' .. v), world_objects, TryTheOnlyCureActionOnAnotherPlayer, v, "Operate", local_player, clicked_player) operate_menu:addOption(getText('UI_ContextMenu_' .. v), world_objects, TryTocAction, v, "Operate", local_player, clicked_player)
end end

View File

@@ -26,10 +26,6 @@ end
----------------------- -----------------------
-- Getters -- Getters
function GetConfirmUI()
return confirm_ui
end
function GetConfirmUIMP() function GetConfirmUIMP()
return confirm_ui_mp; return confirm_ui_mp;
end end
@@ -168,31 +164,23 @@ end
local function OnClickTocDescUI(button, args) local function OnClickTocDescUI(button, args)
-- Gets every arg from main -- Gets every arg from main
local local_player = getPlayer()
local local_player_inventory = local_player:getInventory()
local patient = args.patient local patient = args.patient
local surgeon = args.surgeon local surgeon = args.surgeon
local surgeon_inventory = surgeon:getInventory() local surgeon_inventory = surgeon:getInventory()
-- Validate action
if args.option == "Cut" then if args.option == "Cut" then
TryTocAction(_, desc_ui.part_name, "Cut", surgeon, patient)
if patient == surgeon then
TocCutLocal(_, patient, surgeon, desc_ui.part_name)
else
TryTheOnlyCureActionOnAnotherPlayer(_, desc_ui.part_name, "Cut", surgeon, patient)
end
elseif args.option == "Operate" then elseif args.option == "Operate" then
if patient == surgeon then TryTocAction(_, patient, surgeon, desc_ui.part_name, false)
TocOperateLocal(_, patient, surgeon, desc_ui.part_name, false) -- if patient == surgeon then
else -- TocOperateLocal(_, patient, surgeon, desc_ui.part_name, false)
-- else
TryTheOnlyCureActionOnAnotherPlayer(_, desc_ui.part, "Operate", surgeon, patient) -- TryTocAction(_, desc_ui.part, "Operate", surgeon, patient)
end -- end
elseif args.option == "Equip" then elseif args.option == "Equip" then
-- TODO probably completely broken for MP -- TODO probably completely broken for MP
@@ -243,12 +231,7 @@ end
-----------------------------------------------
-- CREATE UI SECTION -- CREATE UI SECTION
function CreateTocMainUI() function CreateTocMainUI()
@@ -329,7 +312,7 @@ function CreateTocConfirmUIMP()
confirm_ui_mp = NewUI() confirm_ui_mp = NewUI()
confirm_ui_mp.responseReceive = false confirm_ui_mp.responseReceive = false
confirm_ui_mp:addText("text1", "Are you sure ?", "Title", "Center"); confirm_ui_mp:addText("text1", "Are you sure?", "Title", "Center");
confirm_ui_mp:setLineHeightPixel(getTextManager():getFontHeight(confirm_ui_mp.text1.font) + 10) confirm_ui_mp:setLineHeightPixel(getTextManager():getFontHeight(confirm_ui_mp.text1.font) + 10)
confirm_ui_mp:nextLine(); confirm_ui_mp:nextLine();
@@ -366,11 +349,7 @@ end
function OnCreateTheOnlyCureUI() function OnCreateTheOnlyCureUI()
CreateTocMainUI() CreateTocMainUI()
CreateTocDescUI() CreateTocDescUI()
CreateTocConfirmUI() CreateTocConfirmUIMP()
if isClient() then CreateTocConfirmUIMP() end if isClient() then CreateTocConfirmUIMP() end
main_ui:close() main_ui:close()
@@ -517,33 +496,21 @@ function SetupTocDescUI(surgeon, patient, toc_data, part_name)
end end
function SetupTocConfirmUI(surgeon, patient)
-- Add args to button 1, ergo "yes"
confirm_ui.b1:addArg("surgeon", surgeon)
confirm_ui.b1:addArg("patient", patient)
end
-------------------------------------------- --------------------------------------------
-- MP Confirm (I should add it to client too but hey) -- MP Confirm (I should add it to client too but hey not sure how it works tbh)
function SendCommandToConfirmUIMP(action, isBitten, userName, partName) function SendCommandToConfirmUIMP(action, isBitten, userName, partName)
confirm_ui_mp:setInCenterOfScreen() confirm_ui_mp:setInCenterOfScreen()
confirm_ui_mp:bringToTop() confirm_ui_mp:bringToTop()
confirm_ui_mp:open() confirm_ui_mp:open()
if action == "Cut" then
if action == "Cut" or action == "Operate" then
confirm_ui_mp["text4"]:setText("You're gonna " .. action .. " the " .. getDisplayText_TOC(partName) .. " of " .. userName) confirm_ui_mp["text4"]:setText("You're gonna " .. action .. " the " .. getDisplayText_TOC(partName) .. " of " .. userName)
confirm_ui_mp["text3"]:setText("You are well bitten and you have a saw... it's time"); confirm_ui_mp["text2"]:setText("Are you sure?")
confirm_ui_mp["text3"]:setColor(1, 0, 1, 0); confirm_ui_mp["text2"]:setColor(1, 0, 0, 0)
confirm_ui_mp["b1"]:setVisible(true); confirm_ui_mp["b1"]:setVisible(true);
confirm_ui_mp["b2"]:setVisible(true); confirm_ui_mp["b2"]:setVisible(true);
elseif action == "Operate" then
confirm_ui_mp["text4"]:setText("You gonna " .. action .. " the " .. getDisplayText_TOC(partName) .. " of " .. userName)
confirm_ui_mp["text2"]:setText("")
confirm_ui_mp["text3"]:setText("")
confirm_ui_mp["b1"]:setVisible(true)
confirm_ui_mp["b2"]:setVisible(true)
elseif action == "Wait server" then elseif action == "Wait server" then
confirm_ui_mp["text4"]:setText(action) confirm_ui_mp["text4"]:setText(action)
confirm_ui_mp["text3"]:setText("") confirm_ui_mp["text3"]:setText("")
@@ -551,6 +518,8 @@ function SendCommandToConfirmUIMP(action, isBitten, userName, partName)
confirm_ui_mp["b1"]:setVisible(false) confirm_ui_mp["b1"]:setVisible(false)
confirm_ui_mp["b2"]:setVisible(false) confirm_ui_mp["b2"]:setVisible(false)
end end
end end
-------------------------------------------- --------------------------------------------
-- Add TOC element to Health Panel -- Add TOC element to Health Panel
@@ -567,17 +536,17 @@ function ISNewHealthPanel.onClick_TOC(button)
if surgeon then if surgeon then
if surgeon == patient then if surgeon == patient then
SetupTocMainUI(surgeon, surgeon, surgeon:getModData().TOC) SetupTocMainUI(surgeon, surgeon, surgeon:getModData().TOC)
SetupTocConfirmUI(surgeon, surgeon) --SetupTocConfirmUI(surgeon, surgeon)
else else
-- MP stuff, try to get the other player data and display it on the surgeon display -- MP stuff, try to get the other player data and display it on the surgeon display
sendClientCommand(surgeon, "TOC", "GetPlayerData", {surgeon:getOnlineID(), patient:getOnlineID()}) sendClientCommand(surgeon, "TOC", "GetPlayerData", {surgeon:getOnlineID(), patient:getOnlineID()})
SetupTocMainUI(surgeon, patient, MP_other_player_toc_data) SetupTocMainUI(surgeon, patient, MP_other_player_toc_data)
SetupTocConfirmUI(surgeon, patient) --SetupTocConfirmUI(surgeon, patient)
end end
else else
-- This is when surgeon doesnt exist for some reason. -- This is when surgeon doesnt exist for some reason.
SetupTocMainUI(patient, patient, patient:getModData().TOC) SetupTocMainUI(patient, patient, patient:getModData().TOC)
SetupTocConfirmUI(patient, patient) -- SetupTocConfirmUI(patient, patient)
end end
main_ui:toggle() main_ui:toggle()

View File

@@ -1,747 +0,0 @@
local mainUI, descUI, confirmUI, confirmUIMP
function GetConfirmUIMP()
return confirmUIMP;
end
-- Usefull
local function prerenderFuncMP()
local toSee = confirmUIMP;
if confirmUIMP.responseReceive then
if not confirmUIMP.responseCan then
getPlayer():Say("I can't do that !")
confirmUIMP.responseReceive = false;
confirmUIMP:close();
return false;
end
SetConfirmUIMP(confirmUIMP.responseAction, confirmUIMP.responseIsBitten, confirmUIMP.responseUserName, confirmUIMP.responsePartName);
end
end
-- TODO Remove this crap
local function isPlayerHaveSaw()
local playerInv = getPlayer():getInventory();
local item = playerInv:getItemFromType('Saw') or playerInv:getItemFromType('GardenSaw') or playerInv:getItemFromType('Chainsaw');
return item;
end
local function isPlayerHavePainkiller()
local playerInv = getPlayer():getInventory();
local item = playerInv:getItemFromType('Pills');
return item;
end
local function isPlayerHaveBandage()
local playerInv = getPlayer():getInventory();
local item = playerInv:getItemFromType('AlcoholBandage') or playerInv:getItemFromType('Bandage');
return item;
end
local function getImageName(part_name, toc_data)
local part_data = toc_data[part_name];
local name = ""
if part_data.is_cut and part_data.is_cicatrized and part_data.is_prosthesis_equipped then -- Cut and equip
if part_name == "RightHand" or part_name == "LeftHand" then
name = "media/ui/TOC/" .. part_name .. "/Hook.png"
else
name = "media/ui/TOC/" .. part_name .. "/Prothesis.png"
end
elseif part_data.is_cut and part_data.is_cicatrized and not part_data.is_prosthesis_equipped and part_data.is_amputation_shown then -- Cut and heal
name = "media/ui/TOC/" .. part_name .. "/Cut.png"
elseif part_data.is_cut and not part_data.is_cicatrized and part_data.is_amputation_shown and not part_data.is_operated then -- Cut not heal
name = "media/ui/TOC/" .. part_name .. "/Bleed.png"
elseif part_data.is_cut and not part_data.is_cicatrized and part_data.is_amputation_shown and part_data.is_operated then -- Cut not heal
name = "media/ui/TOC/" .. part_name .. "/Operate.png"
elseif part_data.is_cut and not part_data.is_amputation_shown then -- Empty (like hand if forearm cut)
name = "media/ui/TOC/Empty.png"
elseif not part_data.is_cut and getPlayer():getBodyDamage():getBodyPart(TheOnlyCure.GetBodyPartTypeFromBodyPart(part_name)):bitten() then -- Not cut but bitten
name = "media/ui/TOC/" .. part_name .. "/Bite.png"
else -- Not cut
name = "media/ui/TOC/" .. part_name .. "/Base.png"
end
-- If foreaerm equip, change hand
if part_name == "RightHand" and toc_data["RightForearm"].is_prosthesis_equipped then
name = "media/ui/TOC/" .. part_name .. "/Hook.png"
elseif part_name == "LeftHand" and toc_data["LeftForearm"].is_prosthesis_equipped then
name = "media/ui/TOC/" .. part_name .. "/Hook.png"
end
return name;
end
local function partNameToBodyLoc(name)
if name == "RightHand" then return "ArmRight_Prot" end
if name == "RightForearm" then return "ArmRight_Prot" end
if name == "RightArm" then return "ArmRight_Prot" end
if name == "LeftHand" then return "ArmLeft_Prot" end
if name == "LeftForearm" then return "ArmLeft_Prot" 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
local item = wornItems:get(i):getItem();
if item:getBodyLocation() == partNameToBodyLoc(partName) then
return item;
end
end
return false;
end
local function findMinMax(lv)
local min, max
if lv == 1 then
min = 0;
max = 75;
elseif lv == 2 then
min = 75;
max = 150 + 75;
elseif lv == 3 then
min = 150;
max = 300 + 75 + 150;
elseif lv == 4 then
min = 300;
max = 750 + 75 + 150 + 300;
elseif lv == 5 then
min = 750;
max = 1500 + 75 + 150 + 300 + 750;
elseif lv == 6 then
min = 1500;
max = 3000 + 75 + 150 + 300 + 750 + 1500;
elseif lv == 7 then
min = 3000;
max = 4500 + 75 + 150 + 300 + 750 + 1500 + 3000;
elseif lv == 8 then
min = 4500;
max = 6000 + 75 + 150 + 300 + 750 + 1500 + 3000 + 4500;
elseif lv == 9 then
min = 6000;
max = 7500 + 75 + 150 + 300 + 750 + 1500 + 3000 + 4500 + 6000;
elseif lv == 10 then
min = 7500;
max = 9000 + 75 + 150 + 300 + 750 + 1500 + 3000 + 4500 + 6000 + 7500;
end
return min, max;
end
-- end Usefull
-- Function to update text/button of UIs
local function setDescUI(toc_data, part_name)
--we can easily fix this crap from here for MP compat
-- forces sync?
--local player_obj = getSpecificPlayer(player)
-- TODO set correct player
--local testModData = player:getModData()
local part_data = toc_data[part_name]
descUI["textTitle"]:setText(getDisplayText_TOC(part_name))
descUI.partNameAct = part_name
-- Cut and equip
if part_data.is_cut and part_data.is_cicatrized and part_data.is_prosthesis_equipped then
descUI["textEtat"]:setText("Cut and healed")
descUI["textEtat"]:setColor(1, 0, 1, 0)
descUI["b1"]:setText("Unequip")
descUI["b1"]:addArg("option", "Unequip")
descUI["b1"]:setVisible(true)
-- Cut and healed
elseif part_data.is_cut and part_data.is_cicatrized and not part_data.is_prosthesis_equipped and part_data.is_amputation_shown then
descUI["textEtat"]:setText("Cut and healed");
descUI["textEtat"]:setColor(1, 0, 1, 0);
if part_name == "RightArm" or part_name == "LeftArm" then
descUI["b1"]:setVisible(false);
else
descUI["b1"]:setText("Equip");
descUI["b1"]:addArg("option", "Equip");
descUI["b1"]:setVisible(true);
end
-- Cut but not healed
elseif part_data.is_cut and not part_data.is_cicatrized and part_data.is_amputation_shown then
if part_data.is_operated then
if part_data.cicatrization_time > 1000 then
descUI["textEtat"]:setText("Still a long way to go")
descUI["textEtat"]:setColor(1, 0.8, 1, 0.2);
elseif part_data.cicatrization_time > 500 then
descUI["textEtat"]:setText("Starting to get better")
descUI["textEtat"]:setColor(1, 0.8, 1, 0.2)
elseif part_data.cicatrization_time > 100 then
descUI["textEtat"]:setText("Almost cicatrized");
descUI["textEtat"]:setColor(1, 0.8, 1, 0.2);
end
else
if part_data.cicatrization_time > 1000 then
descUI["textEtat"]:setText("It hurts so much...")
descUI["textEtat"]:setColor(1, 1, 0, 0)
elseif part_data.cicatrization_time > 500 then
descUI["textEtat"]:setText("It still hurts a lot")
descUI["textEtat"]:setColor(1, 0.8, 1, 0.2)
elseif part_data.cicatrization_time > 500 then
descUI["textEtat"]:setText("I think it's almost over...")
descUI["textEtat"]:setColor(1, 0.8, 1, 0.2)
end
end
-- Set visibility
if part_data.is_operated then
descUI["b1"]:setVisible(false);
else
descUI["b1"]:setText("Operate");
descUI["b1"]:addArg("option", "Operate");
descUI["b1"]:setVisible(true);
end
elseif part_data.is_cut and not part_data.is_amputation_shown then -- Empty (hand if forearm cut)
descUI["textEtat"]:setText("Nothing here...");
descUI["textEtat"]:setColor(1, 1, 1, 1);
descUI["b1"]:setVisible(false);
elseif not part_data.is_cut and getPlayer():getBodyDamage():getBodyPart(TOC_getBodyPart(part_name)):bitten() then --TODO fix for MP
descUI["textEtat"]:setText("Bitten...");
descUI["textEtat"]:setColor(1, 1, 0, 0);
if isPlayerHaveSaw() then
descUI["b1"]:setVisible(true);
descUI["b1"]:setText("Cut");
descUI["b1"]:addArg("option", "Cut");
else
descUI["b1"]:setVisible(false);
end
elseif not part_data.is_cut then -- Not cut
descUI["textEtat"]:setText("Not cut");
descUI["textEtat"]:setColor(1, 1, 1, 1);
if isPlayerHaveSaw() then
descUI["b1"]:setVisible(true);
descUI["b1"]:setText("Cut");
descUI["b1"]:addArg("option", "Cut");
else
descUI["b1"]:setVisible(false);
end
end
-- Set text for level
local player = getPlayer()
if string.find(part_name, "Right") then
local lv = player:getPerkLevel(Perks.RightHand) + 1;
descUI["textLV2"]:setText("Level: " .. lv .. " / 10");
local xp = player:getXp():getXP(Perks.RightHand);
local min, max = findMinMax(lv);
descUI["pbarNLV"]:setMinMax(min, max);
descUI["pbarNLV"]:setValue(xp);
else
local lv = player:getPerkLevel(Perks.LeftHand) + 1;
descUI["textLV2"]:setText("Level: " .. lv .. " / 10");
local xp = player:getXp():getXP(Perks.LeftHand);
local min, max = findMinMax(lv);
descUI["pbarNLV"]:setMinMax(min, max);
descUI["pbarNLV"]:setValue(xp);
end
end
local function setConfirmUI(action)
confirmUI.actionAct = action;
confirmUI:setInCenterOfScreen();
confirmUI:bringToTop()
confirmUI:open()
if action == "Cut" then
if isPlayerHaveBandage() and isPlayerHavePainkiller() then
confirmUI["text2"]:setText("You have a bandage and some painkillers");
confirmUI["text2"]:setColor(1, 0, 1, 0);
else
confirmUI["text2"]:setText("You do not have a bandage or painkillers");
confirmUI["text2"]:setColor(1, 1, 0, 0);
end
local bitten_status = getPlayer():getBodyDamage():getBodyPart(TheOnlyCure.GetBodyPartTypeFromBodyPart(descUI.partNameAct)):bitten()
if isPlayerHaveSaw() and bitten_status then
confirmUI["text3"]:setText("You are bitten and you have a saw... it's time");
confirmUI["text3"]:setColor(1, 0, 1, 0);
elseif isPlayerHaveSaw() and not bitten_status then
confirmUI["text3"]:setText("What are you doing? You're okay!");
confirmUI["text3"]:setColor(1, 1, 0, 0);
else
confirmUI["text3"]:setText("You miss a saw");
confirmUI["text3"]:setColor(1, 1, 0, 0);
end
elseif action == "Operate" then
confirmUI["text2"]:setText("");
confirmUI["text3"]:setText("You are going to operate " .. getDisplayText_TOC(descUI.partNameAct));
confirmUI["text3"]:setColor(1, 1, 1, 1);
end
end
function SetConfirmUIMP(action, isBitten, userName, partName)
confirmUIMP:setInCenterOfScreen();
confirmUIMP:bringToTop();
confirmUIMP:open();
if action == "Cut" then
confirmUIMP["text4"]:setText("You're gonna " .. action .. " the " .. getDisplayText_TOC(partName) .. " of " .. userName);
if isPlayerHaveBandage() and isPlayerHavePainkiller() then
confirmUIMP["text2"]:setText("You have bandage and painkiller");
confirmUIMP["text2"]:setColor(1, 0, 1, 0);
else
confirmUIMP["text2"]:setText("You miss bandage or painkiller");
confirmUIMP["text2"]:setColor(1, 1, 0, 0);
end
if isPlayerHaveSaw() and isBitten then
confirmUIMP["text3"]:setText("You are well bitten and you have a saw... it's time");
confirmUIMP["text3"]:setColor(1, 0, 1, 0);
confirmUIMP["b1"]:setVisible(true);
confirmUIMP["b2"]:setVisible(true);
elseif isPlayerHaveSaw() and not isBitten then
confirmUIMP["text3"]:setText("What are you doing? You're okay !");
confirmUIMP["text3"]:setColor(1, 1, 0, 0);
confirmUIMP["b1"]:setVisible(true);
confirmUIMP["b2"]:setVisible(true);
else
confirmUIMP["text3"]:setText("You're missing a saw");
confirmUIMP["text3"]:setColor(1, 1, 0, 0);
confirmUIMP["b1"]:setVisible(false);
confirmUIMP["b2"]:setVisible(true);
end
elseif action == "Operate" then
confirmUIMP["text4"]:setText("You gonna " .. action .. " the " .. getDisplayText_TOC(partName) .. " of " .. userName);
confirmUIMP["text2"]:setText("");
confirmUIMP["text3"]:setText("");
confirmUIMP["b1"]:setVisible(true);
confirmUIMP["b2"]:setVisible(true);
elseif action == "Wait server" then
confirmUIMP["text4"]:setText(action);
confirmUIMP["text3"]:setText("");
confirmUIMP["text2"]:setText("");
confirmUIMP["b1"]:setVisible(false);
confirmUIMP["b2"]:setVisible(false);
end
end
local function setImageMainUI(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
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()
if confirmUI.actionAct == "Cut" then
if args.option == "yes" then
-- 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("Nevermind");
end
end
if confirmUI.actionAct == "Operate" then
if args.option == "yes" then
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(ISOperateLimb:new(patient, surgeon, item, descUI.partNameAct, false));
else
player:Say("I need a kit");
end
else
getPlayer():Say("Never mind");
end
end
mainUI:close();
end
local function confirmPressMP(button, args)
local player = getPlayer();
if confirmUIMP.actionAct == "Cut" then
if args.option == "yes" then
getPlayer():Say("Hold on, I believe in you!");
ISTimedActionQueue.add(ISCutLimb:new(confirmUIMP.patient, player, confirmUIMP.partNameAct));
else
getPlayer():Say("Alright...");
end
end
if confirmUIMP.actionAct == "Operate" then
if args.option == "yes" then
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
getPlayer():Say("Don't move! Ok?");
ISTimedActionQueue.add(ISOperateLimb:new(confirmUIMP.patient, player, item, confirmUIMP.partNameAct, false));
else
player:Say("I need a kit");
end
else
getPlayer():Say("Never mind");
end
end
confirmUIMP:close();
confirmUIMP.responseReceive = false;
end
local function mainPress(button, args)
descUI:open()
descUI:setPositionPixel(mainUI:getRight(), mainUI:getY())
setDescUI(args.toc_data, args.part)
end
local function descPress(button, args)
local player = getPlayer();
local playerInv = player:getInventory();
if args.option == "Cut" then
-- TODO Change to correct player
local modData = player:getModData().TOC;
-- Do not cut if prothesis equip
if (string.find(descUI.partNameAct, "Right") and (modData["RightHand"].is_prosthesis_equipped or modData["RightForearm"].is_prosthesis_equipped))
or (string.find(descUI.partNameAct, "Left") and (modData["LeftHand"].is_prosthesis_equipped or modData["LeftForearm"].is_prosthesis_equipped)) then
player:Say("I need to remove my prosthesis first");
mainUI:close();
return false;
end
setConfirmUI("Cut");
elseif args.option == "Operate" then
setConfirmUI("Operate");
elseif args.option == "Equip" then
-- TODO this is really janky
local item = playerInv:getItemFromType('TOC.MetalHand') or playerInv:getItemFromType('TOC.MetalHook') or playerInv:getItemFromType('TOC.WoodenHook');
if item then
ISTimedActionQueue.add(ISInstallProsthesis:new(player, item, player:getBodyDamage():getBodyPart(TOC_getBodyPart(descUI.partNameAct))))
else
player:Say("I need a prosthesis");
end
mainUI:close();
elseif args.option == "Unequip" then
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(surgeon, patient, toc_data)
-- TODO Make it less shitty
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
local function makeMainUI(regen)
mainUI = NewUI()
mainUI:setTitle("The Only Cure Menu");
mainUI:setWidthPercent(0.1);
mainUI:addImageButton("b11", "", mainPress)
mainUI["b11"]:addArg("part", "RightArm")
--mainUI["b11"]:addArg("player", character)
mainUI:addImageButton("b12", "", mainPress);
mainUI["b12"]:addArg("part", "LeftArm");
--mainUI["b12"]:addArg("player", character)
mainUI:nextLine();
mainUI:addImageButton("b21", "", mainPress);
mainUI["b21"]:addArg("part", "RightForearm");
--mainUI["b21"]:addArg("player", character)
mainUI:addImageButton("b22", "", mainPress);
mainUI["b22"]:addArg("part", "LeftForearm");
--mainUI["b22"]:addArg("player", character)
mainUI:nextLine();
mainUI:addImageButton("b31", "", mainPress);
mainUI["b31"]:addArg("part", "RightHand");
--mainUI["b31"]:addArg("player", character)
mainUI:addImageButton("b32", "", mainPress);
mainUI["b32"]:addArg("part", "LeftHand");
--mainUI["b32"]:addArg("player", character)
mainUI:saveLayout();
end
local function makeDescUI()
descUI = NewUI();
descUI:setTitle("The only cure description");
descUI:isSubUIOf(mainUI);
descUI:setWidthPixel(250);
descUI:setColumnWidthPixel(1, 100);
descUI:addText("textTitle", "Right arm", "Large", "Center");
descUI:nextLine();
descUI:addText("textLV2", "Level 3/10", _, "Center");
descUI:nextLine();
descUI:addText("textLV", "Next LV:", _, "Right");
descUI:addProgressBar("pbarNLV", 39, 0, 100);
descUI["pbarNLV"]:setMarginPixel(10, 6);
descUI:nextLine();
descUI:addEmpty("border1");
descUI:setLineHeightPixel(1);
descUI["border1"]:setBorder(true);
descUI:nextLine();
descUI:addEmpty();
descUI:nextLine();
descUI:addText("textEtat", "Is Cut!", "Medium", "Center");
descUI["textEtat"]:setColor(1, 1, 0, 0);
descUI:nextLine();
descUI:addEmpty();
descUI:nextLine();
descUI:addButton("b1", "Operate", descPress);
descUI:saveLayout();
end
local function makeConfirmUI(surgeon, patient)
confirmUI = NewUI();
confirmUI:isSubUIOf(descUI)
confirmUI:addText("text1", "Are you sure ?", "Title", "Center");
confirmUI:setLineHeightPixel(getTextManager():getFontHeight(confirmUI.text1.font) + 10)
confirmUI:nextLine();
confirmUI:addText("text2", "", _, "Center");
confirmUI:nextLine();
confirmUI:addText("text3", "", _, "Center");
confirmUI:nextLine();
confirmUI:addEmpty();
confirmUI:nextLine();
confirmUI:addEmpty();
confirmUI:addButton("b1", "Yes", confirmPress);
confirmUI.b1:addArg("option", "yes");
confirmUI:addEmpty();
confirmUI:addButton("b2", "No", confirmPress);
confirmUI:addEmpty();
confirmUI:nextLine();
confirmUI:addEmpty();
confirmUI:saveLayout();
end
function MakeConfirmUIMP()
confirmUIMP = NewUI();
confirmUIMP.responseReceive = false;
confirmUIMP:addText("text1", "Are you sure ?", "Title", "Center");
confirmUIMP:setLineHeightPixel(getTextManager():getFontHeight(confirmUIMP.text1.font) + 10)
confirmUIMP:nextLine();
confirmUIMP:addText("text4", "", "Medium", "Center");
confirmUIMP:setLineHeightPixel(getTextManager():getFontHeight(confirmUIMP.text4.font) + 10)
confirmUIMP:nextLine();
confirmUIMP:addText("text2", "", _, "Center");
confirmUIMP:nextLine();
confirmUIMP:addText("text3", "", _, "Center");
confirmUIMP:nextLine();
confirmUIMP:addEmpty();
confirmUIMP:nextLine();
confirmUIMP:addEmpty();
confirmUIMP:addButton("b1", "Yes", confirmPressMP);
confirmUIMP.b1:addArg("option", "yes");
confirmUIMP:addEmpty();
confirmUIMP:addButton("b2", "No", confirmPressMP);
confirmUIMP:addEmpty();
confirmUIMP:nextLine();
confirmUIMP:addEmpty();
confirmUIMP:saveLayout();
confirmUIMP:addPrerenderFunction(prerenderFuncMP);
confirmUIMP:close();
end
function OnCreateTheOnlyCureUI()
-- how do we pass the correct player here?
--print(self.character)
makeMainUI()
makeDescUI()
makeConfirmUI()
if isClient() then MakeConfirmUIMP() end
mainUI:close()
end
Events.OnCreateUI.Add(OnCreateTheOnlyCureUI)
-- Add button to health panel
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.character ~= button.otherPlayer then
sendClientCommand(button.otherPlayer, "TOC", "GetPlayerData", {button.otherPlayer:getOnlineID(), button.character:getOnlineID()})
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
setImageMainUI(getPlayer():getModData().TOC)
-- TODO this is wrong, we're still checking for the other player... probably?
end
else
SetCorrectArgsMainUI(getPlayer():getModData().TOC) --myself
setImageMainUI(getPlayer():getModData().TOC)
SetCorrectConfirmUI(getPlayer(), getPlayer()) -- TODO just for test
end
mainUI:toggle()
mainUI:setInCenterOfScreen()
end
function SetCorrectConfirmUI(surgeon, patient)
confirmUI.b1:addArg("surgeon", surgeon)
confirmUI.b1:addArg("patient", patient)
end
local ISHealthPanel_createChildren = ISHealthPanel.createChildren
function ISHealthPanel:createChildren()
ISHealthPanel_createChildren(self);
self.fitness:setWidth(self.fitness:getWidth()/1.5);
--TODO make it bigger
self.TOCButton = ISButton:new(self.fitness:getRight(), self.healthPanel.y, 20, 20, "", self, ISNewHealthPanel.onClick_TOC)
self.TOCButton:setImage(getTexture("media/ui/TOC/iconForMenu.png"))
self.TOCButton.anchorTop = false
self.TOCButton.anchorBottom = true
self.TOCButton:initialise();
self.TOCButton:instantiate();
self:addChild(self.TOCButton);
if getCore():getGameMode() == "Tutorial" then
self.TOCButton:setVisible(false);
end
end
local ISHealthPanel_render = ISHealthPanel.render
function ISHealthPanel:render()
ISHealthPanel_render(self);
self.TOCButton:setY(self.fitness:getY());
end