Skip to content

Instantly share code, notes, and snippets.

@Petethegoat
Created May 1, 2019 22:51
Show Gist options
  • Save Petethegoat/958ef5b3d6e7c54d0e0cd548743c065c to your computer and use it in GitHub Desktop.
Save Petethegoat/958ef5b3d6e7c54d0e0cd548743c065c to your computer and use it in GitHub Desktop.
local menuBook_button_take = tes3ui.registerID("MenuBook_button_take")
local menuBook_button_next = tes3ui.registerID("MenuBook_button_next")
local menuBook_button_prev = tes3ui.registerID("MenuBook_button_prev")
local menuBook_page_1 = tes3ui.registerID("MenuBook_page_1")
local menuBook_page_2 = tes3ui.registerID("MenuBook_page_2")
local menuScroll_scroll = tes3ui.registerID("MenuScroll_Scroll")
local config = mwse.loadConfig("Illiterate")
if not config then
config = {
intThreshold = 25,
useBaseAttribute = true,
}
end
local function literacyCheck()
local success = true
if config.useBaseAttribute then
if tes3.mobilePlayer.intelligence.base <= config.intThreshold then
success = false
end
else
if tes3.mobilePlayer.intelligence.current <= config.intThreshold then
success = false
end
end
return success
end
local function changeChildFonts(page)
for i = 1, #page.children do
page.children[i].font = 2
end
page:updateLayout()
end
local function changeBothPageFonts(menuElement)
local page = menuElement:findChild(menuBook_page_1)
changeChildFonts(page)
page = menuElement:findChild(menuBook_page_2)
changeChildFonts(page)
end
local function onBookOpen(e)
if literacyCheck() then return end
local menu = e.element
local takeButton = menu:findChild(menuBook_button_take)
if takeButton.visible then
changeBothPageFonts(menu)
local nextButton = menu:findChild(menuBook_button_next)
nextButton:register("mouseClick", function(e)
e.source:forwardEvent(e)
changeBothPageFonts(menu)
end)
local prevButton = menu:findChild(menuBook_button_prev)
prevButton:register("mouseClick", function(e)
e.source:forwardEvent(e)
changeBothPageFonts(menu)
end)
menu:register("mouseScrollUp", function(e)
tes3.messageBox("fuck")
nextButton:triggerEvent("mouseClick")
end)
menu:register("mouseScrollDown", function(e)
tes3.messageBox("fuck")
e.source:forwardEvent(e)
prevButton:triggerEvent("mouseClick")
end)
end
end
event.register("uiActivated", onBookOpen, {filter = "MenuBook"})
local function onScrollOpen(e)
if literacyCheck() then return end
local page = e.element:findChild(menuScroll_scroll):getContentElement()
changeChildFonts(page)
end
event.register("uiActivated", onScrollOpen, {filter = "MenuScroll"})
-- Mod Config Menu
local modConfig = {}
function modConfig.onCreate(container)
local mainBlock = container:createThinBorder({})
mainBlock.layoutWidthFraction = 1.0
mainBlock.layoutHeightFraction = 1.0
mainBlock.paddingAllSides = 6
mainBlock.flowDirection = "top_to_bottom"
do
local scaleBlock = mainBlock:createBlock()
scaleBlock.flowDirection = "left_to_right"
scaleBlock.layoutWidthFraction = 1.0
scaleBlock.height = 32
local scaleLabel = scaleBlock:createLabel({ text = string.format("Intelligence Threshold: %d", config.intThreshold) })
local scaleSlider = scaleBlock:createSlider({ current = (config.intThreshold), max = 100, step = 1})
scaleSlider.width = 256
scaleSlider.layoutOriginFractionX = 1.0
scaleSlider.borderRight = 6
scaleSlider:register("PartScrollBar_changed", function(e)
config.intThreshold = (scaleSlider:getPropertyInt("PartScrollBar_current"))
scaleLabel.text = string.format("Intelligence Threshold: %d", config.intThreshold)
end)
end
do
local horizontalBlock = mainBlock:createBlock({})
horizontalBlock.flowDirection = "left_to_right"
horizontalBlock.layoutWidthFraction = 1.0
horizontalBlock.autoHeight = true
local label = horizontalBlock:createLabel({ text = "Use Base or Current Intelligence?" })
label.layoutOriginFractionX = 0.0
local button = horizontalBlock:createButton({ text = (config.useBaseAttribute and "Base" or "Current") })
button.layoutOriginFractionX = 1.0
button.paddingTop = 3
button:register("mouseClick", function()
config.useBaseAttribute = not config.useBaseAttribute
button.text = (config.useBaseAttribute and "Base" or "Current")
end)
end
end
function modConfig.onClose(container)
mwse.log(json.encode(config, { indent = true }))
mwse.saveConfig("Illiterate", config)
end
local function registerModConfig()
mwse.registerModConfig("Illiterate", modConfig)
end
event.register("modConfigReady", registerModConfig)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment