PageRenderTime 892ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/NuclearSample/NuclearSample/NuclearSampleGame.cs

http://nuclearwinter.codeplex.com
C# | 187 lines | 132 code | 40 blank | 15 comment | 5 complexity | 2a92ae435218c40cd9ae5711804e2885 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11. using NuclearWinter;
  12. using NuclearUI = NuclearWinter.UI;
  13. namespace NuclearSample
  14. {
  15. //--------------------------------------------------------------------------
  16. public class NuclearSampleGame : NuclearGame
  17. {
  18. //----------------------------------------------------------------------
  19. internal GameStates.GameStateIntro Intro { get; private set; }
  20. internal GameStates.GameStateMainMenu MainMenu { get; private set; }
  21. //----------------------------------------------------------------------
  22. internal NuclearUI.Style UIStyle { get; private set; }
  23. //----------------------------------------------------------------------
  24. public NuclearSampleGame()
  25. {
  26. Content.RootDirectory = "Content";
  27. Graphics.PreferredBackBufferWidth = 1280;
  28. Graphics.PreferredBackBufferHeight = 720;
  29. }
  30. //----------------------------------------------------------------------
  31. protected override void Initialize()
  32. {
  33. base.Initialize();
  34. SetWindowTitle( "NuclearWinter Sample" );
  35. //------------------------------------------------------------------
  36. Window.AllowUserResizing = true;
  37. Form.MinimumSize = new System.Drawing.Size( 1260, 720 );
  38. IsMouseVisible = true;
  39. //------------------------------------------------------------------
  40. // Game states
  41. Intro = new GameStates.GameStateIntro( this );
  42. MainMenu = new GameStates.GameStateMainMenu( this );
  43. GameStateMgr.SwitchState( Intro );
  44. //------------------------------------------------------------------
  45. Form.Resize += delegate { EnsureProperPresentationParams(); };
  46. }
  47. //----------------------------------------------------------------------
  48. void EnsureProperPresentationParams()
  49. {
  50. if( Form.ClientSize.IsEmpty ) return;
  51. if( Form.ClientSize.Width != GraphicsDevice.Viewport.Width
  52. || Form.ClientSize.Height != GraphicsDevice.Viewport.Height )
  53. {
  54. PresentationParameters updatedPresentationParams = GraphicsDevice.PresentationParameters.Clone();
  55. updatedPresentationParams.BackBufferWidth = Form.ClientSize.Width;
  56. updatedPresentationParams.BackBufferHeight = Form.ClientSize.Height;
  57. GraphicsDevice.Reset( updatedPresentationParams );
  58. }
  59. }
  60. //----------------------------------------------------------------------
  61. protected override void LoadContent()
  62. {
  63. base.LoadContent();
  64. //------------------------------------------------------------------
  65. // UI Style
  66. UIStyle = new NuclearUI.Style();
  67. UIStyle.SmallFont = new NuclearUI.UIFont( Content.Load<SpriteFont>( "Fonts/SmallFont" ), 14, 0 );
  68. UIStyle.MediumFont = new NuclearUI.UIFont( Content.Load<SpriteFont>( "Fonts/MediumFont" ), 18, -2 );
  69. UIStyle.LargeFont = new NuclearUI.UIFont( Content.Load<SpriteFont>( "Fonts/LargeFont" ), 24, 0 );
  70. UIStyle.ExtraLargeFont = new NuclearUI.UIFont( Content.Load<SpriteFont>( "Fonts/LargeFont" ), 24, 0 );
  71. UIStyle.SpinningWheel = Content.Load<Texture2D>( "Sprites/UI/SpinningWheel" );
  72. UIStyle.DefaultTextColor = new Color( 224, 224, 224 );
  73. UIStyle.DefaultButtonHeight = 60;
  74. UIStyle.ButtonFrame = Content.Load<Texture2D>( "Sprites/UI/ButtonFrame" );
  75. UIStyle.ButtonDownFrame = Content.Load<Texture2D>( "Sprites/UI/ButtonFrameDown" );
  76. UIStyle.ButtonHoverOverlay = Content.Load<Texture2D>( "Sprites/UI/ButtonHover" );
  77. UIStyle.ButtonFocusOverlay = Content.Load<Texture2D>( "Sprites/UI/ButtonFocus" );
  78. UIStyle.ButtonDownOverlay = Content.Load<Texture2D>( "Sprites/UI/ButtonPress" );
  79. UIStyle.TooltipFrame = Content.Load<Texture2D>( "Sprites/UI/TooltipFrame" );
  80. UIStyle.ButtonCornerSize = 20;
  81. UIStyle.ButtonVerticalPadding = 10;
  82. UIStyle.ButtonHorizontalPadding = 15;
  83. UIStyle.RadioButtonCornerSize = UIStyle.ButtonCornerSize;
  84. UIStyle.RadioButtonFrameOffset = 7;
  85. UIStyle.ButtonFrameLeft = Content.Load<Texture2D>( "Sprites/UI/ButtonFrameLeft" );
  86. UIStyle.ButtonDownFrameLeft = Content.Load<Texture2D>( "Sprites/UI/ButtonFrameLeftDown" );
  87. UIStyle.ButtonFrameMiddle = Content.Load<Texture2D>( "Sprites/UI/ButtonFrameMiddle" );
  88. UIStyle.ButtonDownFrameMiddle = Content.Load<Texture2D>( "Sprites/UI/ButtonFrameMiddleDown" );
  89. UIStyle.ButtonFrameRight = Content.Load<Texture2D>( "Sprites/UI/ButtonFrameRight" );
  90. UIStyle.ButtonDownFrameRight = Content.Load<Texture2D>( "Sprites/UI/ButtonFrameRightDown" );
  91. UIStyle.EditBoxFrame = Content.Load<Texture2D>( "Sprites/UI/EditBoxFrame" );
  92. UIStyle.EditBoxCornerSize = 20;
  93. UIStyle.Panel = Content.Load<Texture2D>( "Sprites/UI/Panel01" );
  94. UIStyle.PanelCornerSize = 15;
  95. UIStyle.NotebookStyle.TabCornerSize = 15;
  96. UIStyle.NotebookStyle.Tab = Content.Load<Texture2D>( "Sprites/UI/Tab" );
  97. UIStyle.NotebookStyle.TabFocus = Content.Load<Texture2D>( "Sprites/UI/ButtonFocus" );
  98. UIStyle.NotebookStyle.ActiveTab = Content.Load<Texture2D>( "Sprites/UI/ActiveTab" );
  99. UIStyle.NotebookStyle.ActiveTabFocus = Content.Load<Texture2D>( "Sprites/UI/ActiveTabFocused" );
  100. UIStyle.NotebookStyle.TabClose = Content.Load<Texture2D>( "Sprites/UI/TabClose" );
  101. UIStyle.NotebookStyle.TabCloseHover = Content.Load<Texture2D>( "Sprites/UI/TabCloseHover" );
  102. UIStyle.NotebookStyle.TabCloseDown = Content.Load<Texture2D>( "Sprites/UI/TabCloseDown" );
  103. UIStyle.NotebookStyle.UnreadTabMarker = Content.Load<Texture2D>( "Sprites/UI/UnreadTabMarker" );
  104. UIStyle.ListViewStyle.ListViewFrame = Content.Load<Texture2D>( "Sprites/UI/ListFrame" );
  105. UIStyle.ListViewStyle.ListViewFrameCornerSize = 10;
  106. UIStyle.ListRowInsertMarker = Content.Load<Texture2D>( "Sprites/UI/ListRowInsertMarker" );
  107. UIStyle.ListViewStyle.CellFrame = Content.Load<Texture2D>( "Sprites/UI/ListRowFrame" );
  108. UIStyle.ListViewStyle.CellCornerSize = 10;
  109. UIStyle.ListViewStyle.SelectedCellFrame = Content.Load<Texture2D>( "Sprites/UI/ListRowFrameSelected" );
  110. UIStyle.ListViewStyle.CellFocusOverlay = Content.Load<Texture2D>( "Sprites/UI/ListRowFrameFocused" );
  111. UIStyle.ListViewStyle.CellHoverOverlay = Content.Load<Texture2D>( "Sprites/UI/ListRowFrameHover" );
  112. UIStyle.ListViewStyle.ColumnHeaderFrame = Content.Load<Texture2D>( "Sprites/UI/ButtonFrame" ); // FIXME
  113. UIStyle.PopupFrame = Content.Load<Texture2D>( "Sprites/UI/PopupFrame" );
  114. UIStyle.PopupFrameCornerSize = 30;
  115. UIStyle.CheckBoxFrameHover = Content.Load<Texture2D>( "Sprites/UI/CheckBoxFrameHover" );
  116. UIStyle.CheckBoxChecked = Content.Load<Texture2D>( "Sprites/UI/Checked" );
  117. UIStyle.CheckBoxUnchecked = Content.Load<Texture2D>( "Sprites/UI/Unchecked" );
  118. UIStyle.SliderFrame = Content.Load<Texture2D>( "Sprites/UI/ListFrame" );
  119. UIStyle.VerticalScrollbar = Content.Load<Texture2D>( "Sprites/UI/VerticalScrollbar" );
  120. UIStyle.VerticalScrollbarCornerSize = 5;
  121. UIStyle.DropDownBoxEntryHoverOverlay= Content.Load<Texture2D>( "Sprites/UI/ListRowFrameFocused" );
  122. UIStyle.DropDownArrow = Content.Load<Texture2D>( "Sprites/UI/DropDownArrow" );
  123. UIStyle.SplitterFrame = Content.Load<Texture2D>( "Sprites/UI/SplitterFrame" );
  124. UIStyle.SplitterDragHandle = Content.Load<Texture2D>( "Sprites/UI/SplitterDragHandle" );
  125. UIStyle.SplitterCollapseArrow = Content.Load<Texture2D>( "Sprites/UI/SplitterCollapseArrow" );
  126. UIStyle.ProgressBarFrame = Content.Load<Texture2D>( "Sprites/UI/EditBoxFrame" );
  127. UIStyle.ProgressBarFrameCornerSize = 15;
  128. UIStyle.ProgressBar = Content.Load<Texture2D>( "Sprites/UI/ProgressBar" );
  129. UIStyle.ProgressBarCornerSize = 15;
  130. UIStyle.TextAreaFrame = Content.Load<Texture2D>( "Sprites/UI/ListFrame" );
  131. UIStyle.TextAreaFrameCornerSize = 15;
  132. UIStyle.TextAreaGutterFrame = Content.Load<Texture2D>( "Sprites/UI/TextAreaGutterFrame" );
  133. UIStyle.TextAreaGutterCornerSize = 15;
  134. EnsureProperPresentationParams();
  135. }
  136. //----------------------------------------------------------------------
  137. protected override void Update( GameTime _time )
  138. {
  139. base.Update( _time );
  140. }
  141. //----------------------------------------------------------------------
  142. protected override void Draw( GameTime _time )
  143. {
  144. base.Draw( _time );
  145. }
  146. }
  147. }