using Penguloon.Scenes; using Microsoft.Xna.Framework; using System; using System.Collections.Generic; using Penguloon.Levels; using Microsoft.Xna.Framework.Input.Touch; namespace Penguloon.Controls { class LevelSelector : ControlBase { public int PanelWidth { get; set; } public const int PanelMarginX = 30; public const int MaxPanels = 3; int selectedMap = 0; public List Levels { get; set; } = new List(); 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) { UserdataManager.Level = UserdataManager.GetLevel(); this.BackgroundIdle = ContentManager.GetTexture("UI/btnIdle"); this.BackgroundPressed = ContentManager.GetTexture("UI/btnIdle"); this.BackgroundDisabled = ContentManager.GetTexture("UI/btnIdle"); 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; CreateLevels(); } private void LevelSelector_OnClick(object sender, ClickArgs e) { 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 (Panel0.Intersects(fingerRec) && selectedMap > 1) { 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; } } private void CreateLevels() { Levels.Add(new IceLevel()); Levels.Add(new IceLevel2()); Levels.Add(new IceLevel3()); Levels.Add(new SandLevel1()); } public override void Draw(float deltaTime) { // We dont need to draw text or a background //base.Draw(deltaTime); DrawPanels(); } 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, destinationRectangle: Panel1); if (Levels[selectedMap - 1].MinimumLevel > UserdataManager.Level) { ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("SplashArt/locked"), destinationRectangle: Panel1); 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); 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) { ParentScene.Main.SpriteBatch.Draw(Levels[selectedMap + 1].SplashArt, destinationRectangle: Panel3); if (Levels[selectedMap + 1].MinimumLevel > UserdataManager.Level) { ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("SplashArt/locked"), destinationRectangle: Panel3); 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); } ParentScene.Main.SpriteBatch.Draw(Levels[selectedMap].SplashArt, destinationRectangle: Panel2); if (Levels[selectedMap].MinimumLevel > UserdataManager.Level) { ParentScene.Main.SpriteBatch.Draw(ContentManager.GetTexture("SplashArt/locked"), destinationRectangle: Panel2); 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); } private void DrawLevel(Vector2 position, int minLevel) { ParentScene.DrawText(ContentManager.GetFont(StaticUIValues.StatsFont), minLevel.ToString(), new Vector2((int)position.X + ContentManager.GetFont(StaticUIValues.StatsFont).MeasureString(ParentScene.Main.Resources.GetString(Resource.String.StatsLevel) + " ").X, position.Y), new Vector2(0, 0), TextAllignment.LeftBottom, Color.White, Color.Black, 2); ParentScene.DrawText(ContentManager.GetFont(StaticUIValues.StatsFont), ParentScene.Main.Resources.GetString(Resource.String.StatsLevel) + " ", new Vector2((int)position.X, position.Y), new Vector2(0, 0), TextAllignment.LeftBottom, Color.FromNonPremultiplied(111, 138, 183, 255), Color.Black, 2); } } }