From 8f33cf5f122fcce9380e62494aeec39f0444b1a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hora=C8=9Biu=20Mlendea?= Date: Fri, 5 Apr 2024 09:04:58 +0300 Subject: [PATCH 1/3] Fixes: Fixed recruitment troops amount not being visible --- Gui/GuiElements/GuiRecruitmentPanel.cs | 86 +++++++++----------------- Settings/GameDefines.cs | 2 + 2 files changed, 31 insertions(+), 57 deletions(-) diff --git a/Gui/GuiElements/GuiRecruitmentPanel.cs b/Gui/GuiElements/GuiRecruitmentPanel.cs index 4b76be6e..9339daab 100644 --- a/Gui/GuiElements/GuiRecruitmentPanel.cs +++ b/Gui/GuiElements/GuiRecruitmentPanel.cs @@ -2,7 +2,6 @@ using System.Linq; using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; using NuciXNA.Graphics.Drawing; using NuciXNA.Gui.Controls; @@ -15,13 +14,8 @@ namespace Narivia.Gui.Controls { - /// - /// Unit recruitment panel GUI element. - /// public class GuiRecruitmentPanel : GuiPanel { - const int IconSize = 22; - readonly IGameManager gameManager; readonly IWorldManager worldManager; readonly IMilitaryManager militaryManager; @@ -69,9 +63,6 @@ public GuiRecruitmentPanel( FontName = "ButtonFont"; } - /// - /// Loads the content. - /// protected override void DoLoadContent() { base.DoLoadContent(); @@ -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) @@ -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 @@ -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 { @@ -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 { @@ -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 { @@ -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, @@ -258,20 +242,17 @@ 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(); } - /// - /// Unloads the content. - /// protected override void DoUnloadContent() { base.DoUnloadContent(); @@ -279,10 +260,6 @@ protected override void DoUnloadContent() UnregisterEvents(); } - /// - /// Update the content. - /// - /// Game time. protected override void DoUpdate(GameTime gameTime) { base.DoUpdate(gameTime); @@ -310,15 +287,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) @@ -353,13 +332,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); diff --git a/Settings/GameDefines.cs b/Settings/GameDefines.cs index 8c1fda36..7406e83b 100644 --- a/Settings/GameDefines.cs +++ b/Settings/GameDefines.cs @@ -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; From 2a21a6cca0f3140653ba8aedb75fb76bc863ee92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hora=C8=9Biu=20Mlendea?= Date: Fri, 5 Apr 2024 09:13:25 +0300 Subject: [PATCH 2/3] Fixes: Properly close panels --- Gui/GuiElements/GuiPanel.cs | 26 +++++++------------------- Gui/GuiElements/GuiProvincePanel.cs | 8 ++++++++ Gui/GuiElements/GuiRecruitmentPanel.cs | 8 ++++++++ Gui/Screens/GameplayScreen.cs | 3 +++ 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Gui/GuiElements/GuiPanel.cs b/Gui/GuiElements/GuiPanel.cs index 580377d2..84af1148 100644 --- a/Gui/GuiElements/GuiPanel.cs +++ b/Gui/GuiElements/GuiPanel.cs @@ -1,6 +1,5 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; - using NuciXNA.Graphics.Drawing; using NuciXNA.Gui.Controls; using NuciXNA.Input; @@ -28,9 +27,12 @@ public GuiPanel() CrystalColour = Colour.Red; } - /// - /// Loads the content. - /// + public virtual void Close() + { + Hide(); + Closed?.Invoke(this, new MouseButtonEventArgs(MouseButton.Left, ButtonState.Pressed, InputManager.Instance.MouseLocation)); + } + protected override void DoLoadContent() { background = new GuiImage @@ -74,27 +76,16 @@ protected override void DoLoadContent() SetChildrenProperties(); } - /// - /// Unloads the content. - /// protected override void DoUnloadContent() { UnregisterEvents(); } - /// - /// Update the content. - /// - /// Game time. protected override void DoUpdate(GameTime gameTime) { SetChildrenProperties(); } - /// - /// Draw the content on the specified . - /// - /// Sprite batch. protected override void DoDraw(SpriteBatch spriteBatch) { @@ -117,9 +108,6 @@ void SetChildrenProperties() } void OnCloseButtonClicked(object sender, MouseButtonEventArgs e) - { - Hide(); - Closed?.Invoke(this, e); - } + => Close(); } } diff --git a/Gui/GuiElements/GuiProvincePanel.cs b/Gui/GuiElements/GuiProvincePanel.cs index 8b53f053..0170be3f 100644 --- a/Gui/GuiElements/GuiProvincePanel.cs +++ b/Gui/GuiElements/GuiProvincePanel.cs @@ -53,6 +53,14 @@ public GuiProvincePanel( this.holdingManager = holdingManager; } + public override void Close() + { + base.Close(); + + ProvinceId = string.Empty; + currentProvinceId = string.Empty; + } + /// /// Loads the content. /// diff --git a/Gui/GuiElements/GuiRecruitmentPanel.cs b/Gui/GuiElements/GuiRecruitmentPanel.cs index 9339daab..97830e8e 100644 --- a/Gui/GuiElements/GuiRecruitmentPanel.cs +++ b/Gui/GuiElements/GuiRecruitmentPanel.cs @@ -253,6 +253,14 @@ protected override void DoLoadContent() SetChildrenProperties(); } + public override void Close() + { + base.Close(); + + currentUnitIndex = 0; + troopsAmount = 1; + } + protected override void DoUnloadContent() { base.DoUnloadContent(); diff --git a/Gui/Screens/GameplayScreen.cs b/Gui/Screens/GameplayScreen.cs index 3e8d1b45..16402e66 100644 --- a/Gui/Screens/GameplayScreen.cs +++ b/Gui/Screens/GameplayScreen.cs @@ -270,6 +270,9 @@ void NextTurn() { notificationBar.Clear(); + recruitmentPanel.Close(); + provincePanel.Close(); + GameManager.PassTurn(); Dictionary troopsNew = new Dictionary(); From 807003fa6d496102d0eaf62df1110df8fcbf5f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hora=C8=9Biu=20Mlendea?= Date: Fri, 5 Apr 2024 12:27:32 +0300 Subject: [PATCH 3/3] fixes: Fixed card tooltip not dismissing --- Gui/GuiElements/GuiHoldingCard.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Gui/GuiElements/GuiHoldingCard.cs b/Gui/GuiElements/GuiHoldingCard.cs index 0cdda3fa..69f110b3 100644 --- a/Gui/GuiElements/GuiHoldingCard.cs +++ b/Gui/GuiElements/GuiHoldingCard.cs @@ -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