Non-WinForms launcher with auto updater

This commit is contained in:
Regalis
2015-09-11 22:13:44 +03:00
parent ea15397725
commit 29a6260d0f
104 changed files with 46296 additions and 5638 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ using System.Xml.Linq;
namespace Subsurface
{
class GUIComponentStyle
public class GUIComponentStyle
{
public readonly Vector4 Padding;
+17 -9
View File
@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
@@ -15,9 +16,9 @@ namespace Subsurface
BottomRight = (Bottom | Right), BottomLeft = (Bottom | Left), BottomCenter = (CenterX | Bottom)
}
class GUI
public class GUI
{
public static GUIStyle style;
public static GUIStyle Style;
static Texture2D t;
public static SpriteFont Font, SmallFont, LargeFont;
@@ -31,6 +32,13 @@ namespace Subsurface
private static bool pauseMenuOpen;
private static GUIFrame pauseMenu;
public static void Init(ContentManager content)
{
GUI.Font = ToolBox.TryLoadFont("SpriteFont1", content);
GUI.SmallFont = ToolBox.TryLoadFont("SmallFont", content);
GUI.LargeFont = ToolBox.TryLoadFont("LargeFont", content);
}
public static bool PauseMenuOpen
{
get { return pauseMenuOpen; }
@@ -48,7 +56,7 @@ namespace Subsurface
t.SetData<Color>(
new Color[] { Color.White });// fill the texture with white
style = new GUIStyle("Content/UI/style.xml");
Style = new GUIStyle("Content/UI/style.xml");
}
public static void TogglePauseMenu()
@@ -59,10 +67,10 @@ namespace Subsurface
if (pauseMenuOpen)
{
pauseMenu = new GUIFrame(new Rectangle(0,0,200,300), null, Alignment.Center, style);
pauseMenu = new GUIFrame(new Rectangle(0,0,200,300), null, Alignment.Center, Style);
int y = 0;
var button = new GUIButton(new Rectangle(0, y, 0, 30), "Resume", Alignment.CenterX, GUI.style, pauseMenu);
var button = new GUIButton(new Rectangle(0, y, 0, 30), "Resume", Alignment.CenterX, GUI.Style, pauseMenu);
button.OnClicked = TogglePauseMenu;
y += 60;
@@ -72,7 +80,7 @@ namespace Subsurface
SinglePlayerMode spMode = Game1.GameSession.gameMode as SinglePlayerMode;
if (spMode!=null)
{
button = new GUIButton(new Rectangle(0, y, 0, 30), "Load previous", Alignment.CenterX, GUI.style, pauseMenu);
button = new GUIButton(new Rectangle(0, y, 0, 30), "Load previous", Alignment.CenterX, GUI.Style, pauseMenu);
button.OnClicked += TogglePauseMenu;
button.OnClicked += Game1.GameSession.LoadPrevious;
@@ -85,7 +93,7 @@ namespace Subsurface
SinglePlayerMode spMode = Game1.GameSession.gameMode as SinglePlayerMode;
if (spMode != null)
{
button = new GUIButton(new Rectangle(0, y, 0, 30), "Save & quit", Alignment.CenterX, GUI.style, pauseMenu);
button = new GUIButton(new Rectangle(0, y, 0, 30), "Save & quit", Alignment.CenterX, GUI.Style, pauseMenu);
button.OnClicked += QuitClicked;
button.OnClicked += TogglePauseMenu;
button.UserData = "save";
@@ -95,7 +103,7 @@ namespace Subsurface
}
button = new GUIButton(new Rectangle(0, y, 0, 30), "Quit", Alignment.CenterX, GUI.style, pauseMenu);
button = new GUIButton(new Rectangle(0, y, 0, 30), "Quit", Alignment.CenterX, GUI.Style, pauseMenu);
button.OnClicked += QuitClicked;
button.OnClicked += TogglePauseMenu;
}
@@ -118,7 +126,7 @@ namespace Subsurface
Game1.MainMenuScreen.Select();
Game1.MainMenuScreen.SelectTab(null, (int)MainMenuScreen.Tabs.Main);
//Game1.MainMenuScreen.SelectTab(null, (int)MainMenuScreen.Tabs.Main);
return true;
}
+54 -9
View File
@@ -4,7 +4,7 @@ using Microsoft.Xna.Framework.Input;
namespace Subsurface
{
class GUIButton : GUIComponent
public class GUIButton : GUIComponent
{
protected GUITextBlock textBlock;
protected GUIFrame frame;
@@ -16,6 +16,42 @@ namespace Subsurface
public OnPressedHandler OnPressed;
public bool Enabled { get; set; }
public override Color Color
{
get { return base.Color; }
set
{
base.Color = value;
frame.Color = value;
}
}
public override Color HoverColor
{
get { return base.HoverColor; }
set
{
base.HoverColor = value;
frame.HoverColor = value;
}
}
public override Color OutlineColor
{
get { return base.OutlineColor; }
set
{
base.OutlineColor = value;
if (frame != null) frame.OutlineColor = value;
}
}
public Color TextColor
{
get { return textBlock.TextColor; }
set { textBlock.TextColor = value; }
}
public string Text
{
@@ -23,6 +59,8 @@ namespace Subsurface
set { textBlock.Text = value; }
}
public bool Selected { get; set; }
public GUIButton(Rectangle rect, string text, GUIStyle style, GUIComponent parent = null)
: this(rect, text, null, Alignment.Left, style, parent)
{
@@ -39,6 +77,12 @@ namespace Subsurface
}
public GUIButton(Rectangle rect, string text, Color? color, Alignment alignment, GUIStyle style, GUIComponent parent = null)
:this(rect, text, color, alignment, Alignment.Center, style, parent)
{
}
public GUIButton(Rectangle rect, string text, Color? color, Alignment alignment, Alignment textAlignment, GUIStyle style, GUIComponent parent = null)
:base (style)
{
this.rect = rect;
@@ -47,19 +91,20 @@ namespace Subsurface
Enabled = true;
if (parent != null)
parent.AddChild(this);
if (parent != null) parent.AddChild(this);
frame = new GUIFrame(new Rectangle(0,0,0,0), style, this);
if (style!=null) style.Apply(frame, this);
frame = new GUIFrame(Rectangle.Empty, style, this);
if (style != null) style.Apply(frame, this);
textBlock = new GUITextBlock(new Rectangle(0, 0, 0, 0), text,
Color.Transparent, (this.style==null) ? Color.Black : this.style.textColor,
Alignment.Center, style, this);
textBlock = new GUITextBlock(Rectangle.Empty, text,
Color.Transparent, (this.style == null) ? Color.Black : this.style.textColor,
textAlignment, style, this);
}
public override void Draw(SpriteBatch spriteBatch)
{
if (!Visible) return;
if (rect.Contains(PlayerInput.MousePosition) && Enabled && (MouseOn == null || MouseOn == this || IsParentOf(MouseOn)))
{
state = ComponentState.Hover;
@@ -80,7 +125,7 @@ namespace Subsurface
}
else
{
state = ComponentState.None;
state = Selected ? ComponentState.Selected : ComponentState.None;
}
frame.State = state;
+23 -25
View File
@@ -7,7 +7,7 @@ using Microsoft.Xna.Framework.Graphics;
namespace Subsurface
{
abstract class GUIComponent
public abstract class GUIComponent
{
const float FlashDuration = 1.5f;
@@ -53,6 +53,12 @@ namespace Subsurface
set;
}
public bool Visible
{
get;
set;
}
private GUITextBlock toolTipBlock;
//protected float alpha;
@@ -94,7 +100,7 @@ namespace Subsurface
//public Alignment SpriteAlignment { get; set; }
//public bool RepeatSpriteX, RepeatSpriteY;
public Color OutlineColor { get; set; }
public virtual Color OutlineColor { get; set; }
public ComponentState State
{
@@ -125,38 +131,21 @@ namespace Subsurface
set { color = value; }
}
public Color HoverColor
public virtual Color HoverColor
{
get { return hoverColor; }
set { hoverColor = value; }
}
public Color SelectedColor
public virtual Color SelectedColor
{
get { return selectedColor; }
set { selectedColor = value; }
}
//public float Alpha
//{
// get
// {
// return alpha;
// }
// set
// {
// alpha = MathHelper.Clamp(value, 0.0f, 1.0f);
// foreach (GUIComponent child in children)
// {
// child.Alpha = value;
// }
// }
//}
protected GUIComponent(GUIStyle style)
{
//alpha = 1.0f;
Visible = true;
OutlineColor = Color.Transparent;
@@ -218,6 +207,8 @@ namespace Subsurface
public virtual void Draw(SpriteBatch spriteBatch)
{
if (!Visible) return;
Color currColor = color;
if (state == ComponentState.Selected) currColor = selectedColor;
if (state == ComponentState.Hover) currColor = hoverColor;
@@ -255,20 +246,26 @@ namespace Subsurface
public void DrawToolTip(SpriteBatch spriteBatch)
{
int width = 200;
if (!Visible) return;
int width = 400;
if (toolTipBlock==null || (string)toolTipBlock.userData != ToolTip)
{
string wrappedText = ToolBox.WrapText(ToolTip, width, GUI.SmallFont);
toolTipBlock = new GUITextBlock(new Rectangle(0,0,width, wrappedText.Split('\n').Length*15), ToolTip, GUI.style, null, true);
toolTipBlock = new GUITextBlock(new Rectangle(0,0,width, wrappedText.Split('\n').Length*15), ToolTip, GUI.Style, Alignment.TopLeft, Alignment.TopLeft, null, true, GUI.SmallFont);
toolTipBlock.Color = Color.Black*0.7f;
toolTipBlock.OutlineColor = Color.White;
toolTipBlock.userData = ToolTip;
}
toolTipBlock.rect = new Rectangle((int)PlayerInput.MousePosition.X, (int)PlayerInput.MousePosition.Y, toolTipBlock.rect.Width, toolTipBlock.rect.Height);
toolTipBlock.rect = new Rectangle(MouseOn.Rect.Center.X, MouseOn.rect.Bottom, toolTipBlock.rect.Width, toolTipBlock.rect.Height);
toolTipBlock.Draw(spriteBatch);
}
public virtual void Update(float deltaTime)
{
if (!Visible) return;
if (flashTimer>0.0f) flashTimer -= deltaTime;
if (CanBeFocused)
@@ -276,6 +273,7 @@ namespace Subsurface
if (rect.Contains(PlayerInput.MousePosition))
{
MouseOn = this;
//ToolTip = this.ToolTip;
}
else
{
+138
View File
@@ -0,0 +1,138 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Subsurface
{
public class GUIDropDown : GUIComponent
{
private GUIButton button;
private GUIListBox listBox;
public bool Dropped { get; set; }
public object SelectedItemData
{
get
{
if (listBox.Selected == null) return null;
return listBox.Selected.UserData;
}
}
public GUIDropDown(Rectangle rect, string text, GUIStyle style, GUIComponent parent = null)
: base(style)
{
this.rect = rect;
if (parent != null) parent.AddChild(this);
button = new GUIButton(Rectangle.Empty, "", Color.White, Alignment.TopLeft, Alignment.TopLeft, null, this);
button.TextColor = Color.White;
button.Color = Color.Black * 0.8f;
button.HoverColor = Color.DarkGray * 0.8f;
button.OutlineColor = Color.LightGray * 0.8f;
button.OnClicked = OnClicked;
listBox = new GUIListBox(new Rectangle(this.rect.X, this.rect.Bottom, this.rect.Width, 200), style, null);
listBox.OnSelected = SelectItem;
//listBox.ScrollBarEnabled = false;
}
public void AddItem(string text, object userData = null)
{
GUITextBlock textBlock = new GUITextBlock(new Rectangle(0,0,0,20), text, GUI.Style, listBox);
textBlock.UserData = userData;
//int totalHeight = 0;
//foreach (GUIComponent child in listBox.children)
//{
// totalHeight += child.Rect.Height;
//}
//listBox.Rect = new Rectangle(listBox.Rect.X,listBox.Rect.Y,listBox.Rect.Width,totalHeight);
}
private bool SelectItem(GUIComponent component, object obj)
{
GUITextBlock textBlock = component as GUITextBlock;
if (textBlock==null) return false;
button.Text = textBlock.Text;
Dropped = false;
return true;
}
public void SelectItem(object userData)
{
//GUIComponent child = listBox.children.FirstOrDefault(c => c.UserData == userData);
//if (child == null) return;
listBox.Select(userData);
//SelectItem(child, userData);
}
private bool wasOpened;
private bool OnClicked(GUIComponent component, object obj)
{
if (wasOpened) return false;
wasOpened = true;
Dropped = !Dropped;
if (Dropped && parent.children[parent.children.Count-1]!=this)
{
parent.children.Remove(this);
parent.children.Add(this);
}
return true;
}
public override void Update(float deltaTime)
{
if (!Visible) return;
wasOpened = false;
base.Update(deltaTime);
if (Dropped && PlayerInput.LeftButtonClicked())
{
Rectangle listBoxRect = listBox.Rect;
listBoxRect.Width += 20;
if (!listBoxRect.Contains(PlayerInput.MousePosition))
{
Dropped = false;
}
}
button.Update(deltaTime);
if (Dropped) listBox.Update(deltaTime);
}
public override void Draw(SpriteBatch spriteBatch)
{
if (!Visible) return;
base.Draw(spriteBatch);
button.Draw(spriteBatch);
if (!Dropped) return;
listBox.Draw(spriteBatch);
}
}
}
+2 -2
View File
@@ -3,7 +3,7 @@ using System;
namespace Subsurface
{
class GUIFrame : GUIComponent
public class GUIFrame : GUIComponent
{
public GUIFrame(Rectangle rect, GUIStyle style = null, GUIComponent parent = null)
: this(rect, null, (Alignment.Left | Alignment.Top), style, parent)
@@ -39,7 +39,7 @@ namespace Subsurface
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
{
if (!Visible) return;
Color currColor = color;
if (state == ComponentState.Selected) currColor = selectedColor;
+3 -1
View File
@@ -4,7 +4,7 @@ using Microsoft.Xna.Framework.Graphics;
namespace Subsurface
{
class GUIImage : GUIComponent
public class GUIImage : GUIComponent
{
Sprite sprite;
@@ -72,6 +72,8 @@ namespace Subsurface
public override void Draw(SpriteBatch spriteBatch)
{
if (!Visible) return;
Color currColor = color;
if (state == ComponentState.Hover) currColor = hoverColor;
if (state == ComponentState.Selected) currColor = selectedColor;
+12 -7
View File
@@ -5,11 +5,11 @@ using Microsoft.Xna.Framework.Graphics;
namespace Subsurface
{
class GUIListBox : GUIComponent
public class GUIListBox : GUIComponent
{
protected GUIComponent selected;
public delegate bool OnSelectedHandler(object obj);
public delegate bool OnSelectedHandler(GUIComponent component, object obj);
public OnSelectedHandler OnSelected;
public delegate object CheckSelectedHandler();
@@ -34,7 +34,7 @@ namespace Subsurface
return selected;
}
}
public object SelectedData
{
get
@@ -145,13 +145,15 @@ namespace Subsurface
if (child.UserData != selection) continue;
selected = child;
if (OnSelected != null) OnSelected(selected.UserData);
if (OnSelected != null) OnSelected(selected, selected.UserData);
return;
}
}
public override void Update(float deltaTime)
{
if (!Visible) return;
base.Update(deltaTime);
scrollBar.Update(deltaTime);
@@ -165,7 +167,7 @@ namespace Subsurface
if (childIndex >= children.Count || childIndex<0) return;
selected = children[childIndex];
if (OnSelected != null) OnSelected(selected.UserData);
if (OnSelected != null) OnSelected(selected, selected.UserData);
}
public void Deselect()
@@ -238,6 +240,8 @@ namespace Subsurface
public override void Draw(SpriteBatch spriteBatch)
{
if (!Visible) return;
base.Draw(spriteBatch);
frame.Draw(spriteBatch);
@@ -284,7 +288,8 @@ namespace Subsurface
if (CheckSelected() != selected.UserData) selected = null;
}
}
else if (enabled && (MouseOn == this || (MouseOn != null && this.IsParentOf(MouseOn))) && child.Rect.Contains(PlayerInput.MousePosition))
else if (enabled && child.CanBeFocused &&
(MouseOn == this || (MouseOn != null && this.IsParentOf(MouseOn))) && child.Rect.Contains(PlayerInput.MousePosition))
{
child.State = ComponentState.Hover;
if (PlayerInput.LeftButtonClicked())
@@ -293,7 +298,7 @@ namespace Subsurface
selected = child;
if (OnSelected != null)
{
if (!OnSelected(child.UserData)) selected = null;
if (!OnSelected(selected, child.UserData)) selected = null;
}
}
+4 -4
View File
@@ -40,7 +40,7 @@ namespace Subsurface
public GUIMessageBox(string header, string text, string[] buttons, int width=DefaultWidth, int height=DefaultHeight, Alignment textAlignment = Alignment.TopLeft)
: base(new Rectangle(0,0, width, height),
null, Alignment.Center, GUI.style, null)
null, Alignment.Center, GUI.Style, null)
{
//Padding = GUI.style.smallPadding;
@@ -50,14 +50,14 @@ namespace Subsurface
// return;
//}
new GUITextBlock(new Rectangle(0, 0, 0, 30), header, Color.Transparent, Color.White, textAlignment, GUI.style, this, true);
new GUITextBlock(new Rectangle(0, 30, 0, height - 70), text, Color.Transparent, Color.White, textAlignment, GUI.style, this, true);
new GUITextBlock(new Rectangle(0, 0, 0, 30), header, Color.Transparent, Color.White, textAlignment, GUI.Style, this, true);
new GUITextBlock(new Rectangle(0, 30, 0, height - 70), text, Color.Transparent, Color.White, textAlignment, GUI.Style, this, true);
int x = 0;
this.Buttons = new GUIButton[buttons.Length];
for (int i = 0; i < buttons.Length; i++)
{
this.Buttons[i] = new GUIButton(new Rectangle(x, 0, 150, 30), buttons[i], Alignment.Left | Alignment.Bottom, GUI.style, this);
this.Buttons[i] = new GUIButton(new Rectangle(x, 0, 150, 30), buttons[i], Alignment.Left | Alignment.Bottom, GUI.Style, this);
x += this.Buttons[i].Rect.Width + 20;
}
+3 -1
View File
@@ -3,7 +3,7 @@ using Microsoft.Xna.Framework.Graphics;
namespace Subsurface
{
class GUIProgressBar : GUIComponent
public class GUIProgressBar : GUIComponent
{
private bool isHorizontal;
@@ -67,6 +67,8 @@ namespace Subsurface
public override void Draw(SpriteBatch spriteBatch)
{
if (!Visible) return;
if (ProgressGetter != null) BarSize = ProgressGetter();
DrawChildren(spriteBatch);
+5 -1
View File
@@ -4,7 +4,7 @@ using Microsoft.Xna.Framework.Graphics;
namespace Subsurface
{
class GUIScrollBar : GUIComponent
public class GUIScrollBar : GUIComponent
{
public static GUIScrollBar draggingBar;
@@ -122,6 +122,8 @@ namespace Subsurface
public override void Update(float deltaTime)
{
if (!Visible) return;
base.Update(deltaTime);
if (draggingBar != this) return;
@@ -132,6 +134,8 @@ namespace Subsurface
public override void Draw(SpriteBatch spriteBatch)
{
if (!Visible) return;
DrawChildren(spriteBatch);
}
+1 -1
View File
@@ -5,7 +5,7 @@ using System.Collections.Generic;
namespace Subsurface
{
class GUIStyle
public class GUIStyle
{
private Dictionary<string, GUIComponentStyle> componentStyles;
+20 -17
View File
@@ -3,7 +3,7 @@ using Microsoft.Xna.Framework.Graphics;
namespace Subsurface
{
class GUITextBlock : GUIComponent
public class GUITextBlock : GUIComponent
{
protected string text;
@@ -21,8 +21,6 @@ namespace Subsurface
public bool Wrap;
public override Vector4 Padding
{
get { return padding; }
@@ -75,15 +73,6 @@ namespace Subsurface
{
}
public GUITextBlock(Rectangle rect, string text, GUIStyle style, Alignment alignment = Alignment.TopLeft, Alignment textAlignment = Alignment.TopLeft, GUIComponent parent = null, bool wrap = false, SpriteFont font =null)
: this (rect, text, null, null, alignment, textAlignment, style, parent, wrap)
{
this.Font = font == null ? GUI.Font : font;
SetTextPos();
}
public GUITextBlock(Rectangle rect, string text, Color? color, Color? textColor, Alignment textAlignment = Alignment.Left, GUIStyle style = null, GUIComponent parent = null, bool wrap = false)
: this(rect, text,color, textColor, Alignment.TopLeft, textAlignment, style, parent, wrap)
{
@@ -105,24 +94,36 @@ namespace Subsurface
public GUITextBlock(Rectangle rect, string text, Color? color, Color? textColor, Alignment alignment, Alignment textAlignment = Alignment.Left, GUIStyle style = null, GUIComponent parent = null, bool wrap = false)
:base (style)
: this (rect, text, style, alignment, textAlignment, parent, wrap, null)
{
if (color != null) this.color = (Color)color;
if (textColor != null) this.textColor = (Color)textColor;
}
public GUITextBlock(Rectangle rect, string text, GUIStyle style, Alignment alignment = Alignment.TopLeft, Alignment textAlignment = Alignment.TopLeft, GUIComponent parent = null, bool wrap = false, SpriteFont font = null)
:base (style)
{
this.Font = font == null ? GUI.Font : font;
this.rect = rect;
if (color!=null) this.color = (Color)color;
if (textColor!=null) this.textColor = (Color)textColor;
this.text = text;
this.alignment = alignment;
this.textAlignment = textAlignment;
if (parent != null)
parent.AddChild(this);
this.Wrap = wrap;
SetTextPos();
if (rect.Height == 0)
{
this.rect.Height = (int)Font.MeasureString(Text).Y;
}
}
private void SetTextPos()
@@ -201,6 +202,8 @@ namespace Subsurface
public override void Draw(SpriteBatch spriteBatch)
{
if (!Visible) return;
Color currColor = color;
if (state == ComponentState.Hover) currColor = hoverColor;
if (state == ComponentState.Selected) currColor = selectedColor;
+4
View File
@@ -153,6 +153,8 @@ namespace Subsurface
MouseState previousMouse;
public override void Update(float deltaTime)
{
if (!Visible) return;
if (flashTimer > 0.0f) flashTimer -= deltaTime;
if (!Enabled) return;
@@ -186,6 +188,8 @@ namespace Subsurface
public override void Draw(SpriteBatch spriteBatch)
{
if (!Visible) return;
DrawChildren(spriteBatch);
Vector2 caretPos = textBlock.CaretPos;
+9 -13
View File
@@ -4,7 +4,7 @@ using Microsoft.Xna.Framework.Input;
namespace Subsurface
{
class GUITickBox : GUIComponent
public class GUITickBox : GUIComponent
{
GUIFrame box;
GUITextBlock text;
@@ -41,25 +41,24 @@ namespace Subsurface
box.HoverColor = Color.Gray;
box.SelectedColor = Color.DarkGray;
text = new GUITextBlock(new Rectangle(rect.X + 40, rect.Y, 200, rect.Height), label, Color.Transparent, Color.White, Alignment.TopLeft, null, this);
this.rect = new Rectangle(box.Rect.X, box.Rect.Y, 240, rect.Height);
Enabled = true;
}
public override void Update(float deltaTime)
{
if (rect.Width ==420)
{
int asd = 1;
}
//base.Update(deltaTime);
if (!Visible || !Enabled) return;
if (!Enabled) return;
if (text.Rect.Contains(PlayerInput.MousePosition)) MouseOn = this;
if (box.Rect.Contains(PlayerInput.MousePosition))
{
//ToolTip = this.ToolTip;
MouseOn = this;
box.State = ComponentState.Hover;
@@ -84,10 +83,7 @@ namespace Subsurface
public override void Draw(SpriteBatch spriteBatch)
{
if (rect.Width == 420)
{
int asd = 1;
}
if (!Visible) return;
DrawChildren(spriteBatch);
+34 -23
View File
@@ -17,13 +17,26 @@ namespace Subsurface
float state;
public Vector2 Position;
public Vector2 CenterPosition;
public Vector2 TitlePosition;
public Vector2 TitleSize
{
get { return new Vector2(titleTexture.Width, titleTexture.Height); }
}
public float Scale
{
get;
private set;
}
public TitleScreen(GraphicsDevice graphics)
{
backgroundTexture = Game1.TextureLoader.FromFile("Content/UI/titleBackground.png");
monsterTexture = Game1.TextureLoader.FromFile("Content/UI/titleMonster.png");
titleTexture = Game1.TextureLoader.FromFile("Content/UI/titleText.png");
backgroundTexture = TextureLoader.FromFile("Content/UI/titleBackground.png");
monsterTexture = TextureLoader.FromFile("Content/UI/titleMonster.png");
titleTexture = TextureLoader.FromFile("Content/UI/titleText.png");
renderTarget = new RenderTarget2D(graphics, Game1.GraphicsWidth, Game1.GraphicsHeight);
@@ -40,46 +53,44 @@ namespace Subsurface
graphics.SetRenderTarget(renderTarget);
//Debug.WriteLine(stopwatch.Elapsed.TotalMilliseconds);
float scale = Game1.GraphicsHeight/2048.0f;
Scale = Game1.GraphicsHeight/1500.0f;
state += deltaTime;
Vector2 center = new Vector2(Game1.GraphicsWidth*0.3f, Game1.GraphicsHeight/2.0f) + Position*scale;
if (loadState>-1)
{
CenterPosition = new Vector2(Game1.GraphicsWidth*0.3f, Game1.GraphicsHeight/2.0f);
TitlePosition = CenterPosition + new Vector2(-0.0f + (float)Math.Sqrt(state) * 220.0f, 0.0f) * Scale;
TitlePosition.X = Math.Min(TitlePosition.X, (float)Game1.GraphicsWidth / 2.0f);
}
Vector2 titlePos = center + new Vector2(-0.0f + (float)Math.Sqrt(state) * 220.0f, 0.0f) * scale;
titlePos.X = Math.Min(titlePos.X, (float)Game1.GraphicsWidth / 2.0f);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
graphics.Clear(Color.Black);
spriteBatch.Draw(backgroundTexture, center, null, Color.White * Math.Min(state / 5.0f, 1.0f), 0.0f,
spriteBatch.Draw(backgroundTexture, CenterPosition, null, Color.White * Math.Min(state / 5.0f, 1.0f), 0.0f,
new Vector2(backgroundTexture.Width / 2.0f, backgroundTexture.Height / 2.0f),
scale, SpriteEffects.None, 0.2f);
Scale*1.5f, SpriteEffects.None, 0.2f);
spriteBatch.Draw(monsterTexture,
center + new Vector2(state * 100.0f - 1200.0f, state * 30.0f - 100.0f) * scale, null,
Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 0.1f);
CenterPosition + new Vector2((state % 40) * 100.0f - 1800.0f, (state % 40) * 30.0f - 200.0f) * Scale, null,
Color.White, 0.0f, Vector2.Zero, Scale, SpriteEffects.None, 0.1f);
spriteBatch.Draw(titleTexture,
titlePos, null,
Color.White * Math.Min((state - 1.0f) / 5.0f, 1.0f), 0.0f, new Vector2(titleTexture.Width / 2.0f, titleTexture.Height / 2.0f), scale, SpriteEffects.None, 0.0f);
TitlePosition, null,
Color.White * Math.Min((state - 1.0f) / 5.0f, 1.0f), 0.0f, new Vector2(titleTexture.Width / 2.0f, titleTexture.Height / 2.0f), Scale, SpriteEffects.None, 0.0f);
spriteBatch.End();
graphics.SetRenderTarget(null);
Matrix transform = Matrix.CreateTranslation(
new Vector3(Game1.GraphicsWidth / 2.0f,
Game1.GraphicsHeight / 2.0f, 0));
Hull.renderer.RenderBack(spriteBatch, renderTarget, transform);
Hull.renderer.RenderBack(spriteBatch, renderTarget, 0.0f);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
spriteBatch.Draw(titleTexture,
titlePos, null,
Color.White * Math.Min((state - 3.0f) / 5.0f, 1.0f), 0.0f, new Vector2(titleTexture.Width / 2.0f, titleTexture.Height / 2.0f), scale, SpriteEffects.None, 0.0f);
TitlePosition, null,
Color.White * Math.Min((state - 3.0f) / 5.0f, 1.0f), 0.0f, new Vector2(titleTexture.Width / 2.0f, titleTexture.Height / 2.0f), Scale, SpriteEffects.None, 0.0f);
string loadText = "";
if (loadState == 100.0f)