diff --git a/media/lua/client/TOC_API.lua b/media/lua/client/TOC_API.lua new file mode 100644 index 0000000..b54b9c3 --- /dev/null +++ b/media/lua/client/TOC_API.lua @@ -0,0 +1,69 @@ +------------------------------------------ +-- Compatibility Handler by Dhert +------------------------------------------ + +-- TODO Connect this with TOC logic instead of hardcoding it here +local parts = { + "Right_Hand", + "Left_Hand", + "Right_LowerArm", + "Left_LowerArm" +} +-- TODO Connect this with TOC logic instead of hardcoding it here +local vars = { + "isCut", + "isProsthesisEquipped" +} + + +local TOC_Compat = {} + +-- Raw access, must pass valid part +--- @param player IsoPlayer +--- @param part string +--- @return boolean +TOC_Compat.hasArmPart = function(player, part) + if not player or not part then return false end + local data = (player:getModData().TOC and player:getModData().TOC.Limbs) or nil + return not data or not data[part] or (data[part][vars[1]] and data[part][vars[2]]) or not data[part][vars[1]] +end + +-- Raw access, must pass valid parts. Will check for 2 parts (arm and hand) +--- @param player IsoPlayer +--- @param part string +--- @param part2 string +--- @return boolean +TOC_Compat.hasArm = function(player, part, part2) + if not player or not part then return false end + local data = (player:getModData().TOC and player:getModData().TOC.Limbs) or nil + return not data or (not data[part] or (data[part][vars[1]] and data[part][vars[2]]) or not data[part][vars[1]]) or (not data[part] or (data[part2][vars[1]] and data[part2][vars[2]]) or not data[part2][vars[1]]) +end + +-- Check if hand is available +--- @param player IsoPlayer +--- @param left boolean? +--- @return boolean +TOC_Compat.hasHand = function(player, left) + return TOC_Compat.hasArm(player, ((left and parts[2]) or parts[1]), ((left and parts[4]) or parts[3])) +end + +-- Check if both hands are available +--- @param player IsoPlayer +--- @return boolean +TOC_Compat.hasBothHands = function(player) + return TOC_Compat.hasArm(player, parts[1], parts[3]) and TOC_Compat.hasArm(player, parts[2], parts[4]) +end + +-- This returns a number for the hands that you have +----- 11 == both hands +----- 10 == left hand +----- 01 (1) == right hand +----- 00 (0) == no hands +--- @param player IsoPlayer +--- @return integer +TOC_Compat.getHands = function(player) + return ((TOC_Compat.hasArm(player, parts[1], parts[3]) and 1) or 0) + ((TOC_Compat.hasArm(player, parts[2], parts[4]) and 10) or 0) +end + + +return TOC_Compat \ No newline at end of file diff --git a/media/lua/client/UI/TOC_CutLimbHandler.lua b/media/lua/client/UI/TOC_CutLimbHandler.lua index 26b87d4..047fdde 100644 --- a/media/lua/client/UI/TOC_CutLimbHandler.lua +++ b/media/lua/client/UI/TOC_CutLimbHandler.lua @@ -28,13 +28,7 @@ end function CutLimbHandler:addToMenu(context) local types = self:getAllItemTypes(self.items.ITEMS) if #types > 0 then - local option = context:addOption(contextMenuCutLimb, nil) - local subMenu = context:getNew(context) - context:addSubMenu(option, subMenu) - for i=1,#types do - local item = self:getItemOfType(self.items.ITEMS, types[i]) - subMenu:addOption(item:getName(), self, self.onMenuOptionSelected, item:getFullType()) - end + local option = context:addOption(contextMenuCutLimb, self, self.onMenuOptionSelected) end end diff --git a/media/lua/client/UI/TOC_HealthPanel.lua b/media/lua/client/UI/TOC_HealthPanel.lua index 92ad3c8..e5698c7 100644 --- a/media/lua/client/UI/TOC_HealthPanel.lua +++ b/media/lua/client/UI/TOC_HealthPanel.lua @@ -53,4 +53,14 @@ function ISHealthPanel:dropItemsOnBodyPart(bodyPart, items) return end +end + +local og_ISHealthPanel_doBodyPartContextMenu = ISHealthPanel.doBodyPartContextMenu + +function ISHealthPanel:doBodyPartContextMenu(bodyPart, x, y) + og_ISHealthPanel_doBodyPartContextMenu(self, bodyPart, x, y) + local playerNum = self.otherPlayer and self.otherPlayer:getPlayerNum() or self.character:getPlayerNum() + local context = getPlayerContextMenu(playerNum) -- To not recreate it but reuse the one that has been created in the original method + local cutLimbHandler = CutLimbHandler:new(self, bodyPart) + cutLimbHandler:addToMenu(context) end \ No newline at end of file diff --git a/media/lua/shared/Translate/ContextMenu_EN.txt b/media/lua/shared/Translate/ContextMenu_EN.txt new file mode 100644 index 0000000..b680eb8 --- /dev/null +++ b/media/lua/shared/Translate/ContextMenu_EN.txt @@ -0,0 +1,3 @@ +ContextMenu_EN = { + +} diff --git a/media/lua/shared/Translate/UI_EN.txt b/media/lua/shared/Translate/UI_EN.txt new file mode 100644 index 0000000..e51a7fd --- /dev/null +++ b/media/lua/shared/Translate/UI_EN.txt @@ -0,0 +1,2 @@ +UI_EN = { +} \ No newline at end of file