Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local PLAYER = game:WaitForChild("Players").LocalPlayer
- local MenuGui = script.StartScreenAndMenu
- local LoadingThings = MenuGui.LoadingScreenThings
- local Icons = MenuGui.Templates["Monster Icons"]
- local ContentProvider = game:GetService("ContentProvider")
- -- Fires to the server the value of passed arguments
- local MenuGuiEvent = game:WaitForChild("ReplicatedStorage"):WaitForChild("MenuGuiEvent")
- local function FireServer(...) MenuGuiEvent:FireServer(...) end
- local CategoriesOrder = {
- "Kanto",
- "Johto"
- }
- --------------------------------------------------------------------------------
- -- Contains all the information about each category for creating selection menu.
- -- Keys are the names of the category, and values are arrays containing two
- -- dictionaries.
- --
- -- The first dictionary has row count in index 1 and column count in index 2.
- -- Try to keep the rows under 16!
- -- The second dictionary has monsters listed in row-major order. Inputting
- -- "NULL" allows you to skip spaces.
- -- (row-major = left to right, then up to down)
- --------------------------------------------------------------------------------
- local CategoriesTraits ={
- Kanto = {
- {
- 7, 3 -- Rows, Columns
- },
- {
- "Bulbasaur", -- Pokemon
- "Gastly",
- "NULL",
- "NULL",
- "NULL",
- "NULL",
- "NULL",
- "Gastly"
- }
- },
- Johto = {
- {
- 3, 3 -- Rows, Columns
- },
- {
- "Bulbasaur", -- Pokemon
- "Gastly",
- "NULL",
- "NULL",
- "NULL",
- "NULL",
- "NULL",
- "Gastly"
- }
- }
- } -- CategoriesTraits array
- --------------------------------------------------------------------------------
- -- Scans for various assets to load with priority, and puts them in a table.
- --
- -- @param location An asset whose children will be searched
- -- @param storageTable A table to which children are appended
- --------------------------------------------------------------------------------
- local function ScanForAssets(location, storageTable)
- for i, Child in ipairs(location:GetChildren()) do
- if Child:IsA'ImageLabel' then
- table.insert(storageTable, Child)
- elseif Child:IsA'ImageButton' then
- table.insert(storageTable, Child)
- elseif Child:IsA'Sound' then
- table.insert(storageTable, Child)
- end
- ScanForAssets(Child, storageTable)
- end
- end -- function ScanForAssets
- --------------------------------------------------------------------------------
- -- Creates loading screen elements in the bottom right. These are not intrusive,
- -- and appear only as progress reminders. This function is called if loading
- -- was not already completed. The OK TextButton collapses all the elements.
- --
- -- @see TextLabels describing loading progress of client and server assets.
- -- TextButton that causes these labels to disappear.
- --------------------------------------------------------------------------------
- local function LoadingScreen()
- -- Create loading screen components
- local priorityLabel = LoadingThings.PriorityAssetsLabel
- local normalLabel = LoadingThings.NormalAssetsLabel
- local okButton = LoadingThings.OKLoadingButton
- -- OK Button functionality
- local pullPLabel = false
- okButton.Visible = true
- local MouseDown MouseDown = okButton.MouseButton1Down:Connect(function()
- MouseDown:Disconnect()
- okButton:TweenPosition(UDim2.new(1, -28, 1.5, -36), "In", "Back", 1, true, function() okButton:Destroy() end)
- normalLabel:TweenPosition(UDim2.new(0, 0, 0.5, 0), "In", "Back", 1, true, function() normalLabel:Destroy() end)
- if not pullPLabel then
- pullPLabel = true
- priorityLabel:TweenPosition(UDim2.new(0, 0, 0.5, -20), "In", "Back", 1, true, function() priorityLabel:Destroy() end)
- end
- end)
- priorityLabel.Visible = true
- normalLabel.Visible = true
- priorityLabel.Text = "Menu loading hasn't started yet."
- normalLabel.Text = "General loading hasn't started yet."
- local priorityassets = {}
- -- index priority assets
- ScanForAssets(MenuGui.Templates["Monster Icons"], priorityassets)
- -- Load priority assets
- for i = 1, #priorityassets do
- if pullPLabel then return end
- ContentProvider:PreloadAsync({priorityassets[i]})
- priorityLabel.Text = "Menu assets have been loaded:"..math.floor(100*i/#priorityassets).."%..."
- end
- priorityLabel.Text = "Menu assets finished loading!"
- -- Load normal assets
- while (ContentProvider.RequestQueueSize > 0) do
- normalLabel.Text = math.floor(ContentProvider.RequestQueueSize).." assets left..."
- task.wait()
- end
- normalLabel.Text = "All assets finished loading!"
- -- Removes priority label when all assets are completed
- if not pullPLabel then
- priorityLabel:TweenPosition(UDim2.new(1, 0, 0, 0), "In", "Quad", 2, true, function() priorityLabel:Destroy() end)
- end
- _G.hasLoaded = true
- end -- function LoadingScreen
- --------------------------------------------------------------------------------
- -- Creates a start screen. Clicking the start button will prevent this from
- -- showing up again.
- --
- -- @see TextButton(?) that prompts you to start. Other elements unknown(?)
- --------------------------------------------------------------------------------
- local function StartScreen()
- local startButtonBG = LoadingThings.StartButtonBackground
- local startButton = LoadingThings.StartButton
- startButtonBG.Visible = true
- startButton.Visible = true
- startButton.MouseButton1Down:Wait()
- -- Replace this part with a cool cutscene if you want (instead of it just disaperaing )
- startButtonBG.Visible = false
- startButton.Visible = false
- _G.hasSeenStartScreen = true
- end -- function StartScreen
- --------------------------------------------------------------------------------
- -- Creates a category page which is parented to nil. This acts to create buttons
- -- that the user can click to play as a monster, once the page becomes visible.
- --
- -- @param categoryName The name of the category page.
- -- @return ImageLabel that is the created category page
- --------------------------------------------------------------------------------
- local function ConstructMenu(categoryName)
- local categoryData = CategoriesTraits[categoryName]
- local layoutData = categoryData[1]
- local monsData = categoryData[2]
- local XOFFSET = 0.1 -- applies to left and right
- local YOFFSET = 0.1 -- only applies to top
- local XBETWEEN = 0.05 -- in-between columns
- local YBETWEEN = 0.07 -- in-between rows
- local widthPer = (1-2*XOFFSET)/layoutData[1] - XBETWEEN
- local heightPer = (1-YOFFSET)/layoutData[2] - YBETWEEN
- local regionCanvas = MenuGui.Templates.SelectionMenuTemplate:Clone()
- regionCanvas.Name = categoryName
- local initButton = MenuGui.Templates.ButtonTemplate
- local row, column = 1, 1
- for i, MonName in ipairs(monsData) do
- print(MonName)
- if MonName~="NULL" then -- skip option
- local button = initButton:Clone()
- button.Visible = true
- button.TemplateText.Text = MonName
- local maybeImage = Icons:FindFirstChild(MonName)
- button.TemplateImage.Image = maybeImage and maybeImage.Image or ""
- button.Size = UDim2.new(widthPer, 0, heightPer, 0)
- button.Position = UDim2.new(XOFFSET+(row-1)*(widthPer+XBETWEEN), 0, YOFFSET+(column-1)*(heightPer+YBETWEEN))
- button.Parent = regionCanvas
- end
- if row+1>layoutData[1] then
- row=1
- column+=1
- else
- row+=1
- end
- end
- return regionCanvas
- end
- --------------------------------------------------------------------------------
- -- MAIN
- --------------------------------------------------------------------------------
- do
- if not _G.hasLoaded then
- coroutine.wrap(function() LoadingScreen() end)()
- end
- if not _G.hasSeenStartScreen then
- StartScreen()
- end
- local openedSelection = false
- local currentCategory = CategoriesOrder[1]
- local categoryPages = {}
- MenuGui.MenuOpenButton.Visible = true
- for i, Category in ipairs(CategoriesOrder) do
- categoryPages[Category] = ConstructMenu(Category)
- end
- MenuGui.MenuOpenButton.MouseButton1Down:Connect(function()
- if openedSelection then
- categoryPages[currentCategory].Visible = false
- openedSelection = false
- currentCategory = CategoriesOrder[1]
- else
- categoryPages[currentCategory].Visible = true
- categoryPages[currentCategory].Parent = MenuGui
- openedSelection = true
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement