added proper input system (untested)

This commit is contained in:
2018-11-08 23:48:24 -06:00
parent 99a8531b47
commit fcd2278796
8 changed files with 214 additions and 57 deletions

View File

@@ -1,38 +0,0 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.UI.Modular
{
public class Module
{
public Vector2 Position = new Vector2();
public float Width, Height;
public ModuleGroup Parent;
public string Name;
public Color Color;
public virtual void Update(GameTime gameTime)
{
}
public virtual void Draw(SpriteBatch batch)
{
}
public void RemoveFromParent()
{
if (Parent == null)
{
throw new InvalidOperationException("Parent is null.");
}
Parent.RemoveModule(this);
}
}
}

View File

@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.UI.Modular
{
public class Text : Module
public class Text : UIModule
{
private SpriteFont font;
private float scale;

View File

@@ -0,0 +1,62 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using RhythmBullet.Zer01HD.Utilities.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.UI.Modular
{
public class UIModule : IInputListener
{
public Rectangle Bounds;
public UIModuleGroup Parent;
public string Name;
public Color Color;
public virtual void Update(GameTime gameTime)
{
}
public virtual void Draw(SpriteBatch batch)
{
}
public Rectangle ConvertToParentCoordinates(Rectangle bounds)
{
if (Parent != null)
{
Rectangle parentHitbox = Parent.ConvertToParentCoordinates(bounds);
int tX = bounds.X + parentHitbox.X;
int tY = bounds.Y + parentHitbox.Y;
return new Rectangle(tX, tY, bounds.Width, bounds.Height);
} else
{
return bounds;
}
}
public void RemoveFromParent()
{
if (Parent == null)
{
throw new InvalidOperationException("Parent is null.");
}
Parent.RemoveModule(this);
}
public virtual bool KeyboardStateChanged(KeyboardState state)
{
return true;
}
public virtual bool MouseStateChanged(MouseState state)
{
return true;
}
}
}

View File

@@ -5,15 +5,17 @@ using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using RhythmBullet.Zer01HD.Utilities.Input;
namespace RhythmBullet.Zer01HD.UI.Modular
{
public class ModuleGroup : Module
public class UIModuleGroup : UIModule
{
List<Module> modules = new List<Module>();
List<UIModule> modules = new List<UIModule>();
Rectangle scissorBounds;
RasterizerState scissorRasterizer = new RasterizerState();
public ModuleGroup(bool crop = false)
public UIModuleGroup(bool crop = false)
{
if (crop)
{
@@ -28,23 +30,23 @@ namespace RhythmBullet.Zer01HD.UI.Modular
{
batch.End();
batch.Begin(SpriteSortMode.Deferred, null, null, null, scissorRasterizer);
scissorBounds.Width = (int) Width;
scissorBounds.Height = (int) Height;
scissorBounds.X = (int) Position.X;
scissorBounds.Y = (int) Position.Y;
scissorBounds.Width = Bounds.Width;
scissorBounds.Height = Bounds.Height;
scissorBounds.X = Bounds.X;
scissorBounds.Y = Bounds.Y;
Rectangle scissor = scissorBounds;
scissorBounds = batch.GraphicsDevice.ScissorRectangle;
batch.GraphicsDevice.ScissorRectangle = scissor;
}
foreach (Module module in modules)
foreach (UIModule module in modules)
{
float offsetX = module.Position.X;
float offsetY = module.Position.Y;
module.Position.X = Position.X + offsetX;
module.Position.Y = Position.Y + offsetY;
int offsetX = module.Bounds.X;
int offsetY = module.Bounds.Y;
module.Bounds.X = Bounds.X + offsetX;
module.Bounds.Y = Bounds.Y + offsetY;
module.Draw(batch);
module.Position.X = offsetX;
module.Position.Y = offsetY;
module.Bounds.X = offsetX;
module.Bounds.Y = offsetY;
}
if (scissorBounds != null)
@@ -57,15 +59,15 @@ namespace RhythmBullet.Zer01HD.UI.Modular
public override void Update(GameTime gameTime)
{
foreach (Module module in modules)
foreach (UIModule module in modules)
{
module.Update(gameTime);
}
}
public void AddModule(params Module[] addModules)
public void AddModule(params UIModule[] addModules)
{
foreach (Module module in addModules)
foreach (UIModule module in addModules)
{
if (modules.Contains(module))
{
@@ -76,10 +78,28 @@ namespace RhythmBullet.Zer01HD.UI.Modular
}
}
public void RemoveModule(Module module)
public void RemoveModule(UIModule module)
{
module.Parent = null;
modules.Remove(module);
}
public override bool KeyboardStateChanged(KeyboardState state)
{
foreach (UIModule module in modules)
{
module.KeyboardStateChanged(state);
}
return false;
}
public override bool MouseStateChanged(MouseState state)
{
foreach (UIModule module in modules)
{
module.MouseStateChanged(state);
}
return false;
}
}
}