new post | browse code | authors | help | about

LuaBin 2.0

Viewing file root / lua / menu / startgame.lua

  1. //=============================================================================//
  2. //  ___  ___   _   _   _    __   _   ___ ___ __ __
  3. // |_ _|| __| / \ | \_/ |  / _| / \ | o \ o \\ V /
  4. //  | | | _| | o || \_/ | ( |_n| o ||   /   / \ /
  5. //  |_| |___||_n_||_| |_|  \__/|_n_||_|\\_|\\ |_|  2007
  6. //                                                                               
  7. //=============================================================================//
  8.  
  9.  
  10. local PANEL = {}
  11.  
  12. /*---------------------------------------------------------
  13.  
  14. ---------------------------------------------------------*/
  15. function PANEL:Init()
  16.  
  17.         self.StartGame = vgui.Create( "DButton", self )
  18.         self.StartGame:SetText( "Start Game" )
  19.         self.StartGame:SetSize( 100, 20 )
  20.         self.StartGame.DoClick = function() self:LaunchGame() end
  21.         self.StartGame:SetDisabled( true )
  22.        
  23.         self.Help = vgui.Create( "DLabel", self )
  24.         self.Help:SetText( "#ChooseMapHelp" )
  25.         self.Help:SetTextColor( Color( 0, 0, 0, 230 ) )
  26.        
  27.         // Restore the saved hostname
  28.         RunConsoleCommand( "hostname", cookie.GetString( "menuui.hostname", GetConVarString( "hostname" ) ) )
  29.  
  30. end
  31.  
  32. /*---------------------------------------------------------
  33.  
  34. ---------------------------------------------------------*/
  35. function PANEL:Paint()
  36.  
  37.         draw.RoundedBox( 4, 0, 0, self:GetWide(), self:GetTall(), Color( 190, 190, 190, 255 ) )
  38.  
  39. end
  40.  
  41. /*---------------------------------------------------------
  42.  
  43. ---------------------------------------------------------*/
  44. function PANEL:PerformLayout()
  45.  
  46.         self.StartGame:SetPos( self:GetWide() - self.StartGame:GetWide() - 10, self:GetTall() - self.StartGame:GetTall() - 10 )
  47.        
  48.         self.Help:SetPos( 10, 10 )
  49.         self.Help:SizeToContents()
  50.        
  51. end
  52.  
  53.  
  54. /*---------------------------------------------------------
  55.  
  56. ---------------------------------------------------------*/
  57. function PANEL:SetMap( strMap )
  58.  
  59.         self.Map = strMap
  60.         self.StartGame:SetDisabled( false )
  61.  
  62. end
  63.  
  64. /*--------------------------------------------------------
  65.  
  66. ---------------------------------------------------------*/
  67. function PANEL:SetMultiplayer()
  68.         self.Multiplayer = true
  69. end
  70.  
  71.  
  72. /*---------------------------------------------------------
  73.  
  74. ---------------------------------------------------------*/
  75. function PANEL:LaunchGame()
  76.  
  77.         // Error Sound?
  78.         if (!self.Map) then return end
  79.        
  80.         // This hook is used to close all of the GAMEUI windows.
  81.         hook.Call( "StartGame", {} )
  82.        
  83.         RunConsoleCommand( "progress_enable" )
  84.        
  85.         if ( !self.Multiplayer ) then
  86.        
  87.                 RunConsoleCommand( "disconnect" )
  88.                 RunConsoleCommand( "maxplayers", 1 )
  89.                
  90.         else
  91.        
  92.                 RunConsoleCommand( "disconnect" )
  93.                 RunConsoleCommand( "sv_cheats", "0" )
  94.                
  95.                 // Set maxplayers..
  96.                 timer.Simple( 0.1, function() RunConsoleCommand( "maxplayers", GetConVarNumber( "sv_maxplayers" ) ) end )
  97.                
  98.         end
  99.        
  100.         // This tiny delay is to allow the disconnect, then allow maxplayers to change.
  101.         timer.Simple( 0.2, function() RunConsoleCommand( "map", self.Map ) end )
  102.        
  103.         // Save the hostname
  104.         cookie.Set( "menuui.hostname", GetConVarString( "hostname" ) )
  105.                
  106. end
  107.  
  108.  
  109.  
  110. vgui.Register( "StartGame", PANEL, "Panel" )
  111.