fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
be5d99b
settings-overhaul
1local PANEL =class . create ( "Settings" , "Panel" ) 2 3local log =require ( "log" ) 4local json =require ( "serializer.json" ) 5local notification =require ( "notification" ) 6local music =require ( "music" ) 7local overlay =require ( "overlay" ) 8 9require ( "extensions.math" ) 10 11SLIPPI_OFF =1 12SLIPPI_NETPLAY =2 13SLIPPI_REPLAY =3 14 15function PANEL : Settings () 16self : super () -- Initialize our baseclass 17 18self : DockMargin ( 0 , 0 , 0 , 0 ) 19self : SizeToScreen () 20self : SetBackgroundColor ( color_blank ) 21self : SetBorderColor ( color_blank ) 22 23self . PORTSELECT =self : Add ( "PortSelect" ) 24self . SKINSELECT =self : Add ( "SkinSelect" ) 25 26self . COLORSELECT =self : Add ( "ColorSelector" ) 27self . COLORSELECT : SetSize ( 296 + 32 , 256 ) 28self . COLORSELECT : Center () 29self . COLORSELECT : SetVisible ( false ) 30 31self . MAIN =self : Add ( "TabbedPanel" ) 32self . MAIN : SizeToParent () 33self . MAIN : SetSize ( 296 + 32 , 176 ) 34self . MAIN : Center () 35self . MAIN : DockPadding ( 0 , 0 , 0 , 0 ) 36self . MAIN : Center () 37 38self . GENERAL =self . MAIN : AddTab ( "General" , "textures/gui/cog.png" , true ) 39self . GENERAL : SetBackgroundColor ( color ( 200 , 200 , 200 , 255 )) 40 41self . GENERAL . LEFT =self . GENERAL : Add ( "Panel" ) 42self . GENERAL . LEFT : SetWidth ( 158 ) 43self . GENERAL . LEFT : Dock ( DOCK_LEFT ) 44self . GENERAL . LEFT : SetBGColor ( color_blank ) 45self . GENERAL . LEFT : SetBorderColor ( color_blank ) 46self . GENERAL . LEFT : DockPadding ( 0 , 0 , 0 , 0 ) 47 48self . GENERAL . RIGHT =self . GENERAL : Add ( "Panel" ) 49self . GENERAL . RIGHT : SetWidth ( 158 ) 50self . GENERAL . RIGHT : Dock ( DOCK_RIGHT ) 51self . GENERAL . RIGHT : SetBGColor ( color_blank ) 52self . GENERAL . RIGHT : SetBorderColor ( color_blank ) 53self . GENERAL . RIGHT : DockPadding ( 0 , 0 , 0 , 0 ) 54 55self . SLIPPI =self . MAIN : AddTab ( "Slippi" , "textures/gui/slippi.png" ) 56self . SLIPPI : SetBackgroundColor ( color ( 33 , 186 , 69 , 255 )) 57 58self . MELEE =self . MAIN : AddTab ( "Melee" , "textures/gui/melee.png" ) 59self . MELEE : SetBackgroundColor ( color ( 189 , 15 , 23 , 255 )) 60 61self . MELEE . VOLUME =self . MELEE : Add ( "Slider" ) 62self . MELEE . VOLUME : SetValue ( 50 ) 63self . MELEE . VOLUME : Dock ( DOCK_BOTTOM ) 64self . MELEE . VOLUME : SetTooltipTitle ( "VOLUME" ) 65self . MELEE . VOLUME : SetTooltipBody ( [[Adjust the volume of the music.]] ) 66 67local VOLLABEL =self . MELEE : Add ( "Label" ) 68VOLLABEL : SetText ( "Music volume" ) 69VOLLABEL : SetTextAlignment ( "center" ) 70VOLLABEL : SizeToText () 71VOLLABEL : Dock ( DOCK_BOTTOM ) 72VOLLABEL : SetTextColor ( color_white ) 73VOLLABEL : SetShadowDistance ( 1 ) 74VOLLABEL : SetShadowColor ( color_black ) 75VOLLABEL : SetFont ( "fonts/melee-bold.otf" , 12 ) 76 77function self . MELEE . VOLUME : OnValueChanged ( i ) 78music . setVolume ( i ) 79VOLLABEL : SetText (( "Music Volume - %d%%" ): format ( i )) 80end 81 82self . MELEE . LEFT =self . MELEE : Add ( "Panel" ) 83self . MELEE . LEFT : SetWidth ( 158 ) 84self . MELEE . LEFT : Dock ( DOCK_LEFT ) 85self . MELEE . LEFT : SetBGColor ( color_blank ) 86self . MELEE . LEFT : SetBorderColor ( color_blank ) 87self . MELEE . LEFT : DockPadding ( 0 , 0 , 0 , 0 ) 88 89self . MELEE . RIGHT =self . MELEE : Add ( "Panel" ) 90self . MELEE . RIGHT : SetWidth ( 158 ) 91self . MELEE . RIGHT : Dock ( DOCK_RIGHT ) 92self . MELEE . RIGHT : SetBGColor ( color_blank ) 93self . MELEE . RIGHT : SetBorderColor ( color_blank ) 94self . MELEE . RIGHT : DockPadding ( 0 , 0 , 0 , 0 ) 95 96self . SLIPPI . MODE =self . SLIPPI : Add ( "RadioPanel" ) 97self . SLIPPI . MODE : SetWidth ( 158 ) 98self . SLIPPI . MODE : Center ( true , true ) 99 100local off =self . SLIPPI . MODE : AddOption ( SLIPPI_OFF , "Off" ) 101off : SetTooltipTitle ( "SLIPPI MODE" ) 102off : SetTooltipBody ( [[- Off: Use normal game detection. Supported game list can be found on the github README.]] ) 103local netplay =self . SLIPPI . MODE : AddOption ( SLIPPI_NETPLAY , "Rollback/Netplay" ) 104netplay : SetTooltipTitle ( "SLIPPI MODE" ) 105netplay : SetTooltipBody ( [[- Rollback/Netplay: Allows the overlay to work properly when playing Slippi online. Will also actively change the overylay to display your current port.]] ) 106local mirror =self . SLIPPI . MODE : AddOption ( SLIPPI_REPLAY , "Replay/Mirror" ) 107mirror : SetTooltipTitle ( "SLIPPI MODE" ) 108mirror : SetTooltipBody ( [[- Replay/Mirror: Allows the overlay to work when viewing replays or mirroring gameplay from a console.]] ) 109 110self . MELEE . MUSIC =self . MELEE . LEFT : Add ( "Checkbox" ) 111self . MELEE . MUSIC : SetText ( "Music" ) 112self . MELEE . MUSIC : Dock ( DOCK_TOP ) 113 114self . MELEE . MUSIC : SetTooltipTitle ( "MELEE MUSIC" ) 115self . MELEE . MUSIC : SetTooltipBody ( [[Enable/Disable custom music for Melee.]] ) 116 117function self . MELEE . MUSIC : OnToggle ( on ) 118if on then 119music . onStateChange () 120else 121music . kill () 122end 123end 124 125self . MELEE . MUSICLOOP =self . MELEE . LEFT : Add ( "HorizontalSelect" ) 126self . MELEE . MUSICLOOP : Dock ( DOCK_TOP ) 127 128self . MELEE . MUSICLOOP : SetTooltipTitle ( "MUSIC LOOP MODE" ) 129self . MELEE . MUSICLOOP : SetTooltipBody ( [[- Playlist mode: When a song ends, it will play another song in a random order. 130 131-Loop menu: Will play one random song on a loop when in menus. 132 133-Loop stage: Will play one random song on loop when playing on a stage. 134 135-Loop all: Will play one random song on a loop when in the menu system or playing on a stage. 136]] ) 137 138LOOPING_OFF =self . MELEE . MUSICLOOP : AddOption ( "Playlist mode" , true ) -- 1 139LOOPING_MENU =self . MELEE . MUSICLOOP : AddOption ( "Loop menu" ) -- 2 140LOOPING_STAGE =self . MELEE . MUSICLOOP : AddOption ( "Loop stage" ) -- 3 141LOOPING_ALL =self . MELEE . MUSICLOOP : AddOption ( "Loop all" ) -- 4 142 143function self . MELEE . MUSICLOOP : OnSelectOption ( num ) 144music . onLoopChange ( num ) 145end 146 147local SKIPLABEL =self . MELEE . RIGHT : Add ( "Label" ) 148SKIPLABEL : SetText ( "Skip track combo" ) 149SKIPLABEL : SetTextAlignment ( "center" ) 150SKIPLABEL : SizeToText () 151SKIPLABEL : SetHeight ( 24 ) 152SKIPLABEL : Dock ( DOCK_TOP ) 153SKIPLABEL : SetTextColor ( color_white ) 154SKIPLABEL : SetShadowDistance ( 1 ) 155SKIPLABEL : SetShadowColor ( color_black ) 156SKIPLABEL : SetFont ( "fonts/melee-bold.otf" , 12 ) 157 158self . MELEE . MUSICSKIP =self . MELEE . RIGHT : Add ( "GCBind" ) 159self . MELEE . MUSICSKIP : Dock ( DOCK_TOP ) 160self . MELEE . MUSICSKIP : SetTooltipTitle ( "SKIP TRACK COMBO" ) 161self . MELEE . MUSICSKIP : SetTooltipBody ( [[This button will allow you to a set a button combination on your controller to skip the currently playing music track. 162 163NOTE: This button is only usable when in a supported game.]] ) 164 165self . PORTTITLE =self . GENERAL . LEFT : Add ( "Checkbox" ) 166self . PORTTITLE : SetText ( "Port in title" ) 167self . PORTTITLE : Dock ( DOCK_TOP ) 168self . PORTTITLE : SetTooltipTitle ( "PORT IN TITLE" ) 169self . PORTTITLE : SetTooltipBody ( [[Show the current port number being displayed in the application title.]] ) 170 171self . ALWAYSPORT =self . GENERAL . LEFT : Add ( "Checkbox" ) 172self . ALWAYSPORT : SetText ( "Always show port" ) 173self . ALWAYSPORT : Dock ( DOCK_TOP ) 174self . ALWAYSPORT : SetTooltipTitle ( "ALWAYS SHOW PORT" ) 175self . ALWAYSPORT : SetTooltipBody ( [[Always show the current port in the bottom left of the overlay window.]] ) 176 177function self . PORTTITLE : OnToggle () 178love . updateTitle ( love . getTitleNoPort ()) 179end 180 181self . DPAD =self . GENERAL . RIGHT : Add ( "Checkbox" ) 182self . DPAD : SetText ( "Show D-Pad" ) 183self . DPAD : Dock ( DOCK_TOP ) 184self . DPAD : SetTooltipTitle ( "DIRECTIONAL-PAD" ) 185self . DPAD : SetTooltipBody ( [[Enable/disable the directional pad on the overlay.]] ) 186 187self . START =self . GENERAL . RIGHT : Add ( "Checkbox" ) 188self . START : SetText ( "Show Start" ) 189self . START : Dock ( DOCK_TOP ) 190self . START : SetTooltipTitle ( "START BUTTON" ) 191self . START : SetTooltipBody ( [[Enable/disable the start button on the overlay.]] ) 192 193self . HIGH_CONTRAST =self . GENERAL . RIGHT : Add ( "Checkbox" ) 194self . HIGH_CONTRAST : SetText ( "High-contrast" ) 195self . HIGH_CONTRAST : Dock ( DOCK_TOP ) 196self . HIGH_CONTRAST : SetTooltipTitle ( "HIGH-CONTRAST" ) 197self . HIGH_CONTRAST : SetTooltipBody ( [[All buttons and joystick-gates with be filled with black for better viewing visibility. 198 19920XX theme is unsupported]] ) 200 201self . TRANSPARENCY =self . GENERAL . RIGHT : Add ( "Slider" ) 202self . TRANSPARENCY : SetValue ( 100 ) 203self . TRANSPARENCY : Dock ( DOCK_BOTTOM ) 204self . TRANSPARENCY : SetVisible ( love . supportsGameCapture ()) 205self . TRANSPARENCY : SetTooltipTitle ( "TRANSPARENCY" ) 206self . TRANSPARENCY : SetTooltipBody ( [[Adjust how transparent the overlay is. This will only function correctly if you are capturing this window in OBS with a "Game Capture" element with transparency enabled.]] ) 207 208local TLABEL =self . GENERAL . RIGHT : Add ( "Label" ) 209 210function self . TRANSPARENCY : OnValueChanged ( i ) 211TLABEL : SetText (( "Transparency - %d%%" ): format ( i )) 212end 213 214TLABEL : SetText ( "Transparency" ) 215TLABEL : SizeToText () 216TLABEL : SetHeight ( 24 ) 217TLABEL : Dock ( DOCK_BOTTOM ) 218TLABEL : SetTextColor ( color_white ) 219TLABEL : SetShadowDistance ( 1 ) 220TLABEL : SetShadowColor ( color_black ) 221TLABEL : SetFont ( "fonts/melee-bold.otf" , 12 ) 222TLABEL : SetVisible ( love . supportsGameCapture ()) 223 224self . BACKGROUNDCOLOR =self . GENERAL . RIGHT : Add ( "ColorButton" ) 225self . BACKGROUNDCOLOR : SetText ( "Background color" ) 226self . BACKGROUNDCOLOR : Dock ( DOCK_BOTTOM ) 227self . BACKGROUNDCOLOR : SetVisible ( not love . supportsGameCapture ()) 228self . BACKGROUNDCOLOR : SetColor ( color ( 34 , 34 , 34 )) 229self . BACKGROUNDCOLOR : SetTooltipTitle ( "BACKGROUND COLOR" ) 230self . BACKGROUNDCOLOR : SetTooltipBody ( [[Pick a color to change the background color of the overlay window.]] ) 231 232self . BACKGROUNDCOLOR . OnClick =function ( this ) 233self . COLORSELECT : SetColor ( self . BACKGROUNDCOLOR : GetColor ()) 234self . COLORSELECT : SetVisible ( true ) 235self . COLORSELECT : BringToFront () 236end 237 238self . COLORSELECT : SetColorButton ( self . BACKGROUNDCOLOR ) 239 240self . CONFIGDIR =self . GENERAL . LEFT : Add ( "Button" ) 241self . CONFIGDIR : SetText ( "Open config directory" ) 242self . CONFIGDIR : Dock ( DOCK_BOTTOM ) 243self . CONFIGDIR : SetTooltipTitle ( "CONFIGURATION DIRECTORY" ) 244self . CONFIGDIR : SetTooltipBody ( [[This button will open the file explorer to M'Overlay's config directory. 245 246This is also the same directory you use to place all your music for Melee.]] ) 247 248function self . CONFIGDIR : OnClick () 249love . system . openURL (( "file://%s" ): format ( love . filesystem . getSaveDirectory ())) 250end 251 252if love . supportsAttachableConsole () then 253self . DEBUG =self . GENERAL . LEFT : Add ( "Checkbox" ) 254self . DEBUG : SetText ( "Debug console" ) 255self . DEBUG : Dock ( DOCK_BOTTOM ) 256self . DEBUG : SetTooltipTitle ( "DEBUG CONSOLE" ) 257self . DEBUG : SetTooltipBody ( [[Enable/disable a debug console for developer and debugging purposes.]] ) 258 259function self . DEBUG : OnToggle ( on ) 260love . console ( on ) 261end 262end 263 264self . ABOUT =self . MAIN : AddTab ( "About" , "textures/icon.png" ) 265self . ABOUT : SetBackgroundColor ( color_purple ) 266 267local ICON =self . ABOUT : Add ( "Image" ) 268ICON : SetImage ( "textures/icon.png" ) 269ICON : SetPos ( 24 , 0 ) 270ICON : SetSize ( 96 , 96 ) 271ICON : CenterVertical () 272 273local VLABEL =self . ABOUT : Add ( "Button" ) 274VLABEL : SetDrawButton ( false ) 275VLABEL : SetText ( "M'Overlay - " .. love . getMOverlayVersion ()) 276VLABEL : SetTextAlignment ( "center" ) 277VLABEL : SetSize ( 176 , 18 ) 278VLABEL : Dock ( DOCK_RIGHT ) 279VLABEL : SetTextColor ( color_white ) 280VLABEL : SetShadowColor ( color_black ) 281VLABEL : SetShadowDistance ( 1 ) 282VLABEL : SetFont ( "fonts/melee-bold.otf" , 12 ) 283 284function VLABEL : OnClick () 285love . system . openURL (( "https://github.com/bkacjios/m-overlay/tree/v%s" ): format ( love . getMOverlayVersion ())) 286end 287 288self . m_sFileName ="config.json" 289 290--local test = self:Add("ColorPicker") 291--test:SetSize(256, 256) 292end 293 294function PANEL : UpdateSkins () 295self . SKINSELECT : UpdateSkins () 296end 297 298function PANEL : ChangeSkin ( skin ) 299self . SKINSELECT : ChangeSkin ( skin ) 300end 301 302function PANEL : GetSkin () 303return self . SKINSELECT : GetSkin () 304end 305 306function PANEL : GetPort () 307return self . PORTSELECT : GetPort () 308end 309 310function PANEL : ChangePort ( port ) 311self . PORTSELECT : ChangePort ( port ) 312end 313 314function PANEL : Toggle () 315self : SetVisible ( not self : IsVisible ()) 316if not self : IsVisible () then 317gui . hideTooltip () 318self : OnClosed () 319end 320self : Center () 321end 322 323function PANEL : GetSaveTable () 324return { 325[ "port" ] =overlay . getPort (), 326[ "skin" ] =overlay . getSkin (), 327[ "slippi-mode" ] =self : GetSlippiMode (), 328[ "port-in-title" ] =self : IsPortTitleEnabled (), 329[ "always-show-port" ] =self : AlwaysShowPort (), 330[ "high-contrast" ] =self : IsHighContrast (), 331[ "enable-dpad" ] =self : IsDPadEnabled (), 332[ "enable-start" ] =self : IsStartEnabled (), 333[ "debugging" ] =self : IsDebugging (), 334[ "transparency" ] =self : GetTransparency (), 335[ "melee-stage-music" ] =self : PlayStageMusic (), 336[ "melee-stage-music-loop" ] =self : GetMusicLoopMode (), 337[ "melee-stage-music-skip-buttons" ] =self : GetMusicSkipMask (), 338[ "melee-music-volume" ] =self : GetVolume (), 339[ "background-color" ] =self : GetBackgroundColor (), 340} 341end 342 343function PANEL : GetBackgroundColor () 344return self . BACKGROUNDCOLOR : GetColor () 345end 346 347function PANEL : IsBinding () 348return self . MELEE . MUSICSKIP : IsBinding () 349end 350 351function PANEL : GetMusicSkipMask () 352return self . MELEE . MUSICSKIP : GetButtonCombo () 353end 354 355function PANEL : PlayStageMusic () 356return self . MELEE . MUSIC : IsToggled () 357end 358 359function PANEL : GetMusicLoopMode () 360return self . MELEE . MUSICLOOP : GetSelection () 361end 362 363function PANEL : SetVolume ( volume ) 364return self . MELEE . VOLUME : SetValue ( math . clamp ( volume , 0 , 100 )) 365end 366 367function PANEL : GetVolume () 368return self . MELEE . VOLUME : GetValue () 369end 370 371function PANEL : GetSlippiMode () 372return self . SLIPPI . MODE : GetOption () 373end 374 375function PANEL : IsSlippiNetplay () 376return self . SLIPPI . MODE : GetOption () == SLIPPI_NETPLAY 377end 378 379function PANEL : IsSlippiReplay () 380return self . SLIPPI . MODE : GetOption () == SLIPPI_REPLAY 381end 382 383function PANEL : IsPortTitleEnabled () 384return self . PORTTITLE : IsToggled () 385end 386 387function PANEL : AlwaysShowPort () 388return self . ALWAYSPORT : IsToggled () 389end 390 391function PANEL : IsHighContrast () 392return self . HIGH_CONTRAST : IsToggled () 393end 394 395function PANEL : IsDPadEnabled () 396return self . DPAD : IsToggled () 397end 398 399function PANEL : IsStartEnabled () 400return self . START : IsToggled () 401end 402 403function PANEL : IsDebugging () 404return self . DEBUG and self . DEBUG : IsToggled () or false 405end 406 407function PANEL : GetTransparency () 408return self . TRANSPARENCY and self . TRANSPARENCY : GetValue () or nil 409end 410 411function PANEL : OnClosed () 412self : SaveSettings () 413end 414 415function PANEL : NeedsWrite () 416for k , v in pairs ( self : GetSaveTable ()) do 417-- Return true if the last known settings state differs from the current 418if self . m_tSettings [ k ] == nil or self . m_tSettings [ k ] ~= v then 419return true 420end 421end 422return false 423end 424 425function PANEL : SaveSettings () 426if not self : NeedsWrite () then return end -- Stop if we don't need to write any changes 427local f , err =filesystem . newFile ( self . m_sFileName , "w" ) 428if f then 429log . warn ( "Writing to %s" , self . m_sFileName ) 430notification . warning (( "Writing to %s" ): format ( self . m_sFileName )) 431self . m_tSettings =self : GetSaveTable () 432f : write ( json . encode ( self . m_tSettings , true )) 433f : flush () 434f : close () 435else 436log . error ( "Failed writing to %s (%s)" , self . m_sFileName , err ) 437notification . error (( "Failed writing to %s (%s)" ): format ( self . m_sFileName , err )) 438end 439end 440 441function PANEL : LoadSettings () 442local settings =self : GetSaveTable () 443 444local f =filesystem . newFile ( self . m_sFileName , "r" ) 445if f then 446for k , v in pairs ( json . decode ( f : read ())) do 447if settings [ k ] ~= nil then 448settings [ k ] =v 449elseif k == "hide-dpad" then 450settings [ "enable-dpad" ] =not v 451log . debug ( "[CONFIG] Converting old config setting %q" , k ) 452elseif k == "slippi-netplay" and v == true then 453settings [ "slippi-mode" ] =SLIPPI_NETPLAY 454log . debug ( "[CONFIG] Converting old config setting %q" , k ) 455elseif k == "stage-music" or k == "stage-music-loop" or k == "music-volume" then 456settings [ "melee-" .. k ] =v 457log . debug ( "[CONFIG] Converting old config setting %q to %q" , k , "melee-" .. k ) 458else 459log . debug ( "[CONFIG] Ignoring old setting config %q" , k ) 460end 461end 462f : close () 463end 464 465if type ( settings [ "melee-stage-music-loop" ]) == "boolean" and settings [ "melee-stage-music-loop" ] == true then 466settings [ "melee-stage-music-loop" ] =LOOPING_STAGE 467end 468 469self . m_tSettings =settings 470 471overlay . setPort ( settings [ "port" ]) 472overlay . setSkin ( settings [ "skin" ]) 473 474self . PORTTITLE : SetToggle ( settings [ "port-in-title" ], true ) 475self . ALWAYSPORT : SetToggle ( settings [ "always-show-port" ], true ) 476self . HIGH_CONTRAST : SetToggle ( settings [ "high-contrast" ], true ) 477self . DPAD : SetToggle ( settings [ "enable-dpad" ], true ) 478self . START : SetToggle ( settings [ "enable-start" ], true ) 479if self . DEBUG then 480self . DEBUG : SetToggle ( love . hasConsole () or settings [ "debugging" ] or false ) 481end 482self . TRANSPARENCY : SetValue ( settings [ "transparency" ]) 483self . SLIPPI . MODE : SetOption ( settings [ "slippi-mode" ]) 484self . MELEE . MUSIC : SetToggle ( settings [ "melee-stage-music" ], true ) 485self . MELEE . MUSICLOOP : SelectOption ( settings [ "melee-stage-music-loop" ] or LOOPING_OFF , true ) 486self . MELEE . MUSICSKIP : UpdateButtonCombo ( settings [ "melee-stage-music-skip-buttons" ]) 487self . MELEE . VOLUME : SetValue ( settings [ "melee-music-volume" ]) 488self . BACKGROUNDCOLOR : SetColor ( color ( settings [ "background-color" ])) 489end