2018-11-30 02:41:06 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
using Microsoft.Xna.Framework.Input;
|
2019-03-10 06:49:25 +00:00
|
|
|
|
using RecrownedAthenaeum.Render;
|
2018-11-30 02:41:06 +00:00
|
|
|
|
|
2018-12-04 13:45:09 +00:00
|
|
|
|
namespace RecrownedAthenaeum.UI.Modular
|
2018-11-30 02:41:06 +00:00
|
|
|
|
{
|
2019-01-14 06:34:35 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Contains a group of modules and has its own relative coordinate system.
|
|
|
|
|
/// </summary>
|
2018-11-30 02:41:06 +00:00
|
|
|
|
public class UIModuleGroup : UIModule
|
|
|
|
|
{
|
|
|
|
|
List<UIModule> modules = new List<UIModule>();
|
2019-03-21 00:28:16 +00:00
|
|
|
|
ScissorBox scissorBox;
|
2019-01-30 13:46:58 +00:00
|
|
|
|
|
2019-01-15 02:00:11 +00:00
|
|
|
|
/// <summary>
|
2019-03-21 00:28:16 +00:00
|
|
|
|
/// Configuration for starting sprite batch after scissoring. Only used if cropping.
|
2019-01-15 02:00:11 +00:00
|
|
|
|
/// </summary>
|
2019-03-21 00:28:16 +00:00
|
|
|
|
public SpriteBatchSettings spriteBatchSettings;
|
2018-11-30 02:41:06 +00:00
|
|
|
|
|
2019-01-15 02:00:11 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a module group.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="crop">Whether or not to crop out of bounds. Default is false.</param>
|
2019-03-21 00:28:16 +00:00
|
|
|
|
public UIModuleGroup(bool crop = false)
|
2018-11-30 02:41:06 +00:00
|
|
|
|
{
|
2019-03-21 00:28:16 +00:00
|
|
|
|
this.spriteBatchSettings = Configuration.SpriteBatchSettings.Value;
|
2018-11-30 02:41:06 +00:00
|
|
|
|
if (crop)
|
|
|
|
|
{
|
2019-03-21 00:28:16 +00:00
|
|
|
|
scissorBox = new ScissorBox();
|
2018-11-30 02:41:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 06:34:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Draws this group of modules.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="batch">Batch used to draw the group.</param>
|
2018-11-30 02:41:06 +00:00
|
|
|
|
public override void Draw(SpriteBatch batch)
|
|
|
|
|
{
|
2019-03-21 00:28:16 +00:00
|
|
|
|
if (scissorBox != null)
|
2018-11-30 02:41:06 +00:00
|
|
|
|
{
|
|
|
|
|
batch.End();
|
2019-03-21 00:28:16 +00:00
|
|
|
|
scissorBox.Begin(Boundaries, batch, spriteBatchSettings);
|
2018-11-30 02:41:06 +00:00
|
|
|
|
}
|
2019-03-02 05:24:08 +00:00
|
|
|
|
|
2018-11-30 02:41:06 +00:00
|
|
|
|
foreach (UIModule module in modules)
|
|
|
|
|
{
|
2019-03-09 06:57:29 +00:00
|
|
|
|
int offsetX = module.situation.X;
|
|
|
|
|
int offsetY = module.situation.Y;
|
|
|
|
|
module.situation.X = situation.X + offsetX;
|
|
|
|
|
module.situation.Y = situation.Y + offsetY;
|
2018-11-30 02:41:06 +00:00
|
|
|
|
module.Draw(batch);
|
2019-03-09 06:57:29 +00:00
|
|
|
|
module.situation.X = offsetX;
|
|
|
|
|
module.situation.Y = offsetY;
|
2018-11-30 02:41:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-21 00:28:16 +00:00
|
|
|
|
if (scissorBox != null)
|
2018-11-30 02:41:06 +00:00
|
|
|
|
{
|
2019-03-21 00:28:16 +00:00
|
|
|
|
scissorBox.End();
|
|
|
|
|
|
2018-11-30 02:41:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 06:34:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the group of modules.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="gameTime">Game time used.</param>
|
2018-11-30 02:41:06 +00:00
|
|
|
|
public override void Update(GameTime gameTime)
|
|
|
|
|
{
|
|
|
|
|
foreach (UIModule module in modules)
|
|
|
|
|
{
|
|
|
|
|
module.Update(gameTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 05:23:03 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds module(s) to this group.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="addModules">The module(s) to add.</param>
|
2018-11-30 02:41:06 +00:00
|
|
|
|
public void AddModule(params UIModule[] addModules)
|
|
|
|
|
{
|
|
|
|
|
foreach (UIModule module in addModules)
|
|
|
|
|
{
|
|
|
|
|
if (modules.Contains(module))
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException(module.ToString() + " already exists in " + this.ToString());
|
|
|
|
|
}
|
2019-03-10 06:49:25 +00:00
|
|
|
|
module.parent = this;
|
2018-11-30 02:41:06 +00:00
|
|
|
|
modules.Add(module);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 05:23:03 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes given module from group.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="module">module to remove.</param>
|
2018-11-30 02:41:06 +00:00
|
|
|
|
public void RemoveModule(UIModule module)
|
|
|
|
|
{
|
2019-03-10 06:49:25 +00:00
|
|
|
|
module.parent = null;
|
2018-11-30 02:41:06 +00:00
|
|
|
|
modules.Remove(module);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 06:34:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the keyboard state of the modules in this group.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="state">The new state.</param>
|
|
|
|
|
/// <returns>Whether or not to continue updating the other listeners.</returns>
|
2018-11-30 02:41:06 +00:00
|
|
|
|
public override bool KeyboardStateChanged(KeyboardState state)
|
|
|
|
|
{
|
|
|
|
|
foreach (UIModule module in modules)
|
|
|
|
|
{
|
|
|
|
|
module.KeyboardStateChanged(state);
|
|
|
|
|
}
|
|
|
|
|
return base.KeyboardStateChanged(state);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 06:34:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the moues state of the modules in this group.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="state">The new state.</param>
|
|
|
|
|
/// <returns>Whether or not to continue updating other listeners.</returns>
|
2018-11-30 02:41:06 +00:00
|
|
|
|
public override bool MouseStateChanged(MouseState state)
|
|
|
|
|
{
|
|
|
|
|
foreach (UIModule module in modules)
|
|
|
|
|
{
|
|
|
|
|
module.MouseStateChanged(state);
|
|
|
|
|
}
|
|
|
|
|
return base.MouseStateChanged(state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|