improved harpoon gun, misc ui stuff & bugfixes
This commit is contained in:
+11
-31
@@ -65,8 +65,6 @@ namespace Subsurface
|
||||
static Texture2D t;
|
||||
public static SpriteFont font;
|
||||
|
||||
private static GUIProgressBar drowningBar;
|
||||
|
||||
private static GraphicsDevice graphicsDevice;
|
||||
|
||||
|
||||
@@ -87,11 +85,7 @@ namespace Subsurface
|
||||
t = new Texture2D(graphicsDevice, 1, 1);
|
||||
t.SetData<Color>(
|
||||
new Color[] { Color.White });// fill the texture with white
|
||||
|
||||
int width = 200, height = 20;
|
||||
drowningBar = new GUIProgressBar(new Rectangle(Game1.GraphicsWidth / 2 - width / 2, 20, width, height), Color.Blue, 1.0f);
|
||||
|
||||
|
||||
|
||||
style = new GUIStyle("Content/HUD/style.xml");
|
||||
}
|
||||
|
||||
@@ -262,40 +256,26 @@ namespace Subsurface
|
||||
return clicked;
|
||||
}
|
||||
|
||||
public static void Draw(float deltaTime, SpriteBatch spriteBatch)
|
||||
public static void Draw(float deltaTime, SpriteBatch spriteBatch, Camera cam)
|
||||
{
|
||||
spriteBatch.DrawString(font,
|
||||
"FPS: " + (int)Game1.frameCounter.AverageFramesPerSecond
|
||||
+ " - render: "+Game1.renderTimeElapsed,
|
||||
new Vector2(10, 10), Color.White);
|
||||
//spriteBatch.DrawString(font,
|
||||
// "FPS: " + (int)Game1.frameCounter.AverageFramesPerSecond
|
||||
// + " - render: "+Game1.renderTimeElapsed,
|
||||
// new Vector2(10, 10), Color.White);
|
||||
|
||||
spriteBatch.DrawString(font,
|
||||
"Physics: " + Game1.world.UpdateTime
|
||||
+ " - bodies: " + Game1.world.BodyList.Count,
|
||||
new Vector2(10, 30), Color.White);
|
||||
//spriteBatch.DrawString(font,
|
||||
// "Physics: " + Game1.world.UpdateTime
|
||||
// + " - bodies: " + Game1.world.BodyList.Count,
|
||||
// new Vector2(10, 30), Color.White);
|
||||
|
||||
if (Character.Controlled != null)
|
||||
{
|
||||
drowningBar.BarSize = Character.Controlled.Oxygen/100.0f;
|
||||
if (drowningBar.BarSize<1.0f)
|
||||
drowningBar.Draw(spriteBatch);
|
||||
|
||||
if (Character.Controlled.Inventory!=null)
|
||||
Character.Controlled.Inventory.Draw(spriteBatch);
|
||||
}
|
||||
if (Character.Controlled != null) Character.Controlled.DrawHud(spriteBatch, cam);
|
||||
|
||||
DrawMessages(spriteBatch, (float)deltaTime);
|
||||
|
||||
DebugConsole.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
public static void DrawCharacterHUD(SpriteBatch spriteBatch, Character character)
|
||||
{
|
||||
drowningBar.BarSize = character.Oxygen/100.0f;
|
||||
|
||||
drowningBar.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
public static void AddMessage(string message, Color color, float lifeTime = 3.0f)
|
||||
{
|
||||
Vector2 currPos = new Vector2(Game1.GraphicsWidth / 2.0f, Game1.GraphicsHeight * 0.7f);
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
class GUIMessageBox
|
||||
{
|
||||
public static Queue<GUIMessageBox> messageBoxes = new Queue<GUIMessageBox>();
|
||||
|
||||
const int DefaultWidth=400, DefaultHeight=200;
|
||||
|
||||
public delegate bool OnClickedHandler(GUIButton button, object obj);
|
||||
public OnClickedHandler OnClicked;
|
||||
|
||||
GUIFrame frame;
|
||||
GUIButton[] buttons;
|
||||
|
||||
public GUIMessageBox(string header, string text)
|
||||
: this(header, text, new string[] {"OK"})
|
||||
{ }
|
||||
|
||||
public GUIMessageBox(string header, string text, string[] buttons, Alignment textAlignment = (Alignment.Left |Alignment.Top))
|
||||
{
|
||||
frame = new GUIFrame(new Rectangle(Game1.GraphicsWidth/2-DefaultWidth/2, Game1.GraphicsHeight/2-DefaultHeight/2, DefaultWidth, DefaultHeight),
|
||||
GUI.style.backGroundColor, Alignment.CenterX, GUI.style);
|
||||
frame.Padding = GUI.style.smallPadding;
|
||||
|
||||
if (buttons == null || buttons.Length == 0)
|
||||
{
|
||||
DebugConsole.ThrowError("Creating a message box with no buttons isn't allowed");
|
||||
}
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 5, 0, 30), header, Color.Transparent, Color.White, textAlignment, frame, true);
|
||||
new GUITextBlock(new Rectangle(0,50,0,DefaultHeight-70),text, Color.Transparent, Color.White, textAlignment, frame, 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], GUI.style, Alignment.Left, frame);
|
||||
this.buttons[i].OnClicked = ButtonClicked;
|
||||
x += this.buttons[i].Rect.Width + 20;
|
||||
}
|
||||
}
|
||||
|
||||
private bool ButtonClicked(GUIButton button, object obj)
|
||||
{
|
||||
if (OnClicked==null) return true;
|
||||
|
||||
return OnClicked(button, obj);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user