public void AddItem(HistoryItem item) { //pop in new button at top var newTile = Instantiate(historyTilePrefab, historyPanel.transform, false) as GameObject; var buttonRect = newTile.GetComponent<RectTransform>(); buttonRect.anchoredPosition3D = new Vector3(18.5f, panelTop, 0); var view = newTile.GetComponent<HistoryTileView>(); view.item = item; //view.HistoryHoverSignal = HistoryHoverSignal; float buttonHeight = buttonRect.sizeDelta.y * 1.3f * canvas.scaleFactor; newTile.transform.localScale = Vector3.zero; iTweenExtensions.ScaleTo(newTile, Vector3.one, 1f, 0f, EaseType.easeInOutBounce); //animate everything down foreach (var icon in icons) { iTweenExtensions.MoveToLocal( icon.historyTile, icon.historyTile.transform.localPosition.AddY(-buttonHeight), 1f, 0f ); } var borderGo = newTile.transform.FindChild("Border").gameObject; var cardGo = newTile.transform.FindChild("Card").gameObject; var borderSvg = borderGo.GetComponent<SVGImage>(); var cardSvg = cardGo.GetComponent<SVGImage>(); cardSvg.vectorGraphics = iconMap[item.type]; borderSvg.color = item.initiatingPlayerId != players.OpponentId(turns.currentPlayerId) ? Colors.friendlyColor : Colors.enemyColor; icons.Add(new HistoryIcon() { historyTile = newTile, borderSvg = borderSvg }); //check for popping the end off if (icons.Count > maxItems) { var toRemove = icons[0]; iTweenExtensions.ScaleTo(toRemove.historyTile, scaleOutVec, 1f, 0f, EaseType.easeInCirc); Destroy(toRemove.historyTile, 1f); icons.Remove(toRemove); } }
/// <summary> /// Get or create the current history item for the activating piece Id which the history items are grouped by /// If one doesn't exist, create it with the player and type passed /// </summary> private HistoryItem GetCurrent(int? activatingPieceId, HistoryItemType type, int player) { if (!activatingPieceId.HasValue) { //Dictionary can't store null values as keys so hack it to sentinal activatingPieceId = -1; } if (currentItems.ContainsKey(activatingPieceId)) { return currentItems[activatingPieceId]; } var currentItem = new HistoryItem() { type = type, initiatingPlayerId = player, spellDamage = possibleActions.GetSpellDamage(player), pieceChanges = new List<HistoryPieceChange>(), }; currentItems[activatingPieceId] = currentItem; return currentItem; }