void OnApplicationQuit() { if (Keeper.instance != null) { SKDataManager.SaveData(); } }
public SlotList(float width, float height) { _width = width; _height = height; touchableRect = new Rect(-_width / 2, -10000, _width - Config.SLOT_HEIGHT * 2 - Config.PADDING_XS * 2, 20000);//infinite height because thaat's how i doooo _scroller = new RXScroller(0, _minScrollY, _maxScrollY); _touchSlot = Futile.touchManager.GetTouchSlot(0); AddChild(slotContainer = new FContainer()); List <Player> players = SKDataManager.GetPlayers(); for (int p = 0; p < players.Count; p++) { AddSlotForPlayer(players[p], false); } Reorder(false, false); ListenForUpdate(HandleUpdate); _isInitializing = false; }
void OnApplicationPause(bool isPaused) { if (Keeper.instance != null) { SKDataManager.SaveData(); } }
public Keeper() { instance = this; SKDataManager.LoadData(); CellManager.Recalculate(); AddChild(mainContainer = new FContainer()); SetupMegaBoxes(); mainContainer.AddChild(slotList = new SlotList(Config.LIST_WIDTH, Config.HEIGHT)); AddChild(effectContainer = new FContainer()); slotList.SignalPlayerChange += HandlePlayerChange; HandlePlayerChange(); Futile.screen.SignalResize += HandleSignalResize; Futile.instance.SignalLateUpdate += HandleLateUpdate; FSoundManager.PlaySound("UI/Start"); }
public static PlayerColor GetNextUnusedColor() { List <PlayerColor> usedColors = SKDataManager.GetUsedColors(); int c = 0; //remove all the usedColors until we find an unused color (which is really the LEAST used color) while (true) { PlayerColor checkColor = allColors[c % allColors.Count]; //get next color in all int usedIndex = usedColors.IndexOf(checkColor); //if it's already used, then we don't want to use it if (usedIndex == -1) { return(checkColor); } else { usedColors.RemoveAt(usedIndex); } c++; } }
//called by player editor public void RemovePlayerEditor() { EnableMegaBoxes(); EnableList(); isEditorOpen = false; //resume math mode on the player view (if needed) if (playerEditor.slot != null) { playerEditor.slot.ResumeMathMode(); } playerEditor.Destroy(); playerEditor = null; SKDataManager.MarkDirty(); }
public void RemoveSlotForPlayer(Player player, bool shouldDoInstantly, bool shouldReorder) { Slot slotToRemove = GetSlotForPlayer(player); if (slotToRemove == null) { return; } _slots.Remove(slotToRemove); if (shouldDoInstantly) { slotToRemove.Destroy(); } else { float duration = 0.3f; slotToRemove.buildInTweenable.To(0, duration, new TweenConfig().onComplete(slotToRemove.Destroy)); Go.to(slotToRemove, duration, new TweenConfig().floatProp("scale", 0.8f)); } //move all the indexes below it down (so they don't think they have to animate) for (int s = 0; s < _slots.Count; s++) { if (_slots[s].index > slotToRemove.index) { _slots[s].index--; } } if (shouldReorder) { Reorder(false, false); } if (SignalPlayerChange != null) { SignalPlayerChange(); } SKDataManager.MarkDirty(); }
void HandleLateUpdate() { FSoundManager.soundSource.pitch = Time.timeScale; //slow down sounds when time is slow CellManager.Refresh(); SKDataManager.Update(); }
public void Reorder(bool shouldWaitUntilMathModeFinishes, bool shouldScrollToTop, bool isFlipping) { if (_slots.Count == 0) { return; //no need sorting things that don't exist :) } if (shouldWaitUntilMathModeFinishes) { for (int s = 0; s < _slots.Count; s++) { if (_slots[s].scoreBox.mathMode.amount > 0) { return; //don't sort if one of them is in math mode } } } _isFlipping = isFlipping; List <Slot> originalSlots = new List <Slot>(_slots); //create a copy Slot oldWinningSlot = _slots[0]; float totalHeight = _slots.Count * (Config.SLOT_HEIGHT + Config.PADDING_M) - Config.PADDING_M; _minScrollY = Mathf.Min(0, -(totalHeight - _height) / 2 - Config.PADDING_M); _maxScrollY = Mathf.Max(0, (totalHeight - _height) / 2 + Config.PADDING_M); _canScroll = (totalHeight > _height); _slots.Sort(SlotSorter); for (int s = 0; s < _slots.Count; s++) { Slot slot = _slots[s]; slotContainer.AddChildAtIndex(slot, 0); //add at the bottom float newY = totalHeight * 0.5f - Config.SLOT_HEIGHT * 0.5f - (Config.SLOT_HEIGHT + Config.PADDING_M) * s; if (slot.index == -1) //it's new! { slot.y = newY; float delay; if (_isInitializing) { delay = 0.2f + (float)s * 0.1f; } else { delay = _slots.Count == 1 ? 0 : 0.3f; //only delay if there are other players } //note how we make the tween longer AND delay it by the delay. weird effect :) Go.killAllTweensWithTarget(slot.buildInTweenable); Go.to(slot.buildInTweenable, 0.5f + delay, new TweenConfig().floatProp("amount", 1.0f).setDelay(delay)); } else if (slot.index < s) //moving down { Go.killAllTweensWithTarget(slot.buildInTweenable); Go.to(slot.buildInTweenable, 0.5f, new TweenConfig().floatProp("amount", 1.0f)); Go.killAllTweensWithTarget(slot); Go.to(slot, 0.5f, new TweenConfig().floatProp("y", newY).setEaseType(EaseType.ExpoInOut)); float delta = s - slot.index; float scaleAmount = 0.04f + delta * 0.0075f; //slot shrink more the farther it travels downward RXTweenable tw = new RXTweenable(0.0f); tw.SignalChange += () => { slot.scale = 1.0f - scaleAmount * RXEase.UpDown(tw.amount, RXEase.SineIn); }; Go.to(tw, 0.5f, new TweenConfig().floatProp("amount", 1.0f).setEaseType(EaseType.Linear)); } else if (slot.index > s) //moving up { Go.killAllTweensWithTarget(slot.buildInTweenable); Go.to(slot.buildInTweenable, 0.5f, new TweenConfig().floatProp("amount", 1.0f)); Go.killAllTweensWithTarget(slot); Go.to(slot, 0.5f, new TweenConfig().floatProp("y", newY).setEaseType(EaseType.ExpoInOut)); //slot grows more the farther it travels upward float delta = slot.index - s; float scaleAmount = 0.04f + delta * 0.0075f; RXTweenable tw = new RXTweenable(0.0f); tw.SignalChange += () => { slot.scale = 1.0f + scaleAmount * RXEase.UpDown(tw.amount, RXEase.SineIn); }; Go.to(tw, 0.5f, new TweenConfig().floatProp("amount", 1.0f).setEaseType(EaseType.Linear)); } else { if (slot.y != newY) { Go.killAllTweensWithTarget(slot.buildInTweenable); Go.to(slot.buildInTweenable, 0.5f, new TweenConfig().floatProp("amount", 1.0f)); Go.killAllTweensWithTarget(slot); Go.to(slot, 0.5f, new TweenConfig().floatProp("y", newY).setEaseType(EaseType.ExpoInOut)); } } slot.index = s; } bool isThereANewWinner = (oldWinningSlot != _slots[0]); if (isThereANewWinner || shouldScrollToTop) { ScrollToTop(1.0f); } else if (!_canScroll) { ScrollToTop(0.5f); //make sure it's always centered } if (isThereANewWinner) { //TODO: play winner sound _slots[0].player.color.PlayNormalSound(); } if (!RXUtils.AreListsEqual(_slots, originalSlots)) { FSoundManager.PlaySound("UI/Sort"); } SKDataManager.MarkDirty(); _isFlipping = false; }
public ResetGroup(float width) { this.width = width; AddChild(plusBox = new MathBox(MathType.Plus)); AddChild(minusBox = new MathBox(MathType.Minus)); AddChild(zeroBox = new ZeroBox()); AddChild(cancelBox = new SpriteBox(Player.NullPlayer, "Icons/Cancel", 100, 100)); AddChild(okBox = new SpriteBox(Player.NullPlayer, "Icons/Checkmark", 100, 100)); plusBox.hasFastRepeatZones = true; minusBox.hasFastRepeatZones = true; if (PlayerPrefs.HasKey(PREFS_KEY)) { zeroBox.resetAmount = PlayerPrefs.GetInt(PREFS_KEY); } float boxSize = Config.SLOT_HEIGHT; float padding = Config.PADDING_S; plusBox.SetSize(boxSize, boxSize); minusBox.SetSize(boxSize, boxSize); zeroBox.SetSize(width - boxSize * 2 - padding * 2, boxSize); plusBox.SetPosition(zeroBox.width / 2 + padding + plusBox.width / 2, padding / 2 + plusBox.height / 2); minusBox.SetPosition(-zeroBox.width / 2 - padding - minusBox.width / 2, padding / 2 + minusBox.height / 2); zeroBox.SetPosition(0, padding / 2 + zeroBox.height / 2); cancelBox.SetSize((width - padding) / 2, boxSize); okBox.SetSize((width - padding) / 2, boxSize); cancelBox.SetPosition(-padding / 2 - cancelBox.width / 2, -padding / 2 - cancelBox.height / 2); okBox.SetPosition(padding / 2 + okBox.width / 2, -padding / 2 - okBox.height / 2); minusBox.SignalTick += (b, ticks) => { zeroBox.resetAmount -= ticks; UpdateResetAmount(); }; plusBox.SignalTick += (b, ticks) => { zeroBox.resetAmount += ticks; UpdateResetAmount(); }; zeroBox.SignalRelease += (b) => { zeroBox.DoTapEffect(); FSoundManager.PlaySound("UI/ResetToZero"); zeroBox.resetAmount = 0; UpdateResetAmount(); }; cancelBox.SignalRelease += (b) => { Keeper.instance.slotList.ApplyResetScores(false); cancelBox.isTouchable = false; cancelBox.DoTapEffect(); Keeper.instance.EndResetMode(); FSoundManager.PlaySound("UI/Cancel"); }; okBox.SignalRelease += (b) => { Keeper.instance.slotList.ApplyResetScores(true); okBox.isTouchable = false; okBox.DoTapEffect(); Keeper.instance.EndResetMode(); FSoundManager.PlaySound("UI/ResetOk"); SKDataManager.MarkDirty(); }; UpdateResetAmount(); instance = this; }