////////////////////////////////////////// /// SetColor() /// Sets the color of this game piece. ////////////////////////////////////////// public void SetColor( AbilityColors i_eColor, Color i_color ) { // set the color on the image for this element Image.color = i_color; // save our color m_eColor = i_eColor; }
////////////////////////////////////////// /// OnResourceGained() /// Callback for when this character gains /// a resource. ////////////////////////////////////////// private void OnResourceGained( AbilityColors i_eResource ) { // loop through all the abilities this char has until we find one that uses the incoming resource foreach ( AbilityView_Draft ability in AbilityViews ) { AbilityColors eResource = ability.GetResourceUsed(); if ( eResource == i_eResource ) ability.GainResource(); } }
////////////////////////////////////////// /// SetColor() /// Sets the color of this game piece. ////////////////////////////////////////// public void SetColor(AbilityColors i_eColor, Color i_color) { // set the color on the image for this element Image.color = i_color; // save our color m_eColor = i_eColor; }
////////////////////////////////////////// /// ChainComplete() /// Called on a game piece when it is /// part of an active chain that is /// completed. ////////////////////////////////////////// public void ChainComplete() { // get the next color in the cycle AbilityColors eColor = GetColor(); AbilityColors eColorNext = GameBoard_Chain.Instance.GetNextColor(eColor); Color colorNext = GameBoard_Chain.Instance.GetAbilityColor(eColorNext); // set that as this piece's color SetColor(eColorNext, colorNext); }
////////////////////////////////////////// /// OnResourceGained() /// Callback for when this character gains /// a resource. ////////////////////////////////////////// private void OnResourceGained(AbilityColors i_eResource) { // loop through all the abilities this char has until we find one that uses the incoming resource foreach (AbilityView_Draft ability in AbilityViews) { AbilityColors eResource = ability.GetResourceUsed(); if (eResource == i_eResource) { ability.GainResource(); } } }
////////////////////////////////////////// /// OnMoveMade() /// Callback for when a player choses a /// game piece on the board. ////////////////////////////////////////// private void OnGamePiecePicked(GamePiece_Draft i_piece) { // what resource did this game piece represent? AbilityColors eResource = i_piece.GetColor(); // grant a resource to whomever is the current player DefaultModel dataChar = TurnManager.Instance.GetCurrentCharacter(); string strMessageKey = "GainResource_" + dataChar.GetPropertyValue <string>("Name"); Messenger.Broadcast <AbilityColors>(strMessageKey, eResource); // a valid move has been taken, so send out a message Messenger.Broadcast("MoveMade"); }
////////////////////////////////////////// /// SetUpBoard() ////////////////////////////////////////// private void SetUpBoard() { // first get all of the pieces GamePiece_Draft[] arrayPieces = gameObject.GetComponentsInChildren <GamePiece_Draft>(); List <GamePiece_Draft> listPieces = new List <GamePiece_Draft>(arrayPieces); foreach (GamePiece_Draft piece in listPieces) { // choose a random color AbilityColors eColor = ListUtils.GetRandomElement <AbilityColors>(ValidColors); Color color = PieceColors[(int)eColor]; // set that color onto the piece piece.SetColor(eColor, color); } }
////////////////////////////////////////// /// GetNextColor() /// Based on the incoming color, returns the /// next color in the cycle. ////////////////////////////////////////// public AbilityColors GetNextColor(AbilityColors i_eColor) { if (i_eColor == AbilityColors.Red) { return(AbilityColors.Black); } else if (i_eColor == AbilityColors.Black) { return(AbilityColors.Blue); } else if (i_eColor == AbilityColors.Blue) { return(AbilityColors.Yellow); } else // yellow { return(AbilityColors.Red); } }
////////////////////////////////////////// /// Init() /// Inits this UI with the incoming /// ability data. ////////////////////////////////////////// public override void Init(AbilityData i_data) { base.Init(i_data); // cache some parts of the view m_goElements = gameObject.FindInChildren("Elements"); m_fDefaultPreferredHeight = gameObject.GetComponent <LayoutElement>().preferredHeight; // listen for messages ListenForMessages(true); // add this ability's description as a tooltip AddTooltip(i_data); // loop through all the required colors of an ability and set the tile to that color // this isn't exactly safe, but I'll make sure # of colors < # of tiles for now for (int i = 0; i < CostTiles.Count; ++i) { // the image on the UI Image image = CostTiles[i]; if (i < m_dataAbility.RequiredColors.Count) { // get the color for this part of the ability AbilityColors eColor = m_dataAbility.RequiredColors[i]; Color color = GameBoard_Chain.Instance.GetAbilityColor(eColor); // set the image to whatever color the ability uses image.color = color; } else { // destroy the image; it's not necessary Destroy(image.gameObject); } } }
public Color GetAbilityColor(AbilityColors i_eColor) { return(PieceColors[(int)i_eColor]); }