Advertisement
CluelessDev

MainMenus controller

Oct 9th, 2022
1,350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 26.17 KB | None | 0 0
  1. --[[
  2.     ## This controller controls all gui input, and navigation from the "Main Menus", which are:
  3.     * Team Selection
  4.     * Shop
  5.     * In-Game Settings
  6.     * Tasks (yet to be added)
  7.     * Rewards (yet to be added)
  8.  
  9.     ## You can enter the previously mentioned Main Menus  from the main menu and the in-game side buttons
  10.     ## Aside from that this controller Initializes all the main menus (populating buttons, setting up connections, and clean up)
  11.  
  12. ]]
  13. --!== ================================================================================||>
  14. --!==                                     SERVICES
  15. --!== ================================================================================||>
  16. local Players           = game:GetService("Players")
  17. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  18. local Teams             = game:GetService("Teams")
  19. local StarterGui        = game:GetService("StarterGui")
  20. local TweenService      = game:GetService("TweenService")
  21. local CollectionService = game:GetService('CollectionService')
  22.  
  23.  
  24.  
  25. --!== ================================================================================||>
  26. --!==                                   DEPENDENCIES
  27. --!== ================================================================================||>
  28. --=============================== Data Modules ===============================||>
  29. local Data      = ReplicatedStorage:FindFirstChild("Data")
  30. local Events    = ReplicatedStorage:FindFirstChild("Events")
  31.  
  32.  
  33. local Enums   = require(Data:FindFirstChild("Enums"))
  34. local Structs = require(Data:FindFirstChild("Structs"))
  35.  
  36.  
  37. local InGameSettingsData = require(Data:FindFirstChild("InGameSettingsData"))
  38. local RolesComponent     = require(Data:FindFirstChild("RolesComponent"))
  39.  
  40.  
  41.  
  42. --=============================== Utils ===============================||>
  43. local Packages: Folder = ReplicatedStorage.Packages
  44. local Trove  = require(Packages.Trove)
  45.  
  46.  
  47.  
  48. --!== ================================================================================||>
  49. --!==                               MAIN MENUS RUNTIME
  50. --!== ================================================================================||>
  51. --=============================== Upvalues ===============================||>
  52. local LocalPlayer: Player  = Players.LocalPlayer
  53. local PlayerGui: PlayerGui = Players.LocalPlayer.PlayerGui
  54.  
  55.  
  56. local BUTTON_HOVER_HIGHLIGHT = Color3.fromRGB(255, 255, 255)
  57. local ROLE_SELECTED_HIGHLIGHT = Color3.fromRGB(255, 255, 155)
  58.  
  59. ---* Enums ||>
  60. local RolesEnum = Enums.RolesEnum.Roles
  61.  
  62.  
  63. ---* Main Menu Cinematics Upvalues ||>
  64. local Camera: Camera          = workspace.CurrentCamera
  65. local CurrentCinematicCamTween: Tween     = nil
  66. local stopCinematics: boolean = false
  67.  
  68.  
  69. ---* Remote Events ||>
  70. local EnterRoleSelection: RemoteEvent = Events:FindFirstChild("EnterRoleSelection")
  71. local ExitRoleSelection: RemoteEvent  = Events:FindFirstChild("ExitRoleSelection")
  72. local SetRole: RemoteEvent            = Events:FindFirstChild("SetRole")
  73. local RoleSelected: RemoteEvent       = Events:FindFirstChild("RoleSelected")
  74.  
  75. local EnterGame: RemoteEvent= Events:FindFirstChild("EnterGame")
  76.  
  77.  
  78. ---* Signals ||>
  79. local StopMainMenuCinematics = Enums.Signals.StopMainMenuCinematics
  80. local SetHudVisibility       = Enums.Signals.SetHudVisibility
  81.  
  82.  
  83.  
  84. ---* Player Data Folders ||>
  85. local plrStates = LocalPlayer:WaitForChild("States")
  86. local InMainMenu: BoolValue    = plrStates:FindFirstChild("InMainMenu")
  87. local InGame: BoolValue        = plrStates:FindFirstChild("InGame")
  88. local SelectingRole: BoolValue = plrStates:FindFirstChild("SelectingRole")
  89. local InMenu: BoolValue        = plrStates:FindFirstChild("InMenu")
  90.  
  91. local plrRoles = LocalPlayer:WaitForChild("Roles")
  92. local OwnedRoles = plrRoles:FindFirstChild("OwnedRoles")
  93.  
  94.  
  95. --#! NOTE
  96. --## Collection Service tags behavior is used to handle state to not depend on a hardcoded ui path
  97. --## Which changes A TON (I shuffle things around a lot)
  98.  
  99.  
  100.  
  101. -- !== ================================================================================||>
  102. -- !==                         Main Menus Screen Gui's Initialization
  103. -- !== ================================================================================||>
  104. --## Hides the defult Roblox leaderboard
  105. StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
  106.  
  107. --## SetTrove
  108. local MainMenuTrove = Trove.new()
  109.  
  110. --## Set Main Menus initial state when player joins
  111. local MainMenus: Folder = PlayerGui:WaitForChild("MainMenus")
  112.  
  113. local MainMenuGui: ScreenGui = MainMenus.MainMenu
  114. MainMenuGui.Enabled      = true
  115. MainMenuGui.ResetOnSpawn = false
  116.  
  117.  
  118. local SideButtonsGui: ScreenGui = MainMenus.SideButtons
  119. SideButtonsGui.Enabled      = false
  120. SideButtonsGui.ResetOnSpawn = false
  121.  
  122.  
  123. local TeamSelectionGui: ScreenGui  = MainMenus.TeamSelection
  124. TeamSelectionGui.Enabled      = false
  125. TeamSelectionGui.ResetOnSpawn = false
  126.  
  127. local ShopGui: ScreenGui = MainMenus.Shop
  128. ShopGui.Enabled      = false
  129. ShopGui.ResetOnSpawn = false
  130.  
  131. local InGameSettingsGui: ScreenGui = MainMenus.InGameSettings
  132. InGameSettingsGui.Enabled      = false
  133. InGameSettingsGui.ResetOnSpawn = false
  134.  
  135.  
  136. local TasksGui: ScreenGui = MainMenus.Tasks
  137. TasksGui.Enabled      = false
  138. TasksGui.ResetOnSpawn = false
  139.  
  140. local RewardsGui: ScreenGui = MainMenus.Rewards
  141. RewardsGui.Enabled      = false
  142. RewardsGui.ResetOnSpawn = false
  143.  
  144.  
  145. -- =============================== Main menus buttons generic behaviors ===============================||>
  146. --## Close the Main menu when clicked
  147. for _, menuBtn: ImageButton in CollectionService:GetTagged("MainMenuBtn") do
  148.     menuBtn.MouseButton1Click:Connect(function()
  149.         MainMenuGui.Enabled = false
  150.     end)
  151. end
  152.  
  153.  
  154.  
  155. ---* Main Menus back btns ||>
  156. --## All back buttons either go close the HUD (if in game) or go back to the main menu (if in main menu)
  157. for _, backBtn: ImageButton in CollectionService:GetTagged("BackBtn") do
  158.     backBtn.MouseButton1Click:Connect(function()
  159.         if InMainMenu.Value then
  160.             MainMenuGui.Enabled = true
  161.  
  162.         elseif InGame.Value then
  163.             InMenu.Value = false
  164.             SetHudVisibility:Fire(true) --## when pressing a backBtn while in-game, show the HUD
  165.         end
  166.     end)    
  167. end
  168.  
  169.  
  170. ---* Enter game button ||>
  171. for _, enterGameBtn: GuiButton in CollectionService:GetTagged("EnterGameBtn") do
  172.     --## stop camera cinematics And change Player GUI state to in-game
  173.     MainMenuTrove:Add(enterGameBtn.MouseButton1Click:Connect(function()
  174.         EnterGame:FireServer()
  175.     end))
  176. end
  177.  
  178.    
  179.  
  180.  
  181.  
  182.  
  183. ---* Enter game (Exit Main Menu), turn off in-game cinematics ||>
  184. --## And change Player GUI state to in-game
  185. local ChangeBtn: ImageButton = TeamSelectionGui:FindFirstChild("ChangeButton", true)
  186. local PlayBtn: ImageButton   = TeamSelectionGui:FindFirstChild("PlayButton", true)
  187.  
  188. EnterGame.OnClientEvent:Connect(function()
  189.     --## the change btn is under the playbtn, this is just for
  190.     --## Flavour reasons (sure I could have changed the text but it's whatever).
  191.    
  192.     PlayBtn.Visible   = false
  193.     ChangeBtn.Visible = true
  194.  
  195.     stopCinematics           = true
  196.     TeamSelectionGui.Enabled = false
  197.  
  198.     CurrentCinematicCamTween:Cancel()
  199.  
  200.     Camera.CameraType    = Enum.CameraType.Custom
  201.     Camera.CameraSubject = LocalPlayer.Character
  202.  
  203.     SetHudVisibility:Fire(true)  --## Enable the HUD
  204.  
  205.  
  206.     MainMenuTrove:Destroy()
  207.     EnterGame:FireServer()
  208.     StopMainMenuCinematics:Fire()
  209. end)
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219. ---* Entry Points||>
  220.  
  221. --## Note that both the Main Menu and side buttons are the entry points for:
  222. --## Shop, Team selection, Tasks, In-game settings, rewards, etc!
  223.  
  224. --=============================== Main Menu ===============================||>
  225. --#! this gui only shows up once when the player joins the game.
  226. do
  227.     local MenuButtonsFrame: Frame = MainMenuGui.Container.MenuButtonsFrame
  228.  
  229.     --## Play Button goes to team selection menu, which is already handled via
  230.     --## Enter EnterRolesMenuBtn Tag, therefor ommited
  231.  
  232.     local ShopBtn: ImageButton = MenuButtonsFrame.ShopButton
  233.     ShopBtn.MouseButton1Click:Connect(function()
  234.         ShopGui.Enabled     = true
  235.     end)
  236.  
  237.     local InGameSettingsButton: ImageButton = MenuButtonsFrame.InGameSettingsButton
  238.     MainMenuTrove:Add(InGameSettingsButton.MouseButton1Click:Connect(function()
  239.         InGameSettingsGui.Enabled = true
  240.     end))
  241.  
  242. end
  243.  
  244.  
  245.  
  246. --=============================== Side Buttons ===============================||>
  247. --#! This gui only show up in-game.
  248.  
  249. do
  250.     --## When the player spawns enable the side buttons gui
  251.     StopMainMenuCinematics:Connect(function()
  252.         SideButtonsGui.Enabled = true
  253.     end)
  254.  
  255.  
  256.     --## Listen for side buttons being clicked for menus
  257.     --## Visibility
  258.  
  259.     local ShopBtnCont: ImageLabel = SideButtonsGui.Container.ShopButtonFrame
  260.     local ShopBtn: ImageButton    = ShopBtnCont.ShopButton
  261.     ShopBtn.MouseButton1Click:Connect(function()
  262.         ShopGui.Enabled = true
  263.     end)
  264.  
  265.  
  266.     local InGameSettingsBtnCont: ImageLabel = SideButtonsGui.Container.InGameSettingsButtonFrame
  267.     local InGameSettingsBtn: ImageButton    = InGameSettingsBtnCont.InGameSettingsButton
  268.     InGameSettingsBtn.MouseButton1Click:Connect(function()
  269.         InGameSettingsGui.Enabled = true
  270.     end)
  271.  
  272.  
  273.     local TeamsBtnCont: ImageLabel = SideButtonsGui.Container.TeamsButtonFrame
  274.     local TeamsBtn: ImageButton    = TeamsBtnCont.TeamsButton
  275.     TeamsBtn.MouseButton1Click:Connect(function()
  276.         TeamSelectionGui.Enabled = true
  277.     end)
  278.  
  279.  
  280.     local TasksBtnFrame: ImageLabel = SideButtonsGui.Container.TasksButtonFrame
  281.     local TasksBtn: ImageButton     = TasksBtnFrame.TasksButton
  282.     TasksBtn.MouseButton1Click:Connect(function()
  283.         TasksGui.Enabled       = true
  284.     end)
  285.  
  286.  
  287.     local RewardsBtnFrame: ImageLabel = SideButtonsGui.Container.RewardsButtonFrame
  288.     local RewardsBtn: ImageButton = RewardsBtnFrame.RewardsButton
  289.     RewardsBtn.MouseButton1Click:Connect(function()
  290.         RewardsGui.Enabled     = true
  291.     end)
  292. end
  293.  
  294. for _, sideButton: ImageButton in CollectionService:GetTagged("SideButtons_SideBtn") do
  295.     sideButton.MouseButton1Click:Connect(function()
  296.         SideButtonsGui.Enabled = false
  297.         SetHudVisibility:Fire(false)  --## Hide the HUD when a side button is clicked
  298.     end)
  299. end
  300.  
  301.  
  302.  
  303. ---* Side buttons Visual modifiers ||>
  304.  
  305. --## Highlight the side button when hobbered
  306. for _, sideBtnFrame: GuiLabel in CollectionService:GetTagged("SideButtons_SideBtnFrame") do
  307.     local SelectionFrame: Frame = sideBtnFrame:FindFirstChild("SelectionFrame")
  308.  
  309.     sideBtnFrame.MouseEnter:Connect(function()
  310.         SelectionFrame.Visible = true
  311.     end)
  312.  
  313.     sideBtnFrame.MouseLeave:Connect(function()
  314.         SelectionFrame.Visible = false
  315.     end)
  316.  
  317.     --## mouse leave wont trigger when the side buttons are hidden sooo
  318.     --## This is to hide the highlight
  319.     SideButtonsGui:GetPropertyChangedSignal("Enabled"):Connect(function()
  320.         if SideButtonsGui.Enabled then
  321.             SelectionFrame.Visible = false
  322.         end
  323.     end)
  324. end
  325.  
  326.  
  327.  
  328.  
  329.  
  330. ---* Main Menus||>
  331. -- !== ================================================================================||>
  332. -- !==                         Role Selection Gui Initialization
  333. -- !== ================================================================================||>  
  334. do
  335.     -- =============================== Roles menu elements initialization  ===============================||>
  336.     local rolesList: Structs.Array<string>      = RolesComponent.GetRolesList()
  337.     local rolesNames: Structs.Array<string>     = RolesComponent.GetRolesNames()
  338.     local rolesThumbails: Structs.Array<string> = RolesComponent.GetRoleThumbnails()
  339.     local lockedRoles                           = RolesComponent:GetLockedRoles()
  340.     local rolesUnlockedByLeveling               = RolesComponent:GetRolesUnlockedByLeveling()
  341.    
  342.     local plrOwnedRoles: Folder & Structs.RoleComponent = LocalPlayer:FindFirstChild("OwnedRoles", true)
  343.  
  344.     local RolesButtonsMenu: ScrollingFrame = TeamSelectionGui:FindFirstChild("TeamButtonsScrollingFrame", true)
  345.     local RoleBtnElem: ImageButton         = CollectionService:GetTagged("RoleBtn")[1]
  346.    
  347.     --## Populate the team selection gui with all team buttons  & initialize buttons appearance
  348.     for roleIndexKey: number, roleName: string in rolesList do
  349.         ---* RoleBtn basic appearance ||>
  350.         local NewRoleButton:ImageButton = RoleBtnElem:Clone()
  351.         NewRoleButton.Name        = roleName
  352.         NewRoleButton.Visible     = true
  353.         NewRoleButton.LayoutOrder = roleIndexKey
  354.  
  355.         local TeamNameLabel: TextLabel = NewRoleButton:FindFirstChild("NameTextLabel", true)
  356.         TeamNameLabel.Text = rolesNames[roleIndexKey]
  357.        
  358.         local TeamThumbnail: ImageLabel = NewRoleButton:FindFirstChild("ThumbnailImageLabel", true)
  359.         TeamThumbnail.Image = rolesThumbails[roleIndexKey] or rolesThumbails[2]
  360.  
  361.  
  362.         ---* RoleBtn locked overlay,  ||>
  363.         local LockedOverlay: Frame = NewRoleButton:FindFirstChild("LockedOverlayFrame")
  364.  
  365.         --## If the role's is in the locked roles table then!
  366.         --## Fill in in the unlock information
  367.         local UnlockRequirementText: TextLabel = LockedOverlay:FindFirstChild("UnlockRequirementTextLabel", true)
  368.         local roleIsLocked: boolean            = lockedRoles[roleIndexKey]
  369.  
  370.         if roleIsLocked then
  371.             local levelNeeded = rolesUnlockedByLeveling[roleIndexKey]
  372.             UnlockRequirementText.Text = "Level "..tostring(levelNeeded)
  373.         end
  374.  
  375.  
  376.         --## If the player DOES NOT own the role then make the locked overlay visible
  377.         --## And flag it so visual modifiers do not apply to it
  378.         local ownsRole: BoolValue  = plrOwnedRoles[roleName]
  379.         if ownsRole.Value == false then
  380.             LockedOverlay.Visible = true
  381.             CollectionService:AddTag(NewRoleButton, "RolesMenu_LockedRoleBtn")
  382.         end
  383.  
  384.  
  385.  
  386.         local rolePlayerLimit = RolesComponent.GetRolePlayerLimit(roleIndexKey)
  387.         local TeamLimitFrame: Frame    = NewRoleButton:FindFirstChild("TeamLimitFrame")
  388.         local TeamLimitText: TextLabel = TeamLimitFrame:FindFirstChild("TeamLimitTextLabel")
  389.        
  390.         if rolePlayerLimit then
  391.             TeamLimitText.Text = tostring(0).."/"..tostring(rolePlayerLimit)
  392.         else
  393.             TeamLimitText.Text = tostring(0).."/".."∞"
  394.         end
  395.  
  396.        
  397.         NewRoleButton.MouseButton1Click:Connect(function()
  398.             if CollectionService:HasTag(NewRoleButton, "RolesMenu_LockedRoleBtn") then return end
  399.             CollectionService:AddTag(NewRoleButton, "RoleBtn_Selected")
  400.         end)
  401.  
  402.         NewRoleButton.MouseEnter:Connect(function()
  403.             if CollectionService:HasTag(NewRoleButton, "RolesMenu_LockedRoleBtn") then return end
  404.             CollectionService:AddTag(NewRoleButton, "RoleBtn_Hover")
  405.         end)
  406.  
  407.         NewRoleButton.MouseLeave:Connect(function()
  408.             if CollectionService:HasTag(NewRoleButton, "RoleBtn_Selected") then return end
  409.             CollectionService:RemoveTag(NewRoleButton, "RoleBtn_Hover")
  410.         end)
  411.  
  412.         NewRoleButton.Parent = RolesButtonsMenu
  413.     end
  414.  
  415.  
  416.  
  417.     -- =============================== Roles Menu Elements generic behaviors & modifiers ===============================||>
  418.     local function UpdateRolePlayerCountText(roleBtnName, roleIndexKey)
  419.         local rolePlayerLimit: Structs.Array<number> = RolesComponent.GetRolePlayerLimit(roleIndexKey)
  420.         local playersInRole: number                  = #CollectionService:GetTagged(roleBtnName)
  421.  
  422.         local RoleBtn: ImageButton = RolesButtonsMenu:FindFirstChild(roleBtnName, true)
  423.        
  424.         local TeamLimitFrame: Frame    = RoleBtn:FindFirstChild("TeamLimitFrame")
  425.         local TeamLimitText: TextLabel = TeamLimitFrame:FindFirstChild("TeamLimitTextLabel")
  426.        
  427.         if rolePlayerLimit then
  428.             TeamLimitText.Text = tostring(playersInRole).."/"..tostring(rolePlayerLimit)
  429.         else
  430.             TeamLimitText.Text = tostring(playersInRole).."/".."∞"
  431.         end
  432.     end
  433.    
  434.    
  435.    
  436.  
  437.     ---* Roles Menu State & Navigation ||>
  438.     for _, enterRolesMenuBtn: GuiButton in CollectionService:GetTagged("EnterRolesMenuBtn") do
  439.         enterRolesMenuBtn.MouseButton1Click:Connect(function()
  440.             EnterRoleSelection:FireServer()
  441.             TeamSelectionGui.Enabled = true
  442.         end)
  443.     end
  444.    
  445.     for _, exitRolesMenuBtn: GuiButton in CollectionService:GetTagged("ExitRolesMenuBtn") do
  446.         exitRolesMenuBtn.MouseButton1Click:Connect(function()
  447.             ExitRoleSelection:FireServer()
  448.             TeamSelectionGui.Enabled = false
  449.  
  450.             local SelectedRoleBtn = CollectionService:GetTagged("RoleBtn_Selected")[1]
  451.             CollectionService:RemoveTag(SelectedRoleBtn, "RoleBtn_Selected")
  452.         end)    
  453.     end
  454.    
  455.    
  456.     for _, setRoleBtn: GuiButton in CollectionService:GetTagged("SetRolesBtn") do
  457.         setRoleBtn.MouseButton1Click:Connect(function()
  458.             if SelectingRole.Value == true then return end
  459.  
  460.             local SelectedRoleBtn = CollectionService:GetTagged("RoleBtn_Selected")[1]
  461.             SetRole:FireServer(SelectedRoleBtn.Name)
  462.         end)
  463.     end
  464.  
  465.  
  466.     for _, roleBtn: GuiButton in CollectionService:GetTagged("RoleBtn") do
  467.         --## Request to set/change role
  468.         roleBtn.MouseButton1Click:Connect(function()
  469.             print(roleBtn)
  470.             RoleSelected:FireServer(roleBtn.Name) --> flips menu state
  471.         end)
  472.     end
  473.    
  474.  
  475.     SetRole.OnClientEvent:Connect(function()
  476.         TeamSelectionGui.Enabled = false
  477.         SideButtonsGui.Enabled   = true
  478.        
  479.         SetHudVisibility:Fire(true)
  480.         local PreviouslySelectedRoleBtn = CollectionService:GetTagged("RoleBtn_Selected")[1]
  481.         CollectionService:RemoveTag(PreviouslySelectedRoleBtn, "RoleBtn_Selected")
  482.     end)
  483.      
  484.  
  485.  
  486.     ---* Roles button Visual modifiers ||>
  487.     CollectionService:GetInstanceAddedSignal("RoleBtn_Selected"):Connect(function(roleBtn: ImageButton)
  488.         --#!//TODO Add sound feedback depending if the team is owned or not
  489.        
  490.         local SelectionOverlay: Frame = roleBtn:FindFirstChild("SelectionOverlayFrame", true)
  491.         SelectionOverlay.Visible = true
  492.    
  493.         local OverlayFrame: Frame     = SelectionOverlay:FindFirstChild("OverlayFrame")
  494.         OverlayFrame.BackgroundColor3 = ROLE_SELECTED_HIGHLIGHT
  495.        
  496.        
  497.         --## Swap the selected role btn if it's different from the curr. selected
  498.         --## That'll also automatically change the selection overlay!
  499.  
  500.         local PreviouslySelectedRoleBtn = CollectionService:GetTagged("RoleBtn_Selected")[1]
  501.         if PreviouslySelectedRoleBtn.Name == roleBtn.Name then return end
  502.  
  503.         CollectionService:RemoveTag(PreviouslySelectedRoleBtn, "RoleBtn_Selected")
  504.     end)
  505.    
  506.    
  507.     CollectionService:GetInstanceRemovedSignal("RoleBtn_Selected"):Connect(function(roleBtn: ImageButton)
  508.         local SelectionOverlay: Frame = roleBtn:FindFirstChild("SelectionOverlayFrame", true)
  509.         SelectionOverlay.Visible = false
  510.    
  511.         local OverlayFrame: Frame = SelectionOverlay:FindFirstChild("OverlayFrame")
  512.         OverlayFrame.BackgroundColor3 = BUTTON_HOVER_HIGHLIGHT
  513.  
  514.        
  515.         --## When the roleBtn is selected, it will not loose the hover tag on mouse
  516.         --## Leave! Which causes a state bug when the role btn is deselected so to prevent that
  517.         --## We remove the lingering "Hover" tag when the button looses the "Selected" tag.
  518.  
  519.         CollectionService:RemoveTag(roleBtn, "RoleBtn_Hover")
  520.     end)
  521.    
  522.    
  523.  
  524.     CollectionService:GetInstanceAddedSignal("RoleBtn_Hover"):Connect(function(roleBtn: ImageButton)
  525.         local SelectionOverlay: Frame = roleBtn:FindFirstChild("SelectionOverlayFrame", true)
  526.         SelectionOverlay.Visible = true
  527.     end)
  528.    
  529.    
  530.     CollectionService:GetInstanceRemovedSignal("RoleBtn_Hover"):Connect(function(roleBtn: ImageButton)        
  531.         local SelectionOverlay: Frame = roleBtn:FindFirstChild("SelectionOverlayFrame", true)
  532.         SelectionOverlay.Visible = false
  533.     end)
  534.  
  535.    
  536.    
  537.     ---* Roles Player count UI update ||>
  538.     for roleIndexKey, roleTag: TextLabel in RolesComponent.GetRolesList() do
  539.         CollectionService:GetInstanceAddedSignal(roleTag):Connect(function()
  540.             UpdateRolePlayerCountText(roleTag, roleIndexKey)
  541.         end)
  542.     end
  543.    
  544.     for roleIndexKey, roleTag: TextLabel in RolesComponent.GetRolesList() do
  545.         CollectionService:GetInstanceRemovedSignal(roleTag):Connect(function()
  546.             UpdateRolePlayerCountText(roleTag, roleIndexKey)
  547.         end)
  548.     end
  549.    
  550.    
  551.     ---* Hide Locked Role overlay if the player unlocks it ||>
  552.     CollectionService:GetInstanceAddedSignal("RoleBtn"):Connect(function(roleBtn: ImageButton)
  553.         local roleOwnershipVal = OwnedRoles:FindFirstChild(roleBtn.Name)
  554.         local LockedOverlay: Frame = roleBtn:FindFirstChild("LockedOverlayFrame")
  555.    
  556.         roleOwnershipVal.Changed:Connect(function(isOwner)
  557.             LockedOverlay.Visible = not isOwner
  558.         end)
  559.     end)
  560. end
  561.  
  562.  
  563.  
  564.  
  565. --=============================== In-Game Settings Gui Initialization ===============================||>
  566. do
  567.     local inGameSettings: InGameSettingsList         = InGameSettingsData.GetInGameSettingsList()
  568.     local inGameSettingTypes:InGameSettingsTypesEnum = InGameSettingsData.GetInGameSettingTypesEnum()
  569.  
  570.     ---* Text ||>
  571.     local SettingsFrame: ScrollingFrame = InGameSettingsGui:FindFirstChild("SettingsScrollingFrame", true)
  572.    
  573.  
  574.     local SliderAndToggleSettingFrame: Frame = CollectionService:GetTagged("InGameSetting_SliderAndToggle")[1]
  575.     local ToggleSettingFrame: Frame          = CollectionService:GetTagged("InGameSetting_Toggle")[1]
  576.  
  577.     --## Settings factory, Generate and mount In-game settings gui containers into the In-Game settings menu
  578.     task.spawn(function()
  579.         for key, setting: InGameSettingComponent in inGameSettings do
  580.             local newSetting: Frame = nil
  581.  
  582.             if setting.Type == inGameSettingTypes.SliderAndToggleSetting then
  583.                 newSetting = SliderAndToggleSettingFrame:Clone()
  584.                 newSetting.Name = key
  585.  
  586.             elseif setting.Type == inGameSettingTypes.JustToggleSetting then
  587.                 newSetting = ToggleSettingFrame:Clone()
  588.             end
  589.  
  590.             newSetting.Name    = key
  591.             newSetting.Visible = true
  592.  
  593.             local SettingNameLabel: TextLabel = newSetting:FindFirstChild("NameTextLabel", true)
  594.             SettingNameLabel.Text = setting.Name
  595.  
  596.             newSetting.Parent = SettingsFrame
  597.  
  598.         end  
  599.     end)
  600.  
  601.  
  602.     local BackButton: ImageButton = InGameSettingsGui:FindFirstChild("BackButton", true)
  603.     BackButton.MouseButton1Click:Connect(function()
  604.         print("Save behavior not implemented")
  605.         InGameSettingsGui.Enabled = false
  606.     end)
  607. end
  608.  
  609.  
  610.  
  611. --=============================== Shop Initialization & Controls ===============================||>
  612. do
  613.     --## These buttons are just to cycle between both shops and to make
  614.     --## Shop titles and contents visible/invisible
  615.  
  616.     local CashShop: Frame          = ShopGui:FindFirstChild("CashShopFrame", true)
  617.     local CashShopTitle: TextLabel = ShopGui:FindFirstChild("CashShopTitleTextlLabel", true)
  618.  
  619.     local GamePassesShop: Frame          = ShopGui:FindFirstChild("GamepassesShopFrame",  true)
  620.     local GamepassesShopTitle: TextLabel = ShopGui:FindFirstChild("GamepassesShopTitleTextLabel", true)
  621.  
  622.     --#!//TODO Populate both menus here
  623.    
  624.     local CashShopMenuBtn: ImageButton   = ShopGui:FindFirstChild("CashShopMenuButton", true)
  625.     CashShopMenuBtn.MouseButton1Click:Connect(function()
  626.         CashShop.Visible       = true
  627.         GamePassesShop.Visible = false
  628.        
  629.         CashShopTitle.Visible       = true
  630.         GamepassesShopTitle.Visible = false
  631.     end)
  632.  
  633.  
  634.     local GamepassesBtn: ImageButton   = ShopGui:FindFirstChild("GamepassesShopMenuButton", true)
  635.     GamepassesBtn.MouseButton1Click:Connect(function()
  636.         CashShop.Visible       = false
  637.         GamePassesShop.Visible = true
  638.  
  639.         CashShopTitle.Visible       = false
  640.         GamepassesShopTitle.Visible = true
  641.     end)
  642.  
  643.  
  644.     local BackBtn: ImageButton = ShopGui:FindFirstChild("BackButton", true)
  645.     BackBtn.MouseButton1Click:Connect(function()
  646.         ShopGui.Enabled = false
  647.     end)
  648. end
  649.  
  650.  
  651. --=============================== Tasks Menu ===============================||>
  652.  
  653. do
  654.     local BackBtn: ImageLabel = TasksGui:FindFirstChild("BackButton", true)
  655.     BackBtn.MouseButton1Click:Connect(function()
  656.         TasksGui.Enabled = false
  657.     end)
  658. end
  659.  
  660.  
  661.  
  662. --=============================== Daily Rewards Menu ===============================||>
  663. do
  664.     local ClaimBtn: ImageLabel = RewardsGui:FindFirstChild("ClaimButton", true)
  665.     ClaimBtn.MouseButton1Click:Connect(function()
  666.         RewardsGui.Enabled     = false
  667.         SideButtonsGui.Enabled = true
  668.     end)
  669.  
  670.     local BackBtn: ImageLabel = RewardsGui:FindFirstChild("BackButton", true)
  671.  
  672.     BackBtn.MouseButton1Click:Connect(function()
  673.         RewardsGui.Enabled     = false
  674.     end)
  675. end
  676.  
  677.  
  678. --=============================== Main Menu Cinnematics ===============================||>
  679. do
  680.     Camera.CameraType = Enum.CameraType.Scriptable
  681.  
  682.     local CameraModels: table = workspace.Cameras:GetChildren()
  683.     local TweenInfo = TweenInfo.new(
  684.         5,
  685.         Enum.EasingStyle.Sine,
  686.         Enum.EasingDirection.InOut,
  687.         0,
  688.         false,
  689.         0
  690.     )
  691.  
  692.     task.spawn(function()
  693.         while true do
  694.             for _, cameraModel: Model in ipairs(CameraModels) do
  695.                 if  stopCinematics == true then
  696.                     break
  697.                 end
  698.        
  699.                 local startPoint: CFrame = cameraModel.Camera1.CFrame
  700.                 local endPoint: CFrame   = cameraModel.Camera2.CFrame
  701.        
  702.                 Camera.CameraSubject = cameraModel.Camera1
  703.                 Camera.CFrame        = startPoint
  704.                
  705.                 local CameraTween: Tween = TweenService:Create(Camera, TweenInfo, {CFrame = endPoint})
  706.                 CurrentCinematicCamTween = CameraTween
  707.                 CameraTween:Play()
  708.        
  709.                 CameraTween.Completed:Wait()
  710.             end
  711.             task.wait()
  712.         end  
  713.     end)
  714. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement