progress on text buttons (untested)

This commit is contained in:
Harrison Deng 2018-11-22 01:12:40 -06:00
parent f63a7b76e3
commit 6f43cbffbb
7 changed files with 76 additions and 13 deletions

View File

@ -54,6 +54,8 @@
<Compile Include="Audio\Visualizer\HorizontalVisualizer.cs" /> <Compile Include="Audio\Visualizer\HorizontalVisualizer.cs" />
<Compile Include="Screens\MainMenu\MainPage.cs" /> <Compile Include="Screens\MainMenu\MainPage.cs" />
<Compile Include="Screens\Transitions\FadeAwayTransition.cs" /> <Compile Include="Screens\Transitions\FadeAwayTransition.cs" />
<Compile Include="Utilities\DataTypes\NinePatch.cs" />
<Compile Include="Utilities\UI\Modular\Modules\Interactive\TextButton.cs" />
<Compile Include="Utilities\Camera\Camera2D.cs" /> <Compile Include="Utilities\Camera\Camera2D.cs" />
<Compile Include="Utilities\ContentSystem\NormalContentResolver.cs" /> <Compile Include="Utilities\ContentSystem\NormalContentResolver.cs" />
<Compile Include="Utilities\Input\IInputListener.cs" /> <Compile Include="Utilities\Input\IInputListener.cs" />
@ -61,7 +63,7 @@
<Compile Include="Utilities\Input\InputUtilities.cs" /> <Compile Include="Utilities\Input\InputUtilities.cs" />
<Compile Include="Utilities\Persistence\Preferences.cs" /> <Compile Include="Utilities\Persistence\Preferences.cs" />
<Compile Include="Utilities\ScreenSystem\ScreenManager.cs" /> <Compile Include="Utilities\ScreenSystem\ScreenManager.cs" />
<Compile Include="Utilities\UI\Modular\Modules\Interactive\BasicButton.cs" /> <Compile Include="Utilities\UI\Modular\Modules\Interactive\Button.cs" />
<Compile Include="Utilities\ScreenSystem\ITransition.cs" /> <Compile Include="Utilities\ScreenSystem\ITransition.cs" />
<Compile Include="Utilities\ScreenSystem\LoadingScreen.cs" /> <Compile Include="Utilities\ScreenSystem\LoadingScreen.cs" />
<Compile Include="Screens\MainMenu\MainScreen.cs" /> <Compile Include="Screens\MainMenu\MainScreen.cs" />
@ -152,7 +154,9 @@
<None Include="app.manifest" /> <None Include="app.manifest" />
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup>
<Folder Include="Screens\UI\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" /> <Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />
<Import Project="..\packages\BulletSharp.0.11.1\build\net40-client\BulletSharp.targets" Condition="Exists('..\packages\BulletSharp.0.11.1\build\net40-client\BulletSharp.targets')" /> <Import Project="..\packages\BulletSharp.0.11.1\build\net40-client\BulletSharp.targets" Condition="Exists('..\packages\BulletSharp.0.11.1\build\net40-client\BulletSharp.targets')" />

View File

@ -3,12 +3,16 @@ using Microsoft.Xna.Framework.Graphics;
using RhythmBullet.UI.Book; using RhythmBullet.UI.Book;
using RhythmBullet.Utilities.ContentSystem; using RhythmBullet.Utilities.ContentSystem;
using RhythmBullet.Utilities.UI.Modular.Modules; using RhythmBullet.Utilities.UI.Modular.Modules;
using RhythmBullet.Utilities.UI.Modular.Modules.Interactive;
namespace RhythmBullet.Screens.MainMenu namespace RhythmBullet.Screens.MainMenu
{ {
internal class MainPage : Page internal class MainPage : Page
{ {
Image title; Image title;
TextButton playButton;
TextButton quitButton;
internal MainPage(ContentManagerController assets) : base(0, 0) internal MainPage(ContentManagerController assets) : base(0, 0)
{ {
title = new Image(assets.Get<Texture2D>("title")); title = new Image(assets.Get<Texture2D>("title"));

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace RhythmBullet.Utilities.DataTypes namespace RhythmBullet.Utilities.DataTypes
{ {
public struct NinePatch public class NinePatch
{ {
public Color color; public Color color;
readonly Texture2D texture; readonly Texture2D texture;
@ -34,8 +34,6 @@ namespace RhythmBullet.Utilities.DataTypes
this.c = c; this.c = c;
this.d = d; this.d = d;
sourceRectangle = new Rectangle();
drawnRectangle = new Rectangle();
color = Color.White; color = Color.White;
} }

View File

@ -1,5 +1,7 @@
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using RhythmBullet.UI.Modular; using RhythmBullet.UI.Modular;
using RhythmBullet.Utilities.DataTypes;
using RhythmBullet.Utilities.Input; using RhythmBullet.Utilities.Input;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -11,13 +13,20 @@ namespace RhythmBullet.Utilities.UI.Modular.Modules.Interactive
{ {
public delegate bool Clicked(); public delegate bool Clicked();
public class BasicButton : UIModuleGroup public class Button : UIModule
{ {
private NinePatch background;
public event Clicked Listeners; public event Clicked Listeners;
public BasicButton() public Button(NinePatch background = null)
{ {
this.background = background;
}
public override void Draw(SpriteBatch batch)
{
background?.Draw(batch, bounds);
base.Draw(batch);
} }
public sealed override bool MouseStateChanged(MouseState state) public sealed override bool MouseStateChanged(MouseState state)
@ -29,7 +38,8 @@ namespace RhythmBullet.Utilities.UI.Modular.Modules.Interactive
OnClick(); OnClick();
} }
Highlighted = true; Highlighted = true;
} else }
else
{ {
Highlighted = false; Highlighted = false;
} }

View File

@ -0,0 +1,37 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RhythmBullet.UI.Modular.Modules;
using RhythmBullet.Utilities.DataTypes;
using RhythmBullet.Utilities.UI.Modular.Modules.Interactive;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RhythmBullet.Utilities.UI.Modular.Modules.Interactive
{
internal class TextButton : Button
{
private TextLabel label;
internal TextButton(string text, SpriteFont font, NinePatch background) : base(background)
{
label = new TextLabel(font, text);
label.autoScale = true;
}
public override void Update(GameTime gameTime)
{
label.bounds = bounds;
label.Update(gameTime);
base.Update(gameTime);
}
public override void Draw(SpriteBatch batch)
{
label.Draw(batch);
base.Draw(batch);
}
}
}

View File

@ -51,11 +51,21 @@ namespace RhythmBullet.UI.Modular
Parent.RemoveModule(this); Parent.RemoveModule(this);
} }
/// <summary>
/// Called whenever the keyboard state is changed.
/// </summary>
/// <param name="state">The current keyboard state.</param>
/// <returns>Returning whether or not to continue to call the next listener.</returns>
public virtual bool KeyboardStateChanged(KeyboardState state) public virtual bool KeyboardStateChanged(KeyboardState state)
{ {
return true; return true;
} }
/// <summary>
/// Called whenever the state of the mouse changes. This includes movement.
/// </summary>
/// <param name="state">The current state of the mouse.</param>
/// <returns>Returning whether or not to continue to call the next listener.</returns>
public virtual bool MouseStateChanged(MouseState state) public virtual bool MouseStateChanged(MouseState state)
{ {
return true; return true;

View File

@ -46,8 +46,8 @@ namespace RhythmBullet.UI.Modular
{ {
int offsetX = module.bounds.X; int offsetX = module.bounds.X;
int offsetY = module.bounds.Y; int offsetY = module.bounds.Y;
module.bounds.X = bounds.X + offsetX; module.bounds.X = bounds.X + offsetX - (int)module.origin.X;
module.bounds.Y = bounds.Y + offsetY; module.bounds.Y = bounds.Y + offsetY - (int)module.origin.Y;
module.Draw(batch); module.Draw(batch);
module.bounds.X = offsetX; module.bounds.X = offsetX;
module.bounds.Y = offsetY; module.bounds.Y = offsetY;
@ -94,7 +94,7 @@ namespace RhythmBullet.UI.Modular
{ {
module.KeyboardStateChanged(state); module.KeyboardStateChanged(state);
} }
return false; return base.KeyboardStateChanged(state);
} }
public override bool MouseStateChanged(MouseState state) public override bool MouseStateChanged(MouseState state)
@ -103,7 +103,7 @@ namespace RhythmBullet.UI.Modular
{ {
module.MouseStateChanged(state); module.MouseStateChanged(state);
} }
return false; return base.MouseStateChanged(state);
} }
} }
} }