private void SetStartDialogNormal(int level, int levelsPerStage) { // Show the Quest Dialog if this is the first time playing the first level of a stage int remainder; int stageIndex = Math.DivRem(level, levelsPerStage, out remainder); stageIndex -= remainder == 0 ? 1 : 0; if (remainder == 1) { this.CompletedImage.SetActive(false); string key = string.Format("{0}_{1}", SharedResources.TimesLevelPlayedPrefix, level); int timesPlayed = PlayerPrefsFast.GetInt(key, 0); this.gameObject.SetActive(timesPlayed == 0); for (int i = 0; i < this.StageMapping.Length; i++) { this.StageMapping[i].SetActive(i == stageIndex); } foreach (IdkyKeyValuePairGameObject specialStageMapping in this.SpecialStageMappings) { specialStageMapping.GetValue().SetActive(false); } } }
private void SetStartDialogSpecial(SpecialStage specialStage) { // Show the Quest Dialog if this is the first time playing the a level in the special stage string key = string.Format("{0}_{1}", SharedResources.SpecialStageStartQuestDialogShownKey, specialStage.StageId); bool shown = PlayerPrefsFast.GetBool(key, false); if (!shown) { this.CompletedImage.SetActive(false); this.gameObject.SetActive(true); foreach (GameObject dialog in this.StageMapping) { dialog.SetActive(false); } foreach (IdkyKeyValuePairGameObject specialStageMapping in this.SpecialStageMappings) { specialStageMapping.GetValue().SetActive(specialStageMapping.GetKey().Equals(specialStage.StageId)); } PlayerPrefsFast.SetBool(key, true); PlayerPrefsFast.Flush(); } }
private void InitStoreData() { VirtualCurrencies = StoreInfo.Currencies; VirtualGoods = StoreInfo.Goods; VirtualCurrencyPacks = StoreInfo.CurrencyPacks; VirtualGoodsDictionary = new Dictionary <string, VirtualGood>(); foreach (VirtualGood virtualGood in VirtualGoods) { VirtualGoodsDictionary.Add(virtualGood.ItemId, virtualGood); } this.UpdateStoreBalances(); Debug.Log("GNOME: Notifying Shop Data Initialized"); this.NotifyShopDataInitialized(); // Give 10 tokens for free if it's the first time playing if (PlayerPrefsFast.GetBool(SharedResources.FirstTimeUserKey, true)) { StoreInventory.GiveItem(GnomeStoreAssets.TokenId, 10); PlayerPrefsFast.SetBool(SharedResources.FirstTimeUserKey, false); PlayerPrefsFast.Flush(); } this.NotifyTokensChanged(); }
private void OnEnable() { int timeToComplete = PlayerPrefsFast.GetInt( string.Format("{0}_{1}", SharedResources.TimesLevelPlayedToCompletePrefix, this.level), 0); int levelsUnlocked = PlayerPrefsFast.GetInt(SharedResources.LevelUnlockedKey, 1); this.ButtonCompleted.SetActive(false); this.ButtonCompletedFirstTry.SetActive(false); this.ButtonLocked.SetActive(false); this.ButtonUnlocked.SetActive(false); if (this.level <= levelsUnlocked) { if (timeToComplete == 0) { // Didn't pass level yet this.ButtonUnlocked.SetActive(true); } else if (timeToComplete == 1) { // Passed the level on the first try this.ButtonCompletedFirstTry.SetActive(true); } else { // Passed the level, but not on the first try this.ButtonCompleted.SetActive(true); } } else { // Level still locked this.ButtonLocked.SetActive(true); } }
private void Awake() { if (Instance != null && Instance != this) { Destroy(this.gameObject); } Instance = this; this.Paused = false; // Make sure music and sound fx is on by default if it's never been initialized if (!PlayerPrefsFast.HasKey(this.MusicOptionKey)) { PlayerPrefsFast.SetBool(this.MusicOptionKey, true); PlayerPrefsFast.Flush(); } if (!PlayerPrefsFast.HasKey(this.SoundOptionKey)) { PlayerPrefsFast.SetBool(this.SoundOptionKey, true); PlayerPrefsFast.Flush(); } this.CheckOptions(); this.BackgroundMusicSource = this.gameObject.AddComponent <AudioSource>(); this.BackgroundMusicSource.loop = true; this.ContinuousSoundSource = this.gameObject.AddComponent <AudioSource>(); this.ContinuousSoundSource.loop = true; DontDestroyOnLoad(this.gameObject); }
private void SetCompletedIcons() { // Didn't initialize yet if (this.levelSelectCreator == null) { return; } // Get the first and last level in the stage int lastLevelInStage = this.levelSelectCreator.LevelsPerStage * this.stageNumber; int firstLevelInStage = lastLevelInStage - this.levelSelectCreator.LevelsPerStage + 1; int levelUnlocked = PlayerPrefsFast.GetInt(SharedResources.LevelUnlockedKey, 1); // Stage is completed if the level after the last level in the stage is unlocked bool isStageCompleted = levelUnlocked > lastLevelInStage; // Stage is unlocked if the first level in the stage is unlocked bool isStageUnlocked = levelUnlocked >= firstLevelInStage; // Turn on the appropriate icon this.StageCompletedIcon.SetActive(isStageCompleted); this.StageNotCompletedIcon.SetActive(!isStageCompleted && isStageUnlocked); this.LockedStageIcon.SetActive(!isStageUnlocked); // Enable the button only if the stage is unlocked if (isStageUnlocked) { this.ActivateOnClick.ActivateTarget = this.stageSelectOverrideActivateTarget; this.ActivateOnClick.DeactivateTarget = this.stageSelectOverrideDeactivateTarget; } }
private void OnEnable() { string key = string.Format("{0}_{1}_{2}", SharedResources.TimesLevelPlayedToCompletePrefix, this.stageId, this.level); int timeToComplete = PlayerPrefsFast.GetInt(key, 0); this.ButtonCompleted.SetActive(false); this.ButtonCompletedFirstTry.SetActive(false); this.ButtonUnlocked.SetActive(false); if (timeToComplete == 0) { // Didn't pass level yet this.ButtonUnlocked.SetActive(true); } else if (timeToComplete == 1) { // Passed the level on the first try this.ButtonCompletedFirstTry.SetActive(true); } else { // Passed the level, but not on the first try this.ButtonCompleted.SetActive(true); } }
private void OnClick() { // Log what button the user clicked for rating us GoogleAnalyticsV3.instance.LogEvent(new EventHitBuilder().SetEventCategory("Rating").SetEventAction(this.Option.ToString())); PlayerPrefsFast.SetInt(this.OptionKey, (int)this.Option); PlayerPrefsFast.Flush(); }
public void OnStateChanged(bool state) { // Set the state this.CurrentState = state; this.EnableObjects(); // Save the state PlayerPrefsFast.SetBool(this.OptionKey, state); PlayerPrefsFast.Flush(); SoundManager.Instance.RecheckSounds(); }
private void Awake() { try { this.CurrentState = PlayerPrefsFast.GetBool(this.OptionKey, this.DefaultState); this.EnableObjects(); } catch { // Set a default for this new key this.OnStateChanged(this.DefaultState); } }
private void OnSignedOut(object sender, EventArgs args) { if (Debug.isDebugBuild) { Debug.Log("Signed Out"); } // Signed out, so next time don't silently sign in PlayerPrefsFast.SetBool(this.GooglePlusKey, false); PlayerPrefsFast.Flush(); this.SetActiveState(); }
public void SkipLevel() { #if UNITY_ANDROID // Prevent clicking if the Ad is visible (one of the gotchas for Chartboost on Android) if (AdManager.Instance != null && AdManager.Instance.IsImpressionVisible()) { return; } #endif Dictionary <int, string> mapping = this.specialStageMode ? this.SpecialStage.LevelMapping.Mapping : this.levelMapping.Mapping; // This is already the last level if (this.Level == mapping.Count) { return; } if (this.specialStageMode) { // Special stages always has all levels unlocked this.NextLevel(); } else { // Get the level that's been unlocked int levelUnlocked = PlayerPrefsFast.GetInt(SharedResources.LevelUnlockedKey, this.Level); // If the next level is unlocked, go to the next level if (levelUnlocked > this.Level) { this.NextLevel(); } else { if (ShopManager.Instance.Tokens >= this.SkipLevelCost) { this.UseTokensMessage.text = string.Format("Use {0} tokens to skip this level?", this.SkipLevelCost); // Show Skip Level pop up if there's enough tokens this.UseTokensPopUp.SetActive(true); } else { this.NotEnoughTokensPopUp.SetActive(true); } } } }
public bool EnterHighScore(float score) { bool isNewHighScore = false; float highScore = PlayerPrefsFast.GetFloat(SharedResources.HighScoreKey, 0); if (score > highScore) { isNewHighScore = true; PlayerPrefsFast.SetFloat(SharedResources.HighScoreKey, score); PlayerPrefsFast.Flush(); FacebookManager.Instance.PostHighScore((uint)score); } return(isNewHighScore); }
private void SetEndDialogSpecial(SpecialStage specialStage) { // Show the Quest Dialog if all the special stages are beaten string key = string.Format("{0}_{1}", SharedResources.SpecialStageEndQuestDialogShownKey, specialStage.StageId); bool shown = PlayerPrefsFast.GetBool(key, false); if (!shown) { bool hasLevelIncomplete = false; foreach (int levelInStage in specialStage.LevelMapping.Keys) { string levelKey = string.Format( "{0}_{1}_{2}", SharedResources.TimesLevelPlayedToCompletePrefix, specialStage.StageId, levelInStage); int timesToCompleteLevel = PlayerPrefsFast.GetInt(levelKey, 0); // Check if the level has been completed yet if (timesToCompleteLevel == 0) { hasLevelIncomplete = true; break; } } if (!hasLevelIncomplete) { this.CompletedImage.SetActive(true); this.gameObject.SetActive(true); foreach (GameObject dialog in this.StageMapping) { dialog.SetActive(false); } foreach (IdkyKeyValuePairGameObject specialStageMapping in this.SpecialStageMappings) { specialStageMapping.GetValue().SetActive(specialStageMapping.GetKey().Equals(specialStage.StageId)); } PlayerPrefsFast.SetBool(key, true); PlayerPrefsFast.Flush(); } } }
public void UseTokensAndSkipLevel() { if (ShopManager.Instance.UseTokens(this.SkipLevelCost)) { // Log that the level was skipped with tokens GoogleAnalyticsV3.instance.LogEvent("Levels", "Skipped With Tokens", "Level " + this.Level, 1); // Unlock the next level int levelUnlocked = PlayerPrefsFast.GetInt(SharedResources.LevelUnlockedKey, this.Level); levelUnlocked++; PlayerPrefsFast.SetInt(SharedResources.LevelUnlockedKey, levelUnlocked); PlayerPrefsFast.Flush(); this.SkipLevel(); } }
private void OnSignInSucceeded(object sender, EventArgs args) { if (Debug.isDebugBuild) { Debug.Log("Sign In Succeeded"); } // Successfully signed in, so silently sign in next time PlayerPrefsFast.SetBool(this.GooglePlusKey, true); PlayerPrefsFast.Flush(); /* * if (this.clicked) * { * LevelDataInitializer.InitializeLevels(); * } */ this.clicked = false; this.SetActiveState(); }
private void Start() { // Get the current prize index int index = PlayerPrefsFast.GetInt(this.RewardIndexKey, 0); // Get the last time a reward was given string lastDateString = PlayerPrefsFast.GetString(this.LastDateRewardKey, string.Empty); DateTime lastDate; bool parsed = DateTime.TryParse(lastDateString, out lastDate); if (parsed) { // Give reward after 1 day if (lastDate.AddDays(1) <= DateTime.Now) { // Give reward, and then set it to the next index index++; List <Transform> childRewards = this.RewardsGrid.GetChildList(); // Make sure we don't give more rewards that we hvae set up if (index <= childRewards.Count) { foreach (Transform child in childRewards) { DailyReward dailyReward = child.GetComponent <DailyReward>(); if (dailyReward != null) { dailyReward.SetCurrentReward(index); if (dailyReward.Day == index) { this.centerOnChildTarget = child.GetComponent <UICenterOnChild>(); } } } PlayerPrefsFast.SetInt(this.RewardIndexKey, index); PlayerPrefsFast.SetString(this.LastDateRewardKey, DateTime.Now.ToString()); PlayerPrefsFast.Flush(); this.RewardsGrid.enabled = true; this.RewardsGrid.repositionNow = true; this.refreshGrid = true; } else { this.gameObject.SetActive(false); } } else { this.gameObject.SetActive(false); } } else { // It's the first time, so set the date as now PlayerPrefsFast.SetString(this.LastDateRewardKey, DateTime.Now.ToString()); PlayerPrefsFast.Flush(); this.gameObject.SetActive(false); } }
private void ApplyMove(MovementDirection direction) { Debug.Log(string.Format("Applying move {0}", direction.ToString())); if (this.selectedGamePiece != null && this.selectedGamePiece.GameBlock is IGameBlockParent) { Debug.Log("Applying move"); BlockMovement move; bool moveApplied = this.selectedGamePiece.ApplyMove(null, direction, out move); if (moveApplied) { Debug.Log("Move applied"); this.movesHistory.Push(move); if (this.firstMove) { this.firstMove = false; this.startLevelTime = Time.time; // Update the number of times played string key = this.specialStageMode ? string.Format( "{0}_{1}_{2}", SharedResources.TimesLevelPlayedPrefix, this.SpecialStage.StageId, this.Level) : string.Format("{0}_{1}", SharedResources.TimesLevelPlayedPrefix, this.Level); int timesPlayed = PlayerPrefsFast.GetInt(key, 0); timesPlayed++; PlayerPrefsFast.SetInt(key, timesPlayed); PlayerPrefsFast.Flush(); } this.goToNextLevel = this.GameBoard.IsSolved(); if (this.goToNextLevel) { this.endLevelTime = Time.time; bool fastComplete = this.endLevelTime - this.startLevelTime <= this.FastCompleteTime; // Set the number of times it took to complete this level. Only set this once. string key = this.specialStageMode ? string.Format( "{0}_{1}_{2}", SharedResources.TimesLevelPlayedToCompletePrefix, this.SpecialStage.StageId, this.Level) : string.Format("{0}_{1}", SharedResources.TimesLevelPlayedToCompletePrefix, this.Level); int timesToComplete = PlayerPrefsFast.GetInt(key, 0); if (timesToComplete == 0) { string timesPlayedKey = this.specialStageMode ? string.Format( "{0}_{1}_{2}", SharedResources.TimesLevelPlayedPrefix, this.SpecialStage.StageId, this.Level) : string.Format("{0}_{1}", SharedResources.TimesLevelPlayedPrefix, this.Level); timesToComplete = PlayerPrefsFast.GetInt(timesPlayedKey, 1); PlayerPrefsFast.SetInt(key, timesToComplete); bool beatOnFirstTry = timesToComplete == 1; bool beatOnTooManyTries = timesToComplete >= this.PlayedTooManyTimes; // Give a free token if passed on the first try if (beatOnFirstTry && fastComplete && !this.usedUndo) { ShopManager.Instance.GiveTokens(this.FastCompleteReward); this.ResultsScreenFreeToken.GetComponent <UILabel>().text = string.Format( "You earned {0} free tokens!", this.FastCompleteReward); } else if (beatOnFirstTry && !this.usedUndo) { ShopManager.Instance.GiveTokens(1); this.ResultsScreenFreeToken.GetComponent <UILabel>().text = "You earned a free token!"; } else if (beatOnTooManyTries) { this.PlayedTooManyTimesSounds.SetActive(true); } this.ResultsScreenFreeToken.SetActive(beatOnFirstTry && !usedUndo); } else { // This level has been beaten before, so no free token this.ResultsScreenFreeToken.SetActive(false); this.PlayedTooManyTimesSounds.SetActive(false); } if (!this.specialStageMode) { // Unlock the next level if needed int levelUnlocked = PlayerPrefsFast.GetInt(SharedResources.LevelUnlockedKey, this.Level); if (levelUnlocked <= this.Level) { levelUnlocked++; PlayerPrefsFast.SetInt(SharedResources.LevelUnlockedKey, levelUnlocked); } } // Log how many tries it took to complete the level string levelPlayed = this.specialStageMode ? string.Format("{0}_{1}", this.SpecialStage.StageId, this.Level) : this.Level.ToString(); GoogleAnalyticsV3.instance.LogEvent("Levels", "Completed Level", levelPlayed, timesToComplete); PlayerPrefsFast.Flush(); } } } else { Debug.Log("Gamepiece is null"); } }
private void LoadPuzzleIntoTable() { // Clear the animation queue this.setAnimationQueue.Clear(); // Clear the history this.movesHistory = new Stack <BlockMovement>(); // Fudge Factor so it doesn't use up the whole space, just most of it const float FudgeFactor = .95f; string puzzleName = this.specialStageMode ? this.SpecialStage.LevelMapping.Mapping[this.Level] : this.levelMapping.Mapping[this.Level]; this.GameBoard = GameBoardXmlIo.ReadGameBoard(puzzleName); TutorialMessage tutorial = null; if (!this.specialStageMode) { tutorial = this.Tutorials.FirstOrDefault(t => t.Level == this.Level); } // Set the number of columns IGameBlock[,] trimmedBoard = this.GameBoard.GetTrimmedBoard(); int rows = trimmedBoard.GetLength(0); int columns = trimmedBoard.GetLength(1); this.Table.columns = columns; GamePiece[,] gamePieces = new GamePiece[rows, columns]; // Calculate what is available for width and height float availableWidth = this.TableLimits.localSize.x * FudgeFactor; float availableHeight = this.TableLimits.localSize.y * FudgeFactor; // Show the tutorial if (tutorial != null) { // Account for the size of the tutorial tip availableHeight -= this.TutorialSize; this.TutorialTipStripObject.SetActive(true); this.TutorialTipStripMessage.text = tutorial.Message; } else { this.TutorialTipStripObject.SetActive(false); } availableWidth /= columns; availableHeight /= rows; // Choose the smallest size otherwise it will be too big to fit this.BlockSize = Math.Min((int)Math.Floor(Math.Min(availableWidth, availableHeight)), this.MaxBlockSize); for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { IGameBlock gameBlock = trimmedBoard[i, j]; GamePiece block = NGUITools.AddChild(this.Table.gameObject, this.GamePiece.gameObject).GetComponent <GamePiece>(); block.GameBlock = gameBlock; block.SetBlockSize(this.BlockSize); block.SetAnimationMappings(this.animationMappingsDictionary); block.LoadImage(); block.SubscribeToGameBlockEvents(); if (gameBlock != null) { block.name = string.Format("{0}-{1}: {2}", gameBlock.IndexRow, gameBlock.IndexColumn, gameBlock.GetBlockString()); } else { block.name = "Null Block"; } this.Table.children.Add(block.transform); gamePieces[i, j] = block; } } // Center the table float heightOffset = (float)(rows * this.BlockSize) / 2; float widthOffset = -(float)(columns * this.BlockSize) / 2; this.Table.transform.localPosition = new Vector3(widthOffset, heightOffset + this.VerticalOffset); this.Table.enabled = true; this.Table.repositionNow = true; this.firstMove = true; // Show the indicator that this is the first time the level is played string key = this.specialStageMode ? string.Format("{0}_{1}_{2}", SharedResources.TimesLevelPlayedPrefix, this.SpecialStage.StageId, this.Level) : string.Format("{0}_{1}", SharedResources.TimesLevelPlayedPrefix, this.Level); int timesPlayed = PlayerPrefsFast.GetInt(key, 0); this.FirstTimeIndicator.SetActive(timesPlayed == 0); this.CurrentLevelText.text = string.Format("Level {0}", this.Level); if (!this.specialStageMode) { foreach (TutorialAnimation tutorialAnimation in this.TutorialAnimations) { if (tutorialAnimation.Level == this.Level) { NGUITools.AddChild(gamePieces[tutorialAnimation.Row, tutorialAnimation.Column].gameObject, tutorialAnimation.Animation); } } } }
private void ShowRateUsDialog() { // Don't show it again if it's already shown if (this.shownRateUsDialog) { return; } this.levelsCompleted++; // Only show it after complete a certain number of levels if (this.levelsCompleted >= this.LevelsCompleteBeforeShowingRateUs) { SetRateOptionOnClick.RateOptions rateOption = (SetRateOptionOnClick.RateOptions)PlayerPrefsFast.GetInt(this.RateOptionKey, 0); // Only show it if it's not been rated yet switch (rateOption) { case SetRateOptionOnClick.RateOptions.NotRated: this.RateUsDialog.SetActive(true); break; case SetRateOptionOnClick.RateOptions.Rated: case SetRateOptionOnClick.RateOptions.DoNotShowAgain: break; } // Set the flag so it doesn't try to show the Rate Us dialog again this.shownRateUsDialog = true; } }
private void Start() { SetRateOptionOnClick.RateOptions rateOption = (SetRateOptionOnClick.RateOptions)PlayerPrefsFast.GetInt(this.RateOptionKey, 0); // Only show it if it's not been rated yet switch (rateOption) { case SetRateOptionOnClick.RateOptions.NotRated: this.gameObject.SetActive(true); break; case SetRateOptionOnClick.RateOptions.Rated: case SetRateOptionOnClick.RateOptions.DoNotShowAgain: this.gameObject.SetActive(false); break; } }
private void CheckOptions() { // Check if music and sound fx can be played this.PlayMusic = PlayerPrefsFast.GetBool(this.MusicOptionKey); this.PlaySounds = PlayerPrefsFast.GetBool(this.SoundOptionKey); }
public void SetSpecialStageCompletedIcons(bool unlocked = false) { // Didn't initialize yet if (this.levelSelectCreator == null) { return; } this.IsUnlocked = ShopManager.GoodsBalances[this.specialStage.StageId] > 0 || unlocked; if (this.IsUnlocked) { bool hasLevelIncomplete = false; foreach (int levelInStage in this.specialStage.LevelMapping.Keys) { string key = string.Format( "{0}_{1}_{2}", SharedResources.TimesLevelPlayedToCompletePrefix, this.specialStage.StageId, levelInStage); int timesToCompleteLevel = PlayerPrefsFast.GetInt(key, 0); // Check if the level has been completed yet if (timesToCompleteLevel == 0) { hasLevelIncomplete = true; break; } } this.StageCompletedIcon.SetActive(!hasLevelIncomplete); this.StageNotCompletedIcon.SetActive(hasLevelIncomplete); this.StageLockedIcon.SetActive(false); // Set the stage select activate targets if it's unlocked if (this.ActivateOnClick != null) { this.ActivateOnClick.ActivateTarget = this.stageSelectOverrideActivateTarget; this.ActivateOnClick.DeactivateTarget = this.stageSelectOverrideDeactivateTarget; } } else { SpecialStageLifetimeVg specialStageLifetimeVg = GnomeStoreAssets.GetSpecialStagesStatic()[this.specialStage.StageId]; if (specialStageLifetimeVg != null) { if (specialStageLifetimeVg.CanPurchase) { // Show purchase with tokens pop up this.ActivateOnClick.ActivateTarget = this.purchaseStagePopUp.gameObject; this.ActivateOnClick.DeactivateTarget = this.levelSelectCreator.gameObject; } else { // Show reward only pop up this.ActivateOnClick.ActivateTarget = this.rewardedOnlyPopUp; this.ActivateOnClick.DeactivateTarget = this.levelSelectCreator.gameObject; } } this.StageLockedIcon.SetActive(true); this.StageCompletedIcon.SetActive(false); this.StageNotCompletedIcon.SetActive(false); } }