add SpiffUI-Inventory

This commit is contained in:
davidh
2022-04-25 22:46:18 -05:00
parent af774cf5ae
commit d887c29b81
9 changed files with 1381 additions and 0 deletions

View File

@@ -0,0 +1,579 @@
------------------------------------------
-- SpiffUI Main Library
------------------------------------------
-- Authors:
---- @dhert (2022)
------------------------------------------
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
-- The above copyright notice and this permission notice shall be included in all
-- copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
------------------------------------------
------------------------------------------
-- Set the SpiffUI lib version
local SPIFFUI_VERSION = 1 --<<< DO NOT CHANGE UNLESS YOU KNOW WHAT YOU'RE DOING
if SpiffUI then
if SpiffUI.Version >= SPIFFUI_VERSION then
return -- Don't do anything else
else
-- We only want the newest version, and this is it
Events.OnGameBoot.Remove(SpiffUI.firstBoot)
SpiffUI = nil
end
end
------------------------------------------
-- Start SpiffUI
SpiffUI = {}
SpiffUI.Version = SPIFFUI_VERSION
------------------------------------------
-- Register Module
function SpiffUI:Register(name)
if not SpiffUI[name] then
-- Add Key for our module
table.insert(SpiffUI, name)
-- Add module
SpiffUI[name] = {}
end
return SpiffUI[name]
end
------------------------------------------
-- Overrides for already-defined keys
SpiffUI.KeyDefaults = {}
-- Add a new Key Default
function SpiffUI:AddKeyDefault(name, key)
SpiffUI.KeyDefaults[name] = tonumber(key)
end
-- Add an array of keys
---- Expected:
---- binds {
---- ["Name"] = key,
---- }
function SpiffUI:AddKeyDefaults(binds)
for i,j in pairs(binds) do
self:AddKeyDefault(i,j)
end
end
------------------------------------------
-- Keys that will be removed from the binds
SpiffUI.KeyDisables = {}
-- Add a new Key Disable
function SpiffUI:AddKeyDisable(name)
-- We do it where the name is the index to avoid dupes
SpiffUI.KeyDisables[name] = true
end
-- Add an array of keys
---- Expected:
---- binds {
---- ["Name"] = true,
---- }
function SpiffUI:AddKeyDisables(binds)
for i,_ in pairs(binds) do
self:AddKeyDisable(i)
end
end
------------------------------------------
-- New Keys to Add
SpiffUI.KeyBinds = {
{
name = '[SpiffUI]', -- Title
}
}
-- Add a new Key Bind
---- Expected:
---- bind = {
---- name = 'KeyBind', -- Name of Key
---- key = Keyboard.KEY, -- Key
---- qBlock = true, -- Don't perform key action with queue
---- Down = actionDown, -- Action on Down -- Receives playerObj -- Optional
---- Hold = actionHold, -- Action on Hold -- Receives playerObj -- Optional
---- Up = actionUp -- Action on Up -- Receives playerObj -- Optional
---- }
function SpiffUI:AddKeyBind(bind)
--SpiffUI.KeyDefaults[name] = tonumber(key)
table.insert(SpiffUI.KeyBinds, bind)
end
-- Add an array of keys
---- Expected:
---- binds = {
---- {
---- name = 'KeyBind', -- Name of Key
---- key = Keyboard.KEY, -- Key
---- qBlock = true, -- Don't perform key action with queue
---- Down = actionDown, -- Action on Down -- Receives playerObj -- Optional
---- Hold = actionHold, -- Action on Hold -- Receives playerObj -- Optional
---- Up = actionUp -- Action on Up -- Receives playerObj -- Optional
---- },
---- }
function SpiffUI:AddKeyBinds(binds)
for _,j in ipairs(binds) do
self:AddKeyBind(j)
end
end
------------------------------------------
-- Key Handlers
-- Common things to check for when checking a key
---- Returns the player object if successful
SpiffUI.preCheck = function()
local player = getSpecificPlayer(0)
if not player or player:isDead() or player:isAsleep() then
return nil
end
if UIManager.getSpeedControls() and (UIManager.getSpeedControls():getCurrentGameSpeed() == 0) then
return nil
end
return player
end
local function keyDown(key)
local player = SpiffUI.preCheck(key)
if not player then return end
for _,bind in ipairs(SpiffUI.KeyBinds) do
if key == getCore():getKey(bind.name) then
if bind.Down then
local queue = ISTimedActionQueue.queues[player]
if bind.qBlock and queue and #queue.queue > 0 then
return
end
bind.Down(player)
end
break
end
end
end
local function keyHold(key)
local player = SpiffUI.preCheck(key)
if not player then return end
for _,bind in ipairs(SpiffUI.KeyBinds) do
if key == getCore():getKey(bind.name) then
if bind.Hold then
local queue = ISTimedActionQueue.queues[player]
if bind.qBlock and queue and #queue.queue > 0 then
return
end
bind.Hold(player)
end
break
end
end
end
local function keyRelease(key)
local player = SpiffUI.preCheck(key)
if not player then return end
for _,bind in ipairs(SpiffUI.KeyBinds) do
if key == getCore():getKey(bind.name) then
if bind.Up then
local queue = ISTimedActionQueue.queues[player]
if bind.qBlock and queue and #queue.queue > 0 then
return
end
bind.Up(player)
end
break
end
end
end
------------------------------------------
-- Key Action Handlers
---- used mostly for radials
SpiffUI.action = {
ticks = 0,
delay = 500,
ready = true,
wasVisible = false
}
-- onKeyDown starts an action
SpiffUI.onKeyDown = function(player)
-- The radial menu will also close without updating me
---- So we need to catch this
local radialMenu = getPlayerRadialMenu(0)
if SpiffUI.action.ready and (not radialMenu:isReallyVisible() and SpiffUI.action.wasVisible) then
SpiffUI.action.ready = true
end
-- True means we're not doing another action
if SpiffUI.action.ready then
-- Hide Radial Menu on Press if applicable
if radialMenu:isReallyVisible() and getCore():getOptionRadialMenuKeyToggle() then
radialMenu:removeFromUIManager()
setJoypadFocus(player:getPlayerNum(), nil)
SpiffUI.action.wasVisible = false
SpiffUI.action.ready = true
return
end
SpiffUI.action.ticks = getTimestampMs()
SpiffUI.action.ready = false
SpiffUI.action.wasVisible = false
end
end
-- We check here and set our state if true on hold
SpiffUI.holdTime = function()
if SpiffUI.action.ready then return false end
SpiffUI.action.ready = (getTimestampMs() - SpiffUI.action.ticks) >= SpiffUI.action.delay
return SpiffUI.action.ready
end
-- We check here and set our state if true on release
SpiffUI.releaseTime = function()
if SpiffUI.action.ready then return false end
SpiffUI.action.ready = (getTimestampMs() - SpiffUI.action.ticks) < SpiffUI.action.delay
return SpiffUI.action.ready
end
SpiffUI.resetKey = function()
SpiffUI.action.ready = true
end
------------------------------------------
-- ISEquippedItem Buttons
SpiffUI.equippedItem = {
["Inventory"] = true,
["Health"] = true,
["Craft"] = true,
["Movable"] = true,
["Search"] = true,
["Map"] = true,
["MiniMap"] = true,
["Debug"] = true,
["Client"] = true,
["Admin"] = true
}
function SpiffUI:updateEquippedItem()
-- Redo the ISEquippedItem tree based on what we set
local player = getPlayerData(0)
local y = player.equipped.invBtn:getY()
for i,v in pairs(SpiffUI.equippedItem) do
if i == "Inventory" then
player.equipped.invBtn:setVisible(v)
if v then
y = player.equipped.invBtn:getY() + player.equipped.inventoryTexture:getHeightOrig() + 5
end
elseif i == "Health" then
player.equipped.healthBtn:setVisible(v)
player.equipped.healthBtn:setY(y)
if v then
y = player.equipped.healthBtn:getY() + player.equipped.heartIcon:getHeightOrig() + 5
end
elseif i == "Craft" then
player.equipped.craftingBtn:setVisible(v)
player.equipped.craftingBtn:setY(y)
if v then
y = player.equipped.craftingBtn:getY() + player.equipped.craftingIcon:getHeightOrig() + 5
end
elseif i == "Movable" then
player.equipped.movableBtn:setVisible(v)
player.equipped.movableBtn:setY(y)
player.equipped.movableTooltip:setY(y)
player.equipped.movablePopup:setY(y)
if v then
y = player.equipped.movableBtn:getBottom() + 5
end
elseif i == "Search" then
player.equipped.searchBtn:setVisible(v)
player.equipped.searchBtn:setY(y)
if v then
y = player.equipped.searchBtn:getY() + player.equipped.searchIconOff:getHeightOrig() + 5
end
elseif i == "Map" then
if ISWorldMap.IsAllowed() then
player.equipped.mapBtn:setVisible(v)
player.equipped.mapBtn:setY(y)
if ISMiniMap.IsAllowed() then
player.equipped.mapPopup:setY(10 + y)
end
if v then
y = player.equipped.mapBtn:getBottom() + 5
end
end
elseif i == "Debug" then
if getCore():getDebug() or (ISDebugMenu.forceEnable and not isClient()) then
player.equipped.debugBtn:setVisible(v)
player.equipped.debugBtn:setY(y)
if v then
y = player.equipped.debugBtn:getY() + player.equipped.debugIcon:getHeightOrig() + 5
end
end
elseif i == "Client" then
if isClient() then
player.equipped.clientBtn:setVisible(v)
player.equipped.clientBtn:setY(y)
if v then
y = player.equipped.clientBtn:getY() + player.equipped.clientIcon:getHeightOrig() + 5
end
end
elseif i == "Admin" then
if isClient() then
player.equipped.adminBtn:setVisible(v)
player.equipped.adminBtn:setY(y)
end
end
end
end
------------------------------------------
function SpiffUI:OnGameStart()
for _,j in ipairs(SpiffUI) do
local mod = SpiffUI[j]
if mod and mod.Start then
mod.Start()
end
end
Events.OnKeyStartPressed.Add(keyDown)
Events.OnKeyKeepPressed.Add(keyHold)
Events.OnKeyPressed.Add(keyRelease)
self:updateEquippedItem()
end
function SpiffUI:ModOptions()
SpiffUI.config = {}
if ModOptions and ModOptions.getInstance then
local function apply(data)
local options = data.settings.options
-- Set options
end
local SPIFFCONFIG = {
options_data = {
applyNewKeybinds = {
name = "UI_ModOptions_SpiffUI_applyNewKeybinds",
default = false
},
runAllResets = {
name = "UI_ModOptions_SpiffUI_runAllResets",
default = false,
tooltip = "UI_ModOptions_SpiffUI_tooltip_runResets"
}
},
mod_id = "SpiffUI",
mod_shortname = "SpiffUI",
mod_fullname = getText("UI_Name_SpiffUI")
}
local optionsInstance = ModOptions:getInstance(SPIFFCONFIG)
ModOptions:loadFile()
-- Modal for our Apply Defaults key
local applyKeys = optionsInstance:getData("applyNewKeybinds")
function applyKeys:buildString(text,h)
for name,key in pairs(SpiffUI.KeyDefaults) do
text = text .. getText("UI_ModOptions_SpiffUI_Modal_aNKChild", getText("UI_optionscreen_binding_" .. name), getKeyName(key))
h = h + 20
end
return text,h
end
function applyKeys:onUpdate(newValue)
if newValue then
applyKeys:set(false)
local w,h = 350,120
local text = getText("UI_ModOptions_SpiffUI_Modal_applyNewKeybinds")
text,h = self:buildString(text,h)
SpiffUI.settingsModal(w, h, text, self, applyKeys.apply)
end
end
function applyKeys:apply(button)
self.modal = nil
if button.internal == "NO" then
return
end
for name,key in pairs(SpiffUI.KeyDefaults) do
for i,v in ipairs(MainOptions.keyText) do
if not v.value then
if v.txt:getName() == name then
v.keyCode = key
v.btn:setTitle(getKeyName(key))
break
end
end
end
end
getCore():saveOptions()
MainOptions.instance.gameOptions.changed = false
end
local runResets = optionsInstance:getData("runAllResets")
function runResets:buildString(text,h)
for _,j in ipairs(SpiffUI) do
local mod = SpiffUI[j]
if mod and mod.Reset then
if mod.resetDesc then
text = text .. mod.resetDesc
else
text = text .. " <LINE> " .. j
end
h = h + 20
end
end
return text,h
end
function runResets:onUpdate(newValue)
if newValue then
runResets:set(false)
-- quick check if we're in game
local player = getPlayerData(0)
if not player then return end
local w,h = 350,120
local text = getText("UI_ModOptions_SpiffUI_Modal_runResets")
text,h = self:buildString(text,h)
SpiffUI.settingsModal(w, h, text, self, runResets.apply)
end
end
function runResets:apply(button)
self.modal = nil
if button.internal == "NO" then
return
end
for _,j in ipairs(SpiffUI) do
local mod = SpiffUI[j]
if mod and mod.Reset then
mod.Reset()
end
end
MainOptions.instance.gameOptions.changed = false
end
Events.OnPreMapLoad.Add(function()
apply({settings = SPIFFCONFIG})
end)
end
end
-- Due to SpiffUI being loaded as one of the first mods, it will be one of the first to Boot
---- We don't want that, we want this to be last. So, this makes sure of that.
SpiffUI.firstBoot = function()
Events.OnGameBoot.Add(function()
SpiffUI:OnGameBoot()
end)
Events.OnGameBoot.Remove(SpiffUI.firstBoot)
end
function SpiffUI:OnGameBoot()
self:ModOptions()
for _,j in ipairs(SpiffUI) do
local mod = SpiffUI[j]
if mod and mod.Boot then
mod.Boot()
end
end
-- Let's Remove some keys
for name,_ in pairs(SpiffUI.KeyDisables) do
local found = false
for i = 1, #keyBinding do
if keyBinding[i].value == name then
table.remove(keyBinding, i)
print("Removed Keybind: " .. name)
found = true
break
end
end
-- We may have a SpiffUI key we want to remove
if not found then
for i,bind in ipairs(SpiffUI.KeyBinds) do
if bind.name == name then
table.remove(SpiffUI.KeyBinds, i)
print("Removed SpiffUI Keybind: " .. name)
break
end
end
end
end
-- Now let's add ours!
for _, bind in ipairs(SpiffUI.KeyBinds) do
table.insert(keyBinding, { value = bind.name, key = bind.key })
end
-- Events
Events.OnGameStart.Add(function()
SpiffUI:OnGameStart()
end)
Events.OnCreatePlayer.Add(function(id)
SpiffUI:OnCreatePlayer(id)
end)
end
function SpiffUI:OnCreatePlayer(id)
for _,j in ipairs(SpiffUI) do
local mod = SpiffUI[j]
if mod and mod.CreatePlayer then
mod.CreatePlayer(id)
end
end
end
------------------------------------------
SpiffUI.settingsModal = function(w, h, text, key, callback)
key.modal = ISModalRichText:new((getCore():getScreenWidth() / 2) - w / 2,
(getCore():getScreenHeight() / 2) - h / 2, w, h,
text, true, MainOptions.instance, callback)
key.modal:initialise()
key.modal:setCapture(true)
key.modal:setAlwaysOnTop(true)
key.modal:addToUIManager()
if MainOptions.joyfocus then
MainOptions.joyfocus.focus = key.modal
updateJoypadFocus(key.joyfocus)
end
end
------------------------------------------
Events.OnGameBoot.Add(SpiffUI.firstBoot)
-- Hello SpiffUI :)
print(getText("UI_Hello_SpiffUI"))

View File

@@ -0,0 +1,534 @@
------------------------------------------
-- SpiffUI Inventory
------------------------------------------
-- Add module
SpiffUI = SpiffUI or {}
-- Register our inventory
local spiff = SpiffUI:Register("inventory")
------------------------------------------
-- on game start, we take over the Inventory
local function spiffInit(id)
-- We still setup our stuff, but if not enabled nothing happens
local player = getSpecificPlayer(id)
local isMouse = (id == 0) and (not JoypadState.players[1])
local inv = getPlayerInventory(id)
local loot = getPlayerLoot(id)
if spiff.config.enabled then
-- Set the inventories to be closed on start
--local isVis = inv:getIsVisible()
inv:InitSUI()
loot:InitSUI()
end
-- Make them Friends!
inv.friend = loot
loot.friend = inv
if isMouse then
-- Start collapsed tho
inv:Collapse(true, "Start")
loot:Collapse(true, "Start")
end
-- Sometimes we just have to re-run this, nbd
SpiffUI:updateEquippedItem()
end
-- Reset our inventory to the default location
---- This only occurs for user "0" as this is the only user that uses mouse/keys
local function spiffReset()
local isMouse = (not JoypadState.players[1])
if isMouse then
getPlayerInventory(0):SUIReset()
getPlayerLoot(0):SUIReset()
end
end
spiff.CreatePlayer = spiffInit
spiff.Reset = spiffReset
spiff.resetDesc = " <LINE> Inventory Panel Location & Size "
------------------------------------------
function ISInventoryPage:isMouseInBuffer()
if self.resizeWidget2.resizing then return true end
-- So the inventory disappearing isn't so sensitive
local buffer = 32
local boX = buffer * (-1)
local boY = 0 -- can't really go further up at the top
local boW = self:getWidth() + buffer
local boH = self:getHeight() + buffer
local x = self:getMouseX()
local y = self:getMouseY()
return (x >= boX and x <= boW) and (y >= boY and y <= boH)
end
function ISInventoryPage:isMouseIn()
if self.resizeWidget2.resizing then return true end
-- So the inventory disappearing isn't so sensitive
local boX = 0
local boY = 0 -- can't really go further up at the top
local boW = self:getWidth()
local boH = self:getHeight()
local x = self:getMouseX()
local y = self:getMouseY()
return (x >= boX and x <= boW) and (y >= boY and y <= boH)
end
function ISInventoryPage:isMouseInTop()
-- So the inventory disappearing isn't so sensitive
local buffer = 32
local boX = buffer * (-1)
local boY = 0 -- can't really go further up at the top
local boW = self:getWidth() + buffer
local boH = self:titleBarHeight() + buffer
local x = self:getMouseX()
local y = self:getMouseY()
return (x >= boX and x <= boW) and (y >= boY and y <= boH)
end
local _ISInventoryPage_update = ISInventoryPage.update
function ISInventoryPage:update()
if not spiff.config.enabled then
_ISInventoryPage_update(self)
return
end
if not self.isMouse then
_ISInventoryPage_update(self)
------------------------------------------
self.closeButton:setVisible(false)
self.infoButton:setVisible(false)
self.pinButton:setVisible(false)
self.collapseButton:setVisible(false)
self.resizeWidget:setVisible(false)
return
end
if not self.onCharacter then
if self.coloredInv and (self.inventory ~= self.coloredInv or self.isCollapsed) then
if self.coloredInv:getParent() then
self.coloredInv:getParent():setHighlighted(false)
end
self.coloredInv = nil;
end
if not self.isCollapsed and self.inventory:getParent() and (instanceof(self.inventory:getParent(), "IsoObject") or instanceof(self.inventory:getParent(), "IsoDeadBody")) then
self.inventory:getParent():setHighlighted(true, false);
self.inventory:getParent():setHighlightColor(getCore():getObjectHighlitedColor());
self.coloredInv = self.inventory;
end
if not self.isCollapsed and self.inventoryPane.inventory:getType() == "floor" and self.inventoryPane.inventory:getItems():isEmpty() then
if self.autoHide and self.holdOpen and not self.prevMouse then
self:Collapse(true, "No Floor Items")
end
end
end
------------------------------------------
self.collapseCounter = 0
self.wasVisible = not self.isCollapsed
if not self.isCollapsed then
-- When we stop dragging, set panel to close after next mouseout or click, or set to tie with our friend
if not self.fVisible and (not ISMouseDrag.dragging or #ISMouseDrag.dragging == 0) and self.fromDrag then
self.fromDrag = false
self.autoHide = true
self.wasDrag = self.friend.mouseOver
self.holdOpen = not self.wasDrag
end
-- If we're not dragging anything and we're not moused over and not from where we started, close
if not self.fVisible and (not ISMouseDrag.dragging or #ISMouseDrag.dragging == 0) and self.toDrag and not self.mouseOver then
self.toDrag = false
self.autoHide = true
end
-- If we have dragged items, but we're not in our window
if not self.fVisible and (ISMouseDrag.dragging and #ISMouseDrag.dragging > 0) and self.toDrag and not self:isMouseInBuffer() then
self.toDrag = false
self.autoHide = true
end
-- If we're no longer dragging items, but we're still on our window
if not self.fVisible and (not ISMouseDrag.dragging or #ISMouseDrag.dragging == 0) and self.toDrag and self:isMouseInBuffer() then
self.toDrag = false
end
-- If we should autohide
--- prevmouse is to not have this happen immediately, we need a tick for other logic to kick in on state change
--- holdOpen should prevent the window from closing if we click on an object
--- We do this here so we can check the mouse location with our buffer
if not self.fVisible and self.autoHide and not self.prevMouse and not self.holdOpen and not self.fromDrag and not self.toDrag and not self.wasDrag and not self:isMouseInBuffer() then
self:Collapse(true, "Autohide")
end
else
-- If we are dragging items from the other inventory to our window
if not self.fVisible and (ISMouseDrag.dragging and #ISMouseDrag.dragging > 0) and not self.fromDrag and self:isMouseInBuffer() then
self:Collapse(false, "From Drag!")
self.toDrag = true
self.autoHide = true
end
-- If mouse is at the top of the screen, show
if not self.fVisible and not self.toDrag and not self.fromDrag and not isMouseButtonDown(1) then
if not self.friend.wasVisible then
if self:isMouseInTop() then
self:Collapse(false, "MouseMoveIn")
self.autoHide = true
end
else
if self:isMouseIn() then
self:Collapse(false, "MouseMoveInFriend")
self.autoHide = true
end
end
end
if self.fVisible then
self:Collapse(false, "force visible")
end
end
------------------------------------------
if not self.onCharacter then
-- add "remove all" button for trash can/bins
self.removeAll:setVisible(self:isRemoveButtonVisible())
local playerObj = getSpecificPlayer(self.player)
if self.lastDir ~= playerObj:getDir() then
self.lastDir = playerObj:getDir()
self:refreshBackpacks()
elseif self.lastSquare ~= playerObj:getCurrentSquare() then
self.lastSquare = playerObj:getCurrentSquare()
self:refreshBackpacks()
end
-- If the currently-selected container is locked to the player, select another container.
local object = self.inventory and self.inventory:getParent() or nil
if #self.backpacks > 1 and instanceof(object, "IsoThumpable") and object:isLockedToCharacter(playerObj) then
local currentIndex = self:getCurrentBackpackIndex()
local unlockedIndex = self:prevUnlockedContainer(currentIndex, false)
if unlockedIndex == -1 then
unlockedIndex = self:nextUnlockedContainer(currentIndex, false)
end
if unlockedIndex ~= -1 then
self:selectContainer(self.backpacks[unlockedIndex])
if playerObj:getJoypadBind() ~= -1 then
self.backpackChoice = unlockedIndex
end
end
end
end
self:syncToggleStove()
------------------------------------------
self.closeButton:setVisible(false)
self.infoButton:setVisible(false)
self.pinButton:setVisible(false)
self.collapseButton:setVisible(false)
self.resizeWidget:setVisible(false)
end
------------------------------------------
-- ISInventoryPage:setVisible
local _ISInventoryPage_setVisible = ISInventoryPage.setVisible
function ISInventoryPage:setVisible(vis)
if not spiff.config.enabled or not self.isMouse then
_ISInventoryPage_setVisible(self, vis)
return
end
-- This gets called at the start of the game before init, so just don't do anything yet.
if not self.friend then return end
self:Collapse(not vis, "setVisible")
if vis then
--- This is really only called when the world interacts now
--- So let's treat it as such
self.holdOpen = true
self.autoHide = true
end
end
------------------------------------------
-- ISInventoryPage:getIsVisible
local _ISInventoryPage_getIsVisible = ISInventoryPage.getIsVisible
function ISInventoryPage:getIsVisible()
if not spiff.config.enabled or not self.isMouse then
return _ISInventoryPage_getIsVisible(self)
end
return not self.isCollapsed
end
------------------------------------------
-- ISInventoryPage:onMouseMove
local _ISInventoryPage_onMouseMove = ISInventoryPage.onMouseMove
function ISInventoryPage:onMouseMove(...)
if not spiff.config.enabled or not self.isMouse then
_ISInventoryPage_onMouseMove(self, ...)
return
end
-- Disable this
self.collapseCounter = 0
if isGamePaused() then
return
end
-- if we're collapsed and pressing right mouse, we're probably aiming
--- this shouldn't trigger the inventory
if self.isCollapsed and isMouseButtonDown(1) then
return
end
self.mouseOver = true
-- Disable inventory window moving
if self.moving then
self.moving = false
end
-- camera panning
local panCameraKey = getCore():getKey("PanCamera")
if self.isCollapsed and panCameraKey ~= 0 and isKeyDown(panCameraKey) then
return
end
self.fromDrag = false
-- If we are dragging items from this inventory
if (ISMouseDrag.dragging and #ISMouseDrag.dragging > 0) and not self.toDrag and not self.fromDrag then
self.fromDrag = true
end
-- First we touch the window, then close
if self.holdOpen then
self.holdOpen = false
end
self.prevMouse = self.mouseOver
end
------------------------------------------
-- ISInventoryPage:onMouseMoveOutside
local _ISInventoryPage_onMouseMoveOutside = ISInventoryPage.onMouseMoveOutside
function ISInventoryPage:onMouseMoveOutside(...)
if not spiff.config.enabled or not self.isMouse then
_ISInventoryPage_onMouseMoveOutside(self, ...)
return
end
if isGamePaused() then
return
end
self.mouseOver = false;
if self.moving then
self.moving = false
end
if self.wasDrag then
self.wasDrag = self.friend.mouseOver
end
self.prevMouse = self.mouseOver
end
------------------------------------------
-- ISInventoryPage:onMouseDownOutside
local _ISInventoryPage_onMouseDownOutside = ISInventoryPage.onMouseDownOutside
function ISInventoryPage:onMouseDownOutside(...)
if not spiff.config.enabled or not self.isMouse then
_ISInventoryPage_onMouseDownOutside(self, ...)
return
end
if not self.fVisible and not self.isCollapsed and not self:isMouseInBuffer() and not self.fromDrag and not self.toDrag and not self.wasDrag then
self:Collapse(true, "onMouseDownOutside")
end
end
------------------------------------------
-- ISInventoryPage:onRightMouseDownOutside
local _ISInventoryPage_onRightMouseDownOutside = ISInventoryPage.onRightMouseDownOutside
function ISInventoryPage:onRightMouseDownOutside(...)
if not spiff.config.enabled or not self.isMouse then
_ISInventoryPage_onRightMouseDownOutside(self, ...)
return
end
if not self.fVisible and not self.isCollapsed and not self:isMouseInBuffer() and not self.fromDrag and not self.toDrag and not self.wasDrag then
self:Collapse(true, "onRightMouseDownOutside")
end
end
function ISInventoryPage:Collapse(collapse, why)
--if self.isCollapsed == collapse then return end
-- local label
-- if self.onCharacter then
-- label = "Player"
-- else
-- label = "Loot"
-- end
-- if collapse then
-- print("Collapsing: " .. label .. " | " .. why)
-- else
-- print("Showing: " .. label .. " | " .. why)
-- end
-- If we get here and there's no friend, re-run the init
if not self.friend then
spiffInit(self.player)
end
self.isCollapsed = collapse
if self.isCollapsed then
self:setMaxDrawHeight(self:titleBarHeight())
self.holdOpen = false
if spiff.config.enabled then
if self.friend.isCollapsed then
_ISInventoryPage_setVisible(self, false)
_ISInventoryPage_setVisible(self.friend, false)
end
end
else
if isClient() and not self.onCharacter then
self.inventoryPane.inventory:requestSync()
end
self:clearMaxDrawHeight()
self.collapseCounter = 0
if spiff.config.enabled then
_ISInventoryPage_setVisible(self, true)
_ISInventoryPage_setVisible(self.friend, true)
end
end
end
------------------------------------------
-- ISInventoryPage:createChildren
local _ISInventoryPage_createChildren = ISInventoryPage.createChildren
function ISInventoryPage:createChildren()
_ISInventoryPage_createChildren(self)
if spiff.config.enabled and self.isMouse then
self.closeButton:setVisible(false)
self.infoButton:setVisible(false)
self.pinButton:setVisible(false)
self.collapseButton:setVisible(false)
self.resizeWidget:setVisible(false)
self.infoButton:setX(self.closeButton:getX())
self.minimumHeight = getPlayerScreenHeight(self.player) / 4
end
end
function ISInventoryPage:InitSUI()
-- Cache our player
self.playerObj = getSpecificPlayer(self.player)
-- If player is on a controller
self.isMouse = (self.player == 0) and (not JoypadState.players[1])
-- If force visible
self.fVisible = false
-- autohide is used on mouse-over only
self.autoHide = false
-- Used to toggle Autohide until interaction with window
self.holdOpen = false
-- If being dragged to
self.toDrag = false
-- If dragged from here
self.fromDrag = false
-- If was opened from drag
self.wasDrag = false
self.wasVisible = false
end
function ISInventoryPage:SUIReset()
local x = getPlayerScreenLeft(self.player)
local y = getPlayerScreenTop(self.player)
local w = getPlayerScreenWidth(self.player)
local h = getPlayerScreenHeight(self.player)
local divhei = 0
local divwid = 0
divhei = h / 3;
if w < h then
divhei = h / 4;
end
divwid = round(w / 3)
if divwid < 256 + 32 then
-- min width of ISInventoryPage
divwid = 256 + 32
end
if self.onCharacter then
self:setX(x + w / 2 - divwid)
else
self:setX(x + w / 2)
end
self:setY(y)
self:setWidth(divwid)
self:setHeight(divhei)
-- Set the column sizes too!
local column2 = 48
local column3 = (self.width - column2) / 4
local column3 = math.ceil(column3*self.inventoryPane.zoom)
local column3 = (column3) + 100
self.inventoryPane.column2 = column2
self.inventoryPane.column3 = column3
self.inventoryPane.nameHeader:setX(column2)
self.inventoryPane.nameHeader:setWidth((column3 - column2))
self.inventoryPane.typeHeader:setX(column3-1)
self.inventoryPane.typeHeader:setWidth(self.width - column3 + 1)
end
ISInventoryPage.SpiffOnKey = function(playerObj)
local player = getPlayerInventory(0)
local loot = getPlayerLoot(0)
local state = not player.isCollapsed
if not spiff.config.enabled then
state = not player:getIsVisible()
player:setVisible(state)
loot:setVisible(state)
return
end
-- if dragging and tab is pressed, don't do the toggle. it resets the state
if (not ISMouseDrag.dragging or #ISMouseDrag.dragging == 0) then
player:Collapse(state, "Toggle")
loot:Collapse(state, "Toggle")
end
-- still set this tho
player.fVisible = not state
loot.fVisible = not state
end

View File

@@ -0,0 +1,78 @@
------------------------------------------
-- SpiffUI Inventory Module
------------------------------------------
SpiffUI = SpiffUI or {}
-- Register our inventory
local spiff = SpiffUI:Register("inventory")
spiff.config = {
enabled = true
}
local function SpiffUIBoot()
if ModOptions and ModOptions.getInstance then
local function apply(data)
local options = data.settings.options
-- Set options
spiff.config.enabled = options.enableInv
SpiffUI.equippedItem["Inventory"] = not options.hideInv
end
local function applyGame(data)
apply(data)
local options = data.settings.options
SpiffUI:updateEquippedItem()
end
local INVCONFIG = {
options_data = {
enableInv = {
name = "UI_ModOptions_SpiffUI_Inv_enable",
default = true,
tooltip = "UI_ModOptions_SpiffUI_Inv_tooltip_enable",
OnApplyMainMenu = apply,
OnApplyInGame = apply,
},
hideInv = {
name = "UI_ModOptions_SpiffUI_Inv_hideInv",
default = true,
OnApplyMainMenu = apply,
OnApplyInGame = applyGame,
},
},
mod_id = "SpiffUI - Inventory",
mod_shortname = "SpiffUI-Inv",
mod_fullname = getText("UI_Name_SpiffUI_Inv")
}
local optionsInstance = ModOptions:getInstance(INVCONFIG)
ModOptions:loadFile()
Events.OnPreMapLoad.Add(function()
apply({settings = INVCONFIG})
end)
end
local defKeys = {
["Toggle mode"] = Keyboard.KEY_I,
["Toggle Moveable Panel Mode"] = 0
}
SpiffUI:AddKeyDefaults(defKeys)
local keyBind = {
name = 'SpiffUI_Inv',
key = Keyboard.KEY_TAB,
qBlock = false,
Down = ISInventoryPage.SpiffOnKey
}
SpiffUI:AddKeyBind(keyBind)
SpiffUI:AddKeyDisable("Toggle Inventory")
-- Hello :)
print(getText("UI_Hello_SpiffUI_Inv"))
end
spiff.Boot = SpiffUIBoot

View File

@@ -0,0 +1,27 @@
UI_EN = {
-- SpiffUI
UI_Hello_SpiffUI = "Hello SpiffUI!",
UI_Name_SpiffUI = "SpiffUI",
UI_optionscreen_binding_SpiffUI = "SpiffUI"
UI_ModOptions_SpiffUI_applyNewKeybinds = "Set SpiffUI Recommended Keybinds",
UI_ModOptions_SpiffUI_Modal_applyNewKeybinds = "<CENTRE><SIZE:medium> Set SpiffUI Keybinds <LINE><LINE><LEFT><SIZE:small> Sets the following Keybinds: <LINE>",
UI_ModOptions_SpiffUI_Modal_aNKChild = " <LINE> %1 to: [%2] ",
UI_ModOptions_SpiffUI_runAllResets = "Run All SpiffUI Resets",
UI_ModOptions_SpiffUI_tooltip_runResets = "Only works In-Game!",
UI_ModOptions_SpiffUI_Modal_runResets = "<CENTRE><SIZE:medium> SpiffUI Reset <LINE><LINE><LEFT><SIZE:small> The following will be reset: <LINE>",
-- SpiffUI -- Inventory
UI_Hello_SpiffUI_Inv = "Hello SpiffUI - Inventory!",
UI_Name_SpiffUI_Inv = "SpiffUI - Inventory",
UI_ModOptions_SpiffUI_Inv_enable = "Enable SpiffUI Inventory",
UI_ModOptions_SpiffUI_Inv_tooltip_enable = "Note: A Restart is Required if In-Game!",
UI_ModOptions_SpiffUI_Inv_hideInv = "Hide Inventory Button",
UI_optionscreen_binding_SpiffUI_Inv = "Toggle Inventory"
}

View File

@@ -0,0 +1,10 @@
name=SpiffUI - Inventory
id=SpiffUI-Inv
authors=dhert
description=Change the hiding/showing behavior of the Inventory Windows
pzversion=41
tags=Interface
poster=poster.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

View File

@@ -0,0 +1,69 @@
# SpiffUI - Inventory
![poster](Contents/mods/SpiffUI-Inventory/poster.png)
## About SpiffUI
SpiffUI is an attempt to make the Project Zomboid in-game UI more player-friendly. The UI currently acts like a windowing system overtop a video game; similar in behavior to the Openbox/Fluxbox windowing system for a Linux Desktop. This is works as the complexity of the game warrants this, but with little tweaks it can be so much better.
There will be several independent modules released under the SpiffUI name that each change/add their own features.
**Supports B41+. Works in Multiplayer**
## SpiffUI - Inventory
Changes the default behavior of the Loot and Player Inventories in how they are displayed.
For starters, the Inventory and Loot panels are hidden until the player triggers an interaction.
The Inventory is now bound to the "Tab" key by default. Pressing Tab will open/close both the inventory and loot panels for the player, the panels cannot be closed when open in this way until you press the key again.
Bringing the mouse to the top of the screen will show the inventory or loot panel allowing easy access; you can freely switch between which panel is open by moving the mouse. The panel is automatically hidden after losing mouse focus.
Panels are no longer able to be resized horizontally or moved around. They are instead locked to the top of the screen in the default location, and can only be resized vertically. The "Close", "Info", "Collapse", and "Pin" buttons are also hidden.
Clicking on a world container will show the loot panel and lock it open until the window is interacted with, an external mouse click, or if you walk away changing the loot panel to a blank floor.
Even when "hidden", the panels are only a small mouse-movement or key-press away!
Option to Hide the "Inventory" button in the left panel. (I know the keybind, I don't need it)
The Inventory/Loot Panel rules should make sense in normal usage, but may take a small adjustment to your playstyle. Try it for yourself and let me know what you think!
If playing with a controller these rules will not apply.
## SpiffUI Configuration
If ModOptions is installed (Recommended) SpiffUI will appear as a category. This is intended to have common configuration across all of SpiffUI, as well as tools to help configure the game to SpiffUI recommendations.
- Set SpiffUI Recommended Keybinds
- Default: (None) It's a Button!
- Sets keybinds for built-in keys to recommended defaults. A dialog will ask confirming this change, and will display the changes it will make.
- Run All SpiffUI Resets
- Default: (None) It's a Button!
- Runs all "Reset" functions for SpiffUI modules. A user is able to change where the UI is, its size, etc. This will set this to default. A dialog will ask confirming this change, and will display the changes it will make.
- **NOTE:** This will only be usable in-game.
## SpiffUI - Inventory Configuration
- Enable SpiffUI Inventory
- Default: True
- Enables all SpiffUI Inventory changes. Disable to return to all vanilla behavior.
- **NOTE:** A restart will be required if in-game
- Hide Inventory Button
- Default: True
- Hides the Inventory button in the left sidemenu
## Known Issues
- The Dialog Box shown for the SpiffUI options will trigger the game to be unpaused if in-game.
- Controllers do not gain focus to the Settings Dialog; please use a mouse for now.
- Initiating a splitscreen game does not move Player 1's Inventory/Loot panels. This is vanilla behavior, but complicates things as you cannot move these panels with this mod.
## Translations
This mod is currently only in English! If you would like to help with translations, please submit a Pull Request.
```
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -0,0 +1,84 @@
version=1
id=2799848602
title=SpiffUI - Inventory
description=[h1]Supports B41+. Works in Multiplayer[/h1]
description=[h3]A new save is not required[/h3]
description=
description=[h2]About SpiffUI[/h2]
description=
description=SpiffUI is an attempt to make the Project Zomboid in-game UI more player-friendly. The UI currently acts like a windowing system overtop a video game; similar in behavior to the Openbox/Fluxbox windowing system for a Linux Desktop. This is works as the complexity of the game warrants this, but with little tweaks it can be so much better.
description=
description=There will be several independent modules released under the SpiffUI name that each change/add their own features. This allows me to make modifications to these independently, and allow you, the user, to choose which are active.
description=
description=[h2]About SpiffUI[/h2]
description=
description=Changes the default behavior of the Loot and Player Inventories in how they are displayed.
description=
description=For starters, the Inventory and Loot panels are hidden until the player triggers an interaction.
description=
description=The Inventory is now bound to the "Tab" key by default. Pressing Tab will open/close both the inventory and loot panels for the player, the panels cannot be closed when open in this way until you press the key again.
description=
description=Bringing the mouse to the top of the screen will show the inventory or loot panel allowing easy access; you can freely switch between which panel is open by moving the mouse. The panel is automatically hidden after losing mouse focus.
description=
description=Panels are no longer able to be resized horizontally or moved around. They are instead locked to the top of the screen in the default location, and can only be resized vertically. The "Close", "Info", "Collapse", and "Pin" buttons are also hidden.
description=
description=Clicking on a world container will show the loot panel and lock it open until the window is interacted with, an external mouse click, or if you walk away changing the loot panel to a blank floor.
description=
description=Even when "hidden", the panels are only a small mouse-movement or key-press away!
description=
description=Option to Hide the "Inventory" button in the left panel. (I know the keybind, I don't need it)
description=
description=The Inventory/Loot Panel rules should make sense in normal usage, but may take a small adjustment to your playstyle. Try it for yourself and let me know what you think!
description=
description=If playing with a controller these rules will not apply.
description=
description=I HIGHLY recommend that you run both the "Set SpiffUI Recommended Keybinds" and "Run All SpiffUI Resets" after you first install and start the game!
description=
description=[h2]SpiffUI Configuration[/h2]
description=
description=[url=https://steamcommunity.com/workshop/filedetails/?id=2169435993]ModOptions[/url] is required for futher configuration, but the mod will function without.
description=If ModOptions is installed (Recommended) SpiffUI will appear as a category. This is intended to have common configuration across all of SpiffUI, as well as tools to help configure the game to SpiffUI recommendations.
description=
description=[table]
description=[tr]
description=[th]Name[/th]
description=[th]Default[/th]
description=[th]Description[/th]
description=[/tr]
description=[tr]
description=[td]Set SpiffUI Recommended Keybinds[/td]
description=[td](None) It's a Button![/td]
description=[td]Sets keybinds for built-in keys to recommended defaults. A dialog will ask confirming this change, and will display the changes it will make.[/td]
description=[/tr]
description=[tr]
description=[td]Run All SpiffUI Resets[/td]
description=[td](None) It's a Button![/td]
description=[td]Runs all "Reset" functions for SpiffUI modules. A user is able to change where the UI is, its size, etc. This will set this to default. A dialog will ask confirming this change, and will display the changes it will make. PLEASE NOTE: This will only be usable in-game.[/td]
description=[/tr]
description=[/table]
description=
description=[h2]SpiffUI - Inventory Configuration[/h2]
description=
description=[table]
description=[tr]
description=[th]Name[/th]
description=[th]Default[/th]
description=[th]Description[/th]
description=[/tr]
description=[tr]
description=[td]Enable SpiffUI Inventory[/td]
description=[td]True[/td]
description=[td]Enables all SpiffUI Inventory changes. Disable to return to all vanilla behavior. NOTE: A restart will be required if in-game[/td]
description=[/tr]
description=[tr]
description=[td]Hide Inventory Button[/td]
description=[td]True[/td]
description=[td]Hides the Inventory button in the left sidemenu[/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;Framework;Interface;Misc
visibility=friendsOnly