base2
This commit is contained in:
parent
7590907b20
commit
98d193b7e0
3 changed files with 140 additions and 44 deletions
|
@ -9,6 +9,7 @@ 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;
|
||||
|
||||
|
@ -23,6 +24,12 @@ public class ItemDisplayLabel : DrawableUIElement
|
|||
public string text1;
|
||||
public float scale1;
|
||||
private DrawableUIElement icon;
|
||||
private HoverState presentState = HoverState.None;
|
||||
private HoverWindow hoverWindow = null;
|
||||
public string discriptions1;
|
||||
public Dictionary<string, int> resourcesNeededToCraft1;
|
||||
public HoverState hoverState = HoverState.None;
|
||||
private ContentManager content;
|
||||
|
||||
|
||||
public ItemDisplayLabel(UIManager manager) : base(manager)
|
||||
|
@ -51,6 +58,7 @@ public class ItemDisplayLabel : DrawableUIElement
|
|||
|
||||
public override void LoadTexture(ContentManager content)
|
||||
{
|
||||
this.content = content;
|
||||
icon.LoadTexture(content);
|
||||
base.LoadTexture(content);
|
||||
if (itemTextureName == "")
|
||||
|
@ -71,9 +79,71 @@ public class ItemDisplayLabel : DrawableUIElement
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Update(GameTime gameTime)
|
||||
{
|
||||
if (rectangle.Intersects(new Rectangle(Mouse.GetState().Position, Point.Zero)))
|
||||
{
|
||||
hoverState = HoverState.Hovering;
|
||||
}
|
||||
else
|
||||
{
|
||||
hoverState = HoverState.None;
|
||||
}
|
||||
|
||||
if (hoverState == HoverState.Hovering)
|
||||
{
|
||||
if (presentState != hoverState)
|
||||
{
|
||||
if (resourcesNeededToCraft1 == null)
|
||||
{
|
||||
resourcesNeededToCraft1 = new Dictionary<string, int>();
|
||||
}
|
||||
|
||||
hoverWindow = new HoverWindow(Manager)
|
||||
{
|
||||
rectangle = new Rectangle(Mouse.GetState().Position.X, Mouse.GetState().Position.Y, rectangle.Width, rectangle.Height * 10),
|
||||
mainColor = Color.Gray,
|
||||
tagItem = text1,
|
||||
discriptions = discriptions1,
|
||||
resourcesNeededToCraft = resourcesNeededToCraft1,
|
||||
fontColor2 = fontColor1,
|
||||
fontName2 = fontName1,
|
||||
scale2 = scale1,
|
||||
itemTextureName1 = itemTextureName
|
||||
};
|
||||
hoverWindow.Initialize(content);
|
||||
hoverWindow.LoadTexture(content);
|
||||
}
|
||||
|
||||
hoverWindow.rectangle.X = Mouse.GetState().Position.X;
|
||||
hoverWindow.rectangle.Y = Mouse.GetState().Position.Y;
|
||||
hoverWindow.Update(gameTime);
|
||||
}
|
||||
else if (hoverState == HoverState.None)
|
||||
{
|
||||
if (presentState != hoverState)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
presentState = hoverState;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch _spriteBatch)
|
||||
{
|
||||
|
||||
if (hoverState == HoverState.None)
|
||||
{
|
||||
_spriteBatch.Draw(texture, rectangle, Color.White);
|
||||
}
|
||||
else if (hoverState == HoverState.Hovering)
|
||||
{
|
||||
_spriteBatch.Draw(texture, rectangle, new Color(211, 211, 211));
|
||||
}
|
||||
base.Draw(_spriteBatch);
|
||||
_spriteBatch.Draw(texture, rectangle, Color.White);
|
||||
}
|
||||
|
|
|
@ -51,7 +51,8 @@ public class BaseGUI : AbstractGUI
|
|||
|
||||
DrawableUIElement baseItemBack = new DrawableUIElement(Manager)
|
||||
{
|
||||
rectangle = new Rectangle(width / 2 - (height / 16 + (int)(width / 2.5)) / 2, height / 2 - (int)(height / 1.5) / 2,
|
||||
rectangle = new Rectangle(width / 2 - (height / 16 + (int)(width / 2.5)) / 2,
|
||||
height / 2 - (int)(height / 1.5) / 2,
|
||||
height / 40 + width / 5, (int)(height / 1.5)),
|
||||
mainColor = Color.LightGray
|
||||
};
|
||||
|
@ -69,7 +70,7 @@ public class BaseGUI : AbstractGUI
|
|||
{
|
||||
if (item.Value > 0)
|
||||
{
|
||||
textureName = AppManager.Instance.ItemManager.GetItemInfo(item.Key).textureName;
|
||||
ItemInfo itemInfo = AppManager.Instance.ItemManager.GetItemInfo(item.Key);
|
||||
var temp = new ItemDisplayLabel(Manager)
|
||||
{
|
||||
rectangle = new Rectangle(width / 2 - (height / 16 + (int)(width / 2.5)) / 2 + height / 80,
|
||||
|
@ -79,10 +80,12 @@ public class BaseGUI : AbstractGUI
|
|||
text1 = item.Key,
|
||||
scale1 = 0.4f,
|
||||
count = item.Value,
|
||||
itemTextureName = textureName,
|
||||
itemTextureName = itemInfo.textureName,
|
||||
fontColor1 = Color.White,
|
||||
mainColor = Color.Gray,
|
||||
fontName1 = "Fonts\\Font3"
|
||||
fontName1 = "Fonts\\Font4",
|
||||
discriptions1 = itemInfo.description,
|
||||
resourcesNeededToCraft1 = itemInfo.resourcesNeededToCraft
|
||||
};
|
||||
Elements.Add(temp);
|
||||
temp.Initialize();
|
||||
|
@ -97,49 +100,59 @@ public class BaseGUI : AbstractGUI
|
|||
buttonIndex = 0;
|
||||
foreach (var item in items)
|
||||
{
|
||||
ItemInfo itemInfo = AppManager.Instance.ItemManager.GetItemInfo(item.Key);
|
||||
if (itemInfo.isCraftable)
|
||||
try
|
||||
{
|
||||
Dictionary<string, int> needToCraft = AppManager.Instance.ItemManager.GetItemInfo(item.Key).resourcesNeededToCraft;
|
||||
numberCraftItem = playerItems[needToCraft.Keys.First()] / needToCraft.Values.First();
|
||||
foreach (var itemNeedToCraft in needToCraft)
|
||||
ItemInfo itemInfo = AppManager.Instance.ItemManager.GetItemInfo(item.Key);
|
||||
if (itemInfo.isCraftable)
|
||||
{
|
||||
int xValue = playerItems[itemNeedToCraft.Key] / itemNeedToCraft.Value;
|
||||
if (numberCraftItem > xValue)
|
||||
Dictionary<string, int> needToCraft =
|
||||
AppManager.Instance.ItemManager.GetItemInfo(item.Key).resourcesNeededToCraft;
|
||||
numberCraftItem = playerItems[needToCraft.Keys.First()] / needToCraft.Values.First();
|
||||
foreach (var itemNeedToCraft in needToCraft)
|
||||
{
|
||||
numberCraftItem = xValue;
|
||||
int xValue = playerItems[itemNeedToCraft.Key] / itemNeedToCraft.Value;
|
||||
if (numberCraftItem > xValue)
|
||||
{
|
||||
numberCraftItem = xValue;
|
||||
}
|
||||
}
|
||||
|
||||
if (numberCraftItem > 0)
|
||||
{
|
||||
var temp = new ItemDisplayButton(Manager)
|
||||
{
|
||||
rectangle = new Rectangle(
|
||||
width / 2 - (height / 16 + (int)(width / 2.5)) / 2 + height / 20 + width / 5,
|
||||
height / 2 - (int)(height / 1.5) / 2 + height / 80 +
|
||||
(height / 20 + height / 80) * (buttonIndex),
|
||||
(int)(width / 5), (int)(height / 20)),
|
||||
text1 = item.Key,
|
||||
scale1 = 0.4f,
|
||||
count = numberCraftItem,
|
||||
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 += () =>
|
||||
{
|
||||
AppManager.Instance.playerData.CraftItem(item.Key);
|
||||
AppManager.Instance.SetGUI(new BaseGUI());
|
||||
};
|
||||
|
||||
buttonIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
if (numberCraftItem > 0)
|
||||
{
|
||||
var temp = new ItemDisplayButton(Manager)
|
||||
{
|
||||
rectangle = new Rectangle(width / 2 - (height / 16 + (int)(width / 2.5)) / 2 + height / 20 + width / 5,
|
||||
height / 2 - (int)(height / 1.5) / 2 + height / 80 + (height / 20 + height / 80) * (buttonIndex),
|
||||
(int)(width / 5), (int)(height / 20)),
|
||||
text1 = item.Key,
|
||||
scale1 = 0.4f,
|
||||
count = numberCraftItem,
|
||||
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 += () =>
|
||||
{
|
||||
AppManager.Instance.playerData.CraftItem(item.Key);
|
||||
AppManager.Instance.SetGUI(new BaseGUI());
|
||||
};
|
||||
|
||||
buttonIndex++;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,5 +176,12 @@ public class BaseGUI : AbstractGUI
|
|||
AppManager.Instance.SetGUI(new BaseGUI());
|
||||
}
|
||||
}
|
||||
foreach (var item in ItemDisplayLabelsList)
|
||||
{
|
||||
if (item.Update(gameTime))
|
||||
{
|
||||
AppManager.Instance.SetGUI(new BaseGUI());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -36,7 +36,14 @@ namespace ZoFo.GameCore.GameManagers.ItemManager
|
|||
items[item.Key] -= item.Value;
|
||||
}
|
||||
|
||||
items[itemTag] += 1;
|
||||
if (items.Keys.Contains(itemTag))
|
||||
{
|
||||
items[itemTag] += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
items.Add(itemTag, 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -48,7 +55,6 @@ namespace ZoFo.GameCore.GameManagers.ItemManager
|
|||
items.Add("wood", 5);
|
||||
items.Add("steel", 110);
|
||||
items.Add("rock", 6);
|
||||
items.Add("pickaxe", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue