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