diff options
Diffstat (limited to 'Penguloon/Controls')
| -rw-r--r-- | Penguloon/Controls/Button.cs | 2 | ||||
| -rw-r--r-- | Penguloon/Controls/ControlBase.cs | 5 | ||||
| -rw-r--r-- | Penguloon/Controls/LevelSelector.cs | 83 | ||||
| -rw-r--r-- | Penguloon/Controls/ObjectSelector.cs | 86 |
4 files changed, 160 insertions, 16 deletions
diff --git a/Penguloon/Controls/Button.cs b/Penguloon/Controls/Button.cs index 757b87d..542fb7f 100644 --- a/Penguloon/Controls/Button.cs +++ b/Penguloon/Controls/Button.cs @@ -12,7 +12,7 @@ namespace Penguloon.Controls this.BackgroundDisabled = ContentManager.GetTexture("UI/btnDisabled"); this.Text = text; - this.ForeColor = Color.Gray; + this.ForeColor = Color.White; this.BorderColor = Color.Gray; this.BorderWidth = 0; this.Font = ContentManager.GetFont(StaticUIValues.MenuFont); diff --git a/Penguloon/Controls/ControlBase.cs b/Penguloon/Controls/ControlBase.cs index b6b7a57..bbd3a14 100644 --- a/Penguloon/Controls/ControlBase.cs +++ b/Penguloon/Controls/ControlBase.cs @@ -25,6 +25,7 @@ namespace Penguloon.Controls public Texture2D BackgroundDisabled { get; set; } public event EventHandler OnMissClick; + public event EventHandler<ClickArgs> OnFingerDown; public event EventHandler<ClickArgs> OnClick; public event EventHandler<MoveArgs> OnMove; @@ -92,7 +93,7 @@ namespace Penguloon.Controls if (touchRec.Intersects(controlRec)) { - if (touchLocations[i].State == TouchLocationState.Released) + if (touchLocations[i].State == TouchLocationState.Released && this.ControlState == ControlState.Pressed) { this.ControlState = ControlState.Idle; OnClick?.Invoke(this, new ClickArgs(touchLocations[i].Position)); @@ -101,10 +102,12 @@ namespace Penguloon.Controls if (touchLocations[i].State == TouchLocationState.Pressed) { this.ControlState = ControlState.Pressed; + OnFingerDown?.Invoke(this, new ClickArgs(touchLocations[i].Position)); } if (touchLocations[i].State == TouchLocationState.Moved) { + OnFingerDown?.Invoke(this, new ClickArgs(touchLocations[i].Position)); touchLocations[i].TryGetPreviousLocation(out TouchLocation touch); OnMove?.Invoke(this, new MoveArgs(touchLocations[i].Position, touch.Position)); } diff --git a/Penguloon/Controls/LevelSelector.cs b/Penguloon/Controls/LevelSelector.cs index c04aef3..0309b68 100644 --- a/Penguloon/Controls/LevelSelector.cs +++ b/Penguloon/Controls/LevelSelector.cs @@ -17,9 +17,11 @@ namespace Penguloon.Controls public List<LevelBase> Levels { get; set; } = new List<LevelBase>(); + public Rectangle Panel0 { get; set; } public Rectangle Panel1 { get; set; } public Rectangle Panel2 { get; set; } public Rectangle Panel3 { get; set; } + public Rectangle Panel4 { get; set; } public LevelSelector(SceneBase parentScene, Vector2 position, Vector2 size) : base(parentScene, position, size) { @@ -31,16 +33,21 @@ namespace Penguloon.Controls PanelWidth = ((int)((StaticUIValues.ScreenViewport.X - ((MaxPanels + 1) * PanelMarginX)) / MaxPanels)); + int panel0posX = (PanelMarginX + (PanelMarginX * 0) + (PanelWidth * -1)) + 40; int panel1posX = (PanelMarginX + (PanelMarginX * 0) + (PanelWidth * 0)) + 20; int panel2posX = (PanelMarginX + (PanelMarginX * 1) + (PanelWidth * 1)); int panel3posX = (PanelMarginX + (PanelMarginX * 2) + (PanelWidth * 2)) - 20; + int panel4posX = (PanelMarginX + (PanelMarginX * 3) + (PanelWidth * 3)) - 80; int sidePanelMarginY = 25; int centerPanelWidth = (int)(PanelWidth * 1.2); + int outterPanelHeight = (int)((size.Y - sidePanelMarginY) * 0.8); + Panel0 = new Rectangle(panel0posX, (int)position.Y + (sidePanelMarginY / 2) + ((((int)size.Y - sidePanelMarginY) - outterPanelHeight) / 2), (int)(PanelWidth), outterPanelHeight); Panel1 = new Rectangle(panel1posX, (int)position.Y + (sidePanelMarginY / 2), (int)(PanelWidth * 1), (int)size.Y - sidePanelMarginY); Panel2 = new Rectangle(panel2posX - ((centerPanelWidth - PanelWidth) / 2), (int)position.Y, centerPanelWidth, (int)size.Y); Panel3 = new Rectangle(panel3posX, (int)position.Y + (sidePanelMarginY / 2), (int)(PanelWidth * 1), (int)size.Y - sidePanelMarginY); + Panel4 = new Rectangle(panel4posX, (int)position.Y + (sidePanelMarginY / 2) + ((((int)size.Y - sidePanelMarginY) - outterPanelHeight) / 2), (int)(PanelWidth), outterPanelHeight); this.OnClick += LevelSelector_OnClick; @@ -51,21 +58,46 @@ namespace Penguloon.Controls { Rectangle fingerRec = new Rectangle(e.ClickPosition.ToPoint(), new Point(1, 1)); + if (Panel2.Intersects(fingerRec) && Levels[selectedMap].MinimumLevel <= UserdataManager.Level) + { + SoundManager.PlayClickSound(); + SceneManager.GameScene = new GameScene(ParentScene.Main, Levels[selectedMap]); + SceneManager.SelectedScene = SelectedScene.Ingame; + + SoundManager.PlayClickSound2(); + return; + } + if (Panel1.Intersects(fingerRec) && selectedMap > 0) { selectedMap--; + + SoundManager.PlayClickSound2(); + return; } - if (Panel2.Intersects(fingerRec) && Levels[selectedMap].MinimumLevel <= UserdataManager.Level) + if (Panel0.Intersects(fingerRec) && selectedMap > 1) { - SoundManager.PlayClickSound(); - SceneManager.GameScene = new GameScene(ParentScene.Main, Levels[selectedMap]); - SceneManager.SelectedScene = SelectedScene.Ingame; + selectedMap -= 2; + + SoundManager.PlayClickSound2(); + return; } if (Panel3.Intersects(fingerRec) && selectedMap < Levels.Count - 1) { selectedMap++; + + SoundManager.PlayClickSound2(); + return; + } + + if (Panel4.Intersects(fingerRec) && selectedMap < Levels.Count - 2) + { + selectedMap += 2; + + SoundManager.PlayClickSound2(); + return; } } @@ -85,6 +117,23 @@ namespace Penguloon.Controls private void DrawPanels() { + if (selectedMap - 2 >= 0) + { + ParentScene.Main.SpriteBatch.Draw(Levels[selectedMap - 2].SplashArt, + destinationRectangle: Panel0); + + if (Levels[selectedMap - 2].MinimumLevel > UserdataManager.Level) + { + ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("SplashArt/locked"), + destinationRectangle: Panel0); + + ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/lock"), + destinationRectangle: new Rectangle(Panel0.X + 25, Panel0.Y + 25, 100, 100)); + + //DrawLevel(new Vector2(Panel0.X + 25, Panel0.Y + Panel0.Height - 20), Levels[selectedMap - 2].MinimumLevel); + } + } + if (selectedMap - 1 >= 0) { ParentScene.Main.SpriteBatch.Draw(Levels[selectedMap - 1].SplashArt, @@ -97,9 +146,24 @@ namespace Penguloon.Controls ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/lock"), destinationRectangle: new Rectangle(Panel1.X + 25, Panel1.Y + 25, 100, 100)); + } + DrawLevel(new Vector2(Panel1.X + 25, Panel1.Y + Panel1.Height - 10), Levels[selectedMap - 1].MinimumLevel); + } + + if (selectedMap + 2 < Levels.Count) + { + ParentScene.Main.SpriteBatch.Draw(Levels[selectedMap + 2].SplashArt, + destinationRectangle: Panel4); + + if (Levels[selectedMap + 2].MinimumLevel > UserdataManager.Level) + { + ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("SplashArt/locked"), + destinationRectangle: Panel4); - DrawLevel(new Vector2(Panel1.X + 25, Panel1.Y + Panel1.Height - 10), Levels[selectedMap - 1].MinimumLevel); + ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/lock"), + destinationRectangle: new Rectangle(Panel4.X + 25, Panel4.Y + 25, 100, 100)); } + DrawLevel(new Vector2(Panel4.X + 25, Panel4.Y + Panel4.Height - 10), Levels[selectedMap + 2].MinimumLevel); } if (selectedMap + 1 < Levels.Count) @@ -114,9 +178,8 @@ namespace Penguloon.Controls ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/lock"), destinationRectangle: new Rectangle(Panel3.X + 25, Panel3.Y + 25, 100, 100)); - - DrawLevel(new Vector2(Panel3.X + 25, Panel3.Y + Panel3.Height - 10), Levels[selectedMap + 1].MinimumLevel); } + DrawLevel(new Vector2(Panel3.X + 25, Panel3.Y + Panel3.Height - 10), Levels[selectedMap + 1].MinimumLevel); } ParentScene.Main.SpriteBatch.Draw(Levels[selectedMap].SplashArt, @@ -129,9 +192,9 @@ namespace Penguloon.Controls ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/lock"), destinationRectangle: new Rectangle(Panel2.X + 25, Panel2.Y + 25, 100, 100)); - - DrawLevel(new Vector2(Panel2.X + 25, Panel2.Y + Panel2.Height - 10), Levels[selectedMap].MinimumLevel); } + + DrawLevel(new Vector2(Panel2.X + 25, Panel2.Y + Panel2.Height - 10), Levels[selectedMap].MinimumLevel); } private void DrawLevel(Vector2 position, int minLevel) @@ -146,7 +209,7 @@ namespace Penguloon.Controls ParentScene.Main.Resources.GetString(Resource.String.StatsLevel) + " ", new Vector2((int)position.X, position.Y), new Vector2(0, 0), - TextAllignment.LeftBottom, Color.FromNonPremultiplied(200, 200, 200, 200), Color.Black, 2); + TextAllignment.LeftBottom, Color.FromNonPremultiplied(111, 138, 183, 255), Color.Black, 2); } } }
\ No newline at end of file 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 |
