Advertisement
Jousway

SimWheel 0.7

Sep 11th, 2017
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.74 KB | None | 0 0
  1. local cursong = 1
  2. local curdiff = 1
  3. local curmode = 1
  4. local searchopt = "Search:"
  5. local songlist = {}
  6.  
  7. function Resize(width,height,setwidth,sethight)
  8.  
  9.     if height >= sethight and width >= setwidth then
  10.         if height*(setwidth/sethight) >= width then
  11.             return sethight/height
  12.         else
  13.             return setwidth/width
  14.         end
  15.     elseif height >= sethight then
  16.         return sethight/height
  17.     elseif width >= setwidth then
  18.         return setwidth/width
  19.     else
  20.         return 1
  21.     end
  22. end
  23.  
  24. function MainLoadSongs(self)
  25.     local songs = SONGMAN:GetAllSongs()
  26.  
  27.     for i = 1,#songs do
  28.         if songs[i]:GetStepsByStepsType('StepsType_Dance_Single')[1] then
  29.             local diffname = {}
  30.             local difftype = {}
  31.             for i2 = 1,#songs[i]:GetStepsByStepsType('StepsType_Dance_Single') do
  32.                 diffname[#diffname+1] = ToEnumShortString(songs[i]:GetStepsByStepsType('StepsType_Dance_Single')[i2]:GetStepsType())
  33.                 difftype[#difftype+1] = ToEnumShortString(songs[i]:GetStepsByStepsType('StepsType_Dance_Single')[i2]:GetDifficulty())
  34.             end
  35.            
  36.             local CDTitlePath
  37.             local CDTitleHash
  38.             if songs[i]:GetCDTitlePath() then
  39.                 CDTitlePath = songs[i]:GetCDTitlePath()
  40.                 CDTitleHash = FILEMAN:GetHashForFile(songs[i]:GetCDTitlePath())
  41.             else
  42.                 CDTitlePath = THEME:GetPathG("","_blank")
  43.                 CDTitleHash = 9999999999
  44.             end
  45.            
  46.             local BannerPath
  47.             if songs[i]:HasBanner() then
  48.                 BannerPath = songs[i]:GetBannerPath()
  49.             else
  50.                 BannerPath = THEME:GetPathG("","_blank")
  51.             end
  52.            
  53.             local BackgroundPath
  54.             if songs[i]:HasBackground() then
  55.                 BackgroundPath = songs[i]:GetBackgroundPath()
  56.             else
  57.                 BackgroundPath = THEME:GetPathG("","_blank")
  58.             end
  59.                    
  60.             --1 title, 2 subtitle, 3 artist, 4 genre, 5 bpm, 6 diffname, 7 difftype, 8 song -- Just in case, 9CDTitleHash, 10CDTitleLoc, 11BannerLoc, 12 BackgroundLoc
  61.             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}
  62.         end
  63.     end
  64. end
  65.  
  66. function sort(searchinput)
  67.  
  68.     local sortedsongs = {}
  69.    
  70.     local str = string.match(searchinput, "Search:(.+)")
  71.     if str == nil then str = "" end
  72.  
  73.     for songno in pairs(songlist) do
  74.         if string.find(str, "artist;") then
  75.             local substr = string.match(searchinput, "artist;(.+)")
  76.             if string.find(string.lower(songlist[songno][3]), substr) then
  77.                 sortedsongs[#sortedsongs+1] = songno
  78.             end
  79.         elseif string.find(str, "subtitle;") then
  80.             local substr = string.match(searchinput, "subtitle;(.+)")
  81.             if string.find(string.lower(songlist[songno][2]), substr) then
  82.                 sortedsongs[#sortedsongs+1] = songno
  83.             end
  84.         elseif string.find(str, "genre;") then
  85.             local substr = string.match(searchinput, "genre;(.+)")
  86.             if string.find(string.lower(songlist[songno][4]), substr) then
  87.                 sortedsongs[#sortedsongs+1] = songno
  88.             end
  89.         elseif string.find(str, "bpm;") then
  90.             local substr = string.match(searchinput, "bpm;(.+)")
  91.             local BPM = {}
  92.             for BPM1 in string.gmatch(substr, "%d+") do BPM[#BPM+1] = BPM1 end
  93.             if #BPM == 1 then
  94.                 if tonumber(string.format("%.0f",songlist[songno][5][1])) == tonumber(BPM[1]) then
  95.                     sortedsongs[#sortedsongs+1] = songno
  96.                 end
  97.             elseif BPM[1] then
  98.                 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
  99.                     sortedsongs[#sortedsongs+1] = songno
  100.                 end
  101.             end
  102.         elseif string.find(str, "sort;") then
  103.             sortedsongs[#sortedsongs+1] = songno
  104.         else
  105.             if string.find(string.lower(songlist[songno][1]), str) then
  106.                 sortedsongs[#sortedsongs+1] = songno
  107.             end
  108.         end
  109.     end
  110.    
  111.     local sorting = {}
  112.    
  113.     if string.find(str, "sort;") then
  114.         for i = 1,#sortedsongs do
  115.             local DisplayTitle = songlist[sortedsongs[i]][1]
  116.             local DisplaySubTitle = songlist[sortedsongs[i]][2]
  117.             local DisplayArtist = songlist[sortedsongs[i]][3]
  118.             local BPM = tonumber(string.format("%.0f",songlist[sortedsongs[i]][5][1]))
  119.             local CDTitle = songlist[sortedsongs[i]][9]
  120.             sorting[#sorting+1] = {sortedsongs[i],DisplayTitle,DisplaySubTitle,DisplayArtist,BPM,CDTitle}
  121.         end
  122.         if string.find(str, "sort;title") then
  123.             table.sort(sorting, function(a,b) return a[2]<b[2] end)
  124.             for i2 = 1,#sorting do sortedsongs[i2] = sorting[i2][1] end
  125.         elseif string.find(str, "sort;subtitle") then
  126.             table.sort(sorting, function(a,b) return a[3]<b[3] end)
  127.             for i2 = 1,#sorting do sortedsongs[i2] = sorting[i2][1] end
  128.         elseif string.find(str, "sort;artist") then
  129.             table.sort(sorting, function(a,b) return a[4]<b[4] end)
  130.             for i2 = 1,#sorting do sortedsongs[i2] = sorting[i2][1] end
  131.         elseif string.find(str, "sort;bpm") then
  132.             table.sort(sorting, function(a,b) return a[5]<b[5] end)
  133.             for i2 = 1,#sorting do sortedsongs[i2] = sorting[i2][1] end
  134.         elseif string.find(str, "sort;cdtitle") then
  135.             table.sort(sorting, function(a,b) return a[6]<b[6] end)
  136.             for i2 = 1,#sorting do sortedsongs[i2] = sorting[i2][1] end
  137.         end
  138.     end
  139.    
  140.     return sortedsongs
  141. end
  142.  
  143. function SimWheel(Base)
  144.    
  145.     local wheellist = Def.ActorFrame{
  146.         OnCommand=function(self) SCREENMAN:GetTopScreen():AddInputCallback(wheelinput) wheelact = self end;
  147.         NextScreenCommand=function(self) GAMESTATE:ApplyGameCommand(); end;
  148.     }
  149.    
  150.     wheellist[#wheellist+1] = Def.Sound{Name="SoundChange";File=THEME:GetPathS("ScreenSelectMaster", "change")}
  151.     wheellist[#wheellist+1] = Def.Sound{Name="SoundStart";File=THEME:GetPathS("ScreenSelectMaster", "start")}
  152.    
  153.     validsongno = sort(searchopt)
  154.    
  155.     if validsongno[cursong] == nil then cursong = 1 end
  156.    
  157.     if #validsongno ~= 0 then
  158.         if tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][1])) == tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][2])) then
  159.             bpm = tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][1]))
  160.         else
  161.             bpm = tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][1])).."-"..tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][2]))
  162.         end
  163.         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}
  164.         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}
  165.         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}
  166.         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"))}
  167.         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"))}
  168.         wheellist[#wheellist+1] = LoadFont("OptionRow Title") .. {Name="BPM";Text="BPM:"..bpm;OnCommand=cmd(x,-32;y,32;horizalign,right;diffuse,color("#000000"))}
  169.     end
  170.    
  171.     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"))}
  172.    
  173.     local pos2 = 0
  174.     local pos3 = #validsongno-1
  175.    
  176.     for i = -Base[2],Base[2] do
  177.         local cursong2 = cursong
  178.         local pos = i
  179.         if #validsongno == 0 then
  180.             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}
  181.         else
  182.             if pos > #validsongno then
  183.                 pos2 = pos2 + 1
  184.                 if pos2 > #validsongno then pos2 = 1 end
  185.                 i = pos2
  186.             end
  187.             if pos*-1 > #validsongno then
  188.                 pos3 = pos3 + 1
  189.                 if pos3 > #validsongno then pos3 = 1 end
  190.                 i = pos3
  191.             end
  192.             if cursong+i < 1 then cursong2 = #validsongno+cursong end
  193.             if cursong+i > #validsongno then cursong2 = (#validsongno-cursong)*-1 end
  194.             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}
  195.             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}
  196.             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}
  197.         end
  198.     end
  199.    
  200.     function wheelinput(event) 
  201.         if validsongno[cursong] == nil then cursong = 1 end
  202.        
  203.         if ToEnumShortString(event.type) == "FirstPress" and curmode == 2 then 
  204.             let = ToEnumShortString(event.DeviceInput.button)
  205.             if let == "space" then let = " " end
  206.             if let == "backspace" then
  207.                 if searchopt ~= "Search:" then
  208.                     searchopt = string.match(searchopt, "(.+).")
  209.                 end
  210.             else
  211.                 if string.len(let) > 1 then let = "" end
  212.                 searchopt = searchopt..let
  213.             end
  214.            
  215.            
  216.             wheelact:GetChild("Search"):settext(searchopt)
  217.         end
  218.    
  219.         if not event.PlayerNumber then return end
  220.        
  221.         if ToEnumShortString(event.type) == "Repeat" then
  222.             if event.GameButton == "MenuDown" and curmode == 1 then
  223.                 wheelact:GetChild("SoundChange"):play()
  224.                 cursong = cursong + 1
  225.             end
  226.             if event.GameButton == "MenuUp" and curmode == 1 then
  227.                 wheelact:GetChild("SoundChange"):play()
  228.                 cursong = cursong - 1
  229.             end
  230.         end
  231.        
  232.         if ToEnumShortString(event.type) == "FirstPress" then      
  233.             if event.GameButton == "Back" then
  234.                 GAMESTATE:ApplyGameCommand(Base[1]);
  235.             end        
  236.             if event.GameButton == "MenuDown" and curmode == 1 then
  237.                 wheelact:GetChild("SoundChange"):play()
  238.                 cursong = cursong + 1
  239.             end
  240.             if event.GameButton == "MenuUp" and curmode == 1 then
  241.                 wheelact:GetChild("SoundChange"):play()
  242.                 cursong = cursong - 1
  243.             end
  244.             if event.GameButton == "MenuLeft" and curmode == 1 then
  245.                 wheelact:GetChild("SoundChange"):play()
  246.                 curdiff = curdiff + 1
  247.             end
  248.             if event.GameButton == "MenuRight" and curmode == 1 then
  249.                 wheelact:GetChild("SoundChange"):play()
  250.                 curdiff = curdiff - 1
  251.             end
  252.             if event.GameButton == "Start" and curmode == 1 and #validsongno ~= 0 then
  253.                 wheelact:GetChild("SoundStart"):play()
  254.                 GAMESTATE:SetCurrentPlayMode('PlayMode_Regular')
  255.                 GAMESTATE:SetCurrentSong(songlist[validsongno[cursong]][8])
  256.                 GAMESTATE:SetCurrentSteps(PLAYER_1,songlist[validsongno[cursong]][8]:GetStepsByStepsType('StepsType_Dance_Single')[curdiff])
  257.                 SCREENMAN:GetTopScreen():SetNextScreenName("ScreenGameplay"):StartTransitioningScreen("SM_GoToNextScreen")
  258.             end
  259.            
  260.             if event.GameButton == "Select" and curmode == 1 then
  261.                 wheelact:GetChild("SoundStart"):play()
  262.                 curmode = 2
  263.             end        
  264.             if event.GameButton == "Start" and curmode == 2 then
  265.                 wheelact:GetChild("SoundStart"):play()
  266.                 validsongno = sort(searchopt)
  267.                 curmode = 1
  268.             end        
  269.         end
  270.                    
  271.         if cursong > #validsongno then cursong = 1 end
  272.         if cursong < 1 then cursong = #validsongno end
  273.         if #validsongno == 0 then
  274.             wheelact:GetChild("DiffName"):settext("")
  275.             wheelact:GetChild("DiffType"):settext("")
  276.             wheelact:GetChild("BPM"):settext("")
  277.         else
  278.             if tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][1])) == tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][2])) then
  279.                 bpm = tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][1]))
  280.             else
  281.                 bpm = tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][1])).."-"..tonumber(string.format("%.0f",songlist[validsongno[cursong]][5][2]))
  282.             end
  283.             if curdiff > #songlist[validsongno[cursong]][6] then curdiff = 1 end
  284.             if curdiff < 1 then curdiff = #songlist[validsongno[cursong]][6] end
  285.             if event.GameButton == "MenuDown" or event.GameButton == "MenuUp" then
  286.                 if curmode == 1 then
  287.                     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)
  288.                     wheelact:GetChild("Banner"):LoadFromCachedBanner(songlist[validsongno[cursong]][11]):zoom(Resize(wheelact:GetChild("Banner"):GetWidth(),wheelact:GetChild("Banner"):GetHeight(),256,80)*3.2)
  289.                     wheelact:GetChild("CDTitle"):LoadFromCached("CDTitle",songlist[validsongno[cursong]][10]):zoom(Resize(wheelact:GetChild("CDTitle"):GetWidth(),wheelact:GetChild("CDTitle"):GetHeight(),80,60)*3.2)
  290.                 end
  291.             end
  292.             if ToEnumShortString(event.type) == "Release" then 
  293.                 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)
  294.                 wheelact:GetChild("Banner"):Load(songlist[validsongno[cursong]][11]):zoom(Resize(wheelact:GetChild("Banner"):GetWidth(),wheelact:GetChild("Banner"):GetHeight(),256,80)*3.2)
  295.                 wheelact:GetChild("CDTitle"):Load(songlist[validsongno[cursong]][10]):zoom(Resize(wheelact:GetChild("CDTitle"):GetWidth(),wheelact:GetChild("CDTitle"):GetHeight(),80,60)*3.2)
  296.             end
  297.             wheelact:GetChild("DiffName"):settext(songlist[validsongno[cursong]][6][curdiff])  
  298.             wheelact:GetChild("DiffType"):settext(songlist[validsongno[cursong]][7][curdiff])
  299.             wheelact:GetChild("BPM"):settext("BPM:"..bpm)
  300.         end
  301.        
  302.         local pos2 = 0
  303.         local pos3 = #validsongno-1
  304.        
  305.         for i = -Base[2],Base[2] do
  306.             local cursong2 = cursong
  307.             local pos = i
  308.             if #validsongno == 0 then
  309.                 wheelact:GetChild("TitScroll"..pos):settext("No Valid Songs Found")
  310.                 wheelact:GetChild("SubScroll"..pos):settext("")
  311.                 wheelact:GetChild("ArtScroll"..pos):settext("")
  312.             else
  313.                 if pos > #validsongno then
  314.                     pos2 = pos2 + 1
  315.                     if pos2 > #validsongno then pos2 = 1 end
  316.                     i = pos2
  317.                 end
  318.                 if pos*-1 > #validsongno then
  319.                     pos3 = pos3 + 1
  320.                     if pos3 > #validsongno then pos3 = 1 end
  321.                     i = pos3
  322.                 end
  323.                 if cursong+i < 1 then cursong2 = #validsongno+cursong end
  324.                 if cursong+i > #validsongno then cursong2 = (#validsongno-cursong)*-1 end
  325.                 wheelact:GetChild("TitScroll"..pos):settext(songlist[validsongno[cursong2+i]][1])
  326.                 wheelact:GetChild("SubScroll"..pos):settext(songlist[validsongno[cursong2+i]][2])
  327.                 wheelact:GetChild("ArtScroll"..pos):settext(songlist[validsongno[cursong2+i]][3])
  328.             end
  329.         end
  330.     end
  331.  
  332.     return wheellist
  333. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement