Functional networkevent validation, functional single player saving, requireditem ui texts, titlescreen & loading
This commit is contained in:
+20
-9
@@ -60,7 +60,7 @@ namespace Subsurface
|
||||
pos = position;
|
||||
this.lifeTime = lifeTime;
|
||||
|
||||
size = GUI.font.MeasureString(text);
|
||||
size = GUI.Font.MeasureString(text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,8 @@ namespace Subsurface
|
||||
public static GUIStyle style;
|
||||
|
||||
static Texture2D t;
|
||||
public static SpriteFont font;
|
||||
public static SpriteFont Font, SmallFont;
|
||||
|
||||
|
||||
private static GraphicsDevice graphicsDevice;
|
||||
|
||||
@@ -257,21 +258,21 @@ namespace Subsurface
|
||||
}
|
||||
|
||||
DrawRectangle(sb, rect, color, true);
|
||||
sb.DrawString(font, text, new Vector2(rect.X + 10, rect.Y + 10), Color.White);
|
||||
sb.DrawString(Font, text, new Vector2(rect.X + 10, rect.Y + 10), Color.White);
|
||||
|
||||
return clicked;
|
||||
}
|
||||
|
||||
public static void Draw(float deltaTime, SpriteBatch spriteBatch, Camera cam)
|
||||
{
|
||||
spriteBatch.DrawString(font,
|
||||
spriteBatch.DrawString(Font,
|
||||
"FPS: " + (int)Game1.frameCounter.AverageFramesPerSecond
|
||||
+ " - Physics: " + Game1.World.UpdateTime
|
||||
+ " - bodies: " + Game1.World.BodyList.Count,
|
||||
new Vector2(10, 10), Color.White);
|
||||
|
||||
|
||||
spriteBatch.DrawString(font,
|
||||
spriteBatch.DrawString(Font,
|
||||
"Camera pos: " + Game1.GameScreen.Cam.Position,
|
||||
new Vector2(10, 30), Color.White);
|
||||
|
||||
@@ -295,17 +296,27 @@ namespace Subsurface
|
||||
if (GUIMessageBox.messageBoxes.Count > 0)
|
||||
{
|
||||
var messageBox = GUIMessageBox.messageBoxes.Peek();
|
||||
if (messageBox != null) messageBox.Update(deltaTime);
|
||||
if (messageBox != null)
|
||||
{
|
||||
GUIComponent.MouseOn = messageBox;
|
||||
messageBox.Update(deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddMessage(string message, Color color, float lifeTime = 3.0f)
|
||||
public static void AddMessage(string message, Color color, float lifeTime = 3.0f, bool playSound = true)
|
||||
{
|
||||
if (messages.Count>0 && messages[messages.Count-1].Text == message)
|
||||
{
|
||||
messages[messages.Count - 1].LifeTime = lifeTime;
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 currPos = new Vector2(Game1.GraphicsWidth / 2.0f, Game1.GraphicsHeight * 0.7f);
|
||||
currPos.Y += messages.Count * 30;
|
||||
|
||||
messages.Add(new GUIMessage(message, color, currPos, lifeTime));
|
||||
PlayMessageSound();
|
||||
if (playSound) PlayMessageSound();
|
||||
}
|
||||
|
||||
public static void PlayMessageSound()
|
||||
@@ -331,7 +342,7 @@ namespace Subsurface
|
||||
|
||||
msg.Pos = MathUtils.SmoothStep(msg.Pos, currPos, deltaTime*20.0f);
|
||||
|
||||
spriteBatch.DrawString(font, msg.Text,
|
||||
spriteBatch.DrawString(Font, msg.Text,
|
||||
new Vector2((int)msg.Pos.X, (int)msg.Pos.Y),
|
||||
msg.Color * alpha, 0.0f,
|
||||
new Vector2((int)(0.5f * msg.Size.X), (int)(0.5f * msg.Size.Y)), 1.0f, SpriteEffects.None, 0.0f);
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace Subsurface
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
if (rect.Contains(PlayerInput.GetMouseState.Position) && Enabled && (MouseOn == this || IsParentOf(MouseOn)))
|
||||
if (rect.Contains(PlayerInput.GetMouseState.Position) && Enabled && (MouseOn == null || MouseOn == this || IsParentOf(MouseOn)))
|
||||
{
|
||||
state = ComponentState.Hover;
|
||||
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed)
|
||||
@@ -75,7 +75,7 @@ namespace Subsurface
|
||||
if (OnClicked != null)
|
||||
{
|
||||
if (OnClicked(this, UserData)) state = ComponentState.Selected;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -23,6 +23,8 @@ namespace Subsurface
|
||||
|
||||
protected Rectangle rect;
|
||||
|
||||
public bool CanBeFocused;
|
||||
|
||||
protected Vector4 padding;
|
||||
|
||||
protected Color color;
|
||||
@@ -34,6 +36,12 @@ namespace Subsurface
|
||||
|
||||
protected ComponentState state;
|
||||
|
||||
public virtual SpriteFont Font
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
//protected float alpha;
|
||||
|
||||
public GUIComponent Parent
|
||||
@@ -139,10 +147,12 @@ namespace Subsurface
|
||||
|
||||
OutlineColor = Color.Transparent;
|
||||
|
||||
Font = GUI.Font;
|
||||
|
||||
sprites = new List<Sprite>();
|
||||
children = new List<GUIComponent>();
|
||||
|
||||
|
||||
CanBeFocused = true;
|
||||
|
||||
if (style!=null) style.Apply(this);
|
||||
}
|
||||
@@ -196,13 +206,17 @@ namespace Subsurface
|
||||
|
||||
public virtual void Update(float deltaTime)
|
||||
{
|
||||
if (rect.Contains(PlayerInput.MousePosition))
|
||||
if (CanBeFocused)
|
||||
{
|
||||
MouseOn = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (MouseOn == this) MouseOn = null;
|
||||
if (rect.Contains(PlayerInput.MousePosition))
|
||||
{
|
||||
MouseOn = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (MouseOn == this) MouseOn = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach (GUIComponent child in children)
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace Subsurface
|
||||
}
|
||||
|
||||
|
||||
DrawChildren(spriteBatch);
|
||||
DrawChildren(spriteBatch);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,6 +50,8 @@ namespace Subsurface
|
||||
|
||||
public bool Close(GUIButton button, object obj)
|
||||
{
|
||||
if (parent != null) parent.RemoveChild(this);
|
||||
|
||||
messageBoxes.Dequeue();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -125,17 +125,12 @@ namespace Subsurface
|
||||
{
|
||||
if (text==null) return;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Vector2 size = MeasureText();
|
||||
|
||||
if (wrap && rect.Width>0)
|
||||
{
|
||||
text = text.Replace("\n"," ");
|
||||
text = ToolBox.WrapText(text, rect.Width);
|
||||
text = ToolBox.WrapText(text, rect.Width, Font);
|
||||
|
||||
Vector2 newSize = MeasureText();
|
||||
|
||||
@@ -177,7 +172,7 @@ namespace Subsurface
|
||||
Vector2 size = Vector2.Zero;
|
||||
while (size == Vector2.Zero)
|
||||
{
|
||||
try { size = GUI.font.MeasureString((text == "") ? " " : text); }
|
||||
try { size = Font.MeasureString((text == "") ? " " : text); }
|
||||
catch { text = text.Substring(0, text.Length - 1); }
|
||||
}
|
||||
|
||||
@@ -196,7 +191,7 @@ namespace Subsurface
|
||||
|
||||
if (!string.IsNullOrEmpty(text))
|
||||
{
|
||||
spriteBatch.DrawString(GUI.font,
|
||||
spriteBatch.DrawString(Font,
|
||||
text,
|
||||
new Vector2(rect.X, rect.Y) + textPos,
|
||||
textColor * (textColor.A / 255.0f),
|
||||
|
||||
@@ -30,6 +30,16 @@ namespace Subsurface
|
||||
set;
|
||||
}
|
||||
|
||||
public override SpriteFont Font
|
||||
{
|
||||
set
|
||||
{
|
||||
base.Font = value;
|
||||
if (textBlock == null) return;
|
||||
textBlock.Font = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override Color Color
|
||||
{
|
||||
get { return color; }
|
||||
@@ -59,13 +69,12 @@ namespace Subsurface
|
||||
String filtered = "";
|
||||
foreach (char c in value)
|
||||
{
|
||||
if (GUI.font.Characters.Contains(c))
|
||||
filtered += c;
|
||||
if (Font.Characters.Contains(c)) filtered += c;
|
||||
}
|
||||
|
||||
textBlock.Text = filtered;
|
||||
|
||||
if (GUI.font.MeasureString(textBlock.Text).X > rect.Width)
|
||||
if (Font.MeasureString(textBlock.Text).X > rect.Width)
|
||||
{
|
||||
//recursion to ensure that text cannot be larger than the box
|
||||
Text = textBlock.Text.Substring(0, textBlock.Text.Length - 1);
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
class TitleScreen
|
||||
{
|
||||
private Texture2D backgroundTexture,monsterTexture,titleTexture;
|
||||
|
||||
readonly RenderTarget2D renderTarget;
|
||||
|
||||
float state;
|
||||
|
||||
public Vector2 Position;
|
||||
|
||||
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");
|
||||
|
||||
renderTarget = new RenderTarget2D(graphics, Game1.GraphicsWidth, Game1.GraphicsHeight);
|
||||
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, GraphicsDevice graphics, float loadState, float deltaTime)
|
||||
{
|
||||
//if (stopwatch == null)
|
||||
//{
|
||||
// stopwatch = new Stopwatch();
|
||||
// stopwatch.Start();
|
||||
//}
|
||||
|
||||
graphics.SetRenderTarget(renderTarget);
|
||||
//Debug.WriteLine(stopwatch.Elapsed.TotalMilliseconds);
|
||||
|
||||
float scale = Game1.GraphicsHeight/2048.0f;
|
||||
|
||||
state += deltaTime;
|
||||
|
||||
Vector2 center = new Vector2(Game1.GraphicsWidth*0.3f, Game1.GraphicsHeight/2.0f) + Position*scale;
|
||||
|
||||
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,
|
||||
new Vector2(backgroundTexture.Width / 2.0f, backgroundTexture.Height / 2.0f),
|
||||
scale, 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);
|
||||
|
||||
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);
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
graphics.SetRenderTarget(null);
|
||||
|
||||
Matrix transform = Matrix.CreateTranslation(
|
||||
new Vector3(Game1.GraphicsWidth / 2.0f,
|
||||
Game1.GraphicsHeight / 2.0f, 0));
|
||||
|
||||
Hull.renderer.RenderBack(graphics, renderTarget, transform);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
string loadText = (loadState<100.0f) ? "Loading... "+(int)loadState+" %" : "Press any key to continue";
|
||||
spriteBatch.DrawString(GUI.Font, loadText, new Vector2(Game1.GraphicsWidth/2.0f - 50.0f, Game1.GraphicsHeight*0.8f), Color.White);
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user