Add ClothingActions

This commit is contained in:
davidh
2022-03-29 21:37:17 -05:00
parent dd7134882c
commit 917d3a88a6
9 changed files with 389 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
------------------------------------------
-- Clothing Actions
------------------------------------------
CARMconfig = {
filter = false,
delay = false
}
local function ClothingActions()
local CARMbindings = {
{
name = '[ClothingActionsRM]'
},
{
name = 'CARM',
key = Keyboard.KEY_Z
}
}
for _, bind in ipairs(CARMbindings) do
if (bind.key or not bind.action) then
table.insert(keyBinding, { value = bind.name, key = bind.key })
end
end
if ModKey then
local CARMMODbindings = {
name = 'CARMMK',
key = 0
}
ModKey:AddBinding(CARMMODbindings)
end
if ModOptions and ModOptions.getInstance then
local function apply(data)
local player = getSpecificPlayer(0)
local values = data.settings.options
CARMconfig.filter = values.filter
CARMconfig.delay = values.delay
end
local CARMCONFIG = {
options_data = {
filter = {
default = false,
name = getText("UI_ModOptions_CARMfilter"),
OnApplyMainMenu = apply,
OnApplyInGame = apply
},
delay = {
default = false,
name = getText("UI_ModOptions_CARMdelay"),
OnApplyMainMenu = apply,
OnApplyInGame = apply
}
},
mod_id = "ClothingActionsRadialMenu",
mod_shortname = "CARM",
mod_fullname = getText("UI_optionscreen_binding_ClothingActionsRM")
}
local optionsInstance = ModOptions:getInstance(CARMCONFIG)
ModOptions:loadFile()
Events.OnGameStart.Add(function()
apply({settings = CARMCONFIG})
end)
end
print(getText("UI_Init_ClothingActionsRM"))
end
ClothingActions()

View File

@@ -0,0 +1,189 @@
------------------------------------------
-- Clothing Actions Radial Menu
------------------------------------------
CARadialMenu = ISBaseObject:derive("CARadialMenu")
------------------------------------------
local CACommand = ISBaseObject:derive("CACommand")
function CACommand:new(menu, item, text, itype, action)
local o = ISBaseObject.new(self)
o.menu = menu
o.player = menu.player
o.item = item
o.text = text
o.itype = itype
o.action = action
return o
end
function CACommand:fillMenu(menu)
menu:addSlice(self.text, self.item:getTexture(), self.invoke, self)
end
function CACommand:invoke()
ISTimedActionQueue.add(ISClothingExtraAction:new(self.player, self.item, self.itype))
end
------------------------------------------
function CARadialMenu:center()
local menu = getPlayerRadialMenu(self.playerNum)
local x = getPlayerScreenLeft(self.playerNum)
local y = getPlayerScreenTop(self.playerNum)
local w = getPlayerScreenWidth(self.playerNum)
local h = getPlayerScreenHeight(self.playerNum)
x = x + w / 2
y = y + h / 2
menu:setX(x - menu:getWidth() / 2)
menu:setY(y - menu:getHeight() / 2)
end
local function checkClothes(item)
-- If there's extra options
if item and item:getClothingItemExtraOption() then
-- Check if we have the filter enabled or clothes, and, item is not watch or filter
if (instanceof(item, "Clothing") or CARMconfig.filter) and (not instanceof(item, "AlarmClockClothing") or CARMconfig.filter) then
return true
end
end
return false
end
function CARadialMenu:fillMenu()
local menu = getPlayerRadialMenu(self.playerNum)
menu:clear()
local commands = {}
local clothes = self.player:getWornItems()
for i=0, clothes:size() - 1 do
local item = clothes:get(i):getItem()
if checkClothes(item) then
for i=0,item:getClothingItemExtraOption():size()-1 do
local action = item:getClothingItemExtraOption():get(i)
local itemType = moduleDotType(item:getModule(), item:getClothingItemExtra():get(i))
table.insert(commands, CACommand:new(self, item, getText("ContextMenu_" .. action), itemType, action))
end
end
end
for _,command in ipairs(commands) do
local count = #menu.slices
command:fillMenu(menu)
if count == #menu.slices then
menu:addSlice(nil, nil, nil)
end
end
end
function CARadialMenu:display()
local menu = getPlayerRadialMenu(self.playerNum)
self:center()
menu:addToUIManager()
if JoypadState.players[self.playerNum+1] then
menu:setHideWhenButtonReleased(Joypad.RBumper)
setJoypadFocus(self.playerNum, menu)
self.player:setJoypadIgnoreAimUntilCentered(true)
end
end
function CARadialMenu:new(player)
local o = ISBaseObject.new(self)
o.player = player
o.playerNum = player:getPlayerNum()
return o
end
local ticks = 0
local wasVisible = false
function CARadialMenu.checkKey(key)
if key ~= getCore():getKey("CARM") then
return false
end
if UIManager.getSpeedControls() and (UIManager.getSpeedControls():getCurrentGameSpeed() == 0) then
return false
end
local player = getSpecificPlayer(0)
if not player or player:isDead() then
return false
end
if player:isSeatedInVehicle() then
return false
end
local queue = ISTimedActionQueue.queues[player]
if queue and #queue.queue > 0 then
return false
end
if getCell():getDrag(0) then
return false
end
return true
end
function CARadialMenu.onKeyPress(key)
if not CARadialMenu.checkKey(key) then
return
end
local radialMenu = getPlayerRadialMenu(0)
if radialMenu:isReallyVisible() and getCore():getOptionRadialMenuKeyToggle() then
wasVisible = true
radialMenu:removeFromUIManager()
return
end
ticks = getTimestampMs()
wasVisible = false
end
function CARadialMenu.onKeyHold(key)
if not CARadialMenu.checkKey(key) then
return
end
if wasVisible then
return
end
local radialMenu = getPlayerRadialMenu(0)
local delay = 500
if CARMconfig.delay then
delay = 0
end
if (getTimestampMs() - ticks >= delay) and not radialMenu:isReallyVisible() then
local menu = CARadialMenu:new(getSpecificPlayer(0))
menu:fillMenu()
menu:display()
end
end
function CARadialMenu.onKeyRelease(key)
if not CARadialMenu.checkKey(key) then
return
end
local radialMenu = getPlayerRadialMenu(0)
if (radialMenu:isReallyVisible() or wasVisible) then
if not getCore():getOptionRadialMenuKeyToggle() then
radialMenu:removeFromUIManager()
end
return
end
end
Events.OnGameStart.Add(function()
Events.OnKeyStartPressed.Add(CARadialMenu.onKeyPress)
Events.OnKeyKeepPressed.Add(CARadialMenu.onKeyHold)
Events.OnKeyPressed.Add(CARadialMenu.onKeyRelease)
end)

View File

@@ -0,0 +1,16 @@
------------------------------------------
-- Clothing Actions Clothing Extra Action override
------------------------------------------
-- I just want to change a few of the init things
local _ISClothingExtraAction_new = ISClothingExtraAction.new
function ISClothingExtraAction:new(...)
local o = _ISClothingExtraAction_new(self, ...)
o.stopOnWalk = false
o.maxTime = 25
o.useProgressBar = false
if o.character:isTimedActionInstant() then
o.maxTime = 1
end
return o
end

View File

@@ -0,0 +1,8 @@
UI_EN = {
UI_Init_ClothingActionsRM = "Hello from Clothing Actions - Radial Menu!",
UI_optionscreen_binding_ClothingActionsRM = "Clothing Actions - Radial Menu",
UI_optionscreen_binding_CARM = "Show Clothing Actions Radial Menu",
UI_optionscreen_binding_CARMMK = "Show Clothing Actions Radial Menu",
UI_ModOptions_CARMfilter = "Disable Clothing Filter (Shows bags, watches, etc)",
UI_ModOptions_CARMdelay = "Show Radial Menu Immediately on Press"
}

View File

@@ -0,0 +1,10 @@
name=Clothing Actions - Radial Menu
id=ClothingActionsRM
authors=dhert
description=A Radial Menu for quick access to equipped clothing actions
pzversion=41
tags=Immersion;Realistic
poster=poster.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 717 KiB

41
ClothingActions/README.md Normal file
View File

@@ -0,0 +1,41 @@
# Clothing Actions - Radial Menu
![poster](Contents/mods/ClothingActions/poster.png)
**Supports B41+. Works in Multiplayer**
A QOL mod for Project Zomboid that displays a Radial Menu for all Extra Clothing Actions that can be performed on currently worn items. Less fumbling through your Inventory!
For example, gives quick access to turn your Hat, put up your Hoodie's Hood, and others!
This mod also adds a timer when performing an Extra Clothing Action instead of it being instant. The time is half of the standard equip time, and actually allows your character to show an equip animation. To compensate for this (small) added time, you can now walk during these actions.
Tested with (and highly recommend!):
- [Authentic Z](https://steamcommunity.com/sharedfiles/filedetails/?id=2335368829)
- [Spongie's Clothing](https://steamcommunity.com/sharedfiles/filedetails/?id=2684285534)
Should work with any other mods that add ExtraClothingOptions to item definitions too.
I'm not sure if this will work with controllers as this is not how I play Project Zomboid. Also, not sure if this will work for other local players (shared screen co-op)
## Configuration
Default keybind is to the "Z" key. Configurable in the "Keybinds" menu.
[ModOptions](https://steamcommunity.com/workshop/filedetails/?id=2169435993) is required for futher configuration, but the mod will function without.
- Disable Clothing Filter
- Default: Disabled
- Disables the filter for clothes. Show Actions on Bags (ex: Fanny Packs) and Watches
- Show Radial Menu Immediately on Press
- Default: Disabled
- Shows Radial Menu when key is pressed. By default, a press and hold is required
## Translations
This mod is currently only in English. If you would like to contribute a translation, please submit a pull request! I will happily credit here and on the Steam Workshop Page!
```
Workshop ID: 2786689104
Mod ID: ClothingActionsRM
```

BIN
ClothingActions/preview.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

View File

@@ -0,0 +1,49 @@
version=1
id=2786689104
title=Clothing Actions - Radial Menu
description=[h1]Supports B41+. Works in Multiplayer[/h1]
description=[h3]A new save is not required[/h3]
description=
description=A QOL mod for Project Zomboid that displays a Radial Menu for all Extra Clothing Actions that can be performed on currently worn items. Less fumbling through your Inventory!
description=
description=For example, gives quick access to turn your Hat, put up your Hoodie's Hood, and others!
description=
description=This mod also adds a timer when performing an Extra Clothing Action instead of it being instant. The time is half of the standard equip time, and actually allows your character to show an equip animation. To compensate for this (small) added time, you can now walk during these actions.
description=
description=Tested with (and highly recommend!):
description=[url=https://steamcommunity.com/sharedfiles/filedetails/?id=2335368829]Authentic Z[/url]
description=[url=https://steamcommunity.com/sharedfiles/filedetails/?id=2684285534]Spongie's Clothing[/url]
description=
description=Should work with any other mods that add ExtraClothingOptions to item definitions too.
description=
description=I'm not sure if this will work with controllers as this is not how I play Project Zomboid. Also, not sure if this will work for other local players (shared screen co-op)
description=
description=[h2]Configuration[/h2]
description=
description=Default keybind is to the "Z" key. Configurable in the "Keybinds" menu.
description=
description=[url=https://steamcommunity.com/workshop/filedetails/?id=2169435993]ModOptions[/url] is required for futher configuration, but the mod will function without.
description=
description=[table]
description=[tr]
description=[th]Name[/th]
description=[th]Default[/th]
description=[th]Description[/th]
description=[/tr]
description=[tr]
description=[td]Disable Clothing Filter[/td]
description=[td]Disabled[/td]
description=[td]Disables the filter for clothes. Show Actions on Bags (ex: Fanny Packs) and Watches[/td]
description=[/tr]
description=[tr]
description=[td]Show Radial Menu Immediately on Press[/td]
description=[td]Disabled[/td]
description=[td]Shows Radial Menu when key is pressed. By default, a press and hold is required[/td]
description=[/tr]
description=[/table]
description=
description=[h2]Translations[/h2]
description=
description=This mod is currently only in English. If you would like to contribute a translation, please submit a pull request on [url=https://github.com/hlfstr/pz-mods]GitHub![/url] I will happily give credit!
tags=Build 41;Interface;Realistic
visibility=friendsOnly