public void Update(User user) { this.user = user; button.Update(); if (rewardPopup.Active) { rewardPopup.Update(); } if (user != null) { TimeSpan nextGiftTime = user.LastReceivedGift.AddHours(HOURS_UNTIL_NEXT_GIFT) - DateTime.Now; timeUntilGift = nextGiftTime.Hours.ToString("00") + ":" + nextGiftTime.Minutes.ToString("00") + ":" + nextGiftTime.Seconds.ToString("00"); if (rewardPopup.Active && !showingGift) { rewardPopup.Text = string.Format("You have already collected your daily gift. You can receive another in {0}.", timeUntilGift); } } }
public void Update() { if (imgIndex == 0) { // We are on the first image prevPageButton.Active = false; } else { prevPageButton.Active = true; } if (imgIndex == tutorialImages.Count - 1) { // We are on the last image nextPageButton.Active = false; } else { nextPageButton.Active = true; } nextPageButton.Update(); prevPageButton.Update(); }
public void Update(ref User user, GameTime gameTime) { pwButton.Active = state != ShopState.Powerups; skinButton.Active = state != ShopState.Skins; skinButton.Text = LanguageTranslator.Translate("Snakes"); pwButton.Text = LanguageTranslator.Translate("Powerups"); skinButton.Width = pwButton.Width; pwButton.X = windowWidth / 2 - (SPACING / 2 + pwButton.Width); skinButton.X = windowWidth / 2 + SPACING / 2; pwButton.Update(); skinButton.Update(); if (skinPage < 0) { skinPage = 0; } if (skinPages.Count <= 1) { // Both buttons should be disabled, as there is only 1 page // This must be tested for first, otherwise, since the page always starts equal to 0, the below criteria will be met // and the game will act like there are 2 pages when there is only 1 nextPageButton.Active = false; prevPageButton.Active = false; // Since there is only one page, we have to set the page integer to 0 skinPage = 0; } else if (skinPage == 0) { // There is another page, but we are on the first. Therefore, we cannot go backwards, so we'll disable the backwards button nextPageButton.Active = true; prevPageButton.Active = false; } else if (skinPage + 1 == skinPages.Count) { // We are on the last page, so the forward button must be disabled nextPageButton.Active = false; prevPageButton.Active = true; } else { // We must be somewhere in the middle, so both buttons should be enabled nextPageButton.Active = true; prevPageButton.Active = true; } this.user = user; int row = 0; int lastX = 0; int lastY = 0; int interfacesInCurrentRow = 0; switch (state) { #region Powerups case ShopState.Powerups: row = 0; lastX = X_OFFSET; lastY = Y_OFFSET; interfacesInCurrentRow = 0; if (pwInterfaces.Count > 0) { foreach (ShopItemInterface si in pwInterfaces) { si.X = lastX; lastX += si.Width + SPACING; if (interfacesInCurrentRow >= ITEMS_PER_ROW) { row++; si.X = lastX = X_OFFSET; lastX += si.Width + SPACING; interfacesInCurrentRow = 0; } if (row == 0) { si.Y = lastY; } else if (row == 1) { si.Y = lastY + SPACING + si.Height; } interfacesInCurrentRow++; } } foreach (ShopItemInterface si in pwInterfaces) { si.Update(user.Coins >= si.Cost); } break; #endregion #region Skins case ShopState.Skins: // Update ShopItemInterface values row = 0; lastX = X_OFFSET; lastY = Y_OFFSET; interfacesInCurrentRow = 0; if (skinPage <= skinPages.Count - 1) { foreach (ShopItemInterface si in skinPages[skinPage]) { si.X = lastX; lastX += si.Width + SPACING; if (interfacesInCurrentRow >= ITEMS_PER_ROW) { row++; si.X = lastX = X_OFFSET; lastX += si.Width + SPACING; interfacesInCurrentRow = 0; } if (row == 0) { si.Y = lastY; } else if (row == 1) { si.Y = lastY + SPACING + si.Height; } interfacesInCurrentRow++; } } bool skinNotOwned = true; foreach (ShopItemInterface si in skinPages[skinPage]) { foreach (Skin s in user.Skins) { if (!(si.ItemSkin.MemberEquals(s))) { // If true, the current ShopItemInterface's skin is owned by the signed-in user skinNotOwned = true; } else { skinNotOwned = false; break; // We have found the skin in the user's inventory. Continued running of this loop may result in this value incorrectly // being set to true } } bool isBuyButtonActive = (user.Coins >= si.Cost) && skinNotOwned; si.Update(isBuyButtonActive); } break; #endregion } // We need to do it this way, because the delegates for when items are bought won't work, // as no parameters can be passed in to an OnButtonClick delegate foreach (InventoryItem item in itemsToAdd) { user.Inventory.Add(item); } itemsToAdd.Clear(); foreach (Skin skin in skinsToAdd) { user.Skins.Add(skin); } skinsToAdd.Clear(); nextPageButton.Update(); prevPageButton.Update(); user.Coins -= coinsToRemove; coinsToRemove = 0; }
public void Update() { trashButton.Update(new OnButtonHover(TrashHover), new OnButtonHover(TrashUnHover)); usernameButton.Update(new OnButtonHover(UsernameHover), new OnButtonHover(UsernameUnHover)); }
public void Update(GameTime gameTime, EnterDirection enterDir) { // Update Location if (viewButton != null) { viewButton.Text = LanguageTranslator.Translate("View"); } if (enterDir == EnterDirection.Top && bgRect.Y == windowHeight) { bgRect.Y = 0 - bgRect.Height; } if (enterDir == EnterDirection.Bottom && bgRect.Y == 0 - bgRect.Height) { bgRect.Y = windowHeight; } hideButton.X = (bgRect.Width + bgRect.X) - (SPACING + hideButton.Width); hideButton.Y = bgRect.Y + (bgRect.Height / 2 - (hideButton.Height / 2)); if (viewButton != null) { viewButton.X = hideButton.X - (viewButton.Width + SPACING); viewButton.Y = hideButton.Y; } textPos.X = bgRect.X + SPACING; textPos.Y = bgRect.Y + SPACING; // Update Objects if (viewButton != null && showing) { viewButton.Update(); } hideButton.Update(); if (showing) { timer.Update(gameTime); } if (timer.QueryWaitTime(gameTime)) { leaving = true; } #region Entering and Leaving Animation if (entering) { currentDir = enterDir; if (enterDir == EnterDirection.Top) { if (bgRect.Y < SPACING) { bgRect.Y += 2; } else { entering = false; } } else if (enterDir == EnterDirection.Bottom) { if (bgRect.Y > windowHeight - bgRect.Height - SPACING) { bgRect.Y -= 2; } else { entering = false; } } } else if (leaving) { if (bgRect.Y < windowHeight / 2) { if (bgRect.Y >= 0 - bgRect.Height) { bgRect.Y -= 2; } else { leaving = false; showing = false; } } else { if (bgRect.Y < windowHeight) { bgRect.Y += 2; } else { leaving = false; showing = false; } } } #endregion }
public void Update() { toggleButton.Update(); }
public void Update(GameTime gameTime) { if (cursorBlinkTimer.QueryWaitTime(gameTime)) { showCursor = !showCursor; } cursorRectangle.Y = DrawRectangle.Y + CURSOR_SPACING; cursorBlinkTimer.Update(gameTime); textPos.X = DrawRectangle.X + TEXT_EDGE_SPACING_X; textPos.Y = DrawRectangle.Y + TEXT_EDGE_SPACING_Y; if (checkForClickButton != null) { checkForClickButton.X = X; checkForClickButton.Y = Y; checkForClickButton.Update(); } if (Active) { keyboard = Keyboard.GetState(); pressedKeys = keyboard.GetPressedKeys(); key = Microsoft.Xna.Framework.Input.Keys.None; if (pressedKeys.Count() > 0) { var keys = pressedKeys.Where(x => x != Microsoft.Xna.Framework.Input.Keys.LeftShift && x != Microsoft.Xna.Framework.Input.Keys.RightShift && x != Microsoft.Xna.Framework.Input.Keys.LeftControl && x != Microsoft.Xna.Framework.Input.Keys.RightControl && !lastKeys.Contains(x)).ToList(); if (keys.Count > 0) { key = keys[0]; } else if (pressedKeys.Contains(lastKey)) { // Only allow key spamming if there is only one character key pressed key = lastKey; } } keyName = key.ToString(); if (key != Microsoft.Xna.Framework.Input.Keys.None) { // We know at this point that we are typing a key, like Enter or Backspace or a letter, number, or symbol if (!spammingKey) { // We must first check to see if we have been pressing the key before if (lastKeys.Contains(key)) { // We have to check the long timer pressKeysTimerLong.Update(gameTime); if (pressKeysTimerLong.QueryWaitTime(gameTime)) { spammingKey = true; HandleKey(key); } } else { pressKeysTimerLong.Reset(); HandleKey(key); } } else { if (lastKeys.Contains(key)) { pressKeysTimerShort.Update(gameTime); if (pressKeysTimerShort.QueryWaitTime(gameTime)) { // We are pressing & holding a key and can now "spam" it HandleKey(key); } } else { spammingKey = false; } } } lastKey = key; #region Handle Caret Moving if (keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left) && !arrowKeyPrevDown) { arrowKeyPrevDown = true; if (cursorPosition > 0) { cursorRectangle.X -= (int)font.MeasureString(text[cursorPosition - 1].ToString()).X + cursorRectangle.Width; cursorPosition--; } } else if (keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right) && !arrowKeyPrevDown) { arrowKeyPrevDown = true; if (cursorPosition < text.Length) { cursorRectangle.X += (int)font.MeasureString(text[cursorPosition].ToString()).X + cursorRectangle.Width; cursorPosition++; } } else if (!(keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left) || keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right))) { arrowKeyPrevDown = false; } if (keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Home)) { cursorPosition = 0; cursorRectangle.X = DrawRectangle.X + TEXT_EDGE_SPACING_X; } else if (keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.End)) { cursorPosition = text.Length; cursorRectangle.X = DrawRectangle.X + ((int)font.MeasureString(text).X + cursorRectangle.Width); } #endregion #region Paste Support if ((keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftControl) || keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.RightControl)) && keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.V) && !shortcutPreviouslyPressed) { string clipboardText = Clipboard.GetText(); if (!(font.MeasureString(text + clipboardText).X > DrawRectangle.Width)) { // The clipboard text is short enough, and will not extend past the textbox's length text += clipboardText; } shortcutPreviouslyPressed = true; } else if (!((keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftControl) || keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.RightControl)) && keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.V))) { shortcutPreviouslyPressed = false; } #endregion MouseState mouse = Mouse.GetState(); Rectangle mouseRect = new Rectangle(mouse.X, mouse.Y, 1, 1); if (!(DrawRectangle.Intersects(mouseRect)) && mouse.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) { Active = false; } lastKeys = pressedKeys; } }