summaryrefslogtreecommitdiff
path: root/Penguloon/Controls/ObjectSelector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Penguloon/Controls/ObjectSelector.cs')
-rw-r--r--Penguloon/Controls/ObjectSelector.cs86
1 files changed, 82 insertions, 4 deletions
diff --git a/Penguloon/Controls/ObjectSelector.cs b/Penguloon/Controls/ObjectSelector.cs
index a155601..277107b 100644
--- a/Penguloon/Controls/ObjectSelector.cs
+++ b/Penguloon/Controls/ObjectSelector.cs
@@ -5,6 +5,7 @@ using Penguloon.Objects;
using Penguloon.Scenes;
using System.Collections.Generic;
using System;
+using Microsoft.Xna.Framework.Graphics;
namespace Penguloon.Controls
{
@@ -24,6 +25,9 @@ namespace Penguloon.Controls
public List<Tuple<ObjectBase, int>> Objects { get; set; } = new List<Tuple<ObjectBase, int>>();
+ public bool DrawInfoPanel { get; set; } = false;
+ public int TouchedObjectIndex { get; set; }
+
public ObjectSelector(Map map, SceneBase parentScene, Vector2 position, Vector2 size) : base(parentScene, position, size)
{
this.Map = map;
@@ -32,12 +36,15 @@ namespace Penguloon.Controls
this.BackgroundDisabled = ContentManager.GetTexture("UI/objectSelectionBackground");
this.OnClick += ObjectSelector_OnClick;
+ this.OnFingerDown += ObjectSelector_OnFingerDown;
LoadObjects();
}
- private void ObjectSelector_OnClick(object sender, ClickArgs e)
+ private void ObjectSelector_OnFingerDown(object sender, ClickArgs e)
{
+ DrawInfoPanel = true;
+
int rows = 4;
if (Objects.Count > 8)
@@ -55,8 +62,39 @@ namespace Penguloon.Controls
for (int i = 0; i < Objects.Count; i++)
{
- if (Objects[i].Item2 > Map.Level.Money) continue;
+ int posX = ((i + 1) % 2 != 0) ? oddX : evenX;
+ int posY = (i / 2) * height;
+
+ Rectangle rec = new Rectangle(posX, (int)Position.Y + posY, width, height);
+
+ if (fingerRec.Intersects(rec))
+ {
+ TouchedObjectIndex = i;
+
+ return;
+ }
+ }
+ }
+
+ private void ObjectSelector_OnClick(object sender, ClickArgs e)
+ {
+ int rows = 4;
+
+ if (Objects.Count > 8)
+ {
+ rows = (int)Math.Ceiling((double)Objects.Count / 2);
+ }
+
+ int width = (int)Size.X / 2;
+ int height = (int)Size.Y / rows;
+
+ int oddX = (int)Position.X;
+ int evenX = (int)Position.X + width;
+ Rectangle fingerRec = new Rectangle((int)e.ClickPosition.X, (int)e.ClickPosition.Y, 1, 1);
+
+ for (int i = 0; i < Objects.Count; i++)
+ {
int posX = ((i + 1) % 2 != 0) ? oddX : evenX;
int posY = (i / 2) * height;
@@ -64,6 +102,10 @@ namespace Penguloon.Controls
if (fingerRec.Intersects(rec))
{
+ TouchedObjectIndex = i;
+
+ if (Objects[i].Item2 > Map.Level.Money) continue;
+
if (SelectedObjectIndex != i)
{
SelectedObjectIndex = i;
@@ -84,10 +126,13 @@ namespace Penguloon.Controls
Objects.Add(new Tuple<ObjectBase,int>(new PenguinObject(Map), 250));
Objects.Add(new Tuple<ObjectBase, int>(new GoldPenguinObject(Map), 360));
Objects.Add(new Tuple<ObjectBase, int>(new CannonObject(Map), 650));
+ Objects.Add(new Tuple<ObjectBase, int>(new HealthGeneratorObject(Map), 150));
}
public override void Update(float deltaTime, TouchLocation[] touchLocations)
{
+ DrawInfoPanel = false;
+
base.Update(deltaTime, touchLocations);
}
@@ -121,10 +166,11 @@ namespace Penguloon.Controls
destinationRectangle: new Rectangle(posX, (int)Position.Y + posY, width, height));
}
- int widthToDraw = height - (padding * 2);
+ int widthToDraw = (height / Objects[i].Item1.TileSpanY) - (padding * 2);
+ int heightToDraw = (height / Objects[i].Item1.TileSpanX) - (padding * (3 - Objects[i].Item1.TileSpanX));
ParentScene.Main.SpriteBatch.Draw(Objects[i].Item1.Texture,
- destinationRectangle: new Rectangle(posX + (width - widthToDraw) / 2, (int)Position.Y + posY + padding, widthToDraw, height - (padding * 2)));
+ destinationRectangle: new Rectangle(posX + (width - widthToDraw) / 2, (int)Position.Y + posY + (height / 2) - (heightToDraw / 2), widthToDraw, heightToDraw));
ParentScene.DrawText(ContentManager.GetFont("Fonts/GWENT/36"), Objects[i].Item2.ToString(), new Vector2(posX, (int)Position.Y + posY),
new Vector2(width, height), TextAllignment.CenterBottom, Color.White, Color.Black, 2);
@@ -140,6 +186,38 @@ namespace Penguloon.Controls
ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/objectSelectionBorder"),
destinationRectangle: new Rectangle(oddX, (int)Position.Y + (x * height), (int)Size.X, 4));
}
+
+ if(DrawInfoPanel)
+ DrawSelectedInfoPanel();
+ }
+
+ private void DrawSelectedInfoPanel()
+ {
+ Texture2D panel = ContentManager.GetTexture("UI/textPanel");
+
+ int padding = 15;
+ Vector2 panelPos = new Vector2(padding, (int)StaticUIValues.ScreenViewport.Y - (int)StaticUIValues.IngameInfoPanelSize.Y + padding);
+
+ string[] Lines;
+ Lines = new string[Objects[TouchedObjectIndex].Item1.infoText.Split(new string[] { "\n" }, StringSplitOptions.None).Length];
+
+ Lines = Objects[TouchedObjectIndex].Item1.infoText.Split(new string[] { "\n" }, StringSplitOptions.None);
+
+ if (panel != null)
+ {
+ ParentScene.Main.SpriteBatch.Draw(panel,
+ destinationRectangle: new Rectangle(0, (int)StaticUIValues.ScreenViewport.Y - (int)StaticUIValues.IngameInfoPanelSize.Y,
+ (int)StaticUIValues.IngameInfoPanelSize.X, (int)StaticUIValues.IngameInfoPanelSize.Y));
+ }
+
+ int lineHeight = (int)ContentManager.GetFont(StaticUIValues.IngameFont).MeasureString("zulul").Y;
+
+ for (int i = 0; i < Lines.Length; i++)
+ {
+ ParentScene.DrawText(ContentManager.GetFont(StaticUIValues.IngameFont), Lines[i].Trim(),
+ new Vector2(panelPos.X, panelPos.Y + (i * lineHeight)), new Vector2(), TextAllignment.LeftTop,
+ Color.White, Color.Black, 2);
+ }
}
}
} \ No newline at end of file