Skip to content

Commit

Permalink
Merge pull request #16 from hmlendea/fixes
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
hmlendea authored Apr 8, 2024
2 parents 7e1d594 + 807003f commit 295d830
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 76 deletions.
6 changes: 6 additions & 0 deletions Gui/GuiElements/GuiHoldingCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public void SetHoldingProperties(Holding holding)
HoldingName = holding.Name;
}

public override void Hide()
{
base.Hide();
tooltip.Hide();
}

protected override void DoLoadContent()
{
icon = new GuiImage
Expand Down
26 changes: 7 additions & 19 deletions Gui/GuiElements/GuiPanel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using NuciXNA.Graphics.Drawing;
using NuciXNA.Gui.Controls;
using NuciXNA.Input;
Expand Down Expand Up @@ -28,9 +27,12 @@ public GuiPanel()
CrystalColour = Colour.Red;
}

/// <summary>
/// Loads the content.
/// </summary>
public virtual void Close()
{
Hide();
Closed?.Invoke(this, new MouseButtonEventArgs(MouseButton.Left, ButtonState.Pressed, InputManager.Instance.MouseLocation));
}

protected override void DoLoadContent()
{
background = new GuiImage
Expand Down Expand Up @@ -74,27 +76,16 @@ protected override void DoLoadContent()
SetChildrenProperties();
}

/// <summary>
/// Unloads the content.
/// </summary>
protected override void DoUnloadContent()
{
UnregisterEvents();
}

/// <summary>
/// Update the content.
/// </summary>
/// <param name="gameTime">Game time.</param>
protected override void DoUpdate(GameTime gameTime)
{
SetChildrenProperties();
}

/// <summary>
/// Draw the content on the specified <see cref="SpriteBatch"/>.
/// </summary>
/// <param name="spriteBatch">Sprite batch.</param>
protected override void DoDraw(SpriteBatch spriteBatch)
{

Expand All @@ -117,9 +108,6 @@ void SetChildrenProperties()
}

void OnCloseButtonClicked(object sender, MouseButtonEventArgs e)
{
Hide();
Closed?.Invoke(this, e);
}
=> Close();
}
}
8 changes: 8 additions & 0 deletions Gui/GuiElements/GuiProvincePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ public GuiProvincePanel(
this.holdingManager = holdingManager;
}

public override void Close()
{
base.Close();

ProvinceId = string.Empty;
currentProvinceId = string.Empty;
}

/// <summary>
/// Loads the content.
/// </summary>
Expand Down
94 changes: 37 additions & 57 deletions Gui/GuiElements/GuiRecruitmentPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Linq;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using NuciXNA.Graphics.Drawing;
using NuciXNA.Gui.Controls;
Expand All @@ -15,13 +14,8 @@

namespace Narivia.Gui.Controls
{
/// <summary>
/// Unit recruitment panel GUI element.
/// </summary>
public class GuiRecruitmentPanel : GuiPanel
{
const int IconSize = 22;

readonly IGameManager gameManager;
readonly IWorldManager worldManager;
readonly IMilitaryManager militaryManager;
Expand Down Expand Up @@ -69,9 +63,6 @@ public GuiRecruitmentPanel(
FontName = "ButtonFont";
}

/// <summary>
/// Loads the content.
/// </summary>
protected override void DoLoadContent()
{
base.DoLoadContent();
Expand Down Expand Up @@ -121,8 +112,8 @@ protected override void DoLoadContent()
{
Id = $"{Id}_{nameof(healthIcon)}",
ContentFile = "Interface/game_icons",
SourceRectangle = new Rectangle2D(0, 0, IconSize, IconSize),
Size = new Size2D(IconSize, IconSize),
SourceRectangle = new Rectangle2D(0, 0, GameDefines.GuiIconSize, GameDefines.GuiIconSize),
Size = new Size2D(GameDefines.GuiIconSize),
Location = new Point2D(
paper.Location.X + GameDefines.GuiSpacing * 2,
paper.Location.Y + GameDefines.GuiSpacing * 2)
Expand All @@ -131,31 +122,31 @@ protected override void DoLoadContent()
{
Id = $"{Id}_{nameof(powerIcon)}",
ContentFile = "Interface/game_icons",
SourceRectangle = new Rectangle2D(IconSize, 0, IconSize, IconSize),
Size = new Size2D(IconSize, IconSize),
SourceRectangle = new Rectangle2D(GameDefines.GuiIconSize, 0, GameDefines.GuiIconSize, GameDefines.GuiIconSize),
Size = new Size2D(GameDefines.GuiIconSize),
Location = new Point2D(
paper.ClientRectangle.Left + GameDefines.GuiSpacing * 2,
paper.ClientRectangle.Bottom - GameDefines.GuiSpacing * 2 - IconSize)
paper.ClientRectangle.Bottom - GameDefines.GuiSpacing * 2 - GameDefines.GuiIconSize)
};
priceIcon = new GuiImage
{
Id = $"{Id}_{nameof(priceIcon)}",
ContentFile = "Interface/game_icons",
SourceRectangle = new Rectangle2D(IconSize * 3, 0, IconSize, IconSize),
Size = new Size2D(IconSize, IconSize),
SourceRectangle = new Rectangle2D(GameDefines.GuiIconSize * 3, 0, GameDefines.GuiIconSize, GameDefines.GuiIconSize),
Size = new Size2D(GameDefines.GuiIconSize),
Location = new Point2D(
paper.ClientRectangle.Right - GameDefines.GuiSpacing * 2 - IconSize,
paper.ClientRectangle.Right - GameDefines.GuiSpacing * 2 - GameDefines.GuiIconSize,
paper.ClientRectangle.Top + GameDefines.GuiSpacing * 2)
};
maintenanceIcon = new GuiImage
{
Id = $"{Id}_{nameof(maintenanceIcon)}",
ContentFile = "Interface/game_icons",
SourceRectangle = new Rectangle2D(IconSize * 3, 0, IconSize, IconSize),
Size = new Size2D(IconSize, IconSize),
Location = new Point2D(
paper.ClientRectangle.Right - GameDefines.GuiSpacing * 2 - IconSize,
paper.ClientRectangle.Bottom - GameDefines.GuiSpacing * 2 - IconSize)
SourceRectangle = new Rectangle2D(GameDefines.GuiIconSize * 3, 0, GameDefines.GuiIconSize, GameDefines.GuiIconSize),
Size = new Size2D(GameDefines.GuiIconSize),
Location = paper.ClientRectangle.BottomRight - new Point2D(
GameDefines.GuiSpacing * 2 + GameDefines.GuiIconSize,
GameDefines.GuiSpacing * 2 + GameDefines.GuiIconSize)
};

healthText = new GuiText
Expand All @@ -165,9 +156,7 @@ protected override void DoLoadContent()
Size = new Size2D(
healthIcon.Size.Width * 2,
healthIcon.Size.Height),
Location = new Point2D(
healthIcon.Location.X + healthIcon.Size.Width + GameDefines.GuiSpacing,
healthIcon.Location.Y)
Location = healthIcon.Location + new Point2D(healthIcon.Size.Width + GameDefines.GuiSpacing, 0)
};
powerText = new GuiText
{
Expand All @@ -176,9 +165,7 @@ protected override void DoLoadContent()
Size = new Size2D(
powerIcon.Size.Width * 2,
powerIcon.Size.Height),
Location = new Point2D(
powerIcon.Location.X + healthIcon.Size.Width + GameDefines.GuiSpacing,
powerIcon.Location.Y)
Location = powerIcon.Location + new Point2D(healthIcon.Size.Width + GameDefines.GuiSpacing, 0)
};
priceText = new GuiText
{
Expand All @@ -187,9 +174,7 @@ protected override void DoLoadContent()
Size = new Size2D(
priceIcon.Size.Width * 2,
priceIcon.Size.Height),
Location = new Point2D(
priceIcon.Location.X - priceIcon.Size.Width * 2 - GameDefines.GuiSpacing,
priceIcon.Location.Y)
Location = priceIcon.Location - new Point2D(priceIcon.Size.Width * 2 + GameDefines.GuiSpacing, 0)
};
maintenanceText = new GuiText
{
Expand All @@ -198,13 +183,12 @@ protected override void DoLoadContent()
Size = new Size2D(
maintenanceIcon.Size.Width * 2,
maintenanceIcon.Size.Height),
Location = new Point2D(
maintenanceIcon.Location.X - maintenanceIcon.Size.Width * 2 - GameDefines.GuiSpacing,
maintenanceIcon.Location.Y)
Location = maintenanceIcon.Location - new Point2D(maintenanceIcon.Size.Width * 2 + GameDefines.GuiSpacing, 0)
};
troopsText = new GuiText
{
Id = $"{Id}_{nameof(troopsText)}",
ForegroundColour = Colour.Gold,
Size = new Size2D(unitBackground.Size.Height, 18),
Location = new Point2D(
unitBackground.ClientRectangle.Left,
Expand Down Expand Up @@ -258,31 +242,32 @@ protected override void DoLoadContent()
(Size.Width - 128) / 2,
Size.Height - 42 - GameDefines.GuiSpacing)
};

RegisterChildren(unitBackground, unitImage, paper);
RegisterChildren(unitText, troopsText);
RegisterChildren(healthIcon, powerIcon, priceIcon, maintenanceIcon);
RegisterChildren(healthText, powerText, priceText, maintenanceText);
RegisterChildren(nextUnitButton, previousUnitButton, addUnitButton, substractUnitButton, recruitButton);

RegisterEvents();
SetChildrenProperties();
}

/// <summary>
/// Unloads the content.
/// </summary>
public override void Close()
{
base.Close();

currentUnitIndex = 0;
troopsAmount = 1;
}

protected override void DoUnloadContent()
{
base.DoUnloadContent();

UnregisterEvents();
}

/// <summary>
/// Update the content.
/// </summary>
/// <param name="gameTime">Game time.</param>
protected override void DoUpdate(GameTime gameTime)
{
base.DoUpdate(gameTime);
Expand Down Expand Up @@ -310,15 +295,17 @@ void UnregisterEvents()

void SetChildrenProperties()
{
unitText.Text = units[currentUnitIndex].Name;
Unit unit = units[currentUnitIndex];

unitText.Text = unit.Name;
troopsText.Text = $"x{troopsAmount}";
healthText.Text = units[currentUnitIndex].Health.ToString();
powerText.Text = units[currentUnitIndex].Power.ToString();
priceText.Text = units[currentUnitIndex].Price.ToString();
maintenanceText.Text = units[currentUnitIndex].Maintenance.ToString();
recruitButton.Text = $"Recruit ({units[currentUnitIndex].Price * troopsAmount}g)";
healthText.Text = unit.Health.ToString();
powerText.Text = unit.Power.ToString();
priceText.Text = unit.Price.ToString();
maintenanceText.Text = unit.Maintenance.ToString();
recruitButton.Text = $"Recruit ({unit.Price * troopsAmount}g)";

unitImage.ContentFile = $"World/Assets/{world.AssetsPack}/units/{units[currentUnitIndex].Id}";
unitImage.ContentFile = $"World/Assets/{world.AssetsPack}/units/{unit.Id}";
}

void SelectUnit(int index)
Expand Down Expand Up @@ -353,13 +340,6 @@ void AddTroops(int delta)
}
}

void OnCancelButtonClick(object sender, MouseButtonEventArgs e)
{
Hide();
SelectUnit(0);
troopsAmount = 0;
}

void OnRecruitButtonClick(object sender, MouseButtonEventArgs e)
{
militaryManager.RecruitUnits(gameManager.PlayerFactionId, units[currentUnitIndex].Id, troopsAmount);
Expand Down
3 changes: 3 additions & 0 deletions Gui/Screens/GameplayScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ void NextTurn()
{
notificationBar.Clear();

recruitmentPanel.Close();
provincePanel.Close();

GameManager.PassTurn();

Dictionary<string, int> troopsNew = new Dictionary<string, int>();
Expand Down
2 changes: 2 additions & 0 deletions Settings/GameDefines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public static class GameDefines
{
public const int MapTileSize = 32;

public const int GuiIconSize = 22;

public const int GuiTileSize = 32;

public const int GuiSpacing = 6;
Expand Down

0 comments on commit 295d830

Please sign in to comment.