1 using Microsoft.Xna.Framework;
2 using Microsoft.Xna.Framework.Graphics;
8 static class HUDLayoutSettings
10 public static bool DebugDraw;
12 private static int inventoryTopY;
13 public static int InventoryTopY
15 get {
return inventoryTopY; }
18 if (value == inventoryTopY) {
return; }
19 inventoryTopY = value;
28 public static Rectangle TutorialObjectiveListArea
53 public static Rectangle InventoryAreaLower
63 public static Rectangle BottomRightInfoArea
68 public static Rectangle HealthBarAfflictionArea
73 public static Rectangle HealthWindowAreaLeft
93 public static int Padding
98 static HUDLayoutSettings()
100 if (GameMain.Instance !=
null)
102 GameMain.Instance.ResolutionChanged += CreateAreas;
104 CharacterInfo.Init();
108 public static RectTransform ToRectTransform(Rectangle rect, RectTransform parent)
110 return new RectTransform(
new Vector2(rect.Width / (
float)GameMain.GraphicsWidth, rect.Height / (
float)GameMain.GraphicsHeight), parent)
112 RelativeOffset =
new Vector2(rect.X / (
float)GameMain.GraphicsWidth, rect.Y / (
float)GameMain.GraphicsHeight)
116 public static void CreateAreas()
118 Padding = (int)(11 * GUI.Scale);
120 if (inventoryTopY == 0) { inventoryTopY = GameMain.GraphicsHeight - 30; }
123 ButtonAreaTop =
new Rectangle(Padding, Padding, GameMain.GraphicsWidth - Padding * 2, (
int)(50 * GUI.Scale));
125 int infoAreaWidth = (int)(142 * GUI.Scale);
126 int infoAreaHeight = (int)(98 * GUI.Scale);
127 int portraitSize = (int)(infoAreaHeight * 0.95f);
128 BottomRightInfoArea =
new Rectangle(GameMain.GraphicsWidth - Padding * 2 - infoAreaWidth, GameMain.GraphicsHeight - Padding * 2 - infoAreaHeight, infoAreaWidth, infoAreaHeight);
129 PortraitArea =
new Rectangle(GameMain.GraphicsWidth - portraitSize, BottomRightInfoArea.Bottom - portraitSize + Padding / 2, portraitSize, portraitSize);
132 int afflictionAreaHeight = (int)(50 * GUI.Scale);
133 int healthBarWidth = BottomRightInfoArea.Width;
135 var healthBarChildStyles = GUIStyle.GetComponentStyle(
"CharacterHealthBar")?.ChildStyles;
136 if (healthBarChildStyles!=
null && healthBarChildStyles.TryGetValue(
"GUIFrame".ToIdentifier(), out var style))
138 if (style.Sprites.TryGetValue(GUIComponent.ComponentState.None, out var uiSprites) && uiSprites.FirstOrDefault() is { } uiSprite)
141 healthBarWidth += (int)(uiSprite.NonSliceSize.X * Math.Min(GUI.Scale, 1f));
144 int healthBarHeight = (int)(50f * GUI.Scale);
145 HealthBarArea =
new Rectangle(BottomRightInfoArea.Right - healthBarWidth + (
int)Math.Floor(1 / GUI.Scale), BottomRightInfoArea.Y - healthBarHeight + GUI.IntScale(10), healthBarWidth, healthBarHeight);
146 HealthBarAfflictionArea =
new Rectangle(HealthBarArea.X, HealthBarArea.Y - Padding - afflictionAreaHeight, HealthBarArea.Width, afflictionAreaHeight);
149 int messageAreaWidth = GameMain.GraphicsWidth / 3;
150 MessageAreaTop =
new Rectangle((GameMain.GraphicsWidth - messageAreaWidth) / 2, ButtonAreaTop.Bottom + ButtonAreaTop.Height, messageAreaWidth, ButtonAreaTop.Height);
152 int chatBoxWidth = (int)(475 * GUI.Scale * GUI.AspectRatioAdjustment);
153 int chatBoxHeight = (int)Math.Max(GameMain.GraphicsHeight * 0.25f, 150);
154 ChatBoxArea =
new Rectangle(Padding, GameMain.GraphicsHeight - Padding - chatBoxHeight, chatBoxWidth, chatBoxHeight);
156 int objectiveAnchorWidth = (int)(250 * GUI.Scale);
157 int objectiveAnchorOffsetY = (int)(150 * GUI.Scale);
158 ObjectiveAnchor =
new Rectangle(Padding, ChatBoxArea.Y - objectiveAnchorOffsetY, objectiveAnchorWidth, 0);
160 int crewAreaY = ButtonAreaTop.Bottom + Padding;
161 int crewAreaHeight = ObjectiveAnchor.Top - Padding - crewAreaY;
163 CrewArea =
new Rectangle(Padding, crewAreaY,
164 (
int)MathHelper.Clamp(400 * GUI.Scale, 220, GameMain.GraphicsHeight * 0.4f),
166 InventoryAreaLower =
new Rectangle(ChatBoxArea.Right + Padding * 7, inventoryTopY, GameMain.GraphicsWidth - Padding * 9 - ChatBoxArea.Width, GameMain.GraphicsHeight - inventoryTopY);
168 int healthWindowWidth = (int)(GameMain.GraphicsWidth * 0.5f);
169 int healthWindowHeight = (int)(GameMain.GraphicsWidth * 0.5f * 0.65f);
170 int healthWindowX = GameMain.GraphicsWidth / 2 - healthWindowWidth / 2;
171 int healthWindowY = GameMain.GraphicsHeight / 2 - healthWindowHeight / 2;
173 HealthWindowAreaLeft =
new Rectangle(healthWindowX, healthWindowY, healthWindowWidth, healthWindowHeight);
175 int objectiveListAreaX = HealthWindowAreaLeft.Right + Padding;
176 int objectiveListAreaY = ButtonAreaTop.Bottom + Padding;
177 TutorialObjectiveListArea =
new Rectangle(objectiveListAreaX, objectiveListAreaY, (GameMain.GraphicsWidth - Padding) - objectiveListAreaX, (HealthBarAfflictionArea.Top - Padding) - objectiveListAreaY);
179 int votingAreaWidth = (int)(400 * GUI.Scale);
180 int votingAreaX = GameMain.GraphicsWidth - Padding - votingAreaWidth;
181 int votingAreaY = Padding + ButtonAreaTop.Height;
184 VotingArea =
new Rectangle(votingAreaX, votingAreaY, votingAreaWidth, 0);
186 ItemHUDArea =
new Rectangle(0, ButtonAreaTop.Bottom, GameMain.GraphicsWidth, GameMain.GraphicsHeight - ButtonAreaTop.Bottom - InventoryAreaLower.Height);
189 public static void Draw(SpriteBatch spriteBatch)
191 DrawRectangle(nameof(ButtonAreaTop), ButtonAreaTop, Color.White * 0.5f);
192 DrawRectangle(nameof(TutorialObjectiveListArea), TutorialObjectiveListArea, GUIStyle.Blue * 0.5f);
193 DrawRectangle(nameof(MessageAreaTop), MessageAreaTop, GUIStyle.Orange * 0.5f);
194 DrawRectangle(nameof(CrewArea), CrewArea, Color.Blue * 0.5f);
195 DrawRectangle(nameof(ChatBoxArea), ChatBoxArea, Color.Cyan * 0.5f);
196 DrawRectangle(nameof(HealthBarArea), HealthBarArea, Color.Red * 0.5f);
197 DrawRectangle(nameof(HealthBarAfflictionArea), HealthBarAfflictionArea, Color.Red * 0.5f);
198 DrawRectangle(nameof(InventoryAreaLower), InventoryAreaLower, Color.Yellow * 0.5f);
199 DrawRectangle(nameof(HealthWindowAreaLeft), HealthWindowAreaLeft, Color.Red * 0.5f);
200 DrawRectangle(nameof(BottomRightInfoArea), BottomRightInfoArea, Color.Green * 0.5f);
201 DrawRectangle(nameof(ItemHUDArea), ItemHUDArea, Color.Magenta * 0.3f);
203 void DrawRectangle(
string label, Rectangle r, Color c)
205 if (!label.IsNullOrEmpty())
207 GUI.DrawString(spriteBatch, r.Location.ToVector2() + Vector2.One * 3, label, c, font: GUIStyle.SmallFont);
209 GUI.DrawRectangle(spriteBatch, r, c);
214 public static class HUD
216 public static bool CloseHUD(Rectangle rect)
219 if (PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.Escape)) {
return true; }
222 if (GUI.MouseOn !=
null) {
return false; }
225 if (Inventory.IsMouseOnInventory) {
return false; }
227 bool input = PlayerInput.PrimaryMouseButtonDown() || PlayerInput.SecondaryMouseButtonClicked();
228 return input && !rect.Contains(PlayerInput.MousePosition);