diff --git a/User Interface Expansion/MWSE/mods/UI Expansion/MenuAlchemy.lua b/User Interface Expansion/MWSE/mods/UI Expansion/MenuAlchemy.lua new file mode 100644 index 0000000..e053898 --- /dev/null +++ b/User Interface Expansion/MWSE/mods/UI Expansion/MenuAlchemy.lua @@ -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) \ No newline at end of file diff --git a/User Interface Expansion/MWSE/mods/UI Expansion/MenuQuantity.lua b/User Interface Expansion/MWSE/mods/UI Expansion/MenuQuantity.lua index 40b4ad8..5c7286b 100644 --- a/User Interface Expansion/MWSE/mods/UI Expansion/MenuQuantity.lua +++ b/User Interface Expansion/MWSE/mods/UI Expansion/MenuQuantity.lua @@ -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")) @@ -10,5 +21,6 @@ local function menuQuantity(e) submitButton:triggerEvent("mouseClick") end }) + checkReverseShiftInAlch(submitButton); end event.register("uiActivated", menuQuantity, { filter = "MenuQuantity"}) \ No newline at end of file diff --git a/User Interface Expansion/MWSE/mods/UI Expansion/MenuServiceTraining.lua b/User Interface Expansion/MWSE/mods/UI Expansion/MenuServiceTraining.lua new file mode 100644 index 0000000..02bdb90 --- /dev/null +++ b/User Interface Expansion/MWSE/mods/UI Expansion/MenuServiceTraining.lua @@ -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"}) \ No newline at end of file diff --git a/User Interface Expansion/MWSE/mods/UI Expansion/common.lua b/User Interface Expansion/MWSE/mods/UI Expansion/common.lua index ddfd015..fed23a0 100644 --- a/User Interface Expansion/MWSE/mods/UI Expansion/common.lua +++ b/User Interface Expansion/MWSE/mods/UI Expansion/common.lua @@ -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 diff --git a/User Interface Expansion/MWSE/mods/UI Expansion/main.lua b/User Interface Expansion/MWSE/mods/UI Expansion/main.lua index 71f4490..de1dcfd 100644 --- a/User Interface Expansion/MWSE/mods/UI Expansion/main.lua +++ b/User Interface Expansion/MWSE/mods/UI Expansion/main.lua @@ -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 }, @@ -47,6 +49,8 @@ local defaultConfig = { saveLoad = true, stat = true, tooltip = true, + training = true, + alchemy = true, }, } local config = table.copy(defaultConfig) @@ -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) diff --git a/User Interface Expansion/MWSE/mods/UI Expansion/mcm.lua b/User Interface Expansion/MWSE/mods/UI Expansion/mcm.lua index f72c869..1fd36da 100644 --- a/User Interface Expansion/MWSE/mods/UI Expansion/mcm.lua +++ b/User Interface Expansion/MWSE/mods/UI Expansion/mcm.lua @@ -179,8 +179,7 @@ function this.onCreate(container) config = this.config, key = "transferItemsByDefault", }) - - -- Toggle displaying the weekday in the rest menu. + createBooleanConfigPackage({ parent = mainPane, label = common.dictionary.configShowWeekDay, @@ -188,6 +187,14 @@ function this.onCreate(container) 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, @@ -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" })