Advertisement
Guest User

My MenuScene Example

a guest
May 18th, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //------------------------------------------------------------------------------
  2. // Main Menu where all the fancy stuff takes place.
  3. //------------------------------------------------------------------------------
  4. class SRMainMenuScene extends GUIMenuScene;
  5.  
  6. event InitMenuScene()
  7. {
  8.     DefaultInputComponent = FindComponentByTag("TitlePage");
  9.  
  10.     FindComponentByTag("TitleBackground").OnMousePressed = TitleBackgroundReleased;
  11.     FindComponentByTag("TitlePage").OnBecomeEnabled = TitleScreenBecomeEnabled;
  12.     FindComponentByTag("TitlePage").OnInputKey = TitleScreenInput;
  13.     FindComponentByTag("CharSelPage").OnInputKey = CharSelScreenInput;
  14.     FindComponentByTag("CharSelPage").OnBecomeEnabled = CharSelScreenBecomeEnabled;
  15.     FindComponentByTag("BackToTitleButton").OnMousePressed = BackToTitleButtonReleased;
  16.     FindComponentByTag("StartButton").OnMousePressed = StartButtonReleased;
  17.  
  18.     super.InitMenuScene();
  19. }
  20.  
  21.  
  22. // Draws the mouse cursor.
  23. // Overriden because our cursor's selection point shall be in the center and not in the top-left corner.
  24. function DrawCursor(Canvas C, float PosX, float PosY, optional bool bHasSelection)
  25. {
  26.     local float CursorScale;
  27.  
  28.     CursorScale = 2*OwnerHUD.ViewX/CursorTexture.SizeX; // 2048 = cursor texture size.
  29.  
  30.     C.SetPos(PosX - CursorScale * (CursorTexture.SizeX/2), PosY - CursorScale * (CursorTexture.SizeX/2));
  31.  
  32.     if (bHasSelection)
  33.     {
  34.         // Set the cursor color
  35.         C.DrawColor = SelectionCursorColor;
  36.         // Draw the texture on the screen
  37.         C.DrawTile(SelectionCursorTexture, CursorScale * SelectionCursorTexture.SizeX, CursorScale * SelectionCursorTexture.SizeY,
  38.                    0.f, 0.f, SelectionCursorTexture.SizeX, SelectionCursorTexture.SizeY,, true);
  39.     }
  40.     else
  41.     {
  42.         // Set the cursor color
  43.         C.DrawColor = CursorColor;
  44.         // Draw the texture on the screen
  45.         C.DrawTile(CursorTexture, CursorScale * CursorTexture.SizeX, CursorScale * CursorTexture.SizeY,
  46.                    0.f, 0.f, CursorTexture.SizeX, CursorTexture.SizeY,, true);
  47.     }
  48. }
  49.  
  50.  
  51. //=============================================================================
  52. // Delegate handlers
  53. //=============================================================================
  54. //-----------------------------------------------------------------------------
  55. // Title Screen
  56. function TitleScreenBecomeEnabled(optional GUIComponent Component)
  57. {
  58.     local AudioComponent AudioComp;
  59.  
  60.     AudioComp = SRMainMenuHUD(OwnerHUD).MenuMusic;
  61.     AudioComp.Stop();
  62.     AudioComp.SoundCue = SoundCue'MyMusic.Sounds.main_title_full_version_Cue';
  63.     AudioComp.Play();
  64. }
  65.  
  66. function bool TitleScreenInput(int ControllerId, name Key, EInputEvent Event, float AmountDepressed = 1.f, bool bGamepad = FALSE)
  67. {
  68.     if (event == IE_Released)
  69.     {
  70.         if (Key == 'Enter' || Key == 'XboxTypeS_Start')
  71.         {
  72.             TitleBackgroundReleased();
  73.             return True;
  74.         }
  75.  
  76.         if (Key == 'Escape')
  77.         {
  78.             ConsoleCommand("exit");
  79.             return True;
  80.         }
  81.     }
  82.     return False;
  83. }
  84.  
  85. // Go from Title screen to the next one.
  86. function TitleBackgroundReleased(optional GUIComponent Component, optional byte ButtonNum)
  87. {
  88.     PushPage(GUIPage(FindComponentByTag("CharSelPage")));
  89.     OwnerHUD.PlaySound(SoundCue'MyUI.Sounds.StartConfirm_Cue', False);
  90.     DefaultInputComponent = FindComponentByTag("CharSelPage");
  91. }
  92.  
  93. //-----------------------------------------------------------------------------
  94. // Character Selection Screen
  95. function CharSelScreenBecomeEnabled(optional GUIComponent Component)
  96. {
  97.     local AudioComponent AudioComp;
  98.  
  99.     AudioComp = SRMainMenuHUD(OwnerHUD).MenuMusic;
  100.     AudioComp.Stop();
  101.     AudioComp.SoundCue = SoundCue'MyMusic.Sounds.a_heros_welcome_Cue';
  102.     AudioComp.Play();
  103. }
  104.  
  105. function bool CharSelScreenInput(int ControllerId, name Key, EInputEvent Event, float AmountDepressed = 1.f, bool bGamepad = FALSE)
  106. {
  107.     if (event == IE_Released)
  108.     {
  109.         if (Key == 'Enter' || Key == 'XboxTypeS_Start')
  110.         {
  111.             StartButtonReleased();
  112.             return True;
  113.         }
  114.     }
  115.     return False;
  116. }
  117.  
  118. // Go from Char Select screen back to title.
  119. function BackToTitleButtonReleased(optional GUIComponent Component, optional byte ButtonNum)
  120. {
  121.     PopPage();
  122.     DefaultInputComponent = FindComponentByTag("TitlePage");
  123. }
  124.  
  125. // Start the actual game map.
  126. function StartButtonReleased(optional GUIComponent Component, optional byte ButtonNum)
  127. {
  128.     FindComponentByTag("StartButton").OnMouseReleased = none;
  129.     OwnerHUD.PlaySound(SoundCue'MyUI.Sounds.StartConfirm_Cue', False);
  130.     ConsoleCommand("open TechDemo");
  131. }
  132.  
  133. //=============================================================================
  134.  
  135. DefaultProperties
  136. {
  137.     bDrawGUIComponents = True
  138.     bCaptureMouseInput = True
  139.     bCaptureKeyInput = True
  140.     CursorTexture = Texture2D'MyUI.HUD.AimCrossred'
  141.     SelectionCursorTexture = Texture2D'MyUI.HUD.AimCrossred'
  142.     SelectionCursorColor = (R=255, G=0, B=0, A=255)
  143.  
  144.  
  145.     // A GUI page for the Title screen.
  146.     Begin Object class=GUIPage Name=TitleScreen
  147.         Tag = "TitlePage"
  148.         PosX = 0.0
  149.         PosY = 0.0
  150.         PosXEnd = 1.0
  151.         PosYEnd = 1.0
  152.  
  153.         // Make the background image a button to capture a mouse input everywhere on the screen.
  154.         Begin Object class=GUIVisualComponent Name=TitleBackgroundImage
  155.             Tag = "TitleBackground"
  156.             PosX = 0.0
  157.             PosY = 0.0
  158.             PosXEnd = 1.0
  159.             PosYEnd = 1.0
  160.  
  161.             bForceNormalDrawInfo = True
  162.  
  163.             // button is simply drawn normal
  164.             DrawInfo(0) = (ComponentTexture=Texture2D'MyUI.TitleScreen.Titelscreen', SubUVEnd=(X=2048,Y=2048))
  165.         End Object
  166.         ChildComponents.Add(TitleBackgroundImage)
  167.  
  168.         // With the huge title screen button, we no longer need an actual button element for this, so make it a VisualComponent instead.
  169.         Begin Object class=GUIVisualComponent Name=TitleConfirmButton
  170.             Tag = "TitleConfirmButton"
  171.             PosX = 0.30
  172.             PosY = 0.65
  173.             PosXEnd = 0.7
  174.             PosYEnd = 0.75
  175.  
  176.             // button is simply drawn normal
  177.             DrawInfo(0) = (bUseMaterial=True, ComponentMaterial=Material'MyUI.TitleScreen.PressStart_Mat', SubUVEnd=(X=1,Y=1))
  178.         End Object
  179.         ChildComponents.Add(TitleConfirmButton)
  180.  
  181.     End Object
  182.     GUIComponents.Add(TitleScreen)
  183.  
  184.  
  185.  
  186.     // A GUI page for the Character Selection screen.
  187.     Begin Object class=GUIPage Name=CharSelectScreen
  188.         Tag = "CharSelPage"
  189.         PosX = 0.0
  190.         PosY = 0.0
  191.         PosXEnd = 1.0
  192.         PosYEnd = 1.0
  193.         bEnabled = False
  194.  
  195.         Begin Object class=GUIVisualComponent Name=CharBackgroundImage
  196.             Tag = "CharBackground"
  197.             PosX = 0.0
  198.             PosY = 0.0
  199.             PosXEnd = 1.0
  200.             PosYEnd = 1.0
  201.  
  202.             bForceNormalDrawInfo = True
  203.  
  204.             // button is simply drawn normal
  205.             DrawInfo(0) = (ComponentTexture=Texture2D'MyUI.CharacterScreen.CharselectBG', SubUVEnd=(X=2048,Y=2048))
  206.         End Object
  207.         ChildComponents.Add(CharBackgroundImage)
  208.  
  209.  
  210.         Begin Object class=GUIButtonComponent Name=PreviousButton
  211.             Tag = "PreviousButton"
  212.             PosX = 0.24
  213.             PosY = 0.37
  214.             PosXEnd = 0.31
  215.             PosYEnd = 0.42
  216.             bDrawCaption = False
  217.  
  218.             bForceNormalDrawInfo = True
  219.             bForceNormalCaptionInfo = True
  220.  
  221.             MouseEnteredSound = SoundCue'MyUI.Sounds.HoverOver_Cue'
  222.  
  223.             // button is simply drawn normal
  224.             DrawInfo(0) = (ComponentTexture=Texture2D'MyUI.CharacterScreen.backbutton', SubUVEnd=(X=256,Y=64))
  225.         End Object
  226.         ChildComponents.Add(PreviousButton)
  227.  
  228.  
  229.         Begin Object class=GUIButtonComponent Name=NextButton
  230.             Tag = "NextButton"
  231.             PosX = 0.687
  232.             PosY = 0.37
  233.             PosXEnd = 0.757
  234.             PosYEnd = 0.42
  235.             bDrawCaption = False
  236.  
  237.             bForceNormalDrawInfo = True
  238.             bForceNormalCaptionInfo = True
  239.  
  240.             MouseEnteredSound = SoundCue'MyUI.Sounds.HoverOver_Cue'
  241.  
  242.             // button is simply drawn normal
  243.             DrawInfo(0) = (ComponentTexture=Texture2D'MyUI.CharacterScreen.NextButton', SubUVEnd=(X=256,Y=64))
  244.         End Object
  245.         ChildComponents.Add(NextButton)
  246.  
  247.  
  248.         Begin Object class=GUIButtonComponent Name=StartButton
  249.             Tag = "StartButton"
  250.             PosX = 0.36
  251.             PosY = 0.744
  252.             PosXEnd = 0.59
  253.             PosYEnd = 0.79
  254.             bDrawCaption = False
  255.  
  256.             bForceNormalDrawInfo = True
  257.             bForceNormalCaptionInfo = True
  258.  
  259.             MouseEnteredSound = SoundCue'MyUI.Sounds.HoverOver_Cue'
  260.  
  261.             // button is simply drawn normal
  262.             DrawInfo(0) = (ComponentTexture=Texture2D'MyUI.CharacterScreen.enterlevel', SubUVEnd=(X=512,Y=64))
  263.         End Object
  264.         ChildComponents.Add(StartButton)
  265.  
  266.  
  267.         Begin Object class=GUIButtonComponent Name=BackToTitleButton
  268.             Tag = "BackToTitleButton"
  269.             PosX = 0.635
  270.             PosY = 0.11
  271.             PosXEnd = 0.76
  272.             PosYEnd = 0.136
  273.             bDrawCaption = False
  274.  
  275.             bForceNormalDrawInfo = True
  276.             bForceNormalCaptionInfo = True
  277.  
  278.             MouseEnteredSound = SoundCue'MyUI.Sounds.HoverOver_Cue'
  279.  
  280.             // button is simply drawn normal
  281.             DrawInfo(0) = (ComponentTexture=Texture2D'MyUI.CharacterScreen.backtotitle', SubUVEnd=(X=256,Y=32))
  282.         End Object
  283.         ChildComponents.Add(BackToTitleButton)
  284.  
  285.     End Object
  286.     GUIComponents.Add(CharSelectScreen)
  287. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement