Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cursong = 1
- local curdiff = 1
- local curmode = 1
- local searchopt = "Search:"
- local songlist = {}
- function Resize(width,height,setwidth,sethight)
- if height >= sethight and width >= setwidth then
- if height*(setwidth/sethight) >= width then
- return sethight/height
- else
- return setwidth/width
- end
- elseif height >= sethight then
- return sethight/height
- elseif width >= setwidth then
- return setwidth/width
- else
- return 1
- end
- end
- function MainLoadSongs(self)
- local songs = SONGMAN:GetAllSongs()
- for i = 1,#songs do
- if songs[i]:GetStepsByStepsType('StepsType_Dance_Single')[1] then
- local diffname = {}
- local difftype = {}
- for i2 = 1,#songs[i]:GetStepsByStepsType('StepsType_Dance_Single') do
- diffname[#diffname+1] = ToEnumShortString(songs[i]:GetStepsByStepsType('StepsType_Dance_Single')[i2]:GetStepsType())
- difftype[#difftype+1] = ToEnumShortString(songs[i]:GetStepsByStepsType('StepsType_Dance_Single')[i2]:GetDifficulty())
- end
- local CDTitlePath
- local CDTitleHash
- if songs[i]:GetCDTitlePath() then
- CDTitlePath = songs[i]:GetCDTitlePath()
- CDTitleHash = FILEMAN:GetHashForFile(songs[i]:GetCDTitlePath())
- else
- CDTitlePath = THEME:GetPathG("","_blank")
- CDTitleHash = 9999999999
- end
- local BannerPath
- if songs[i]:HasBanner() then
- BannerPath = songs[i]:GetBannerPath()
- else
- BannerPath = THEME:GetPathG("","_blank")
- end
- local BackgroundPath
- if songs[i]:HasBackground() then
- BackgroundPath = songs[i]:GetBackgroundPath()
- else
- BackgroundPath = THEME:GetPathG("","_blank")
- end
- --1 title, 2 subtitle, 3 artist, 4 genre, 5 bpm, 6 diffname, 7 difftype, 8 song -- Just in case, 9CDTitleHash, 10CDTitleLoc, 11BannerLoc, 12 BackgroundLoc
- songlist[#songlist+1] = {songs[i]:GetDisplayMainTitle(),songs[i]:GetDisplaySubTitle(),songs[i]:GetDisplayArtist(),songs[i]:GetGenre(),songs[i]:GetDisplayBpms(),diffname,difftype,songs[i],CDTitleHash,CDTitlePath,BannerPath,BackgroundPath}
- end
- end
- end
- function sort(searchinput)
- local sortedsongs = {}
- local str = string.match(searchinput, "Search:(.+)")
- if str == nil then str = "" end
- for songno in pairs(songlist) do
- if string.find(str, "artist;") then
- local substr = string.match(searchinput, "artist;(.+)")
- if string.find(string.lower(songlist[songno][3]), substr) then
- sortedsongs[#sortedsongs+1] = songno
- end
- elseif string.find(str, "subtitle;") then
- local substr = string.match(searchinput, "subtitle;(.+)")
- if string.find(string.lower(songlist[songno][2]), substr) then
- sortedsongs[#sortedsongs+1] = songno
- end
- elseif string.find(str, "genre;") then
- local substr = string.match(searchinput, "genre;(.+)")
- if string.find(string.lower(songlist[songno][4]), substr) then
- sortedsongs[#sortedsongs+1] = songno
- end
- elseif string.find(str, "bpm;") then
- local substr = string.match(searchinput, "bpm;(.+)")
- local BPM = {}
- for BPM1 in string.gmatch(substr, "%d+") do BPM[#BPM+1] = BPM1 end
- if #BPM == 1 then
- if tonumber(string.format("%.0f",songlist[songno][5][1])) == tonumber(BPM[1]) then
- sortedsongs[#sortedsongs+1] = songno
- end
- elseif BPM[1] then
- if tonumber(string.format("%.0f",songlist[songno][5][1])) > tonumber(BPM[1]) and tonumber(string.format("%.0f",songlist[songno][5][2])) < tonumber(BPM[2]) then
- sortedsongs[#sortedsongs+1] = songno
- end
- end
- elseif string.find(str, "sort;") then
- sortedsongs[#sortedsongs+1] = songno
- else
- if string.find(string.lower(songlist[songno][1]), str) then
- sortedsongs[#sortedsongs+1] = songno
- end
- end
- end
- local sorting = {}
- if string.find(str, "sort;") then
- for i = 1,#sortedsongs do
- local DisplayTitle = songlist[sortedsongs[i]][1]
- local DisplaySubTitle = songlist[sortedsongs[i]][2]
- local DisplayArtist = songlist[sortedsongs[i]][3]
- local BPM = tonumber(string.format("%.0f",songlist[sortedsongs[i]][5][1]))
- local CDTitle = songlist[sortedsongs[i]][9]
- sorting[#sorting+1] = {sortedsongs[i],DisplayTitle,DisplaySubTitle,DisplayArtist,BPM,CDTitle}
- end
- if string.find(str, "sort;title") then
- table.sort(sorting, function(a,b) return a[2]<b[2] end)
- for i2 = 1,#sorting do sortedsongs[i2] = sorting[i2][1] end
- elseif string.find(str, "sort;subtitle") then
- table.sort(sorting, function(a,b) return a[3]<b[3] end)
- for i2 = 1,#sorting do sortedsongs[i2] = sorting[i2][1] end
- elseif string.find(str, "sort;artist") then
- table.sort(sorting, function(a,b) return a[4]<b[4] end)
- for i2 = 1,#sorting do sortedsongs[i2] = sorting[i2][1] end
- elseif string.find(str, "sort;bpm") then
- table.sort(sorting, function(a,b) return a[5]<b[5] end)
- for i2 = 1,#sorting do sortedsongs[i2] = sorting[i2][1] end
- elseif string.find(str, "sort;cdtitle") then
- table.sort(sorting, function(a,b) return a[6]<b[6] end)
- for i2 = 1,#sorting do sortedsongs[i2] = sorting[i2][1] end
- end
- end
- return sortedsongs
- end
- function SimWheel(Base)
- local wheellist = Def.ActorFrame{
- OnCommand=function(self) SCREENMAN:GetTopScreen():AddInputCallback(wheelinput) wheelact = self end;
- NextScreenCommand=function(self) GAMESTATE:ApplyGameCommand(); end;
- }
- wheellist[#wheellist+1] = Def.Sound{Name="SoundChange";File=THEME:GetPathS("ScreenSelectMaster", "change")}
- wheellist[#wheellist+1] = Def.Sound{Name="SoundStart";File=THEME:GetPathS("ScreenSelectMaster", "start")}
- validsongno = sort(searchopt)
- if validsongno[cursong] == nil then cursong = 1 end
- if #validsongno ~= 0 then
- if tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][1])) == tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][2])) then
- bpm = tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][1]))
- else
- bpm = tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][1])).."-"..tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][2]))
- end
- wheellist[#wheellist+1] = Def.Sprite{Name="Background";Texture=songlist[validsongno[cursong]][12];OnCommand=function(self) self:zoom(Resize(self:GetWidth(),self:GetHeight(),SCREEN_WIDTH/4,SCREEN_HEIGHT/4)*8) end}
- wheellist[#wheellist+1] = Def.Banner{Name="Banner";Texture=songlist[validsongno[cursong]][11];OnCommand=function(self) self:x(-512+64+16):y(-256):zoom(Resize(self:GetWidth(),self:GetHeight(),256,80)*3.2) end}
- wheellist[#wheellist+1] = Def.Sprite{Name="CDTitle";Texture=songlist[validsongno[cursong]][10];OnCommand=function(self) self:x(-128):y(-256+64):zoom(Resize(self:GetWidth(),self:GetHeight(),80,60)*3.2) end}
- wheellist[#wheellist+1] = LoadFont("OptionRow Title") .. {Name="DiffName";Text=songlist[validsongno[cursong]][6][curdiff];OnCommand=cmd(x,-32;y,-32;horizalign,right;diffuse,color("#000000"))}
- wheellist[#wheellist+1] = LoadFont("OptionRow Title") .. {Name="DiffType";Text=songlist[validsongno[cursong]][7][curdiff];OnCommand=cmd(x,-32;y,0;horizalign,right;diffuse,color("#000000"))}
- wheellist[#wheellist+1] = LoadFont("OptionRow Title") .. {Name="BPM";Text="BPM:"..bpm;OnCommand=cmd(x,-32;y,32;horizalign,right;diffuse,color("#000000"))}
- end
- wheellist[#wheellist+1] = LoadFont("OptionRow Title") .. {Name="Search";Text=searchopt;OnCommand=cmd(x,-SCREEN_CENTER_X*2;y,(-SCREEN_CENTER_Y*2)+16;horizalign,left;diffuse,color("#000000"))}
- local pos2 = 0
- local pos3 = #validsongno-1
- for i = -Base[2],Base[2] do
- local cursong2 = cursong
- local pos = i
- if #validsongno == 0 then
- wheellist[#wheellist+1] = LoadFont("OptionRow Title") .. {Name="Scroll"..i;Text="No Valid Songs Found";OnCommand=cmd(horizalign,left;y,(i*32);diffuse,color("#000000");maxwidth,800);InitCommand=function(self) if i == 0 then self:x(-16) end end}
- else
- if pos > #validsongno then
- pos2 = pos2 + 1
- if pos2 > #validsongno then pos2 = 1 end
- i = pos2
- end
- if pos*-1 > #validsongno then
- pos3 = pos3 + 1
- if pos3 > #validsongno then pos3 = 1 end
- i = pos3
- end
- if cursong+i < 1 then cursong2 = #validsongno+cursong end
- if cursong+i > #validsongno then cursong2 = (#validsongno-cursong)*-1 end
- wheellist[#wheellist+1] = LoadFont("OptionRow Title") .. {Name="TitScroll"..pos;Text=songlist[validsongno[cursong2+i]][1];OnCommand=cmd(horizalign,left;y,(pos*64-16);diffuse,color("#000000");maxwidth,800);InitCommand=function(self) if pos == 0 then self:x(-16) end end}
- wheellist[#wheellist+1] = LoadFont("OptionRow Title") .. {Name="SubScroll"..pos;Text=songlist[validsongno[cursong2+i]][2];OnCommand=cmd(horizalign,left;y,(pos*64);diffuse,color("#000000");maxwidth,800);InitCommand=function(self) if pos == 0 then self:x(-16) end end}
- wheellist[#wheellist+1] = LoadFont("OptionRow Title") .. {Name="ArtScroll"..pos;Text=songlist[validsongno[cursong2+i]][3];OnCommand=cmd(horizalign,left;y,(pos*64+16);diffuse,color("#000000");maxwidth,800);InitCommand=function(self) if pos == 0 then self:x(-16) end end}
- end
- end
- function wheelinput(event)
- if validsongno[cursong] == nil then cursong = 1 end
- if ToEnumShortString(event.type) == "FirstPress" and curmode == 2 then
- let = ToEnumShortString(event.DeviceInput.button)
- if let == "space" then let = " " end
- if let == "backspace" then
- if searchopt ~= "Search:" then
- searchopt = string.match(searchopt, "(.+).")
- end
- else
- if string.len(let) > 1 then let = "" end
- searchopt = searchopt..let
- end
- wheelact:GetChild("Search"):settext(searchopt)
- end
- if not event.PlayerNumber then return end
- if ToEnumShortString(event.type) == "Repeat" then
- if event.GameButton == "MenuDown" and curmode == 1 then
- wheelact:GetChild("SoundChange"):play()
- cursong = cursong + 1
- end
- if event.GameButton == "MenuUp" and curmode == 1 then
- wheelact:GetChild("SoundChange"):play()
- cursong = cursong - 1
- end
- end
- if ToEnumShortString(event.type) == "FirstPress" then
- if event.GameButton == "Back" then
- GAMESTATE:ApplyGameCommand(Base[1]);
- end
- if event.GameButton == "MenuDown" and curmode == 1 then
- wheelact:GetChild("SoundChange"):play()
- cursong = cursong + 1
- end
- if event.GameButton == "MenuUp" and curmode == 1 then
- wheelact:GetChild("SoundChange"):play()
- cursong = cursong - 1
- end
- if event.GameButton == "MenuLeft" and curmode == 1 then
- wheelact:GetChild("SoundChange"):play()
- curdiff = curdiff + 1
- end
- if event.GameButton == "MenuRight" and curmode == 1 then
- wheelact:GetChild("SoundChange"):play()
- curdiff = curdiff - 1
- end
- if event.GameButton == "Start" and curmode == 1 and #validsongno ~= 0 then
- wheelact:GetChild("SoundStart"):play()
- GAMESTATE:SetCurrentPlayMode('PlayMode_Regular')
- GAMESTATE:SetCurrentSong(songlist[validsongno[cursong]][8])
- GAMESTATE:SetCurrentSteps(PLAYER_1,songlist[validsongno[cursong]][8]:GetStepsByStepsType('StepsType_Dance_Single')[curdiff])
- SCREENMAN:GetTopScreen():SetNextScreenName("ScreenGameplay"):StartTransitioningScreen("SM_GoToNextScreen")
- end
- if event.GameButton == "Select" and curmode == 1 then
- wheelact:GetChild("SoundStart"):play()
- curmode = 2
- end
- if event.GameButton == "Start" and curmode == 2 then
- wheelact:GetChild("SoundStart"):play()
- validsongno = sort(searchopt)
- curmode = 1
- end
- end
- if cursong > #validsongno then cursong = 1 end
- if cursong < 1 then cursong = #validsongno end
- if #validsongno == 0 then
- wheelact:GetChild("DiffName"):settext("")
- wheelact:GetChild("DiffType"):settext("")
- wheelact:GetChild("BPM"):settext("")
- else
- if tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][1])) == tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][2])) then
- bpm = tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][1]))
- else
- bpm = tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][1])).."-"..tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][2]))
- end
- if curdiff > #songlist[validsongno[cursong]][6] then curdiff = 1 end
- if curdiff < 1 then curdiff = #songlist[validsongno[cursong]][6] end
- if event.GameButton == "MenuDown" or event.GameButton == "MenuUp" then
- if curmode == 1 then
- wheelact:GetChild("Background"):LoadFromCached("Background",songlist[validsongno[cursong]][12]):zoom(Resize(wheelact:GetChild("Background"):GetWidth(),wheelact:GetChild("Background"):GetHeight(),SCREEN_WIDTH/4,SCREEN_HEIGHT/4)*8)
- wheelact:GetChild("Banner"):LoadFromCachedBanner(songlist[validsongno[cursong]][11]):zoom(Resize(wheelact:GetChild("Banner"):GetWidth(),wheelact:GetChild("Banner"):GetHeight(),256,80)*3.2)
- wheelact:GetChild("CDTitle"):LoadFromCached("CDTitle",songlist[validsongno[cursong]][10]):zoom(Resize(wheelact:GetChild("CDTitle"):GetWidth(),wheelact:GetChild("CDTitle"):GetHeight(),80,60)*3.2)
- end
- end
- if ToEnumShortString(event.type) == "Release" then
- wheelact:GetChild("Background"):Load(songlist[validsongno[cursong]][12]):zoom(Resize(wheelact:GetChild("Background"):GetWidth(),wheelact:GetChild("Background"):GetHeight(),SCREEN_WIDTH/4,SCREEN_HEIGHT/4)*8)
- wheelact:GetChild("Banner"):Load(songlist[validsongno[cursong]][11]):zoom(Resize(wheelact:GetChild("Banner"):GetWidth(),wheelact:GetChild("Banner"):GetHeight(),256,80)*3.2)
- wheelact:GetChild("CDTitle"):Load(songlist[validsongno[cursong]][10]):zoom(Resize(wheelact:GetChild("CDTitle"):GetWidth(),wheelact:GetChild("CDTitle"):GetHeight(),80,60)*3.2)
- end
- wheelact:GetChild("DiffName"):settext(songlist[validsongno[cursong]][6][curdiff])
- wheelact:GetChild("DiffType"):settext(songlist[validsongno[cursong]][7][curdiff])
- wheelact:GetChild("BPM"):settext("BPM:"..bpm)
- end
- local pos2 = 0
- local pos3 = #validsongno-1
- for i = -Base[2],Base[2] do
- local cursong2 = cursong
- local pos = i
- if #validsongno == 0 then
- wheelact:GetChild("TitScroll"..pos):settext("No Valid Songs Found")
- wheelact:GetChild("SubScroll"..pos):settext("")
- wheelact:GetChild("ArtScroll"..pos):settext("")
- else
- if pos > #validsongno then
- pos2 = pos2 + 1
- if pos2 > #validsongno then pos2 = 1 end
- i = pos2
- end
- if pos*-1 > #validsongno then
- pos3 = pos3 + 1
- if pos3 > #validsongno then pos3 = 1 end
- i = pos3
- end
- if cursong+i < 1 then cursong2 = #validsongno+cursong end
- if cursong+i > #validsongno then cursong2 = (#validsongno-cursong)*-1 end
- wheelact:GetChild("TitScroll"..pos):settext(songlist[validsongno[cursong2+i]][1])
- wheelact:GetChild("SubScroll"..pos):settext(songlist[validsongno[cursong2+i]][2])
- wheelact:GetChild("ArtScroll"..pos):settext(songlist[validsongno[cursong2+i]][3])
- end
- end
- end
- return wheellist
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement