Skip to content

Commit

Permalink
remove Compat and Menu handling
Browse files Browse the repository at this point in the history
restructure
add definitions (WIP)
  • Loading branch information
AndreLouisIssa committed May 14, 2024
1 parent e451f0e commit bcdab18
Show file tree
Hide file tree
Showing 13 changed files with 3,192 additions and 393 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Moved ModUtil.Mod.Register and ModData to ModUtil.lua so it will be available earlier in the load order
- Moved ModUtil.Hades.PrintStack config to dedicated module wide config
- Moved to ReturnOfModding layout (still works on ModImporter)

### Removed

- Removed all menu handling capabilities from ModUtil.Hades
- Removed ModUtil.Compat, which includes the old names, such as WrapBaseFunction

## [2.10.1] - 2024-04-24

### Added
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# Mod Utility / ModUtil
Utility mod for mod interactions within lua for SGG's games
see the [Wiki](https://github.com/SGG-Modding/ModUtil/wiki) for more details
Utility mod for mod interactions within lua for SGG's games
116 changes: 0 additions & 116 deletions src/ModUtil.Compat.lua

This file was deleted.

3 changes: 2 additions & 1 deletion src/ModUtil.Extra.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
---@meta _
---@diagnostic disable

ModUtil.IndexArray.Context = { }

Expand Down
178 changes: 6 additions & 172 deletions src/ModUtil.Hades.lua
Original file line number Diff line number Diff line change
@@ -1,93 +1,7 @@
ModUtil.Mod.Register( "Hades", ModUtil )

ModUtil.Table.Merge( ModUtil.Hades, {
PrintStackHeight = 10,
PrintStackCapacity = 80
} )

-- Menu Handling

local menuScreens = { }
local closeFuncs = { }

--[[
Tell each screen anchor that they have been forced closed by the game
--]]
local function forceClosed( triggerArgs )
for _, v in pairs( closeFuncs ) do
v( nil, nil, triggerArgs )
end
closeFuncs = { }
menuScreens = { }
end
OnAnyLoad{ function( triggerArgs ) forceClosed( triggerArgs ) end }
---@meta _
---@diagnostic disable

function ModUtil.Hades.CloseMenu( screen, button )
CloseScreen(GetAllIds(screen.Components), 0.1)
menuScreens[screen.Name] = nil
screen.KeepOpen = false
OnScreenClosed({ Flag = screen.Name })
if TableLength(menuScreens) == 0 then
SetConfigOption({ Name = "FreeFormSelectWrapY", Value = false })
SetConfigOption({ Name = "UseOcclusion", Value = true })
UnfreezePlayerUnit()
DisableShopGamepadCursor()
end
if closeFuncs[screen.Name] then
closeFuncs[screen.Name]( screen, button )
closeFuncs[screen.Name]=nil
end
end

function ModUtil.Hades.OpenMenu( group, closeFunc, openFunc )
if menuScreens[group] then
ModUtil.Hades.CloseMenu(menuScreens[group])
end
if closeFunc then closeFuncs[group]=closeFunc end

local screen = { Name = group, Components = {} }
local components = screen.Components
menuScreens[group] = screen

OnScreenOpened({ Flag = screen.Name, PersistCombatUI = true })

components.Background = CreateScreenComponent({ Name = "BlankObstacle", Group = group })

if openFunc then openFunc(screen) end

return screen
end

function ModUtil.Hades.DimMenu( screen )
if not screen then return end
if not screen.Components.BackgroundDim then
screen.Components.BackgroundDim = CreateScreenComponent({ Name = "rectangle01", Group = screen.Name })
SetScale({ Id = screen.Components.BackgroundDim.Id, Fraction = 4 })
end
SetColor({ Id = screen.Components.BackgroundDim.Id, Color = {0.090, 0.090, 0.090, 0.8} })
end

function ModUtil.Hades.UndimMenu( screen )
if not screen then return end
if not screen.Components.BackgroundDim then return end
SetColor({ Id = screen.Components.BackgroundDim.Id, Color = {0.090, 0.090, 0.090, 0} })
end

function ModUtil.Hades.PostOpenMenu( screen )
if TableLength(menuScreens) == 1 then
SetConfigOption({ Name = "FreeFormSelectWrapY", Value = true })
SetConfigOption({ Name = "UseOcclusion", Value = false })
FreezePlayerUnit()
EnableShopGamepadCursor()
end
thread(HandleWASDInput, screen)
HandleScreenInput(screen)
return screen
end

function ModUtil.Hades.GetMenuScreen( group )
return menuScreens[group]
end
ModUtil.Mod.Register( "Hades", ModUtil )

-- Debug Printing

Expand Down Expand Up @@ -166,9 +80,9 @@ local function closePrintStack()
end

local function orderPrintStack(screen,components)

if screen.CullPrintStack then
local v = screen.TextStack[1]
local v
if screen.CullPrintStack then
v = screen.TextStack[1]
if v.obj then
Destroy({Ids = {v.obj.Id}})
components["TextStack_" .. v.tid] = nil
Expand Down Expand Up @@ -310,86 +224,6 @@ function ModUtil.Hades.PrintStackChunks( text, linespan, ... )
end
end

-- Custom Menus

function ModUtil.Hades.NewMenuYesNo( group, closeFunc, openFunc, yesFunc, noFunc, title, body, yesText, noText, icon, iconScale)

if not group or group == "" then group = "MenuYesNo" end
if not yesFunc then yesFunc = function( ) end end
if not noFunc then noFunc = function( ) end end
if not icon then icon = "AmmoPack" end
if not iconScale then iconScale = 1 end
if not yesText then yesText = "Yes" end
if not noText then noText = "No" end
if not body then body = "Make a choice..." end
if not title then title = group end

local screen = ModUtil.Hades.OpenMenu( group, closeFunc, openFunc )
local components = screen.Components

PlaySound({ Name = "/SFX/Menu Sounds/GodBoonInteract" })

components.LeftPart = CreateScreenComponent({ Name = "TraitTrayBackground", Group = group, X = 1030, Y = 424})
components.MiddlePart = CreateScreenComponent({ Name = "TraitTray_Center", Group = group, X = 660, Y = 464 })
components.RightPart = CreateScreenComponent({ Name = "TraitTray_Right", Group = group, X = 1270, Y = 438 })
SetScaleY({Id = components.LeftPart.Id, Fraction = 0.8})
SetScaleY({Id = components.MiddlePart.Id, Fraction = 0.8})
SetScaleY({Id = components.RightPart.Id, Fraction = 0.8})
SetScaleX({Id = components.MiddlePart.Id, Fraction = 5})


CreateTextBox({ Id = components.Background.Id, Text = " "..title.." ", FontSize = 34,
OffsetX = 0, OffsetY = -225, Color = Color.White, Font = "SpectralSCLight",
ShadowBlur = 0, ShadowColor = {0,0,0,1}, ShadowOffset={0, 1}, Justification = "Center" })
CreateTextBox({ Id = components.Background.Id, Text = " "..body.." ", FontSize = 19,
OffsetX = 0, OffsetY = -175, Width = 840, Color = Color.SubTitle, Font = "CrimsonTextItalic",
ShadowBlur = 0, ShadowColor = {0,0,0,1}, ShadowOffset={0, 1}, Justification = "Center" })

components.Icon = CreateScreenComponent({ Name = "BlankObstacle", Group = group })
Attach({ Id = components.Icon.Id, DestinationId = components.Background.Id, OffsetX = 0, OffsetY = -50})
SetAnimation({ Name = icon, DestinationId = components.Icon.Id, Scale = iconScale })

components.CloseButton = CreateScreenComponent({ Name = "ButtonClose", Scale = 0.7, Group = group })
Attach({ Id = components.CloseButton.Id, DestinationId = components.Background.Id, OffsetX = 0, OffsetY = ScreenCenterY - 315 })
components.CloseButton.OnPressedFunctionName = ModUtil.Hades.CloseMenuYesNo
components.CloseButton.ControlHotkey = "Cancel"

components.YesButton = CreateScreenComponent({ Name = "BoonSlot1", Group = group, Scale = 0.35, })
components.YesButton.OnPressedFunctionName = function(screen, button)
if not yesFunc(screen,button) then
ModUtil.Hades.CloseMenuYesNo(screen,button)
end
end
SetScaleX({Id = components.YesButton.Id, Fraction = 0.75})
SetScaleY({Id = components.YesButton.Id, Fraction = 1.15})
Attach({ Id = components.YesButton.Id, DestinationId = components.Background.Id, OffsetX = -150, OffsetY = 75 })
CreateTextBox({ Id = components.YesButton.Id, Text = " "..yesText.." ",
FontSize = 28, OffsetX = 0, OffsetY = 0, Width = 720, Color = Color.LimeGreen, Font = "AlegreyaSansSCLight",
ShadowBlur = 0, ShadowColor = {0,0,0,1}, ShadowOffset={0, 2}, Justification = "Center"
})

components.NoButton = CreateScreenComponent({ Name = "BoonSlot1", Group = group, Scale = 0.35, })
components.NoButton.OnPressedFunctionName = function(screen, button)
if not noFunc( screen, button ) then
ModUtil.Hades.CloseMenuYesNo( screen, button )
end
end
SetScaleX({Id = components.NoButton.Id, Fraction = 0.75})
SetScaleY({Id = components.NoButton.Id, Fraction = 1.15})
Attach({ Id = components.NoButton.Id, DestinationId = components.Background.Id, OffsetX = 150, OffsetY = 75 })
CreateTextBox({ Id = components.NoButton.Id, Text = noText,
FontSize = 26, OffsetX = 0, OffsetY = 0, Width = 720, Color = Color.Red, Font = "AlegreyaSansSCLight",
ShadowBlur = 0, ShadowColor = {0,0,0,1}, ShadowOffset={0, 2}, Justification = "Center"
})

return ModUtil.Hades.PostOpenMenu( screen )
end

function ModUtil.Hades.CloseMenuYesNo( screen, button )
PlaySound( { Name = "/SFX/Menu Sounds/GeneralWhooshMENU" } )
ModUtil.Hades.CloseMenu( screen, button )
end

-- Trigger Proxy

local triggers = { }
Expand Down
Loading

0 comments on commit bcdab18

Please sign in to comment.