Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alch multi brew, effect filters, auto accept ingred quantity in alch quantity menu #25

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions User Interface Expansion/MWSE/mods/UI Expansion/MenuAlchemy.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
local common = require("UI Expansion.common")
local id_alchemy_create_all_button = tes3ui.registerID("UIEXP_MenuAlchemy_create_all_button")
local id_alchemy_quantity_input = tes3ui.registerID("UIEXP_MenuAlchemy_quantity_input")
local id_alchemy_cancel_button = tes3ui.registerID("UIEXP_MenuAlchemy_cancel_button")

local brewCount = 0

local function onCreateAll(e)
local menu = tes3ui.findMenu(tes3ui.registerID("MenuAlchemy"))
local createbtn = menu.children[2].children[3].children[1]
local quantiyinp = menu.children[2].children[3].children[4].children[1]
local quantity = quantiyinp.text
brewCount = 0
if(tonumber(quantity) ~= nil) then
for i=1,tonumber(quantity) do createbtn:triggerEvent("mouseClick") end
else
tes3.messageBox{ message = "Quantity is Not a Number" }
end
tes3.messageBox{ message = "You have Successfuly Brewed: " .. brewCount .. " potion(s)" }
end

local function onCancel(e)
local menu = tes3ui.findMenu(tes3ui.registerID("MenuAlchemy"))
local createbtn = menu.children[2].children[3].children[1]
local cancelbtn = menu.children[2].children[3].children[2]
cancelbtn:triggerEvent("mouseClick")
end

local function menuAlchemy(e)
local buttonLayout = e.element.children[2].children[3]
local createbtn = e.element.children[2].children[3].children[1]
local cancelbtn = e.element.children[2].children[3].children[2]
local nameInput = e.element.children[2].children[1].children[2].children[1]
local nameBorder = e.element.children[2].children[1].children[2]
createbtn.visible = false
cancelbtn.visible = false
local cancelbtn = e.element.children[2].children[3].children[2]
local input_label = buttonLayout:createLabel{ text = "Quantity:" }
--input_label.borderBottom = 5
local inputBorder = buttonLayout:createThinBorder{}
inputBorder.heightProportional = 1.0
inputBorder.autoWidth = true
inputBorder.minWidth = 50
inputBorder.borderAllSides = 2
inputBorder.childAlignX = 0.5
inputBorder.childAlignY = 0.5
local input = inputBorder:createTextInput{ id = id_alchemy_quantity_input }
input.borderLeft = 5
input.borderRight = 5
input.widget.lengthLimit = 10
input.widget.eraseOnFirstKey = true
input.justifyText = center
input.text = tostring(common.config.alchemyDefaultQuantity)
local buttonCreate = buttonLayout:createButton{id = id_alchemy_create_all_button, text = "Create"}
local buttonCancel = buttonLayout:createButton{ id = id_alchemy_cancel_button, text = "Cancel"}

buttonCreate:register("mouseClick", onCreateAll)
buttonCancel:register("mouseClick", onCancel)

input:register("mouseClick", function()
tes3ui.acquireTextInput(input)
end)
nameInput:register("mouseClick", function()
tes3ui.acquireTextInput(nameInput)
end)
inputBorder:register("mouseClick", function()
tes3ui.acquireTextInput(input)
end)
nameBorder:register("mouseClick", function()
tes3ui.acquireTextInput(nameInput)
end)
end

function onBrew(e)
brewCount = brewCount+1
end

event.register("uiActivated", menuAlchemy, { filter = "MenuAlchemy"})
event.register("potionBrewed", onBrew)
12 changes: 12 additions & 0 deletions User Interface Expansion/MWSE/mods/UI Expansion/MenuQuantity.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
local common = require("UI Expansion.common")


local function checkReverseShiftInAlch(elem)
local alchMenu = tes3ui.findMenu(tes3ui.registerID("MenuAlchemy"))
if(alchMenu ~= nil) then
if (common.config.alchemyDefaultQuantity) then
elem:triggerEvent("mouseClick")
end
end
end


local function menuQuantity(e)
-- Enable keyboard support for the scroll bar.
local scrollBar = e.element:findChild(tes3ui.registerID("MenuQuantity_scrollbar"))
Expand All @@ -10,5 +21,6 @@ local function menuQuantity(e)
submitButton:triggerEvent("mouseClick")
end
})
checkReverseShiftInAlch(submitButton);
end
event.register("uiActivated", menuQuantity, { filter = "MenuQuantity"})
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
local common = require("UI Expansion.common")
local lasttarget

local function onAfterTrainTimer()
if(tes3.menuMode()) then
timer.start({ duration = 0.3, callback = onAfterTrainTimer })
else
if(lasttarget ~= nil) then
tes3.player:activate(lasttarget)
local menu = tes3ui.findMenu(tes3ui.registerID("MenuDialog"))
local trainbtn = menu:findChild(tes3ui.registerID("MenuDialog_service_training"))
trainbtn:triggerEvent("mouseClick")
end
end
end

local function openTraining(e)
e.source:forwardEvent(e)
timer.start({ duration = 0.3, callback = onAfterTrainTimer })
end

local function menuTraining(e)
--local scp = e.element:findChild(tes3ui.registerID("PartScrollPane_Pane"))
local scp = e.element.children[2].children[3].children[1].children[1]
for i,v in ipairs(scp.children) do
v.children[1]:register("mouseClick", openTraining)
end
lasttarget = tes3ui.getServiceActor().reference
local menu = tes3ui.findMenu(tes3ui.registerID("MenuDialog"))
menu.visible = false
end

event.register("uiActivated", menuTraining, { filter = "MenuServiceTraining"})
54 changes: 53 additions & 1 deletion User Interface Expansion/MWSE/mods/UI Expansion/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,61 @@ function filter_functions:clearFilter()
self:setFiltersExact()
end

-- Get the maximum number of visible effects based on current alchemy skill.
local function getVisibleEffectsCount()
local skill = tes3.mobilePlayer.alchemy.current
local gmst = tes3.findGMST(tes3.gmst.fWortChanceValue)
return math.clamp(math.floor(skill / gmst.value), 0, 4)
end

local function getEffectName(effect, stat)
local statName
if effect then
if effect.targetsAttributes then
statName = tes3.findGMST(888 + stat).value
elseif effect.targetsSkills then
statName = tes3.findGMST(896 + stat).value
end

local effectName = tes3.findGMST(1283 + effect.id).value
if statName then
return effectName:match("%S+") .. " " .. statName
else
return effectName
end
end
end

function filter_functions:triggerFilter(params)

local inEffects = false
local inName = false
local item = params.item
-- Search by name.
if (self.searchText and params.text and not string.find(string.lower(params.text), self.searchText, 1, true)) then

if(self.searchText and params.text ) then
inName = string.find(string.lower(params.text), self.searchText, 1, true)
-- Search by effects. | maybe config option
local numVisibleEff = getVisibleEffectsCount()
if(item ~= nil and item.effects ~= nil) then
local isIngred = item.objectType == tes3.objectType.ingredient
for i=1,#item.effects do
if #item.effects >= i and item.effectAttributeIds ~= nil and item.effectSkillIds ~= nil and #item.effectAttributeIds >= i and #item.effectSkillIds >= i then
local effect = tes3.getMagicEffect(item.effects[i])
local target = math.max(item.effectAttributeIds[i], item.effectSkillIds[i])
local effectName = getEffectName(effect,target)
if effectName ~= nil then
inEffects = inEffects or ((not isIngred or i <= numVisibleEff) and string.find(string.lower(effectName), string.lower(self.searchText), 1, true))
end
end
end
end
else
inName = true
end


if(not inName and not inEffects) then
return false
end

Expand Down
14 changes: 14 additions & 0 deletions User Interface Expansion/MWSE/mods/UI Expansion/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ local defaultConfig = {
takeFilteredItems = true,
transferItemsByDefault = false,
displayWeekday = true,
autoAcceptAlchemyQuantityMenu = false,
maxWait = 1,
alchemyDefaultQuantity = 1,
keybindClose = { tes3.scanCode.space },
keybindTakeAll = { tes3.scanCode.leftCtrl, tes3.scanCode.space },
keybindShowAdditionalInfo = { tes3.scanCode.leftAlt },
Expand Down Expand Up @@ -47,6 +49,8 @@ local defaultConfig = {
saveLoad = true,
stat = true,
tooltip = true,
training = true,
alchemy = true,
},
}
local config = table.copy(defaultConfig)
Expand Down Expand Up @@ -181,6 +185,16 @@ local function onInitialized(e)
else
mwse.log("[UI Expansion] Skipping module: tooltip")
end
if (config.components.training) then
dofile("Data Files/MWSE/mods/UI Expansion/MenuServiceTraining.lua")
else
mwse.log("[UI Expansion] Skipping module: training")
end
if (config.components.alchemy) then
dofile("Data Files/MWSE/mods/UI Expansion/MenuAlchemy.lua")
else
mwse.log("[UI Expansion] Skipping module: alchemy")
end
end
event.register("initialized", onInitialized)

Expand Down
26 changes: 23 additions & 3 deletions User Interface Expansion/MWSE/mods/UI Expansion/mcm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,22 @@ function this.onCreate(container)
config = this.config,
key = "transferItemsByDefault",
})

-- Toggle displaying the weekday in the rest menu.

createBooleanConfigPackage({
parent = mainPane,
label = common.dictionary.configShowWeekDay,
config = this.config,
key = "displayWeekday",
})

-- Toggle displaying the weekday in the rest menu.
createBooleanConfigPackage({
parent = mainPane,
label = common.dictionary.autoAcceptAlchemyQuantityMenu,
config = this.config,
key = "autoAcceptAlchemyQuantityMenu",
})

-- Select the maximum wait time.
createConfigSliderPackage({
parent = mainPane,
Expand All @@ -200,9 +207,22 @@ function this.onCreate(container)
step = 1,
})


-- Select the default brew quantity.
createConfigSliderPackage({
parent = mainPane,
label = common.dictionary.alchemyDefaultQuantity,
config = this.config,
key = "alchemyDefaultQuantity",
min = 1,
max = 100,
jump = 5,
step = 1,
})

-- Credits:
mainPane:createLabel({ text = common.dictionary.configCredits }).borderTop = 6
mainPane:createLabel({ text = " Programming: NullCascade, Hrnchamd, Petethegoat, Jiopsi, Remiros, Mort" })
mainPane:createLabel({ text = " Programming: NullCascade, Hrnchamd, Petethegoat, Jiopsi, Remiros, Mort, Wix" })
mainPane:createLabel({ text = " Colored Magic School Icons: R-Zero" })
mainPane:createLabel({ text = " Inventory Filter Icons: Remiros" })
mainPane:createLabel({ text = " Concepts and Testing: Morrowind Modding Community Discord" })
Expand Down