Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ local SettingsMenu = require(game.ReplicatedStorage.Menus.SettingsMenu)
local Configuration = require(game.ReplicatedStorage.Configuration)
local CustomServerSettings = require(game.Workspace.CustomServerSettings)

local withSongList = require(script.withSongList)

local SongSelectMenu = {}

function SongSelectMenu:new(_local_services)
Expand All @@ -21,43 +23,24 @@ function SongSelectMenu:new(_local_services)
local _song_select_ui
local _selected_songkey = SongDatabase:invalid_songkey()
local _is_supporter = false

local _input = _local_services._input
local song_list

local _leaderboard_display

function self:cons()
_song_select_ui = EnvironmentSetup:get_menu_protos_folder().SongSelectUI:Clone()

local song_list = _song_select_ui.SongList

--Expand the scrolling list to fit contents
song_list.UIListLayout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function()
song_list.CanvasSize = UDim2.new(0, 0, 0, song_list.UIListLayout.AbsoluteContentSize.Y)
end)

local song_list_element_proto = song_list.SongListElementProto
song_list_element_proto.Parent = nil
for itr_songkey, itr_songdata in SongDatabase:key_itr() do
local itr_list_element = song_list_element_proto:Clone()
itr_list_element.Parent = song_list
itr_list_element.LayoutOrder = itr_songkey
SongDatabase:render_coverimage_for_key(itr_list_element.SongCover, itr_list_element.SongCoverOverlay, itr_songkey)
itr_list_element.NameDisplay.Text = SongDatabase:get_title_for_key(itr_songkey)
itr_list_element.DifficultyDisplay.Text = string.format("Difficulty: %d",SongDatabase:get_difficulty_for_key(itr_songkey))
if SongDatabase:key_get_audiomod(itr_songkey) == SongDatabase.SongMode.SupporterOnly then
itr_list_element.DifficultyDisplay.Text = itr_list_element.DifficultyDisplay.Text .. " (Supporter Only)"
end

SPUtil:bind_input_fire(itr_list_element, function(input)
self:select_songkey(itr_songkey)
end)
end

_leaderboard_display = LeaderboardDisplay:new(
_song_select_ui.LeaderboardSection,
_song_select_ui.LeaderboardSection.LeaderboardList.LeaderboardListElementProto
)

local function on_song_key_selected(key)
self:select_songkey(key)
end

song_list = withSongList(_song_select_ui.SongList, on_song_key_selected)

_song_select_ui.SongInfoSection.NoSongSelectedDisplay.Visible = true
_song_select_ui.SongInfoSection.SongInfoDisplay.Visible = false
Expand All @@ -79,6 +62,10 @@ function SongSelectMenu:new(_local_services)
_local_services._menus:push_menu(SettingsMenu:new(_local_services))
end)

_song_select_ui.SearchBox:GetPropertyChangedSignal("Text"):Connect(function()
song_list:filter_song_buttons(_song_select_ui.SearchBox.Text)
end)

_song_select_ui.NameDisplay.Text = string.format("%s's Robeats Custom Server", CustomServerSettings.CreatorName)
_song_select_ui.SongInfoSection.NoSongSelectedDisplay.Visible = true

Expand Down Expand Up @@ -120,7 +107,7 @@ function SongSelectMenu:new(_local_services)
_song_select_ui.SongInfoSection.NoSongSelectedDisplay.Visible = false
_selected_songkey = songkey

SongDatabase:render_coverimage_for_key(_song_select_ui.SongInfoSection.SongInfoDisplay.SongCover, _song_select_ui.SongInfoSection.SongInfoDisplay.SongCoverOverlay, _selected_songkey)
-- SongDatabase:render_coverimage_for_key(_song_select_ui.SongInfoSection.SongInfoDisplay.SongCover, _song_select_ui.SongInfoSection.SongInfoDisplay.SongCoverOverlay, _selected_songkey)
_song_select_ui.SongInfoSection.SongInfoDisplay.NameDisplay.Text = SongDatabase:get_title_for_key(_selected_songkey)
_song_select_ui.SongInfoSection.SongInfoDisplay.DifficultyDisplay.Text = string.format("Difficulty: %d",SongDatabase:get_difficulty_for_key(_selected_songkey))
_song_select_ui.SongInfoSection.SongInfoDisplay.ArtistDisplay.Text = SongDatabase:get_artist_for_key(_selected_songkey)
Expand Down Expand Up @@ -166,7 +153,13 @@ function SongSelectMenu:new(_local_services)
_song_select_ui.Parent = EnvironmentSetup:get_player_gui_root()
self:select_songkey(_selected_songkey)
else
_song_select_ui.Parent = nil
if val then
EnvironmentSetup:set_mode(EnvironmentSetup.Mode.Menu)
_song_select_ui.Parent = EnvironmentSetup:get_player_gui_root()
self:select_songkey(_selected_songkey)
else
_song_select_ui.Parent = nil
end
end
end

Expand Down
75 changes: 75 additions & 0 deletions ReplicatedStorage/Menus/SongSelectMenu/withSongList.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
-- AstralKingdoms, kisperal

local SPUtil = require(game.ReplicatedStorage.Shared.SPUtil)
local SongDatabase = require(game.ReplicatedStorage.RobeatsGameCore.SongDatabase)

local function withSongList(_song_list_gui, _on_song_key_selected)
local self = {}

local _song_list_element_proto

function self:cons()
--Expand the scrolling list to fit contents
_song_list_gui.UIListLayout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function()
_song_list_gui.CanvasSize = UDim2.new(0, 0, 0, _song_list_gui.UIListLayout.AbsoluteContentSize.Y)
end)

_song_list_element_proto = _song_list_gui.SongListElementProto
_song_list_element_proto.Parent = nil

for itr_songkey, _ in SongDatabase:key_itr() do
self:add_song_button(itr_songkey)
end
end

function self:is_in_search(search, song_key)
search = search or ""
search = string.split(search, " ")

local _to_search = SongDatabase:get_search_string_for_key(song_key)
local found = 0
for i = 1, #search do
local search_term = search[i]
if string.find(_to_search:lower(), search_term:lower()) ~= nil then
found = found + 1
end
end

return found == #search
end

function self:filter_song_buttons(search)
for _, button in pairs(_song_list_gui:GetChildren()) do
if button:IsA("Frame") then
local song_key = button:GetAttribute("_key")
button.Visible = self:is_in_search(search, song_key)
end
end
end

function self:add_song_button(song_key)
local list_element = _song_list_element_proto:Clone()
list_element.Parent = _song_list_gui
list_element.LayoutOrder = song_key
SongDatabase:render_coverimage_for_key(list_element.SongCover, list_element.SongCoverOverlay, song_key)
list_element.NameDisplay.Text = SongDatabase:get_title_for_key(song_key)
list_element.DifficultyDisplay.Text = string.format("Difficulty: %d",SongDatabase:get_difficulty_for_key(song_key))
if SongDatabase:key_get_audiomod(song_key) == SongDatabase.SongMode.SupporterOnly then
list_element.DifficultyDisplay.Text = list_element.DifficultyDisplay.Text .. " (Supporter Only)"
end

list_element.Name = string.format("SongKey%0d", song_key)
list_element:SetAttribute("_key", song_key)
list_element:SetAttribute("_searchstring", SongDatabase:get_search_string_for_key(song_key))

SPUtil:bind_input_fire(list_element, function(_)
_on_song_key_selected(song_key)
end)
end

self:cons()

return self
end

return withSongList
14 changes: 14 additions & 0 deletions ReplicatedStorage/RobeatsGameCore/SongDatabase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ function SongDatabase:new()
return songdata.AudioDescription
end

function self:get_search_string_for_key(key)
local data = self:get_data_for_key(key)
if data ~= nil then
local _search_data = {
data.AudioArtist,
data.AudioFilename,
data.AudioDifficulty
}

return table.concat(_search_data, " ")
end
return ""
end

function self:invalid_songkey() return -1 end

self:cons()
Expand Down
Binary file modified RobeatsCustomServerTemplate.rbxl
Binary file not shown.