Skip to content

Commit

Permalink
v1.16.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaakma committed Sep 24, 2023
1 parent 5cb0016 commit ecee040
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ local MAX_CAPACITY = 65535
---@field item tes3misc
---@field containerConfig CarryableContainer.containerConfig
---@field data table
---@field filter CarryableContainers.ItemFilter|nil
local CarryableContainer = ItemInstance:new()

---Get a container by its base itemId
Expand Down Expand Up @@ -151,7 +152,7 @@ function CarryableContainer:open()
end
end

function CarryableContainer:recalculateEncumbrance()
function CarryableContainer.recalculateEncumbrance()
local burden = tes3.getEffectMagnitude{reference = tes3.mobilePlayer, effect = tes3.effect.burden}
local feather = tes3.getEffectMagnitude{reference = tes3.mobilePlayer, effect = tes3.effect.feather}
local weight = tes3.player.object.inventory:calculateWeight() + burden - feather
Expand Down Expand Up @@ -199,7 +200,7 @@ function CarryableContainer:updateStats()
self.item.weight = totalWeight
self.item.value = math.floor(totalValue)

self:recalculateEncumbrance()
CarryableContainer.recalculateEncumbrance()
end

function CarryableContainer:isCopy()
Expand Down Expand Up @@ -438,9 +439,9 @@ function CarryableContainer:pickup(e)
return
end

local function stealActivateEvent(e)
local function stealActivateEvent(e2)
event.unregister("activate", stealActivateEvent)
e.claim = true
e2.claim = true
end

local function blockSound()
Expand Down Expand Up @@ -563,7 +564,7 @@ function CarryableContainer:checkAndBlockTransfer()
end

---@class CarryableContainer.openRenameMenu.params
---@field menuModeStaysOpen boolean If true, the menu will stay open after the button is pressed
---@field menuModeStaysOpen boolean? If true, the menu will stay open after the button is pressed
---@field callback fun() Callback function to run after the renaming is complete

---@param e? CarryableContainer.openRenameMenu.params
Expand Down
64 changes: 64 additions & 0 deletions Data Files/MWSE/mods/CraftingFramework/components/MessageMenu.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
local Util = require("CraftingFramework.util.Util")
local Indicator = require("CraftingFramework.components.Indicator")
local logger = Util.createLogger("MessageMenu")
local config = require("CraftingFramework.config")

---@class CraftingFramework.MessageMenu.button : tes3ui.showMessageMenu.params.button
---@field position number @The position of this button in the list of buttons, starting at 0 for the first button.


---@class CraftingFramework.MessageMenu.data
---@field id string The unique ID for this Message Menu
---@field message string
---@field buttons CraftingFramework.MessageMenu.button[]
---@field cancels? boolean
---@field priority? number The priority of this registration of the message menu. When multiple menus with this id are registered, the message and configuration options of the highest priority one will be used.

---@class CraftingFramework.MessageMenu : CraftingFramework.MessageMenu.data
local MessageMenu = {
registeredMenus = {}
}

---@param list1 CraftingFramework.MessageMenu.button[]
---@param list2 CraftingFramework.MessageMenu.button[]
function MessageMenu.mergeButtons(list1, list2)
local merged = {}
for _, button in ipairs(list1) do
local position = button.position or 0
table.insert(merged, position, button)
end

end

---@param data CraftingFramework.MessageMenu.data
function MessageMenu.register(data)
logger:assert(type(data.id) == "string", "id must be a string")
logger:assert(type(data.message) == "string", "message must be a string")
logger:assert(type(data.buttons) == "table", "buttons must be a table")

local messageMenu = {}
messageMenu.id = data.id
messageMenu.message = data.message
messageMenu.buttons = data.buttons
messageMenu.cancels = not not data.cancels
messageMenu.priority = data.priority or 0

local existingMenu = MessageMenu.registeredMenus[messageMenu.id]
if existingMenu then
if existingMenu.priority > messageMenu.priority then
logger:debug("Existing menu has higher priority, using those configs")
messageMenu.message = existingMenu.message
messageMenu.cancels = existingMenu.cancels
messageMenu.priority = existingMenu.priority
end
--Merging buttons
local higherPriorityMenu = existingMenu.priority > messageMenu.priority and existingMenu or messageMenu
local lowerPriorityMenu = existingMenu.priority > messageMenu.priority and messageMenu or existingMenu
messageMenu.buttons = MessageMenu.mergeButtons(higherPriorityMenu.buttons, lowerPriorityMenu.buttons)
end

MessageMenu.registeredMenus[messageMenu.id] = messageMenu
logger:debug("Registered %s as MessageMenu", messageMenu.id)

return messageMenu
end
2 changes: 1 addition & 1 deletion Data Files/The Crafting Framework-metadata.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "The Crafting Framework is library that allows modders to quickly
homepage = "https://www.nexusmods.com/morrowind/mods/51009?tab=files"
repository = "https://github.com/jhaakma/crafting-framework"
authors = [ "Merlord",]
version = "1.16.0"
version = "1.16.1"

[dependencies]
assets = [ "MWSE/mods/CraftingFramework", "Meshes/craftingFramework", "Textures/craftingFramework", "Sound/craftingFramework",]
Expand Down

0 comments on commit ecee040

Please sign in to comment.