From 9d58b4b15ea879e975ad228fe91a2121ce50e60c Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Thu, 18 Jul 2019 22:10:05 -0700 Subject: [PATCH] Finished color picking for character selection screen! --- .../SeasideScrambleMinigame/SSCCamera.cs | 8 + .../SSCMenus/CharacterSelectScreen.cs | 174 ++++++++++++++++-- .../SeasideScramble.cs | 13 +- 3 files changed, 176 insertions(+), 19 deletions(-) diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCCamera.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCCamera.cs index 1e4ef923..5883dff3 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCCamera.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCCamera.cs @@ -12,6 +12,14 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame public xTile.Dimensions.Rectangle viewport; + public Vector2 Position + { + get + { + return new Vector2(this.viewport.X, this.viewport.Y); + } + } + public SSCCamera() { this.viewport = new xTile.Dimensions.Rectangle(StardewValley.Game1.viewport); diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/CharacterSelectScreen.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/CharacterSelectScreen.cs index f7fe81d1..e02e40b1 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/CharacterSelectScreen.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/CharacterSelectScreen.cs @@ -16,22 +16,55 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus StardustCore.UIUtilities.Texture2DExtended background; string menuTitle; - public Color p1DefaultColor = Color.PaleVioletRed; - public Color p2DefaultColor = Color.LightSkyBlue; - public Color p3DefaultColor = Color.LawnGreen; - public Color p4DefaultColor = Color.LightGoldenrodYellow; + public Dictionary playerColorIndex; public Vector2 p1DisplayLocation; + public Vector2 p2DisplayLocation; + public Vector2 p3DisplayLocation; + public Vector2 p4DisplayLocation; + + public List possibleColors; public bool closeMenu; + public Dictionary inputDelays; + public int maxInputDelay = 20; + public CharacterSelectScreen(int x, int y, int width, int height) : base(x, y, width, height, false) { this.background = SeasideScramble.self.textureUtils.getExtendedTexture("SSCMaps", "TitleScreenBackground"); this.menuTitle = "Character Selection"; - this.p1DisplayLocation = this.getRelativePositionToMenu(.1f, .5f); + this.p1DisplayLocation = new Vector2(this.width *.2f, this.height / 2); + this.p2DisplayLocation = new Vector2(this.width *.4f, this.height / 2); + this.p3DisplayLocation = new Vector2(this.width *.6f, this.height / 2); + this.p4DisplayLocation = new Vector2(this.width *.8f, this.height / 2); + + this.possibleColors = new List() + { + Color.PaleVioletRed, + Color.LightSkyBlue, + Color.LawnGreen, + Color.LightGoldenrodYellow, + Color.HotPink, + Color.Red, + Color.Purple + }; + this.playerColorIndex = new Dictionary() + { + { SSCEnums.PlayerID.One,-1}, + { SSCEnums.PlayerID.Two,-1}, + { SSCEnums.PlayerID.Three,-1}, + { SSCEnums.PlayerID.Four,-1}, + }; + this.inputDelays = new Dictionary() + { + { SSCEnums.PlayerID.One,0}, + { SSCEnums.PlayerID.Two,0}, + { SSCEnums.PlayerID.Three,0}, + { SSCEnums.PlayerID.Four,0}, + }; } public CharacterSelectScreen(xTile.Dimensions.Rectangle viewport) : this(0, 0, viewport.Width, viewport.Height) @@ -45,9 +78,9 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus this.yPositionOnScreen = newBounds.Y; this.width = newBounds.Width; this.height = newBounds.Height; - base.gameWindowSizeChanged(oldBounds, newBounds); + //base.gameWindowSizeChanged(oldBounds, newBounds); - this.p1DisplayLocation = this.getRelativePositionToMenu(.1f, .5f); + //this.p1DisplayLocation = new Vector2(this.width/10,this.height/2); } public override void update(GameTime time) @@ -63,30 +96,124 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus } if (p2.IsButtonDown(Buttons.A)) { - throw new NotImplementedException("Need to support player 2!"); + this.initializeCharacter(SSCEnums.PlayerID.Two); } if (p3.IsButtonDown(Buttons.A)) { - throw new NotImplementedException("Need to support player 3!"); + this.initializeCharacter(SSCEnums.PlayerID.Three); } if (p4.IsButtonDown(Buttons.A)) { - throw new NotImplementedException("Need to support player 4!"); + this.initializeCharacter(SSCEnums.PlayerID.Four); } + this.inputDelays[SSCEnums.PlayerID.One]--; + this.inputDelays[SSCEnums.PlayerID.Two]--; + this.inputDelays[SSCEnums.PlayerID.Three]--; + this.inputDelays[SSCEnums.PlayerID.Four]--; + + if (this.inputDelays[SSCEnums.PlayerID.One] < 0) this.inputDelays[SSCEnums.PlayerID.One] = 0; + if (this.inputDelays[SSCEnums.PlayerID.Two] < 0) this.inputDelays[SSCEnums.PlayerID.Two] = 0; + if (this.inputDelays[SSCEnums.PlayerID.Three] < 0) this.inputDelays[SSCEnums.PlayerID.Three] = 0; + if (this.inputDelays[SSCEnums.PlayerID.Four] < 0) this.inputDelays[SSCEnums.PlayerID.Four] = 0; + } + /// + /// Initializes a given character. + /// + /// public void initializeCharacter(SSCEnums.PlayerID player) { if (SeasideScramble.self.players.ContainsKey(player)) { - SeasideScramble.self.players[player] = new SSCPlayer(player); + return; } else { SeasideScramble.self.players.Add(player, new SSCPlayer(player)); + this.iteratePlayerColorIndex(player, 1); + } + this.setPlayerColor(player); + } + + /// + /// Sets a given player's color. + /// + /// + private void setPlayerColor(SSCEnums.PlayerID player) + { + if (SeasideScramble.self.getPlayer(player) == null) return; + SeasideScramble.self.getPlayer(player).setColor(this.possibleColors[this.playerColorIndex[player]]); + } + + /// + /// Iterates the player's color index to get the next possible color. + /// + /// + /// + private void iteratePlayerColorIndex(SSCEnums.PlayerID player,int amount) + { + if(player== SSCEnums.PlayerID.One) + { + if (this.inputDelays[player] != 0) return; + this.inputDelays[player] = this.maxInputDelay; + while (this.doesAnyOtherPlayerHaveThisColor(player) == true) + { + if (this.playerColorIndex[player] >= this.possibleColors.Count) + { + this.playerColorIndex[player] = 0; + } + else if (this.playerColorIndex[player] < 0) + { + this.playerColorIndex[player] = this.possibleColors.Count-1; + } + else + { + this.playerColorIndex[player]+=amount; + } + } + this.playerColorIndex[player] += amount; + if (this.playerColorIndex[player] >= this.possibleColors.Count) + { + this.playerColorIndex[player] = 0; + } + else if (this.playerColorIndex[player] < 0) + { + this.playerColorIndex[player] = this.possibleColors.Count - 1; + } + } - SeasideScramble.self.getPlayer(player).setColor(this.p1DefaultColor); + this.setPlayerColor(player); + } + + /// + /// Checks if a given player has the same color index as another to prevent color duplicates. + /// + /// + /// + /// + private bool doesOtherPlayerHaveThisColor(SSCEnums.PlayerID self, SSCEnums.PlayerID other) + { + if (SeasideScramble.self.getPlayer(other) == null) return false; + if (this.playerColorIndex[self] == this.playerColorIndex[other]) return true; + else return false; + } + /// + /// Checks if any other player has the same color index to prevent color duplicates. + /// + /// + /// + private bool doesAnyOtherPlayerHaveThisColor(SSCEnums.PlayerID self) + { + for(int i = 0; i < 4; i++) + { + SSCEnums.PlayerID other = (SSCEnums.PlayerID)i; + if (other == self) continue; + if (this.doesOtherPlayerHaveThisColor(self, other) == false) continue; + else return true; + } + return false; } public override void receiveLeftClick(int x, int y, bool playSound = true) @@ -96,11 +223,22 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus public override void receiveKeyPress(Keys key) { - if(key== Keys.Enter) + if(key== Keys.Enter || key== Keys.Space) + { + if (SeasideScramble.self.currentNumberOfPlayers > 0) + { + this.setUpForGameplay(); + SeasideScramble.self.menuManager.closeAllMenus(); + } + } + if(key== Keys.A) { - this.setUpForGameplay(); - this.closeMenu = true; - } + this.iteratePlayerColorIndex(SSCEnums.PlayerID.One, -1); + } + if(key== Keys.D) + { + this.iteratePlayerColorIndex(SSCEnums.PlayerID.One, 1); + } } private void setUpForGameplay() @@ -125,10 +263,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus public override void draw(SpriteBatch b) { //Draw background texture. - b.Draw(this.background.texture, new Vector2(this.xPositionOnScreen, this.yPositionOnScreen), SeasideScramble.self.camera.getXNARect(), Color.White); + b.Draw(this.background.texture, new Vector2(0,0), SeasideScramble.self.camera.getXNARect(), Color.White); Vector2 menuTitlePos = Game1.dialogueFont.MeasureString(this.menuTitle); - b.DrawString(Game1.dialogueFont, this.menuTitle, new Vector2((this.width / 2) - (menuTitlePos.X / 2), this.height / 2),Color.White); + b.DrawString(Game1.dialogueFont, this.menuTitle, new Vector2((this.width / 2) - (menuTitlePos.X / 2), this.height / 10),Color.White); if (SeasideScramble.self.getPlayer(SSCEnums.PlayerID.One) != null) { diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScramble.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScramble.cs index 64736740..331a18c6 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScramble.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScramble.cs @@ -23,7 +23,13 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame SeasideScrambleMap currentMap; public Dictionary SeasideScrambleMaps; - public int currentNumberOfPlayers = 0; + public int currentNumberOfPlayers + { + get + { + return this.players.Count; + } + } public const int maxPlayers = 4; public Dictionary players; @@ -196,6 +202,11 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame player.receiveKeyPress(k); } + if (this.menuManager.isMenuUp) + { + this.menuManager.activeMenu.receiveKeyPress(k); + } + } ///