CapsAdmin

Untitled

Jul 20th, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.35 KB | None | 0 0
  1. local events_tutorial =
  2. {
  3.     {
  4.         pos = function(pnl) if pnl.part and pnl.part:IsValid() and pnl.part.ClassName == "group" then return true end end,
  5.         wait = MOUSE_RIGHT,
  6.         text = [[right this group]],
  7.     },
  8.     {
  9.         pos = function(pnl) if pnl.ClassName == "DMenuOption" and pnl:GetText():find("event") then return true end end,
  10.         wait = MOUSE_RIGHT,
  11.         text = [[add the event part to it]],
  12.     },
  13.     {
  14.         pos = function(pnl) if pnl.pac3_sort_pos and pnl.lbl:GetText():find("event") then return true end end,
  15.         wait = MOUSE_RIGHT,
  16.         text = [[change the event to something]],
  17.     }
  18. }
  19.  
  20. tutorial = tutorial or {}
  21. tutorial.Panels = tutorial.Panels or {}
  22.  
  23. local function handle_position(var)
  24.     local T = type(var)
  25.     if T == "function" then
  26.         for key, pnl in pairs(tutorial.Panels) do
  27.             if pnl:IsValid() then
  28.                 if var(pnl) == true then
  29.                     return Vector(pnl:LocalToScreen(pnl:GetWide(), pnl:GetTall()/2))
  30.                 end
  31.             else
  32.                 tutorial.Panels[key] = nil
  33.             end
  34.         end
  35.     end
  36.     if T == "Vector" then
  37.         return var
  38.     end
  39. end
  40.  
  41. local function handle_wait(var)
  42.     local T = type(var)
  43.     if T == "function" then
  44.         return var
  45.     end
  46.    
  47.     if T == "number" then
  48.         return function() return input.IsMouseDown(var) end
  49.     end
  50. end
  51.  
  52. function tutorial.BeginTutorial(data)
  53.     local i = 1
  54.  
  55.     local function step()
  56.         local step_data = data[i]
  57.        
  58.         timer.Simple(0.2, function()
  59.             if step_data then
  60.                 local pos = handle_position(step_data.pos)
  61.                 local done = handle_wait(step_data.wait)
  62.                 local text = markup.Parse(step_data.text)
  63.                
  64.                 print(pos, done, text)
  65.                
  66.                 tutorial.busy = true
  67.                
  68.                 hook.Add("PostRenderVGUI", "tutorial", function()
  69.                     if done() then
  70.                         step()
  71.                     else
  72.                         local flash = math.abs(math.sin(CurTime() * 5)) * 50
  73.                         local w, h = text:Size()
  74.                         surface.SetDrawColor(Color(flash, flash, flash, 255))
  75.                         surface.DrawRect(pos.x - 5, pos.y - 5, w + 5*2, h + 5*2)
  76.                         text:Draw(pos.x , pos.y, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  77.                     end
  78.                 end)
  79.                
  80.                 i = i + 1
  81.             else
  82.                 hook.Remove("PostRenderVGUI", "tutorial")
  83.                 tutorial.busy = false
  84.             end
  85.         end)
  86.     end
  87.    
  88.     step()
  89. end
  90.  
  91. tutorial.vgui_Create = tutorial.vgui_Create or vgui.Create
  92.  
  93. function vgui.Create(...)
  94.     local args = {tutorial.vgui_Create(...)}
  95.    
  96.     table.insert(tutorial.Panels, args[1])
  97.    
  98.     return unpack(args)
  99. end
  100.  
  101. tutorial.BeginTutorial(events_tutorial)
Advertisement
Add Comment
Please, Sign In to add comment