Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Menu Help:
- Use Menu.Structure to create the structure of the menu
- indexing syntax:
- "Order$FIndex$Text"
- Order : A number that indicates the order of which the menu items will appear
- FIndex : Used for indexing a function in Menu.Handling (also sets the Name property)
- Text : Sets the text to be displayed on the menu item
- Note: "0$Menu$" is the same as "0$Menu$Menu"
- Use Menu.Config to configure the display of the menus.
- Setting the size and position will affect only the top menu.
- Use Menu.Alignment for positioning submenus in
- relation to their parent menu.
- Down=1; Right=1; Menus will expand to the right and downward
- Down=-1; Right=1; Menus will expand to the right and upward
- Down=1; Right=-1; Menus will expand to the left and downward
- Down=-1; Right=-1; Menus will expand to the left and upward
- Use Menu.Handle to hold functions used when a menu item is clicked
- When you click on a menu item, using the FIndex
- you specifed, it will look up the index in the
- Menu.Handle table. If it finds a match, it will call
- the function, passing the player and the menu
- item as arguments.
- ]]
- Style = { -- basic color scheme
- Index = {
- ["Background"] = Color3.new(0/255,32/255,96/255),
- ["Border"] = Color3.new(33/255,84/255,185/255),
- ["Selection"] = Color3.new(245/255,205/255,48/255),
- ["Text"] = Color3.new(171/255,214/255,255/255),
- ["Transparency"] = 0.5,
- },
- SetBGColor = function(object,color) object.BackgroundColor3 = Style.Index[color] end,
- }
- Menu = {
- Structure = { -- the menu structure
- ["0$Menu$"] = {
- ["0$Reset$"] = {},
- ["1$Example$Menu Item 2"] = {
- ["0$Example$Menu Item 1"] = {},
- ["1$Example$Menu Item 2"] = {},
- },
- ["2$Example$Menu Item 3"] = {
- ["0$Example$Menu Item 1"] = {},
- ["1$Example$Menu Item 2"] = {
- ["0$Example$Menu Item 1"] = {},
- ["1$Example$Menu Item 2"] = {},
- },
- ["2$Example$Menu Item 3"] = {},
- },
- ["3$Example$Menu Item 4"] = {
- ["0$Example$Menu Item 1"] = {},
- },
- },
- },
- Config = { -- configures the top menu
- BackgroundColor3 = Style.Index["Background"],
- BorderColor3 = Style.Index["Border"],
- TextColor3 = Style.Index["Text"],
- BackgroundTransparency = Style.Index["Transparency"],
- Position = UDim2.new(0,500,0,-20),
- Size = UDim2.new(0,100,0,20),
- },
- Alignment = { -- aligns the menus in relation to the top menu
- Down = 1, -- -1 for Up
- Right = 1, -- -1 for Left
- },
- Handle = { -- handles menu functions
- ["Reset"] = function(player)
- player.Character:BreakJoints()
- end,
- },
- }
- local events = { -- used for handling gui events
- MouseButton1Click = {},
- MouseButton1Down = {},
- MouseButton1Up = {},
- MouseButton2Click = {},
- MouseButton2Down = {},
- MouseButton2Up = {},
- MouseEnter = {},
- MouseLeave = {},
- MouseMoved = {},
- }
- for index,event in pairs(events) do
- setmetatable(event,{
- __call = function(t,object,func,arg)
- if object[index] then
- event[object] = {}
- local eventitem = event[object]
- eventitem["Enabled"] = true
- eventitem["Connection"] = object[index]:connect(function(...)
- if eventitem["Enabled"] then
- func(object,arg,...)
- end
- end)
- else
- error("object not validated by function",0)
- end
- end
- })
- end
- Setup = { -- menu setup functions
- hideMenu = function(player,menu) -- hides a menu item and its submenus
- if menu:IsA"GuiButton" then
- menu.Visible = false
- Style.SetBGColor(menu,"Background")
- for _,submenu in pairs(menu:GetChildren()) do
- Setup.hideMenu(player,submenu)
- end
- end
- end,
- ToggleClick = function(player,value)
- -- Visible and Active don't seem to work properly for textbuttons
- if value then
- player.MenuClick.Value.Parent = player.PlayerGui.Screen
- else
- player.MenuClick.Value.Parent = nil
- end
- end,
- MenuHover = function(object,player) -- hides the submenus of the menu item's siblings and shows the menu item's submenus
- Setup.ToggleClick(player,false)
- local menu = player.PlayerGui.Screen.Menu
- for _,submenu in pairs(object.Parent:GetChildren()) do
- Style.SetBGColor(submenu,"Background")
- for _,submenu in pairs(submenu:GetChildren()) do
- Setup.hideMenu(player,submenu)
- end
- end
- Style.SetBGColor(object,"Selection")
- for _,submenu in pairs(object:GetChildren()) do
- if submenu:IsA"GuiButton" then
- submenu.Visible = true
- end
- end
- end,
- MenuClick = function(object,player) -- handles functions when menu items are clicked
- local run = Menu.Handle[object.Name]
- if run then
- coroutine.resume(coroutine.create(run),player,object)
- end
- local menu = player.PlayerGui.Screen.Menu
- Style.SetBGColor(menu,"Background")
- for _,submenu in pairs(menu:GetChildren()) do
- Setup.hideMenu(player,submenu)
- end
- Setup.ToggleClick(player,false)
- end,
- setupMenu = function(menu,player) -- sets up events for menus
- if menu:IsA"GuiButton" then
- events.MouseEnter(menu,Setup.MenuHover,player)
- events.MouseLeave(menu,function()
- Setup.ToggleClick(player,true)
- end)
- events.MouseButton1Click(menu,Setup.MenuClick,player)
- for _,submenu in pairs(menu:GetChildren()) do
- Setup.setupMenu(submenu,player)
- end
- end
- end,
- }
- function CreateMenu(structure,config,align,first,parent) -- Generates menus from the structure and config
- for info,next in pairs(structure) do
- -- parse the index
- local parsed = {}
- info:gsub("(%d+)$(.+)$(.*)",function(p,n,n2)
- parsed[1] = tonumber(p) or p
- parsed[2] = n or ""
- parsed[3] = n2 ~= "" and n2 or n
- end)
- -- make a new button
- local button = Instance.new("TextButton")
- button.AutoButtonColor = false
- button.ZIndex = 2
- button.Name = parsed[2]
- button.Text = parsed[3]
- -- set properties in config
- for p,v in pairs(config) do button[p] = v end
- if not first then
- -- sub menus only
- local space = 4 -- spacing between menu items
- button.Position = UDim2.new(align.Right,space*align.Right,parsed[1]*align.Down,parsed[1]*space*align.Down)
- button.Size = UDim2.new(1,0,1,0)
- button.Visible = false
- end
- button.Parent = parent
- -- go to next
- CreateMenu(next,config,align,false,button)
- end
- end
- -- create a screen
- local screen = Instance.new("ScreenGui")
- screen.Name = "Screen"
- screen.Parent = game.StarterGui
- -- create the menuclick
- local mc = Instance.new("ImageButton")
- mc.Name = "MenuClick"
- mc.AutoButtonColor = false
- mc.BackgroundTransparency = 1
- mc.Position = UDim2.new(0,0,0,-21)
- mc.Size = UDim2.new(1,0,1,20)
- mc.Parent = screen
- CreateMenu(Menu.Structure,Menu.Config,Menu.Alignment,true,screen)
- function CharacterAdded(player)
- local screen = player.PlayerGui.Screen
- -- setup the events for the menu
- Setup.setupMenu(screen.Menu,player)
- -- make an event to close the menu when clicking outside of it
- events.MouseButton1Click(screen.MenuClick,Setup.MenuClick,player)
- player.MenuClick.Value = screen.MenuClick
- -- menu isn't active yet, so turn off
- Setup.ToggleClick(player,false)
- end
- function onPlayerEntered(player)
- local s = Instance.new("ObjectValue") -- holds the menuclick
- s.Name = "MenuClick"
- s.Parent = player
- if player.Character then CharacterAdded(player) end
- player.CharacterAdded:connect(function() CharacterAdded(player) end)
- end
- game.Players.PlayerAdded:connect(onPlayerEntered)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement