fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
9ce8403
v2.1.1b
1local PANEL =class . create ( "MusicFileSlider" , "Panel" ) 2 3PANEL : ACCESSOR ( "FilePath" , "m_strFilePath" , "" ) 4 5function PANEL : MusicFileSlider () 6self : super () 7 8self : SetHeight ( 56 ) 9 10self . m_pSlider =self : Add ( "SliderPanel" ) 11self . m_pSlider : Dock ( DOCK_RIGHT ) 12self . m_pSlider : SetWidth ( 128 ) 13self . m_pSlider : SetNeedsFocus ( true ) 14 15self . m_pFileName =self : Add ( "LabelIcon" ) 16self . m_pFileName : Dock ( DOCK_FILL ) 17self . m_pFileName : SetTextAlignmentX ( "left" ) 18self . m_pFileName : SetTextAlignmentY ( "center" ) 19self . m_pFileName : SetImage ( "textures/gui/page.png" ) 20self . m_pFileName : SetWrapped ( true ) 21self . m_pFileName : TextMargin ( 28 , 7 , 4 , 4 ) 22 23self : InheritMethods ( self . m_pSlider ) 24self : SetTextFormat ( "%d%%" ) 25end 26 27function PANEL : SetFileName ( str ) 28self . m_pFileName : SetText ( str ) 29end 30 31function PANEL : GetFileName () 32return self . m_pFileName : GetText () 33end 34 35local PANEL =class . create ( "MusicDirectory" , "Panel" ) 36 37function PANEL : MusicDirectory () 38self : super () 39 40self . m_pDirectoryLabel =self : Add ( "ButtonIcon" ) 41self . m_pDirectoryLabel : SetFocusable ( true ) 42self . m_pDirectoryLabel : Dock ( DOCK_TOP ) 43self . m_pDirectoryLabel : SetTextAlignmentX ( "left" ) 44self . m_pDirectoryLabel : SetImage ( "textures/gui/folder_link.png" ) 45 46function self . m_pDirectoryLabel : OnClick () 47love . system . openURL (( "file://%s/%s" ): format ( love . filesystem . getSaveDirectory (), self : GetText ())) 48end 49 50self . m_pFiles =self : Add ( "Panel" ) 51self . m_pFiles : Dock ( DOCK_FILL ) 52self . m_pFiles : DockPadding ( 0 , 0 , 0 , 0 ) 53self . m_pFiles : DockMargin ( 0 , 0 , 0 , 0 ) 54self . m_pFiles : SetDrawPanel ( false ) 55end 56 57function PANEL : SetPath ( str ) 58self . m_pDirectoryLabel : SetText ( str ) 59end 60 61function PANEL : AddFile ( name ) 62local file =self . m_pFiles : Add ( "MusicFileSlider" ) 63file : Dock ( DOCK_TOP ) 64file : SetFileName ( name ) 65return file 66end 67 68function PANEL : GetFiles () 69return self . m_pFiles : GetChildren () 70end 71 72function PANEL : PerformLayout () 73self . m_pFiles : SizeToChildren ( false , true ) 74self : SizeToChildren ( false , true ) 75end 76 77function PANEL : Search ( text ) 78local numVis =0 79for k , child in ipairs ( self . m_pFiles : GetChildren ()) do 80local vis =string . find ( child : GetFileName (): lower (), text : lower (), 1 , true ) ~= nil 81if vis then numVis =numVis + 1 end 82child : SetVisible ( vis ) 83end 84self : SetVisible ( numVis > 0 ) 85end 86 87local PANEL =class . create ( "MusicProbability" , "Panel" ) 88 89local music =require ( "music" ) 90 91local MODE_GLOBAL =0 92local MODE_STATE =1 93 94function PANEL : UpdatePlaylist () 95local mode =self . PROBMODE : GetOption () 96local playlistTree =music . getPlaylistTree () 97 98self . PLAYLIST : Clear () 99 100for folder , entries in pairs ( playlistTree ) do 101local directory =self . PLAYLIST : Add ( "MusicDirectory" ) 102directory : Dock ( DOCK_TOP ) 103directory : SetPath ( folder ) 104 105for k , entry in ipairs ( entries ) do 106local file =directory : AddFile ( entry . FILENAME ) 107local path =entry . FILEPATH 108 109file : SetFilePath ( path ) 110 111self . m_tblStateValues [ MODE_GLOBAL ][ path ] =music . getGlobalFileProbability ( path ) 112self . m_tblStateValues [ MODE_STATE ][ path ] =music . getStateFileProbability ( path ) 113 114file : SetValue ( self . m_tblStateValues [ mode ][ path ]) 115end 116end 117end 118 119function PANEL : GetTableValues () 120local tbl ={} 121for k , directory in ipairs ( self . PLAYLIST : GetCanvas (): GetChildren ()) do 122for k , file in ipairs ( directory : GetFiles ()) do 123tbl [ file : GetFilePath ()] =file : GetValue () 124end 125end 126return tbl 127end 128 129function PANEL : SetTableValues ( tbl ) 130for k , directory in ipairs ( self . PLAYLIST : GetCanvas (): GetChildren ()) do 131for k , file in ipairs ( directory : GetFiles ()) do 132local path =file : GetFilePath () 133if tbl [ path ] then 134file : SetValue ( tbl [ path ]) 135end 136end 137end 138end 139 140function PANEL : ResetAll ( mode ) 141for k , directory in ipairs ( self . PLAYLIST : GetCanvas (): GetChildren ()) do 142for k , file in ipairs ( directory : GetFiles ()) do 143if file : IsVisible () then 144local path =file : GetFilePath () 145 146local value 147 148if mode == MODE_GLOBAL then 149value =music . getGlobalFileProbability ( path ) 150else 151value =music . getStateFileProbability ( path ) 152end 153 154file : SetValue ( value ) 155end 156end 157end 158end 159 160function PANEL : SetAllValue ( value ) 161for k , directory in ipairs ( self . PLAYLIST : GetCanvas (): GetChildren ()) do 162for k , file in ipairs ( directory : GetFiles ()) do 163if file : IsVisible () then 164file : SetValue ( value ) 165end 166end 167end 168end 169 170function PANEL : MusicProbability () 171self : super () 172 173self . TOPBAR =self : Add ( "Panel" ) 174self . TOPBAR : Dock ( DOCK_TOP ) 175self . TOPBAR : SetHeight ( 28 ) 176self . TOPBAR : DockPadding ( 0 , 0 , 0 , 0 ) 177self . TOPBAR : DockMargin ( 0 , 0 , 0 , 0 ) 178self . TOPBAR : SetBorderColor ( color_blank ) 179 180self . SEARCH =self . TOPBAR : Add ( "TextEntry" ) 181self . SEARCH : Dock ( DOCK_FILL ) 182self . SEARCH : SetTextHint ( "Search.." ) 183 184self . SEARCH . OnTextChanged =function ( this , text , add ) 185self . PLAYLIST : SetScroll ( 0 ) 186for k , child in ipairs ( self . PLAYLIST : GetCanvas (): GetChildren ()) do 187child : Search ( text ) 188end 189return true 190end 191 192self . m_tblStateValues ={ 193[ MODE_GLOBAL ] ={} , 194[ MODE_STATE ] ={} , 195} 196 197self . REFRESH =self . TOPBAR : Add ( "ButtonIcon" ) 198self . REFRESH : SetImage ( "textures/gui/arrow_refresh.png" ) 199self . REFRESH : Dock ( DOCK_RIGHT ) 200self . REFRESH : SetText ( "Refresh" ) 201self . REFRESH : SetWidth ( 24 ) 202self . REFRESH : SetTooltipTitle ( "REFRESH" ) 203self . REFRESH : SetTooltipBody ( [[This button will refetch all the songs for the given state of the game. 204 205NOTE: If you are on the menus, pressing this button will display all songs that can play on the menu. If you are on a stage, it will display all songs that can play when on that stage.]] ) 206 207self . PROBMODE =self . TOPBAR : Add ( "RadioPanel" ) 208self . PROBMODE : SetHorizontal ( true ) 209self . PROBMODE : SetDrawPanel ( false ) 210self . PROBMODE : SetDrawLabel ( false ) 211self . PROBMODE : Dock ( DOCK_RIGHT ) 212self . PROBMODE : DockMargin ( 0 , 0 , 0 , 0 ) 213self . PROBMODE : DockPadding ( 0 , 0 , 0 , 0 ) 214 215local global =self . PROBMODE : AddOption ( MODE_GLOBAL , "Global" , true ) 216global : SetWidth ( 70 ) 217global : SetTooltipParent ( self . PROBMODE ) 218global : SetTooltipTitle ( "GLOBAL PROBABILITY" ) 219global : SetTooltipBody ( [[When in global mode, you can adjust the probability the given song will play at a global level. This will apply across all possible game states. 220 221NOTE: A song that has been adjusted in "state" mode will override the probability of its "global" mode value.]] ) 222 223local state =self . PROBMODE : AddOption ( MODE_STATE , "State" ) 224state : SetWidth ( 66 ) 225state : SetTooltipParent ( self . PROBMODE ) 226state : SetTooltipTitle ( "STATE PROBABILITY" ) 227state : SetTooltipBody ( [[When in state mode, you can adjust the probability the given song will play during the currently active state. 228 229NOTE: A "state" refers to the state of the game, such as being on the menus, or within a stage. Each stage is considered its own "state" and will allow you to fine-tune the probability of a single song across multiple states.]] ) 230 231self . PROBMODE . OnSelectOption =function ( this , mode , previous ) 232self . m_tblStateValues [ previous ] =self : GetTableValues () 233self : SetTableValues ( self . m_tblStateValues [ mode ]) 234end 235 236self . REFRESH . OnClick =function ( this ) 237self : UpdatePlaylist () 238end 239 240self . PLAYLIST =self : Add ( "ScrollPanel" ) 241self . PLAYLIST : Dock ( DOCK_FILL ) 242self . PLAYLIST : DockPadding ( 0 , 0 , 0 , 0 ) 243 244self . OPTIONS =self : Add ( "Panel" ) 245self . OPTIONS : Dock ( DOCK_BOTTOM ) 246self . OPTIONS : SetHeight ( 28 ) 247self . OPTIONS : DockPadding ( 0 , 0 , 0 , 0 ) 248self . OPTIONS : DockMargin ( 0 , 0 , 0 , 0 ) 249self . OPTIONS : SetBorderColor ( color_blank ) 250 251self . ZERO =self . OPTIONS : Add ( "ButtonIcon" ) 252self . ZERO : SetImage ( "textures/gui/bullet_arrow_down.png" ) 253self . ZERO : TextMargin ( 24 , 0 , 0 , 0 ) 254self . ZERO : Dock ( DOCK_LEFT ) 255self . ZERO : SetText ( "Zero" ) 256self . ZERO : SetWidth ( 24 ) 257self . ZERO : SetTooltipTitle ( "ZERO" ) 258self . ZERO : SetTooltipBody ( [[Sets all songs on this playlist to have 0% chance of playing.]] ) 259 260self . ZERO . OnClick =function ( this ) 261self : SetAllValue ( 0 ) 262end 263 264self . MID =self . OPTIONS : Add ( "ButtonIcon" ) 265self . MID : SetImage ( "textures/gui/bullet_arrow_center.png" ) 266self . MID : TextMargin ( 24 , 0 , 0 , 0 ) 267self . MID : Dock ( DOCK_LEFT ) 268self . MID : SetText ( "Center" ) 269self . MID : SetWidth ( 24 ) 270self . MID : SetTooltipTitle ( "CENTER" ) 271self . MID : SetTooltipBody ( [[Sets all songs on this playlist to have 50% chance of playing.]] ) 272 273self . MID . OnClick =function ( this ) 274self : SetAllValue ( 50 ) 275end 276 277self . MAX =self . OPTIONS : Add ( "ButtonIcon" ) 278self . MAX : SetImage ( "textures/gui/bullet_arrow_up.png" ) 279self . MAX : TextMargin ( 24 , 0 , 0 , 0 ) 280self . MAX : Dock ( DOCK_LEFT ) 281self . MAX : SetText ( "Max" ) 282self . MAX : SetWidth ( 24 ) 283self . MAX : SetTooltipTitle ( "MAX" ) 284self . MAX : SetTooltipBody ( [[Sets all songs on this playlist to have 100% chance of playing.]] ) 285 286self . MAX . OnClick =function ( this ) 287self : SetAllValue ( 100 ) 288end 289 290self . RESET =self . OPTIONS : Add ( "ButtonIcon" ) 291self . RESET : SetImage ( "textures/gui/arrow_undo.png" ) 292self . RESET : TextMargin ( 24 , 0 , 0 , 0 ) 293self . RESET : Dock ( DOCK_LEFT ) 294self . RESET : SetText ( "Reset" ) 295self . RESET : SetWidth ( 24 ) 296self . RESET : SetTooltipTitle ( "RESET" ) 297self . RESET : SetTooltipBody ( [[Sets all songs on this playlist to their previously known value.]] ) 298 299self . RESET . OnClick =function ( this ) 300self : ResetAll ( self . PROBMODE : GetOption ()) 301end 302 303self . OKAY =self . OPTIONS : Add ( "ButtonIcon" ) 304self . OKAY : SetImage ( "textures/gui/disk.png" ) 305self . OKAY : Dock ( DOCK_RIGHT ) 306self . OKAY : SetText ( "Save" ) 307self . OKAY : SetWidth ( 64 ) 308self . OKAY : SetTooltipTitle ( "SAVE" ) 309self . OKAY : SetTooltipBody ( [[Save all changes to disk and exit.]] ) 310 311self . OKAY . OnClick =function ( this ) 312self : SetVisible ( false ) 313self . m_tblStateValues [ self . PROBMODE : GetOption ()] =self : GetTableValues () 314music . updateGlobalProbabilities ( self . m_tblStateValues [ MODE_GLOBAL ]) 315music . updateStateProbabilities ( self . m_tblStateValues [ MODE_STATE ]) 316music . saveProbabilities () 317end 318 319self . CANCEL =self . OPTIONS : Add ( "ButtonIcon" ) 320self . CANCEL : SetImage ( "textures/gui/cancel.png" ) 321self . CANCEL : Dock ( DOCK_RIGHT ) 322self . CANCEL : SetText ( "Cancel" ) 323self . CANCEL : SetWidth ( 76 ) 324self . CANCEL : SetTooltipTitle ( "CANCEL" ) 325self . CANCEL : SetTooltipBody ( [[Disregard any changes made and exit.]] ) 326 327self . CANCEL . OnClick =function ( this ) 328self : SetVisible ( false ) 329end 330end