HUDInvOtherMenu

This commit is contained in:
dvaer 2024-08-20 01:51:36 +03:00
parent 06ce01e3a3
commit 2d6f8c47da
13 changed files with 359 additions and 17 deletions

View file

@ -0,0 +1,49 @@
using Microsoft.Xna.Framework.Graphics;
using MonogameLibrary.UI.Base;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonogameLibrary.UI.Enums;
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
namespace MonogameLibrary.UI.Elements;
public class Bar : DrawableUIElement
{
public float percent = 0.5f;
private DrawableUIElement barInside;
public Color inColor;
public string inTextureName;
public Bar(UIManager manager, int layerIndex = 0, string textureName = "") : base(manager, layerIndex, textureName)
{
}
public void Initialize()
{
barInside = new DrawableUIElement(Manager)
{
rectangle = new Rectangle(rectangle.X + rectangle.Height / 8, rectangle.Y + rectangle.Height / 8,
(int)((rectangle.Width - rectangle.Height / 4) * percent), rectangle.Height / 8 * 7),
mainColor = inColor,
textureName = inTextureName
};
}
public override void LoadTexture(ContentManager content)
{
barInside.LoadTexture(content);
base.LoadTexture(content);
}
public void Update(GameTime gameTime, float percent)
{
barInside.rectangle = new Rectangle(rectangle.X + rectangle.Height / 8, rectangle.Y + rectangle.Height / 8,
(int)((rectangle.Width - rectangle.Height / 4) * percent), rectangle.Height / 8 * 7);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 256 KiB

After

Width:  |  Height:  |  Size: 3.8 MiB

View file

@ -93,7 +93,7 @@ namespace ZoFo.GameCore
#endregion
Player myPlayer;
public Player myPlayer;
List<MapObject> mapObjects = new List<MapObject>();
List<GameObject> gameObjects = new List<GameObject>();
List<Player> players = new List<Player>();

View file

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Xml;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonogameLibrary.UI.Base;
using MonogameLibrary.UI.Elements;
using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.GameManagers.ItemManager;
namespace ZoFo.GameCore.GUI;
public class ExitGameGUI : AbstractGUI
{
private DrawableUIElement menuBackground;
protected override void CreateUI()
{
int width = AppManager.Instance.CurentScreenResolution.X;
int height = AppManager.Instance.CurentScreenResolution.Y;
menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures/GUI/background/waiting" };
Elements.Add(menuBackground);
menuBackground.LoadTexture(AppManager.Instance.Content);
Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 5, (int)(width / 4), (int)(height / 20)), text = "Ты вышел из игры и потерял весь лут(((", fontColor = Color.Black, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts/Font4"});
Button endButton = new Button(Manager)
{
rectangle = new Rectangle(width / 2 - (width / 15) / 2, height / 2 + height / 4, (int)(width / 15), (int)(height / 20)),
text = "Exit",
scale = 0.3f,
fontColor = Color.White,
mainColor = Color.Gray,
fontName = "Fonts/Font"
};
endButton.LeftButtonPressed += () =>
{
AppManager.Instance.SetGUI(new MainMenuGUI());
};
Elements.Add(endButton);
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
}

View file

@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Xml;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonogameLibrary.UI.Base;
using MonogameLibrary.UI.Elements;
using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.GameManagers.ItemManager;
namespace ZoFo.GameCore.GUI;
public class FinishingGUI : AbstractGUI
{
private List<ItemDisplayLabel> ItemDisplayLabelsList;
private int labelIndex = 0;
private DrawableUIElement menuBackground;
protected override void CreateUI()
{
ItemDisplayLabelsList = new List<ItemDisplayLabel>();
int width = AppManager.Instance.CurentScreenResolution.X;
int height = AppManager.Instance.CurentScreenResolution.Y;
menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures/GUI/background/endGame" };
Elements.Add(menuBackground);
menuBackground.LoadTexture(AppManager.Instance.Content);
Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 15, (int)(width / 4), (int)(height / 20)), text = "Mission completed", fontColor = Color.Black, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts/Font"});
DrawableUIElement inventoryBack = new DrawableUIElement(Manager)
{
rectangle = new Rectangle(width / 2 - height / 80 - width / 5 / 2,
height / 2 - (int)(height / 1.5) / 2,
height / 40 + width / 5, (int)(height / 1.5)),
mainColor = Color.LightGray
};
Elements.Add(inventoryBack);
Button ExitButton = new Button(Manager)
{
rectangle = new Rectangle(width / 2 - width / 15 / 2,
height / 2 + (int)(height / 1.5) / 2 + height / 40, (int)(width / 15), (int)(height / 20)),
text = "Exit",
scale = 0.2f,
fontColor = Color.White,
mainColor = Color.Gray,
fontName = "Fonts\\Font"
};
ExitButton.LeftButtonPressed += () => { AppManager.Instance.SetGUI(new MainMenuGUI()); };
Elements.Add(ExitButton);
//player itams
foreach (var item in AppManager.Instance.client.myPlayer.lootData.loots)
{
if (item.Value > 0)
{
ItemInfo itemInfo = AppManager.Instance.ItemManager.GetItemInfo(item.Key);
var temp = new ItemDisplayLabel(Manager)
{
rectangle = new Rectangle(
width / 2 - width / 5 / 2,
height / 2 - (int)(height / 1.5) / 2 + height / 80 +
(height / 20 + height / 80) * (labelIndex),
(int)(width / 5), (int)(height / 20)),
text1 = item.Key,
scale1 = 0.4f,
count = item.Value,
itemTextureName = itemInfo.textureName,
fontColor1 = Color.White,
mainColor = Color.Gray,
fontName1 = "Fonts\\Font4",
discriptions1 = itemInfo.description,
resourcesNeededToCraft1 = itemInfo.resourcesNeededToCraft
};
Elements.Add(temp);
temp.Initialize();
temp.LoadTexture(AppManager.Instance.Content);
ItemDisplayLabelsList.Add(temp);
labelIndex++;
}
}
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
}

View file

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Xml;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
@ -9,19 +10,43 @@ using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonogameLibrary.UI.Base;
using MonogameLibrary.UI.Elements;
using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.GameManagers.ItemManager;
namespace ZoFo.GameCore.GUI;
public class GameEndedGUI : AbstractGUI
{
private DrawableUIElement menuBackground;
protected override void CreateUI()
{
// int width = AppManager.Instance.inGameHUDHelperResolution.X;
// int height = AppManager.Instance.inGameHUDHelperResolution.Y;
int width = AppManager.Instance.CurentScreenResolution.X;
int height = AppManager.Instance.CurentScreenResolution.Y;
menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures/GUI/background/endGame" };
Elements.Add(menuBackground);
menuBackground.LoadTexture(AppManager.Instance.Content);
Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 5, (int)(width / 4), (int)(height / 20)), text = "The End", fontColor = Color.Black, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts/Font"});
Button endButton = new Button(Manager)
{
rectangle = new Rectangle(width / 2 - (width / 15) / 2, height / 2 + height / 4, (int)(width / 15), (int)(height / 20)),
text = "End",
scale = 0.3f,
fontColor = Color.White,
mainColor = Color.Gray,
fontName = "Fonts/Font"
};
endButton.LeftButtonPressed += () =>
{
AppManager.Instance.SetGUI(new MainMenuGUI());
};
Elements.Add(endButton);
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
}

View file

@ -13,23 +13,68 @@ using ZoFo.GameCore.GameManagers;
namespace ZoFo.GameCore.GUI;
public class HUD : AbstractGUI
public class HUD : AbstractGUI
{
protected override void CreateUI()
private Bar hpBar;
private Bar radBar;
private AbstractGUI overlayGUI;
protected override void CreateUI()
{
int width = AppManager.Instance.CurentScreenResolution.X;
int height = AppManager.Instance.CurentScreenResolution.Y;
Button pauseButton = new Button(Manager)
{ fontName = "Fonts\\Font3", scale = 0.4f, text = "| |", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40), textureName = "Textures\\GUI\\checkboxs_off"};
{ fontName = "Fonts\\Font3", scale = 0.4f, text = "| |", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width - width / 30 - width / 40, height / 30, width / 40, width / 40), textureName = "Textures\\GUI\\checkboxs_off"};
Elements.Add(pauseButton);
pauseButton.LeftButtonPressed += () =>
{
AppManager.Instance.SetGUI(new PauseGUI());
AppManager.Instance.SetGUI(new FinishingGUI());
//overlayGUI = new PauseGUI();
//overlayGUI.Initialize();
//overlayGUI.LoadContent();
};
Button invButton = new Button(Manager)
{ fontName = "Fonts\\Font3", scale = 0.4f, text = "inv", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width - width / 30 - width / 40, height / 15 + width / 40, width / 40, width / 40), textureName = "Textures\\GUI\\checkboxs_off"};
Elements.Add(invButton);
invButton.LeftButtonPressed += () =>
{
overlayGUI = new InventoryGUI();
overlayGUI.Initialize();
overlayGUI.LoadContent();
};
hpBar = new Bar(Manager)
{
rectangle = new Rectangle(width / 2 - width / 8 - width / 16, height - height / 10, width / 8, height / 25),
percent = 1f,
mainColor = Color.LightGray,
inColor = Color.Red
};
hpBar.Initialize();
hpBar.LoadTexture(AppManager.Instance.Content);
radBar = new Bar(Manager)
{
rectangle = new Rectangle(width / 2 + width / 16, height - height / 10, width / 8, height / 25),
percent = 0f,
mainColor = Color.LightGray,
inColor = Color.GreenYellow
};
radBar.Initialize();
radBar.LoadTexture(AppManager.Instance.Content);
}
public override void Update(GameTime gameTime)
{
overlayGUI?.Update(gameTime);
//hpBar.Update(gameTime, AppManager.Instance.client.myPlayer.health / 100f);
//radBar.Update(gameTime, AppManager.Instance.client.myPlayer.rad / 100f);
radBar.Update(gameTime, gameTime.TotalGameTime.Seconds / 100f);
base.Update(gameTime);
}
public override void Draw(SpriteBatch spriteBatch)
{
overlayGUI?.Draw(spriteBatch);
base.Draw(spriteBatch);
}
}

View file

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Xml;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
@ -9,19 +10,83 @@ using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonogameLibrary.UI.Base;
using MonogameLibrary.UI.Elements;
using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.GameManagers.ItemManager;
namespace ZoFo.GameCore.GUI;
public class InventoryGUI : AbstractGUI
{
private List<ItemDisplayButton> ItemDisplayButtonsList;
private int buttonIndex = 0;
protected override void CreateUI()
{
// int width = AppManager.Instance.inGameHUDHelperResolution.X;
// int height = AppManager.Instance.inGameHUDHelperResolution.Y;
ItemDisplayButtonsList = new List<ItemDisplayButton>();
int width = AppManager.Instance.CurentScreenResolution.X;
int height = AppManager.Instance.CurentScreenResolution.Y;
DrawableUIElement inventoryBack = new DrawableUIElement(Manager)
{
rectangle = new Rectangle(width / 2 - height / 80 - width / 5 / 2,
height / 2 - (int)(height / 1.5) / 2 - height / 10,
height / 40 + width / 5, (int)(height / 1.5)),
mainColor = Color.LightGray
};
Elements.Add(inventoryBack);
Button continueButton = new Button(Manager)
{
rectangle = new Rectangle(width / 2 - width / 5 / 2,
height / 2 + (int)(height / 1.5) / 2 + height / 40 - height / 10, (int)(width / 5), (int)(height / 20)),
text = "Continue",
scale = 0.2f,
fontColor = Color.White,
mainColor = Color.Gray,
fontName = "Fonts\\Font"
};
continueButton.LeftButtonPressed += () => { AppManager.Instance.SetGUI(new HUD()); };
Elements.Add(continueButton);
//player itams
foreach (var item in AppManager.Instance.client.myPlayer.lootData.loots)
{
if (item.Value > 0)
{
ItemInfo itemInfo = AppManager.Instance.ItemManager.GetItemInfo(item.Key);
var temp = new ItemDisplayButton(Manager)
{
rectangle = new Rectangle(
width / 2 - width / 5 / 2,
height / 2 - (int)(height / 1.5) / 2 + height / 80 +
(height / 20 + height / 80) * (buttonIndex) - height / 10,
(int)(width / 5), (int)(height / 20)),
text1 = item.Key,
scale1 = 0.4f,
count = item.Value,
itemTextureName = itemInfo.textureName,
fontColor1 = Color.White,
mainColor = Color.Gray,
fontName1 = "Fonts\\Font4",
discriptions1 = itemInfo.description,
resourcesNeededToCraft1 = itemInfo.resourcesNeededToCraft
};
Elements.Add(temp);
temp.Initialize();
temp.LoadTexture(AppManager.Instance.Content);
ItemDisplayButtonsList.Add(temp);
temp.LeftButtonPressed += () =>
{
};
buttonIndex++;
}
}
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
}

View file

@ -56,7 +56,6 @@ namespace ZoFo.GameCore.GameManagers
Content.RootDirectory = "Content";
IsMouseVisible = true;
server = new Server();
playerData = new PlayerData();
ItemManager = new ItemManager.ItemManager();
Instance = this;
@ -102,7 +101,7 @@ namespace ZoFo.GameCore.GameManagers
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
Keyboard.GetState().IsKeyDown(Keys.Escape)) { server.CloseConnection(); Exit(); }
Keyboard.GetState().IsKeyDown(Keys.Escape)) { server?.CloseConnection(); Exit(); }
// debugHud.Set("key", "value");

View file

@ -25,6 +25,7 @@ namespace ZoFo.GameCore.GameManagers.ItemManager
public void Initialize()
{
tagItemPairs = new Dictionary<string, ItemInfo>();
tagItemPairs.Add("Ammo", new ItemInfo("Ammo", "деньги в метро", "Textures\\icons\\Collectables\\Ammo",false,null));
tagItemPairs.Add("wood", new ItemInfo("wood", "бревна кусок", "Textures\\Test\\wood",false,null));
tagItemPairs.Add("rock", new ItemInfo("rock", "пять галек", "Textures\\Test\\rock", false, null));
tagItemPairs.Add("steel", new ItemInfo("steel", "метал, метал, \nжелезо, метал", "Textures\\Test\\steel", false, null));

View file

@ -13,7 +13,7 @@ using ZoFo.GameCore.GUI;
namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables
{
class Ammo:Collectable
class Ammo : Collectable
{
public override StaticGraphicsComponent graphicsComponent { get; } = new(_path + "Ammo");
public Ammo(Vector2 position) : base(position)
@ -26,6 +26,14 @@ namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables
public override void OnInteraction(GameObject sender)
{
DebugHUD.DebugLog("collected");
if (AppManager.Instance.client.myPlayer.lootData.loots.Keys.Contains("Ammo"))
{
AppManager.Instance.client.myPlayer.lootData.loots["Ammo"] += 1;
}
else
{
AppManager.Instance.client.myPlayer.lootData.loots.Add("Ammo", 1);
}
AppManager.Instance.server.AddData(new UpdateLoot("Ammo"));
AppManager.Instance.server.DeleteObject(this);
}

View file

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player
{
class LootData
public class LootData
{
public Dictionary<string, int> loots;

View file

@ -20,12 +20,15 @@ public class Player : LivingEntity
/// </summary>
//public bool IsTryingToShoot { get; set; }
private float speed;
private int health;
public int health = 100;
public int rad = 0;
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "player_look_down" }, "player_look_down");
private LootData lootData;
public LootData lootData;
//public bool isTryingToInteract { get; set; }
public Player(Vector2 position) : base(position)
{
lootData = new LootData();
lootData.loots = new Dictionary<string, int>();
graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 30, 30);
collisionComponent.stopRectangle = new Rectangle(0, 20, 30, 10);
speed = 10;