public void Bind(tnStandardMatchController i_MatchController) { m_MatchController = i_MatchController; // Team 0 - Flag. int team0Id = m_MatchController.GetTeamId(0); tnTeamData team0Data = tnGameData.GetTeamDataMain(team0Id); if (team0Data != null) { SetFlagTeam0(team0Data.icon); } // Team 1 - Flag. int team1Id = m_MatchController.GetTeamId(1); tnTeamData team1Data = tnGameData.GetTeamDataMain(team1Id); if (team1Data != null) { SetFlagTeam1(team1Data.icon); } }
// INTERNALS private void InternalSetResults(tnStandardMatchController i_MathController) { if (i_MathController == null) { return; } // Team 0 tnStandardMatchTeamResults teamResults0 = (tnStandardMatchTeamResults)i_MathController.GetTeamResultsByIndex(0); if (teamResults0 != null) { int teamId0 = teamResults0.id; tnTeamData teamData0 = tnGameData.GetTeamDataMain(teamId0); if (m_Team0Flag != null) { m_Team0Flag.sprite = teamData0.flag; } if (m_Team0Name != null) { m_Team0Name.text = teamData0.name; } if (m_Team0Score != null) { m_Team0Score.text = teamResults0.score.ToString(); } } // Team 1 tnStandardMatchTeamResults teamResults1 = (tnStandardMatchTeamResults)i_MathController.GetTeamResultsByIndex(1); if (teamResults1 != null) { int teamId1 = teamResults1.id; tnTeamData teamData1 = tnGameData.GetTeamDataMain(teamId1); if (m_Team1Flag != null) { m_Team1Flag.sprite = teamData1.flag; } if (m_Team1Name != null) { m_Team1Name.text = teamData1.name; } if (m_Team1Score != null) { m_Team1Score.text = teamResults1.score.ToString(); } } }
// tnMatchResultsController's INTERFACE protected override void ShowResults(tnMatchController i_Controller) { base.ShowResults(i_Controller); if (i_Controller == null) { return; } tnStandardMatchController matchController = (tnStandardMatchController)i_Controller; InternalSetResults(matchController); }
// LOGIC public void Config(tnStandardMatchController i_Controller) { if (viewInstance != null) { if (i_Controller == null) { return; } // Team 0 tnStandardMatchTeamResults teamResults0 = (tnStandardMatchTeamResults)i_Controller.GetTeamResultsByIndex(0); if (teamResults0 != null) { int teamId0 = teamResults0.id; tnTeamData teamData0 = tnGameData.GetTeamDataMain(teamId0); string name = teamData0.name; int score = teamResults0.score; Sprite flag = teamData0.flag; viewInstance.SetTeam0(name, score, flag); } // Team 1 tnStandardMatchTeamResults teamResults1 = (tnStandardMatchTeamResults)i_Controller.GetTeamResultsByIndex(1); if (teamResults1 != null) { int teamId1 = teamResults1.id; tnTeamData teamData1 = tnGameData.GetTeamDataMain(teamId1); string name = teamData1.name; int score = teamResults1.score; Sprite flag = teamData1.flag; viewInstance.SetTeam1(name, score, flag); } } }
private void FillGoalScoredData(int i_SlotIndex, tnStandardMatchController i_MatchController) { if (i_MatchController == null) { return; } int charcatersCount = i_MatchController.charactersCount; // Compute total shots count. int totalGoalScored = 0; for (int characterIndex = 0; characterIndex < charcatersCount; ++characterIndex) { tnStandardMatchCharacterResults characterResults = (tnStandardMatchCharacterResults)i_MatchController.GetCharacterResultsByIndex(characterIndex); if (characterResults != null) { totalGoalScored += characterResults.goalScored; } } // Get best character for this stat. int selectedCharacterIndex = -1; int selectedCharacterId = Hash.s_NULL; int maxGoalScored = int.MinValue; for (int characterIndex = 0; characterIndex < charcatersCount; ++characterIndex) { tnStandardMatchCharacterResults characterResults = (tnStandardMatchCharacterResults)i_MatchController.GetCharacterResultsByIndex(characterIndex); if (characterResults != null) { int characterGoalScored = characterResults.goalScored; if (characterGoalScored > maxGoalScored) { selectedCharacterIndex = characterIndex; selectedCharacterId = characterResults.id; maxGoalScored = characterGoalScored; } } } if (selectedCharacterIndex < 0) { return; } // Get team color. Color teamColor = Color.white; GameObject characterGo = i_MatchController.GetCharacterByIndex(selectedCharacterIndex); if (characterGo != null) { tnCharacterInfo characterInfo = characterGo.GetComponent <tnCharacterInfo>(); if (characterInfo != null) { teamColor = characterInfo.teamColor; } } // Fill data. string playerName = ""; Sprite playerPortrait = null; { tnCharacterData characterData = tnGameData.GetCharacterDataMain(selectedCharacterId); if (characterData != null) { playerName = characterData.displayName; playerPortrait = characterData.uiIconFacingRight; } } string statValue = maxGoalScored.ToString(); float partecipationPercentage = 0f; if (totalGoalScored > 0) { partecipationPercentage = (float)maxGoalScored / (float)totalGoalScored; partecipationPercentage *= 100f; partecipationPercentage = Mathf.Clamp(partecipationPercentage, 0f, 100f); } string partecipationValue = partecipationPercentage.ToString("0.00"); partecipationValue += "%"; FillData(i_SlotIndex, playerName, playerPortrait, teamColor, s_StatName_GoalScored, statValue, s_PartecipationLabel, partecipationValue); }
// INTERNALS private void Internal_Config(tnStandardMatchController i_MatchController) { if (viewInstance == null) { return; } viewInstance.DisableAllEntries(); if (i_MatchController == null) { return; } int charactersCount = i_MatchController.charactersCount; int statsCount = Mathf.Max(1, charactersCount /* / 2*/); // Select N random stats. int[] statsIndices = SelectStats(statsCount); for (int index = 0; index < statsIndices.Length; ++index) { // Get target stat index. int statIndex = statsIndices[index]; StatType statType = (StatType)statIndex; switch (statType) { case StatType.AttractTime: FillAttractTimeData(index, i_MatchController); break; case StatType.BallTouches: FillBallTouchesData(index, i_MatchController); break; case StatType.DashCount: FillDashCountData(index, i_MatchController); break; case StatType.DistanceRun: FillDistanceRunData(index, i_MatchController); break; case StatType.GoalScored: FillGoalScoredData(index, i_MatchController); break; case StatType.Shots: FillShotsData(index, i_MatchController); break; case StatType.ShotsOnTarget: FillShotsOnTarget(index, i_MatchController); break; case StatType.Tackles: FillTacklesData(index, i_MatchController); break; } } }
// LOGIC public void Config(tnStandardMatchController i_MatchController) { Internal_Config(i_MatchController); }