Advertisement
IHATEMICROWAVEOVEN

menuselection v1

Oct 1st, 2023 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.22 KB | None | 0 0
  1. local PLAYER = game:WaitForChild("Players").LocalPlayer
  2. local MenuGui = script.StartScreenAndMenu
  3. local LoadingThings = MenuGui.LoadingScreenThings
  4. local Icons = MenuGui.Templates["Monster Icons"]
  5.  
  6. local ContentProvider = game:GetService("ContentProvider")
  7.  
  8. -- Fires to the server the value of passed arguments
  9. local MenuGuiEvent = game:WaitForChild("ReplicatedStorage"):WaitForChild("MenuGuiEvent")
  10. local function FireServer(...) MenuGuiEvent:FireServer(...) end
  11.  
  12.  
  13.  
  14. local CategoriesOrder = {
  15. "Kanto",
  16. "Johto"
  17. }
  18.  
  19. --------------------------------------------------------------------------------
  20. -- Contains all the information about each category for creating selection menu.
  21. -- Keys are the names of the category, and values are arrays containing two
  22. -- dictionaries.
  23. --
  24. -- The first dictionary has row count in index 1 and column count in index 2.
  25. -- Try to keep the rows under 16!
  26. -- The second dictionary has monsters listed in row-major order. Inputting
  27. -- "NULL" allows you to skip spaces.
  28. -- (row-major = left to right, then up to down)
  29. --------------------------------------------------------------------------------
  30. local CategoriesTraits ={
  31. Kanto = {
  32. {
  33. 7, 3 -- Rows, Columns
  34. },
  35. {
  36. "Bulbasaur", -- Pokemon
  37. "Gastly",
  38. "NULL",
  39. "NULL",
  40. "NULL",
  41. "NULL",
  42. "NULL",
  43. "Gastly"
  44. }
  45. },
  46.  
  47. Johto = {
  48. {
  49. 3, 3 -- Rows, Columns
  50. },
  51. {
  52. "Bulbasaur", -- Pokemon
  53. "Gastly",
  54. "NULL",
  55. "NULL",
  56. "NULL",
  57. "NULL",
  58. "NULL",
  59. "Gastly"
  60. }
  61. }
  62. } -- CategoriesTraits array
  63.  
  64.  
  65.  
  66.  
  67.  
  68. --------------------------------------------------------------------------------
  69. -- Scans for various assets to load with priority, and puts them in a table.
  70. --
  71. -- @param location An asset whose children will be searched
  72. -- @param storageTable A table to which children are appended
  73. --------------------------------------------------------------------------------
  74. local function ScanForAssets(location, storageTable)
  75. for i, Child in ipairs(location:GetChildren()) do
  76. if Child:IsA'ImageLabel' then
  77. table.insert(storageTable, Child)
  78. elseif Child:IsA'ImageButton' then
  79. table.insert(storageTable, Child)
  80. elseif Child:IsA'Sound' then
  81. table.insert(storageTable, Child)
  82. end
  83. ScanForAssets(Child, storageTable)
  84. end
  85. end -- function ScanForAssets
  86.  
  87.  
  88.  
  89. --------------------------------------------------------------------------------
  90. -- Creates loading screen elements in the bottom right. These are not intrusive,
  91. -- and appear only as progress reminders. This function is called if loading
  92. -- was not already completed. The OK TextButton collapses all the elements.
  93. --
  94. -- @see TextLabels describing loading progress of client and server assets.
  95. -- TextButton that causes these labels to disappear.
  96. --------------------------------------------------------------------------------
  97. local function LoadingScreen()
  98. -- Create loading screen components
  99. local priorityLabel = LoadingThings.PriorityAssetsLabel
  100. local normalLabel = LoadingThings.NormalAssetsLabel
  101. local okButton = LoadingThings.OKLoadingButton
  102.  
  103. -- OK Button functionality
  104. local pullPLabel = false
  105. okButton.Visible = true
  106. local MouseDown MouseDown = okButton.MouseButton1Down:Connect(function()
  107. MouseDown:Disconnect()
  108. okButton:TweenPosition(UDim2.new(1, -28, 1.5, -36), "In", "Back", 1, true, function() okButton:Destroy() end)
  109. normalLabel:TweenPosition(UDim2.new(0, 0, 0.5, 0), "In", "Back", 1, true, function() normalLabel:Destroy() end)
  110. if not pullPLabel then
  111. pullPLabel = true
  112. priorityLabel:TweenPosition(UDim2.new(0, 0, 0.5, -20), "In", "Back", 1, true, function() priorityLabel:Destroy() end)
  113. end
  114. end)
  115.  
  116. priorityLabel.Visible = true
  117. normalLabel.Visible = true
  118. priorityLabel.Text = "Menu loading hasn't started yet."
  119. normalLabel.Text = "General loading hasn't started yet."
  120.  
  121. local priorityassets = {}
  122.  
  123. -- index priority assets
  124. ScanForAssets(MenuGui.Templates["Monster Icons"], priorityassets)
  125.  
  126.  
  127. -- Load priority assets
  128. for i = 1, #priorityassets do
  129. if pullPLabel then return end
  130. ContentProvider:PreloadAsync({priorityassets[i]})
  131. priorityLabel.Text = "Menu assets have been loaded:"..math.floor(100*i/#priorityassets).."%..."
  132. end
  133. priorityLabel.Text = "Menu assets finished loading!"
  134.  
  135. -- Load normal assets
  136. while (ContentProvider.RequestQueueSize > 0) do
  137. normalLabel.Text = math.floor(ContentProvider.RequestQueueSize).." assets left..."
  138. task.wait()
  139. end
  140. normalLabel.Text = "All assets finished loading!"
  141.  
  142. -- Removes priority label when all assets are completed
  143. if not pullPLabel then
  144. priorityLabel:TweenPosition(UDim2.new(1, 0, 0, 0), "In", "Quad", 2, true, function() priorityLabel:Destroy() end)
  145. end
  146.  
  147. _G.hasLoaded = true
  148. end -- function LoadingScreen
  149.  
  150.  
  151.  
  152. --------------------------------------------------------------------------------
  153. -- Creates a start screen. Clicking the start button will prevent this from
  154. -- showing up again.
  155. --
  156. -- @see TextButton(?) that prompts you to start. Other elements unknown(?)
  157. --------------------------------------------------------------------------------
  158. local function StartScreen()
  159. local startButtonBG = LoadingThings.StartButtonBackground
  160. local startButton = LoadingThings.StartButton
  161. startButtonBG.Visible = true
  162. startButton.Visible = true
  163.  
  164. startButton.MouseButton1Down:Wait()
  165.  
  166. -- Replace this part with a cool cutscene if you want (instead of it just disaperaing )
  167. startButtonBG.Visible = false
  168. startButton.Visible = false
  169. _G.hasSeenStartScreen = true
  170. end -- function StartScreen
  171.  
  172.  
  173.  
  174. --------------------------------------------------------------------------------
  175. -- Creates a category page which is parented to nil. This acts to create buttons
  176. -- that the user can click to play as a monster, once the page becomes visible.
  177. --
  178. -- @param categoryName The name of the category page.
  179. -- @return ImageLabel that is the created category page
  180. --------------------------------------------------------------------------------
  181. local function ConstructMenu(categoryName)
  182. local categoryData = CategoriesTraits[categoryName]
  183. local layoutData = categoryData[1]
  184. local monsData = categoryData[2]
  185.  
  186. local XOFFSET = 0.1 -- applies to left and right
  187. local YOFFSET = 0.1 -- only applies to top
  188. local XBETWEEN = 0.05 -- in-between columns
  189. local YBETWEEN = 0.07 -- in-between rows
  190. local widthPer = (1-2*XOFFSET)/layoutData[1] - XBETWEEN
  191. local heightPer = (1-YOFFSET)/layoutData[2] - YBETWEEN
  192.  
  193. local regionCanvas = MenuGui.Templates.SelectionMenuTemplate:Clone()
  194. regionCanvas.Name = categoryName
  195. local initButton = MenuGui.Templates.ButtonTemplate
  196. local row, column = 1, 1
  197. for i, MonName in ipairs(monsData) do
  198. print(MonName)
  199. if MonName~="NULL" then -- skip option
  200. local button = initButton:Clone()
  201. button.Visible = true
  202. button.TemplateText.Text = MonName
  203. local maybeImage = Icons:FindFirstChild(MonName)
  204. button.TemplateImage.Image = maybeImage and maybeImage.Image or ""
  205. button.Size = UDim2.new(widthPer, 0, heightPer, 0)
  206. button.Position = UDim2.new(XOFFSET+(row-1)*(widthPer+XBETWEEN), 0, YOFFSET+(column-1)*(heightPer+YBETWEEN))
  207. button.Parent = regionCanvas
  208. end
  209. if row+1>layoutData[1] then
  210. row=1
  211. column+=1
  212. else
  213. row+=1
  214. end
  215. end
  216. return regionCanvas
  217. end
  218.  
  219.  
  220.  
  221.  
  222.  
  223. --------------------------------------------------------------------------------
  224. -- MAIN
  225. --------------------------------------------------------------------------------
  226. do
  227.  
  228. if not _G.hasLoaded then
  229. coroutine.wrap(function() LoadingScreen() end)()
  230. end
  231.  
  232. if not _G.hasSeenStartScreen then
  233. StartScreen()
  234. end
  235.  
  236. local openedSelection = false
  237. local currentCategory = CategoriesOrder[1]
  238. local categoryPages = {}
  239. MenuGui.MenuOpenButton.Visible = true
  240.  
  241. for i, Category in ipairs(CategoriesOrder) do
  242. categoryPages[Category] = ConstructMenu(Category)
  243. end
  244.  
  245. MenuGui.MenuOpenButton.MouseButton1Down:Connect(function()
  246. if openedSelection then
  247. categoryPages[currentCategory].Visible = false
  248. openedSelection = false
  249. currentCategory = CategoriesOrder[1]
  250. else
  251. categoryPages[currentCategory].Visible = true
  252. categoryPages[currentCategory].Parent = MenuGui
  253. openedSelection = true
  254. end
  255. end)
  256. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement