void WriteJudgeNamesXml(XmlWriter writer, int PoolIndex)
    {
        ResultsData RData = TournamentData.FindResultsData((EDivision)CurDivIndex, (ERound)CurRoundIndex, (EPool)PoolIndex);

        int ExCount = RData.ExJudgeIds.Count;

        for (int ExIndex = 0; ExIndex < ExCount; ++ExIndex)
        {
            string JudgeName = NameDatabase.FindInDatabase(RData.ExJudgeIds[ExIndex]).DisplayName;
            writer.WriteElementString("ns2:Ex" + (ExIndex + 1), JudgeName);
        }

        int AiCount = RData.AIJudgeIds.Count;

        for (int AiIndex = 0; AiIndex < AiCount; ++AiIndex)
        {
            string JudgeName = NameDatabase.FindInDatabase(RData.AIJudgeIds[AiIndex]).DisplayName;
            writer.WriteElementString("ns2:Ai" + (AiIndex + 1), JudgeName);
        }

        int DiffCount = RData.DiffJudgeIds.Count;

        for (int DiffIndex = 0; DiffIndex < DiffCount; ++DiffIndex)
        {
            string JudgeName = NameDatabase.FindInDatabase(RData.DiffJudgeIds[DiffIndex]).DisplayName;
            writer.WriteElementString("ns2:Diff" + (DiffIndex + 1), JudgeName);
        }
    }
Example #2
0
    string GetBackupDisplayString(BackupAIData bd)
    {
        TeamData td            = Global.GetTeamData(bd.Data.Division, bd.Data.Round, bd.Data.Pool, bd.Data.Team);
        string   TeamName      = td != null ? td.PlayerNames : "Missing Team";
        NameData JudgeNameData = NameDatabase.FindInDatabase(bd.Data.JudgeNameId);
        string   JudgeName     = JudgeNameData != null ? JudgeNameData.DisplayName : "Missing Judge";
        string   BackupStr     = JudgeName + "  " + bd.Data.Division.ToString() + " " + bd.Data.Round.ToString() + " " +
                                 (char)(bd.Data.Pool + 'A') + " | " + TeamName + " | " + bd.WrittenTime.ToString();

        return(BackupStr);
    }
Example #3
0
 void GetPlayersFromString(string InLine, ref List <PlayerData> OutPlayers)
 {
     for (int PlayerIndex = 0; PlayerIndex < AllPlayers.Count; ++PlayerIndex)
     {
         PlayerData Data = AllPlayers[PlayerIndex];
         if (NameDatabase.FindInDatabase(Data.NameId).IsInLine(InLine))
         {
             OutPlayers.Add(Data);
         }
     }
 }
Example #4
0
    public static NameData TryAddNewName(string InFirstName, string InLastName)
    {
        NameData NewName = NameDatabase.FindInDatabase(InFirstName, InLastName);

        if (NewName == null)
        {
            NewName = new NameData(InFirstName, InLastName);
            Global.AllNameData.AllNames.Add(NewName);

            Global.AllNameData.Save();
        }

        return(NewName);
    }
    void DrawJudgeLabel(ResultsData InRData, int InId)
    {
        GUIStyle JudgeStyle = new GUIStyle("label");

        JudgeStyle.fontSize = 15;
        GUIStyle LabelStyle = new GUIStyle("label");
        NameData NData      = NameDatabase.FindInDatabase(InId);

        if (NData != null)
        {
            string           Str    = NData.DisplayName;
            NetworkJudgeData NJData = GetJudgeDataFromNameId(InRData, NData.Id);
            //Debug.Log(" asdf: " + InRData.AIJudgeIds[0] + "   " + NData.Id + "  " + InId);
            if (NJData != null)
            {
                if (NJData.bJudging)
                {
                    JudgeStyle.normal.textColor = Color.yellow;
                    Str += " - JUDGING";
                }
                else if (NJData.bLocked)
                {
                    JudgeStyle.normal.textColor = Color.green;
                    Str += " - LOCKED";
                }
                else if (NJData.bIsHoldReady)
                {
                    JudgeStyle.normal.textColor = Color.green;
                    Str += " - READY";
                }
                else if (NJData.bEditing)
                {
                    JudgeStyle.normal.textColor = Color.yellow;
                    Str += " - EDITING";
                }
                else
                {
                    JudgeStyle.normal.textColor = Color.red;
                    Str += " - NOT READY";
                }
            }
            else
            {
                JudgeStyle.normal.textColor = LabelStyle.normal.textColor;
                Str += " - NOT CONNECTED";
            }
            GUILayout.Label(Str, JudgeStyle);
        }
    }
    string GetBackupDisplayString(BackupDiffData bd)
    {
        if (bd.Data == null)
        {
            Debug.Log(String.Format(" {0}, {1}, {2} ", bd != null, bd != null && bd.Data != null, bd != null && bd.Data != null ? (int)bd.Data.Pool : 0));
        }

        TeamData td            = Global.GetTeamData(bd.Data.Division, bd.Data.Round, bd.Data.Pool, bd.Data.Team);
        string   TeamName      = td != null ? td.PlayerNames : "Missing Team";
        NameData JudgeNameData = NameDatabase.FindInDatabase(bd.Data.JudgeNameId);
        string   JudgeName     = JudgeNameData != null ? JudgeNameData.DisplayName : "Missing Judge";
        string   BackupStr     = JudgeName + "  " + bd.Data.Division.ToString() + " " + bd.Data.Round.ToString() + " " +
                                 (char)(bd.Data.Pool + 'A') + " | " + TeamName + " | " + bd.WrittenTime.ToString();

        return(BackupStr);
    }
Example #7
0
    // Update is called once per frame
    public void Update()
    {
        UpdateQuitGesture();

        Global.NetObj.UpdateUdpListener();

        Global.NetObj.UpdateClientJudgeState();

        if (bIsJudging && HeaderDrawer.RoutineTime / 60f >= GetRoutineLengthMinutes())
        {
            bRoutineTimeEnded = true;
        }

        TestReadyTimer -= Time.deltaTime;

        if (Global.AllData == null || Global.AllNameData == null)
        {
            return;
        }

        if (CurPool != EPool.None)
        {
            int NameId = GetJudgeNameId();
            if (NameId != -1)
            {
                HeaderDrawer.JudgeName = NameDatabase.FindInDatabase(NameId).DisplayName;
            }
        }

        HeaderDrawer.DivisionString        = CurDivision.ToString();
        HeaderDrawer.RoutineTime           = bIsJudging ? (float)(DateTime.Now - RoutineStartTime).TotalSeconds : 0;
        HeaderDrawer.bShowReadyButton      = bHeadJudgeRequestingReady && !bLockedForJudging && !bRoutineTimeEnded && !bClientReadyToBeLocked;
        HeaderDrawer.bShowFinishedButton   = bRoutineTimeEnded;
        HeaderDrawer.WaitingForJudgesCount = WaitingForJudgesCount;
        HeaderDrawer.bShowWaitingForJudges = WaitingForJudgesCount > 0 && !bLockedForJudging &&
                                             !bIsJudging && !HeaderDrawer.bShowFinishedButton && !HeaderDrawer.bShowReadyButton && !bIsEditing;

        bIsDataDirty = false;
    }
Example #8
0
    public string GetResultsString(int InResultIndex, ECategoryView InCat, bool bInIncludeName, List <RoutineScoreData> sortedScores)
    {
        switch (InCat)
        {
        case ECategoryView.AI:
            if (InResultIndex < AIResults.Count)
            {
                return(System.String.Format((bInIncludeName ? "{6}:  " : "") + "V: {0:0.0}  T: {1:0.0}  M: {2:0.0}  Fw: {3:0.0}  Fm: {4:0.0}  G: {5:0.0}  Total: {7:0.00}",
                                            AIResults[InResultIndex].Variety, AIResults[InResultIndex].Teamwork, AIResults[InResultIndex].Music, AIResults[InResultIndex].Flow,
                                            AIResults[InResultIndex].Form, AIResults[InResultIndex].General,
                                            NameDatabase.FindInDatabase(AIResults[InResultIndex].JudgeNameId).DisplayName, AIResults[InResultIndex].GetTotalPoints()));
            }
            break;

        case ECategoryView.Ex:
            if (InResultIndex < ExResults.Count)
            {
                return(System.String.Format((bInIncludeName ? "{4}:  " : "") + ".1: {0}  .2: {1}  .3: {2}  .5: {3}  Total: {5:0.00}", ExResults[InResultIndex].Point1Count, ExResults[InResultIndex].Point2Count,
                                            ExResults[InResultIndex].Point3Count, ExResults[InResultIndex].Point5Count,
                                            NameDatabase.FindInDatabase(ExResults[InResultIndex].JudgeNameId).DisplayName, ExResults[InResultIndex].GetTotalPoints()));
            }
            break;

        case ECategoryView.Diff:
            if (InResultIndex < DiffResults.Count)
            {
                string Ret = bInIncludeName ? NameDatabase.FindInDatabase(DiffResults[InResultIndex].JudgeNameId).DisplayName + ":  " : "";
                for (int i = 0; i < DiffResults[InResultIndex].NumScores; ++i)
                {
                    Ret += DiffResults[InResultIndex].DiffScores[i].ToString("0.0") + DiffResults[InResultIndex].GetConsecString(i) +
                           ((i < DiffResults[InResultIndex].NumScores - 1) ? ", " : "");
                }
                Ret += "  Total: " + DiffResults[InResultIndex].GetTotalPoints().ToString("0.00");
                return(Ret);
            }
            break;

        case ECategoryView.Overview:
        {
            string Ret      = "";
            float  AIPoints = 0;
            foreach (AIData aid in AIResults)
            {
                AIPoints += aid.GetTotalPoints();
                Ret      += "  AI: " + aid.GetTotalPoints().ToString("0.00");
            }
            float ExPoints = 0;
            foreach (ExData exd in ExResults)
            {
                ExPoints += exd.GetTotalPoints();
                Ret      += "  Ex: " + exd.GetTotalPoints().ToString("0.00");
            }
            float DiffPoints = 0;
            foreach (DiffData dd in DiffResults)
            {
                DiffPoints += dd.GetTotalPoints();
                Ret        += "  Diff: " + dd.GetTotalPoints().ToString("0.00");
            }
            float TotalPoints = AIPoints + ExPoints + DiffPoints;
            if (TotalPoints > 0)
            {
                int resultIndex = 0;
                if (sortedScores != null)
                {
                    foreach (RoutineScoreData score in sortedScores)
                    {
                        if (score == this)
                        {
                            break;
                        }

                        ++resultIndex;
                    }
                }

                Ret += "    Totals:  Diff: " + DiffPoints.ToString("0.00") + " AI: " + AIPoints.ToString("0.00") + " Ex: " +
                       ExPoints.ToString("0.00") + " All: " + TotalPoints.ToString("0.00") + "   Place: " + (resultIndex + 1);
            }

            return(Ret);
        }
        }

        return("");
    }
Example #9
0
    void OnGUI()
    {
        bool bRepaintUpdate = Event.current.ToString() == "Repaint";

        if (GUI.Button(new Rect(Screen.width - 150, Screen.height - 150, 150, 150), "Save"))
        {
            Global.AllData.Save();
        }

        float StartSelectY = 30;
        float SelectHeight = 30;

        DivisionCombo.Draw(new Rect(20, StartSelectY, Screen.width * .18f, SelectHeight));
        RoundCombo.Draw(new Rect(20 + Screen.width * .2f, StartSelectY, Screen.width * .18f, SelectHeight));

        GUILayout.BeginArea(new Rect(20 + Screen.width * .4f, StartSelectY, Screen.width - Screen.width * .4f - 40, SelectHeight));
        GUILayout.BeginHorizontal();

        List <PoolData> Pools = Global.AllData.AllDivisions[DivisionCombo.GetSelectedItemIndex()].Rounds[RoundCombo.GetSelectedItemIndex()].Pools;

        for (int PoolIndex = 0; PoolIndex < Pools.Count; ++PoolIndex)
        {
            DrawPoolButton("Pool: " + Pools[PoolIndex].PoolName, PoolIndex, SelectHeight);
        }

        GUILayout.EndHorizontal();
        GUILayout.EndArea();

        float RightRectStartY = Screen.height * .02f + SelectHeight + StartSelectY;
        Rect  RightRect       = new Rect(20, RightRectStartY, Screen.width * .3f, Screen.height - RightRectStartY - 20);
        Rect  LeftRect        = new Rect(RightRect.x + RightRect.width + Screen.width * .1f, RightRect.y, RightRect.width, Screen.height * .5f);

        if (CurPoolButtonIndex != -1)
        {
            ResultsData RData = TournamentData.FindResultsData((EDivision)DivisionCombo.GetSelectedItemIndex(), (ERound)RoundCombo.GetSelectedItemIndex(), (EPool)CurPoolButtonIndex);
            if (RData == null)
            {
                RData = new ResultsData((EDivision)DivisionCombo.GetSelectedItemIndex(), (ERound)RoundCombo.GetSelectedItemIndex(), (EPool)CurPoolButtonIndex);
                Pools[CurPoolButtonIndex].JudgersId = RData.Id;

                Global.AllData.ResultsList.Add(RData);
            }
            else if (Pools[CurPoolButtonIndex].JudgersId == -1)
            {
                if (RData.Id == -1)
                {
                    RData.Id = ResultsData.GetUniqueId();
                }

                Pools[CurPoolButtonIndex].JudgersId = RData.Id;
            }


            if (RData != null && Global.AllNameData.AllJudges != null)
            {
                GUILayout.BeginArea(RightRect);
                RightScroll = GUILayout.BeginScrollView(RightScroll);
                GUILayout.BeginVertical();

                string NewFilterStr = GUILayout.TextField(JudgeFilterStr);

                if (NewFilterStr != JudgeFilterStr || AvailableJudges.Count == 0)
                {
                    JudgeFilterStr = NewFilterStr;

                    AvailableJudges.Clear();
                    foreach (NameData pd in Global.AllNameData.AllJudges)
                    {
                        if (!IsPlayingInPool(pd, RData) && !RData.ContainsPlayer(pd))
                        {
                            AvailableJudges.Add(pd);
                        }
                    }

                    FilterAvailableJudges(JudgeFilterStr, ref AvailableJudges);
                }

                GUILayout.Space(20);

                GUIStyle LabelStyle  = new GUIStyle("label");
                GUIStyle PlayerStyle = new GUIStyle("label");
                PlayerStyle.alignment = TextAnchor.MiddleLeft;
                foreach (NameData nd in AvailableJudges)
                {
                    bool bMoving = MovingNameId == nd.Id;
                    PlayerStyle.normal.textColor = bMoving ? Color.grey : LabelStyle.normal.textColor;

                    GUIContent PlayerCont = new GUIContent(nd.DisplayName);
                    Vector2    PlayerSize = PlayerStyle.CalcSize(PlayerCont);
                    if (GUILayout.RepeatButton(PlayerCont, PlayerStyle, GUILayout.Width(RightRect.width * .9f), GUILayout.Height(PlayerSize.y)))
                    {
                        MovingNameId = nd.Id;
                    }
                }

                GUILayout.EndVertical();
                GUILayout.EndScrollView();
                GUILayout.EndArea();


                // Left Rect ------------
                GUILayout.BeginArea(LeftRect);
                GUILayout.BeginVertical();
                GUIStyle JudgeStyle = new GUIStyle("label");
                JudgeStyle.alignment = TextAnchor.MiddleLeft;

                GUILayout.BeginVertical();
                GUILayout.Label("AI Judges:", JudgeStyle);
                for (int PlayerIndex = 0; PlayerIndex < Mathf.Max(RData.AIJudgeIds.Count, 3); ++PlayerIndex)
                {
                    int    PlayerId  = -1;
                    bool   bMoving   = false;
                    string PlayerStr = PlayerIndex < 3 ? (PlayerIndex + 1) + ". " : "";
                    if (PlayerIndex < RData.AIJudgeIds.Count)
                    {
                        PlayerId = RData.AIJudgeIds[PlayerIndex];
                        bMoving  = PlayerId == MovingNameId;

                        PlayerStr += NameDatabase.FindInDatabase(PlayerId).DisplayName;
                    }

                    JudgeStyle.normal.textColor = bMoving ? Color.grey : LabelStyle.normal.textColor;

                    GUIContent JudgeCont = new GUIContent(PlayerStr);
                    Vector2    JudgeSize = JudgeStyle.CalcSize(JudgeCont);
                    if (GUILayout.RepeatButton(JudgeCont, JudgeStyle, GUILayout.Width(LeftRect.width * .6f), GUILayout.Height(JudgeSize.y)) && PlayerIndex < RData.AIJudgeIds.Count)
                    {
                        MovingNameId = PlayerId;
                    }
                }
                GUILayout.EndVertical();
                if (bRepaintUpdate)
                {
                    JudgeRects[0]   = GUILayoutUtility.GetLastRect();
                    JudgeRects[0].x = LeftRect.x;
                    JudgeRects[0].y = LeftRect.y;
                }

                GUILayout.BeginVertical();
                GUILayout.Label("Ex Judges:", JudgeStyle);
                for (int PlayerIndex = 0; PlayerIndex < Mathf.Max(RData.ExJudgeIds.Count, 3); ++PlayerIndex)
                {
                    int    PlayerId  = -1;
                    bool   bMoving   = false;
                    string PlayerStr = PlayerIndex < 3 ? (PlayerIndex + 1) + ". " : "";
                    if (PlayerIndex < RData.ExJudgeIds.Count)
                    {
                        PlayerId = RData.ExJudgeIds[PlayerIndex];
                        bMoving  = PlayerId == MovingNameId;

                        PlayerStr += NameDatabase.FindInDatabase(PlayerId).DisplayName;
                    }

                    JudgeStyle.normal.textColor = bMoving ? Color.grey : LabelStyle.normal.textColor;

                    GUIContent JudgeCont = new GUIContent(PlayerStr);
                    Vector2    JudgeSize = JudgeStyle.CalcSize(JudgeCont);
                    if (GUILayout.RepeatButton(JudgeCont, JudgeStyle, GUILayout.Width(LeftRect.width * .6f), GUILayout.Height(JudgeSize.y)) && PlayerIndex < RData.ExJudgeIds.Count)
                    {
                        MovingNameId = PlayerId;
                    }
                }
                GUILayout.EndVertical();
                if (bRepaintUpdate)
                {
                    JudgeRects[1]    = GUILayoutUtility.GetLastRect();
                    JudgeRects[1].x += LeftRect.x;
                    JudgeRects[1].y += LeftRect.y;
                }

                GUILayout.BeginVertical();
                GUILayout.Label("Diff Judges:", JudgeStyle);
                for (int PlayerIndex = 0; PlayerIndex < Mathf.Max(RData.DiffJudgeIds.Count, 3); ++PlayerIndex)
                {
                    int    PlayerId  = -1;
                    bool   bMoving   = false;
                    string PlayerStr = PlayerIndex < 3 ? (PlayerIndex + 1) + ". " : "";
                    if (PlayerIndex < RData.DiffJudgeIds.Count)
                    {
                        PlayerId = RData.DiffJudgeIds[PlayerIndex];
                        bMoving  = PlayerId == MovingNameId;

                        PlayerStr += NameDatabase.FindInDatabase(PlayerId).DisplayName;
                    }

                    JudgeStyle.normal.textColor = bMoving ? Color.grey : LabelStyle.normal.textColor;

                    GUIContent JudgeCont = new GUIContent(PlayerStr);
                    Vector2    JudgeSize = JudgeStyle.CalcSize(JudgeCont);
                    if (GUILayout.RepeatButton(JudgeCont, JudgeStyle, GUILayout.Width(LeftRect.width * .6f), GUILayout.Height(JudgeSize.y)) && PlayerIndex < RData.DiffJudgeIds.Count)
                    {
                        MovingNameId = PlayerId;
                    }
                }
                GUILayout.EndVertical();
                if (bRepaintUpdate)
                {
                    JudgeRects[2]    = GUILayoutUtility.GetLastRect();
                    JudgeRects[2].x += LeftRect.x;
                    JudgeRects[2].y += LeftRect.y;
                }

                GUILayout.EndVertical();
                GUILayout.EndArea();

                if (MovingNameId != -1)
                {
                    GUI.Label(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, 500, 30), NameDatabase.FindInDatabase(MovingNameId).DisplayName);
                }
            }
        }

        float BottomRectX = RightRect.x + RightRect.width + 20;
        float BottomRectY = LeftRect.y + LeftRect.height;

        GUILayout.BeginArea(new Rect(BottomRectX, BottomRectY, Screen.width - BottomRectX - 170, Screen.height - BottomRectY - 20));
        GUILayout.Label("All Judges Names");
        AllJudgesTextScrollPos = GUILayout.BeginScrollView(AllJudgesTextScrollPos);
        string NewAllJudgesString = GUILayout.TextArea(AllJudgesString);

        if (NewAllJudgesString != AllJudgesString)
        {
            AllJudgesString = NewAllJudgesString;
            AvailableJudges.Clear();
            Global.AllNameData.AllJudges.Clear();

            StringReader reader = new StringReader(AllJudgesString);
            string       line   = null;
            while ((line = reader.ReadLine()) != null)
            {
                AddJudgersFromString(line);
            }

            Global.AllNameData.Save();
        }
        GUILayout.EndScrollView();
        GUILayout.EndArea();
    }
    void ExportScheduleToExcel()
    {
        if (CurDivIndex != -1 && CurRoundIndex != -1 && File.Exists(ExcelPath))
        {
            StringWriter OutStr = new StringWriter();

            OutStr.WriteLine((EDivision)(CurDivIndex) + " - " + (ERound)(CurRoundIndex) + "\t\tJudges");
            List <PoolData> Pools     = Global.AllData.AllDivisions[CurDivIndex].Rounds[CurRoundIndex].Pools;
            int             PoolIndex = 0;
            foreach (PoolData pd in Pools)
            {
                OutStr.WriteLine("Pool " + pd.PoolName + "\t\tAI\tEx\tDiff");
                ResultsData JData = TournamentData.FindResultsData((EDivision)CurDivIndex, (ERound)CurRoundIndex, (EPool)PoolIndex);

                int TeamNum = 0;
                foreach (TeamDataDisplay tdd in pd.Teams)
                {
                    ++TeamNum;
                    OutStr.Write(TeamNum + ": " + tdd.Data.PlayerNames + "\t\t");

                    if (JData != null)
                    {
                        int NameId = JData.GetNameId(ECategory.AI, TeamNum - 1);
                        if (NameId != -1)
                        {
                            OutStr.Write(NameDatabase.FindInDatabase(NameId).DisplayName);
                        }
                        OutStr.Write("\t");

                        NameId = JData.GetNameId(ECategory.Ex, TeamNum - 1);
                        if (NameId != -1)
                        {
                            OutStr.Write(NameDatabase.FindInDatabase(NameId).DisplayName);
                        }
                        OutStr.Write("\t");

                        NameId = JData.GetNameId(ECategory.Diff, TeamNum - 1);
                        if (NameId != -1)
                        {
                            OutStr.Write(NameDatabase.FindInDatabase(NameId).DisplayName);
                        }
                        OutStr.WriteLine("\t");
                    }
                }

                OutStr.WriteLine();

                ++PoolIndex;
            }

            int    TempNum      = 0;
            string TempFilePath = Application.persistentDataPath + "/TempExcelStr.txt";
            if (File.Exists(TempFilePath))
            {
                bool bDeletedFile = false;
                while (!bDeletedFile)
                {
                    try
                    {
                        File.Delete(TempFilePath);

                        bDeletedFile = true;
                    }
                    catch
                    {
                        TempFilePath = Application.persistentDataPath + "/TempExcelStr-" + TempNum++ + ".txt";
                    }
                }
            }
            StreamWriter TempFile = new StreamWriter(TempFilePath);
            TempFile.Write(OutStr.ToString());
            TempFile.Close();
            OutStr.Close();

            TempFilePath = TempFilePath.Replace('/', '\\');
            Process.Start(ExcelPath, "\"" + TempFilePath + "\"");
        }
    }
    void OnGUI()
    {
        if (!bIsEditing)
        {
            CatCombo.List(new Rect(20, Screen.height * .03f, Screen.width * .18f, Screen.height * .07f),
                          CatComboList[CatCombo.GetSelectedItemIndex()], CatComboList, CatComboStyle);

            if (CatPickingFrameUpdate != Time.frameCount)
            {
                CatPickingFrameUpdate = Time.frameCount;
                bCatPicking           = CatCombo.IsPicking;
            }
        }

        if (bInEditingMode && CatCombo.GetSelectedItemIndex() == 3)
        {
            bInEditingMode  = false;
            bIsEditing      = false;
            EditAIData      = null;
            EditExData      = null;
            EditDiffData    = null;
            bEditAddNewData = false;
        }

        if (!bIsEditing && GUI.Button(new Rect(Screen.width * .3f, Screen.height * .04f, Screen.width * .25f, Screen.height * .07f), "Export SCHEDULE to Excel"))
        {
            ExportScheduleToExcel();
        }

        if (!bIsEditing && GUI.Button(new Rect(Screen.width * .56f, Screen.height * .04f, Screen.width * .23f, Screen.height * .07f), "Export RESULTS to Excel"))
        {
            ExportResultsToExcel();
        }

        if (GUI.Button(new Rect(Screen.width * .83f, Screen.height * .04f, Screen.width * .17f - 20, Screen.height * .07f), "Send All Teams to Livestream"))
        {
            LiveStream.TeamList teamList = new LiveStream.TeamList();
            EDivision           division = EDivision.Open;
            foreach (DivisionData dd in Global.AllData.AllDivisions)
            {
                ERound round = ERound.Finals;
                foreach (RoundData rd in dd.Rounds)
                {
                    EPool pool = EPool.A;
                    foreach (PoolData pd in rd.Pools)
                    {
                        int teamNumber = 0;
                        foreach (TeamDataDisplay td in pd.Teams)
                        {
                            LiveStream.Team team = new LiveStream.Team(
                                LiveStream.TeamStates.Inited,
                                division.ToString(),
                                round.ToString(),
                                pool.ToString(),
                                teamNumber
                                );

                            foreach (PlayerData playerData in td.Data.Players)
                            {
                                team.Players.Add(new LiveStream.Player(playerData));
                            }

                            teamList.Teams.Add(team);

                            ++teamNumber;
                        }

                        ++pool;
                    }

                    ++round;
                }

                ++division;
            }

            SendRestMessageAsync(teamList);
        }

        #region Round Buttons
        GUIStyle RoundStyle      = new GUIStyle("button");
        string   LongestRoundStr = "Women - Quarterfinals";
        Rect     RoundRect       = new Rect(20, Screen.height * .15f, RoundStyle.CalcSize(new GUIContent(LongestRoundStr)).x + 40, Screen.height * .75f - 20);
        if (!bIsEditing && !bCatPicking)
        {
            GUILayout.BeginArea(RoundRect);

            RoundsScrollPos = GUILayout.BeginScrollView(RoundsScrollPos, GUILayout.MaxHeight(RoundRect.height / 2f));
            GUIStyle RoundButtonStyle = new GUIStyle("button");
            RoundButtonStyle.alignment = TextAnchor.MiddleLeft;
            for (int DivIndex = 0; DivIndex < Global.AllData.AllDivisions.Length; ++DivIndex)
            {
                DivisionData DivData = Global.AllData.AllDivisions[DivIndex];
                if (DivData.HasAnyPoolData())
                {
                    for (int RoundIndex = 0; RoundIndex < DivData.Rounds.Length; ++RoundIndex)
                    {
                        RoundData RData = DivData.Rounds[RoundIndex];
                        if (RData.HasAnyPoolData())
                        {
                            GUIContent RoundContent  = new GUIContent(((EDivision)DivIndex) + " - " + ((ERound)RoundIndex) + (RData.ContainsJudgeScores() ? " - Results" : ""));
                            Vector2    RoundTextSize = RoundButtonStyle.CalcSize(RoundContent);
                            if (GUILayout.Button(RoundContent, RoundButtonStyle, GUILayout.Width(RoundRect.width * .9f), GUILayout.Height(RoundTextSize.y)))
                            {
                                CurDivIndex   = DivIndex;
                                CurRoundIndex = RoundIndex;
                            }
                        }
                    }
                }
            }
            GUILayout.EndScrollView();

            GUILayout.EndArea();
        }
        #endregion

        if (CurDivIndex != -1 && CurRoundIndex != -1)
        {
            float StartX   = RoundRect.x + RoundRect.width + 20;
            Rect  TeamRect = new Rect(StartX, RoundRect.y, Screen.width - StartX - 20, Screen.height - RoundRect.y - 20);
            GUILayout.BeginArea(TeamRect);
            GUILayout.BeginVertical();
            TeamsScrollPos = GUILayout.BeginScrollView(TeamsScrollPos);
            GUILayout.BeginVertical();

            GUIStyle labelStyle = new GUIStyle("label");
            labelStyle.normal.textColor = Color.black;

            if (!bIsEditing)
            {
                List <PoolData> Pools     = Global.AllData.AllDivisions[CurDivIndex].Rounds[CurRoundIndex].Pools;
                int             PoolIndex = 0;
                foreach (PoolData pd in Pools)
                {
                    GUILayout.Label("Pool " + pd.PoolName, labelStyle);

                    // This is a hack to get team result order
                    List <RoutineScoreData> sortedScores = new List <RoutineScoreData>();
                    foreach (TeamDataDisplay tdd in pd.Teams)
                    {
                        if (sortedScores.Count == 0)
                        {
                            sortedScores.Add(tdd.Data.RoutineScores);
                        }
                        else
                        {
                            int insertIndex = 0;
                            foreach (RoutineScoreData score in sortedScores)
                            {
                                if (tdd.Data.RoutineScores.GetTotalPoints() > score.GetTotalPoints())
                                {
                                    sortedScores.Insert(insertIndex, tdd.Data.RoutineScores);
                                    break;
                                }

                                ++insertIndex;
                            }

                            if (insertIndex == sortedScores.Count)
                            {
                                sortedScores.Insert(insertIndex, tdd.Data.RoutineScores);
                            }
                        }
                    }

                    int TeamNum = 0;
                    foreach (TeamDataDisplay tdd in pd.Teams)
                    {
                        ++TeamNum;
                        GUILayout.Label(TeamNum + ": " + tdd.Data.PlayerNames + ":", labelStyle);

                        for (int ScoresIndex = 0; ScoresIndex < (CurCat == ECategoryView.Overview ? 1 : 3); ++ScoresIndex)
                        {
                            GUIStyle EditStyle = new GUIStyle("button");
                            EditStyle.alignment = TextAnchor.MiddleLeft;
                            string ResultsStr = tdd.Data.RoutineScores.GetResultsString(ScoresIndex, CurCat, true, sortedScores);
                            if (ResultsStr.Length > 0)
                            {
                                if (bInEditingMode)
                                {
                                    if (GUILayout.Button("    " + ResultsStr, EditStyle))
                                    {
                                        bIsEditing     = true;
                                        EditPoolIndex  = PoolIndex;
                                        EditTeamIndex  = TeamNum - 1;
                                        EditJudgeIndex = ScoresIndex;
                                    }
                                }
                                else
                                {
                                    GUILayout.Label("    " + ResultsStr, labelStyle);
                                }
                            }
                            else if (bInEditingMode && (ScoresIndex == 0 || tdd.Data.RoutineScores.GetResultsString(ScoresIndex - 1, CurCat, true).Length > 0))
                            {
                                if (GUILayout.Button("    Enter New Scores", EditStyle))
                                {
                                    bIsEditing     = true;
                                    EditPoolIndex  = PoolIndex;
                                    EditTeamIndex  = TeamNum - 1;
                                    EditJudgeIndex = ScoresIndex;
                                }
                            }
                        }
                    }

                    ++PoolIndex;
                }
            }
            else
            {
                TeamData Data = Global.AllData.AllDivisions[CurDivIndex].Rounds[CurRoundIndex].Pools[EditPoolIndex].Teams[EditTeamIndex].Data;
                if (CatCombo.GetSelectedItemIndex() == 0)
                {
                    if (EditAIData == null)
                    {
                        AIData JData = null;
                        if (EditJudgeIndex >= Data.RoutineScores.AIResults.Count)
                        {
                            EditAIData      = new AIData((EDivision)CurDivIndex, (ERound)CurRoundIndex, (EPool)EditPoolIndex, EditTeamIndex);
                            bEditAddNewData = true;
                            EditJudgeName   = "Judge Name";
                        }
                        else
                        {
                            JData      = Data.RoutineScores.AIResults[EditJudgeIndex];
                            EditAIData = new AIData(JData);
                        }
                    }

                    GUILayout.BeginHorizontal();

                    if (EditAIData.JudgeNameId == -1)
                    {
                        GUILayout.Label("Judge:", labelStyle);
                        EditJudgeName = GUILayout.TextField(EditJudgeName);

                        char[]   Seperators = new char[] { ',', ' ' };
                        string[] Splits     = EditJudgeName.Split(Seperators, System.StringSplitOptions.RemoveEmptyEntries);
                        NameData JudgeName  = null;
                        if (Splits.Length == 2)
                        {
                            JudgeName = NameDatabase.FindInDatabase(Splits[0], Splits[1]);

                            if (JudgeName == null)
                            {
                                JudgeName = NameDatabase.FindInDatabase(Splits[1], Splits[0]);
                            }
                        }

                        if (JudgeName != null)
                        {
                            EditAIData.JudgeNameId = JudgeName.Id;
                        }
                    }
                    else
                    {
                        GUILayout.Label(NameDatabase.FindInDatabase(EditAIData.JudgeNameId).DisplayName + ": ", labelStyle);
                    }

                    GUILayout.Label("V: ", labelStyle);
                    float.TryParse(GUILayout.TextField(EditAIData.Variety.ToString()), out EditAIData.Variety);
                    GUILayout.Label("T: ", labelStyle);
                    float.TryParse(GUILayout.TextField(EditAIData.Teamwork.ToString()), out EditAIData.Teamwork);
                    GUILayout.Label("M: ", labelStyle);
                    float.TryParse(GUILayout.TextField(EditAIData.Music.ToString()), out EditAIData.Music);
                    GUILayout.Label("Fm: ", labelStyle);
                    float.TryParse(GUILayout.TextField(EditAIData.Form.ToString()), out EditAIData.Form);
                    GUILayout.Label("Fw: ", labelStyle);
                    float.TryParse(GUILayout.TextField(EditAIData.Flow.ToString()), out EditAIData.Flow);
                    GUILayout.Label("G: ", labelStyle);
                    float.TryParse(GUILayout.TextField(EditAIData.General.ToString()), out EditAIData.General);
                    GUILayout.Label("Total: " + EditAIData.GetTotalPoints().ToString(), labelStyle);

                    GUILayout.EndHorizontal();
                }
                else if (CatCombo.GetSelectedItemIndex() == 1)
                {
                    if (EditExData == null)
                    {
                        ExData JData = null;
                        if (EditJudgeIndex >= Data.RoutineScores.ExResults.Count)
                        {
                            EditExData      = new ExData((EDivision)CurDivIndex, (ERound)CurRoundIndex, (EPool)EditPoolIndex, EditTeamIndex);
                            bEditAddNewData = true;
                            EditJudgeName   = "Judge Name";
                        }
                        else
                        {
                            JData      = Data.RoutineScores.ExResults[EditJudgeIndex];
                            EditExData = new ExData(JData);
                        }
                    }

                    GUILayout.BeginHorizontal();

                    if (EditExData.JudgeNameId == -1)
                    {
                        GUILayout.Label("Judge:", labelStyle);
                        EditJudgeName = GUILayout.TextField(EditJudgeName);

                        char[]   Seperators = new char[] { ',', ' ' };
                        string[] Splits     = EditJudgeName.Split(Seperators, System.StringSplitOptions.RemoveEmptyEntries);
                        NameData JudgeName  = null;
                        if (Splits.Length == 2)
                        {
                            JudgeName = NameDatabase.FindInDatabase(Splits[0], Splits[1]);

                            if (JudgeName == null)
                            {
                                JudgeName = NameDatabase.FindInDatabase(Splits[1], Splits[0]);
                            }
                        }

                        if (JudgeName != null)
                        {
                            EditExData.JudgeNameId = JudgeName.Id;
                        }
                    }
                    else
                    {
                        GUILayout.Label(NameDatabase.FindInDatabase(EditExData.JudgeNameId).DisplayName + ": ", labelStyle);
                    }

                    GUILayout.Label(".1: ", labelStyle);
                    int.TryParse(GUILayout.TextField(EditExData.Point1Count.ToString()), out EditExData.Point1Count);
                    GUILayout.Label(".2: ", labelStyle);
                    int.TryParse(GUILayout.TextField(EditExData.Point2Count.ToString()), out EditExData.Point2Count);
                    GUILayout.Label(".3: ", labelStyle);
                    int.TryParse(GUILayout.TextField(EditExData.Point3Count.ToString()), out EditExData.Point3Count);
                    GUILayout.Label(".5: ", labelStyle);
                    int.TryParse(GUILayout.TextField(EditExData.Point5Count.ToString()), out EditExData.Point5Count);
                    GUILayout.Label("Total: " + EditExData.GetTotalPoints().ToString(), labelStyle);

                    GUILayout.EndHorizontal();
                }
                else if (CatCombo.GetSelectedItemIndex() == 2)
                {
                    if (EditDiffData == null)
                    {
                        DiffData JData = null;
                        if (EditJudgeIndex >= Data.RoutineScores.DiffResults.Count)
                        {
                            EditDiffData    = new DiffData(20, (EDivision)CurDivIndex, (ERound)CurRoundIndex, (EPool)EditPoolIndex, EditTeamIndex);
                            bEditAddNewData = true;
                            EditJudgeName   = "Judge Name";
                        }
                        else
                        {
                            JData        = Data.RoutineScores.DiffResults[EditJudgeIndex];
                            EditDiffData = new DiffData(JData);
                        }
                    }

                    GUILayout.BeginVertical();

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Number of Scores: ", labelStyle);
                    int.TryParse(GUILayout.TextField(EditDiffData.NumScores.ToString()), out EditDiffData.NumScores);
                    EditDiffData.NumScores = Mathf.Clamp(EditDiffData.NumScores, 0, 20);
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();

                    if (EditDiffData.JudgeNameId == -1)
                    {
                        GUILayout.Label("Judge:", labelStyle);
                        EditJudgeName = GUILayout.TextField(EditJudgeName);

                        char[]   Seperators = new char[] { ',', ' ' };
                        string[] Splits     = EditJudgeName.Split(Seperators, System.StringSplitOptions.RemoveEmptyEntries);
                        NameData JudgeName  = null;
                        if (Splits.Length == 2)
                        {
                            JudgeName = NameDatabase.FindInDatabase(Splits[0], Splits[1]);

                            if (JudgeName == null)
                            {
                                JudgeName = NameDatabase.FindInDatabase(Splits[1], Splits[0]);
                            }
                        }

                        if (JudgeName != null)
                        {
                            EditDiffData.JudgeNameId = JudgeName.Id;
                        }
                    }
                    else
                    {
                        GUILayout.Label(NameDatabase.FindInDatabase(EditDiffData.JudgeNameId).DisplayName + ": ", labelStyle);
                    }

                    for (int i = 0; i < EditDiffData.NumScores; ++i)
                    {
                        string DiffStr = GUILayout.TextField(EditDiffData.DiffScores[i].ToString() + EditDiffData.GetConsecString(i));
                        if (DiffStr.Contains("-"))
                        {
                            DiffStr = DiffStr.Replace("-", "");
                            EditDiffData.ConsecScores[i] = -1;
                        }
                        else if (DiffStr.Contains("+"))
                        {
                            DiffStr = DiffStr.Replace("+", "");
                            EditDiffData.ConsecScores[i] = 1;
                        }
                        else
                        {
                            EditDiffData.ConsecScores[i] = 0;
                        }
                        float.TryParse(DiffStr, out EditDiffData.DiffScores[i]);
                    }

                    GUILayout.EndHorizontal();
                    GUILayout.EndVertical();
                }
            }

            GUILayout.EndVertical();
            GUILayout.EndScrollView();

            if (CatCombo.GetSelectedItemIndex() != 3)
            {
                if (!bInEditingMode && GUILayout.Button("Enter Edit Mode", GUILayout.Height(Screen.height * .1f)))
                {
                    bInEditingMode = true;
                }
                else if (bInEditingMode)
                {
                    if (bIsEditing)
                    {
                        GUILayout.BeginHorizontal();

                        if (GUILayout.Button("Delete Score", GUILayout.Height(Screen.height * .1f)))
                        {
                            TeamData Data = Global.AllData.AllDivisions[CurDivIndex].Rounds[CurRoundIndex].Pools[EditPoolIndex].Teams[EditTeamIndex].Data;
                            if (CatCombo.GetSelectedItemIndex() == 0)
                            {
                                if (!bEditAddNewData && EditJudgeIndex < Data.RoutineScores.AIResults.Count)
                                {
                                    Data.RoutineScores.AIResults[EditJudgeIndex] = new AIData();
                                }
                                EditAIData = null;
                            }
                            else if (CatCombo.GetSelectedItemIndex() == 1)
                            {
                                if (!bEditAddNewData && EditJudgeIndex < Data.RoutineScores.ExResults.Count)
                                {
                                    Data.RoutineScores.ExResults[EditJudgeIndex] = new ExData();
                                }
                                EditExData = null;
                            }
                            else if (CatCombo.GetSelectedItemIndex() == 2)
                            {
                                if (!bEditAddNewData && EditJudgeIndex < Data.RoutineScores.DiffResults.Count)
                                {
                                    Data.RoutineScores.DiffResults[EditJudgeIndex] = new DiffData();
                                }
                                EditDiffData = null;
                            }

                            bIsEditing      = false;
                            EditAIData      = null;
                            EditExData      = null;
                            EditDiffData    = null;
                            bEditAddNewData = false;

                            Global.AllData.Save();
                        }

                        if (GUILayout.Button("Discard Changes", GUILayout.Height(Screen.height * .1f)))
                        {
                            bIsEditing      = false;
                            EditAIData      = null;
                            EditExData      = null;
                            EditDiffData    = null;
                            bEditAddNewData = false;
                        }

                        if (GUILayout.Button("Save Changes", GUILayout.Height(Screen.height * .1f)))
                        {
                            TeamData Data = Global.AllData.AllDivisions[CurDivIndex].Rounds[CurRoundIndex].Pools[EditPoolIndex].Teams[EditTeamIndex].Data;
                            if (CatCombo.GetSelectedItemIndex() == 0)
                            {
                                if (bEditAddNewData)
                                {
                                    Data.RoutineScores.AIResults.Add(new AIData(EditAIData));
                                }
                                else
                                {
                                    Data.RoutineScores.AIResults[EditJudgeIndex] = new AIData(EditAIData);
                                }
                                EditAIData = null;
                            }
                            else if (CatCombo.GetSelectedItemIndex() == 1)
                            {
                                if (bEditAddNewData)
                                {
                                    Data.RoutineScores.ExResults.Add(new ExData(EditExData));
                                }
                                else
                                {
                                    Data.RoutineScores.ExResults[EditJudgeIndex] = new ExData(EditExData);
                                }
                                EditExData = null;
                            }
                            else if (CatCombo.GetSelectedItemIndex() == 2)
                            {
                                if (bEditAddNewData)
                                {
                                    Data.RoutineScores.DiffResults.Add(new DiffData(EditDiffData));
                                }
                                else
                                {
                                    Data.RoutineScores.DiffResults[EditJudgeIndex] = new DiffData(EditDiffData);
                                }
                                EditDiffData = null;
                            }

                            bIsEditing      = false;
                            bEditAddNewData = false;

                            Global.AllData.Save();
                        }
                        GUILayout.EndHorizontal();
                    }
                    else if (GUILayout.Button("Exit Edit Mode", GUILayout.Height(Screen.height * .1f)))
                    {
                        bInEditingMode = false;
                    }
                }
            }

            GUILayout.EndVertical();
            GUILayout.EndArea();
        }
    }
    void WriteRawResults()
    {
        StringWriter OutStr = new StringWriter();

        OutStr.WriteLine((EDivision)(CurDivIndex) + " " + (ERound)(CurRoundIndex) + " Results");
        List <PoolData> Pools = Global.AllData.AllDivisions[CurDivIndex].Rounds[CurRoundIndex].Pools;

        foreach (PoolData pd in Pools)
        {
            OutStr.WriteLine("Pool " + pd.PoolName);
            string CatHeaders   = "\t";
            string JudgeHeaders = "\t";
            if (pd.Teams.Count > 0)
            {
                for (int i = 0; i < pd.Teams[0].Data.RoutineScores.AIResults.Count; ++i)
                {
                    if (i == 0)
                    {
                        CatHeaders += "AI";
                    }
                    CatHeaders   += "\t";
                    JudgeHeaders += NameDatabase.FindInDatabase(pd.Teams[0].Data.RoutineScores.AIResults[i].JudgeNameId).DisplayName + "\t";
                }
                for (int i = 0; i < pd.Teams[0].Data.RoutineScores.ExResults.Count; ++i)
                {
                    if (i == 0)
                    {
                        CatHeaders += "Ex";
                    }
                    CatHeaders   += "\t";
                    JudgeHeaders += NameDatabase.FindInDatabase(pd.Teams[0].Data.RoutineScores.ExResults[i].JudgeNameId).DisplayName + "\t";
                }
                for (int i = 0; i < pd.Teams[0].Data.RoutineScores.DiffResults.Count; ++i)
                {
                    if (i == 0)
                    {
                        CatHeaders += "Diff";
                    }
                    CatHeaders   += "\t";
                    JudgeHeaders += NameDatabase.FindInDatabase(pd.Teams[0].Data.RoutineScores.DiffResults[i].JudgeNameId).DisplayName + "\t";
                }
            }
            OutStr.WriteLine(CatHeaders);
            OutStr.WriteLine(JudgeHeaders + "\tTotal\tRank");

            int TeamNum = 1;
            foreach (TeamDataDisplay tdd in pd.Teams)
            {
                string TeamStr = TeamNum + ": " + tdd.Data.PlayerNames + "\t";
                foreach (AIData aid in tdd.Data.RoutineScores.AIResults)
                {
                    TeamStr += aid.GetTotalPoints() + "\t";
                }
                foreach (ExData ed in tdd.Data.RoutineScores.ExResults)
                {
                    TeamStr += ed.GetTotalPoints() + "\t";
                }
                foreach (DiffData dd in tdd.Data.RoutineScores.DiffResults)
                {
                    TeamStr += dd.GetTotalPoints() + "\t";
                }
                OutStr.WriteLine(TeamStr + "\t" + tdd.Data.RoutineScores.GetTotalPoints() + "\t" + GetTeamPlace(pd.Teams, tdd));
                ++TeamNum;
            }

            OutStr.WriteLine();
            OutStr.WriteLine();

            if (pd.Teams.Count > 0)
            {
                int ResultsIndex = 0;
                foreach (AIData aid in pd.Teams[0].Data.RoutineScores.AIResults)
                {
                    string AIHeader = (EDivision)(CurDivIndex) + " " + (ERound)(CurRoundIndex) + " Results\tArtistic Impression\t" +
                                      "Pool " + pd.PoolName + "\t" + NameDatabase.FindInDatabase(aid.JudgeNameId).DisplayName;
                    OutStr.WriteLine(AIHeader);
                    OutStr.WriteLine("\tVariety\tTeamwork\tMusic\tFlow\tForm\tGeneral Impression\tTotal\tRank");
                    int TeamIndex = 1;
                    foreach (TeamDataDisplay tdd in pd.Teams)
                    {
                        if (ResultsIndex < tdd.Data.RoutineScores.AIResults.Count)
                        {
                            AIData Data = tdd.Data.RoutineScores.AIResults[ResultsIndex];
                            int    Rank = 1;
                            foreach (TeamDataDisplay OtherTdd in pd.Teams)
                            {
                                if (ResultsIndex < OtherTdd.Data.RoutineScores.AIResults.Count &&
                                    OtherTdd.Data.RoutineScores.AIResults[ResultsIndex].GetTotalPoints() > Data.GetTotalPoints())
                                {
                                    ++Rank;
                                }
                            }

                            string TeamStr = TeamIndex + ": " + tdd.Data.PlayerNames + "\t" + Data.Variety + "\t" + Data.Teamwork + "\t" +
                                             Data.Music + "\t" + Data.Flow + "\t" + Data.Form + "\t" + Data.General + "\t" + Data.GetTotalPoints() + "\t" + Rank;

                            OutStr.WriteLine(TeamStr);
                            ++TeamIndex;
                        }
                    }

                    ++ResultsIndex;
                    OutStr.WriteLine();
                }

                OutStr.WriteLine();

                ResultsIndex = 0;
                foreach (ExData ed in pd.Teams[0].Data.RoutineScores.ExResults)
                {
                    string ExHeader = (EDivision)(CurDivIndex) + " " + (ERound)(CurRoundIndex) + " Results\tExecution\t" +
                                      "Pool " + pd.PoolName + "\t" + NameDatabase.FindInDatabase(ed.JudgeNameId).DisplayName;
                    OutStr.WriteLine(ExHeader);
                    OutStr.WriteLine("\t.1\t.2\t.3\t.5\tTotal\tRank");
                    int TeamIndex = 1;
                    foreach (TeamDataDisplay tdd in pd.Teams)
                    {
                        if (ResultsIndex < tdd.Data.RoutineScores.ExResults.Count)
                        {
                            ExData Data = tdd.Data.RoutineScores.ExResults[ResultsIndex];
                            int    Rank = 1;
                            foreach (TeamDataDisplay OtherTdd in pd.Teams)
                            {
                                if (ResultsIndex < OtherTdd.Data.RoutineScores.ExResults.Count &&
                                    OtherTdd.Data.RoutineScores.ExResults[ResultsIndex].GetTotalPoints() > Data.GetTotalPoints())
                                {
                                    ++Rank;
                                }
                            }

                            string TeamStr = TeamIndex + ": " + tdd.Data.PlayerNames + "\t" + Data.Point1Count + "\t" + Data.Point2Count + "\t" +
                                             Data.Point3Count + "\t" + Data.Point5Count + "\t" + Data.GetTotalPoints() + "\t" + Rank;

                            OutStr.WriteLine(TeamStr);
                            ++TeamIndex;
                        }
                    }

                    ++ResultsIndex;
                    OutStr.WriteLine();
                }

                OutStr.WriteLine();

                ResultsIndex = 0;
                foreach (DiffData dd in pd.Teams[0].Data.RoutineScores.DiffResults)
                {
                    string ExHeader = (EDivision)(CurDivIndex) + " " + (ERound)(CurRoundIndex) + " Results\tDifficulty\t" +
                                      "Pool " + pd.PoolName + "\t" + NameDatabase.FindInDatabase(dd.JudgeNameId).DisplayName;
                    OutStr.WriteLine(ExHeader);
                    string BlockHeader = "\t";
                    for (int i = 0; i < dd.NumScores; ++i)
                    {
                        BlockHeader += (i + 1) + "\t";
                    }
                    OutStr.WriteLine(BlockHeader + "Total\tRank");
                    int TeamIndex = 1;
                    foreach (TeamDataDisplay tdd in pd.Teams)
                    {
                        if (ResultsIndex < tdd.Data.RoutineScores.DiffResults.Count)
                        {
                            DiffData Data = tdd.Data.RoutineScores.DiffResults[ResultsIndex];
                            int      Rank = 1;
                            foreach (TeamDataDisplay OtherTdd in pd.Teams)
                            {
                                if (ResultsIndex < OtherTdd.Data.RoutineScores.DiffResults.Count &&
                                    OtherTdd.Data.RoutineScores.DiffResults[ResultsIndex].GetTotalPoints() > Data.GetTotalPoints())
                                {
                                    ++Rank;
                                }
                            }

                            string TeamStr = TeamIndex + ": " + tdd.Data.PlayerNames + "\t";
                            for (int i = 0; i < Data.NumScores; ++i)
                            {
                                TeamStr += Data.DiffScores[i] + "\t";
                            }
                            TeamStr += Data.GetTotalPoints() + "\t" + Rank;
                            OutStr.WriteLine(TeamStr);
                            ++TeamIndex;
                        }
                    }

                    ++ResultsIndex;
                    OutStr.WriteLine();
                }
            }
        }

        string TempFilePath = Application.persistentDataPath + "/TempExcelStr.txt";

        if (File.Exists(TempFilePath))
        {
            File.Delete(TempFilePath);
        }
        StreamWriter TempFile = new StreamWriter(TempFilePath);

        TempFile.Write(OutStr.ToString());
        TempFile.Close();
        OutStr.Close();

        TempFilePath = TempFilePath.Replace('/', '\\');

        if (File.Exists(ExcelPath))
        {
            Process.Start(ExcelPath, "\"" + TempFilePath + "\"");
        }
    }
Example #13
0
    // Update is called once per frame
    void Update()
    {
        if (bGetRankings)
        {
            RankingsRequest     = new WWW(RankingURL);
            bWaitingForRankings = true;
            bGetRankings        = false;
            FetchStatus         = "Querying Shrednow.com";
        }
        else if (bWaitingForRankings && RankingsRequest.isDone)
        {
            if (RankingsRequest.error != null)
            {
                FetchStatus = RankingsText = RankingsRequest.error;
            }
            else
            {
                RankingsText = Encoding.UTF7.GetString(RankingsRequest.bytes, 0, RankingsRequest.bytes.Length);

                //int RankStartIndex = "<td align=\"center\">".Length;
                string       line    = null;
                StringReader AllText = new StringReader(RankingsText);
                AllPlayers.Clear();
                while ((line = AllText.ReadLine()) != null)
                {
                    // Old Arthur parsing
                    //if (line.StartsWith("<td align=\"center\">"))
                    //{
                    //    PlayerData NewData = new PlayerData();
                    //    int.TryParse(line.Substring(RankStartIndex, line.IndexOf('<', RankStartIndex) - RankStartIndex), out NewData.Rank);
                    //    int StartNameIndex = line.IndexOf("</td><td>") + "</td><td>".Length;
                    //    string LastName = line.Substring(StartNameIndex, line.IndexOf(',', StartNameIndex) - StartNameIndex);
                    //    string FirstName = line.Substring(line.IndexOf(',', StartNameIndex) + 2, line.IndexOf('<', StartNameIndex) - line.IndexOf(',', StartNameIndex) - 2);
                    //    int StartPointsIndex = line.IndexOf("</td><td align=\"center\">", StartNameIndex + FirstName.Length + LastName.Length + 10) +
                    //        "</td><td align=\"center\">".Length;
                    //    float.TryParse(line.Substring(StartPointsIndex, line.IndexOf('<', StartPointsIndex) - StartPointsIndex), out NewData.RankingPoints);

                    //    NameData NewName = NameDatabase.TryAddNewName(FirstName, LastName);
                    //    NewData.NameId = NewName.Id;

                    //    AllPlayers.Add(NewData);
                    //}

                    line = line.Trim();

                    string RankTd = "<td height=19 class=xl6322297 style='height:14.5pt'>";

                    string NameClass   = "xl1522297";
                    string PointsClass = "xl6322297";

                    // New Kolja parsing
                    if (line.StartsWith(RankTd))
                    {
                        PlayerData NewData = new PlayerData();
                        string     rankStr = line.Trim().Replace(RankTd, "");
                        rankStr = rankStr.Replace("</td>", "");
                        int.TryParse(rankStr, out NewData.Rank);
                        AllText.ReadLine();

                        string NameLine           = AllText.ReadLine().Trim().Replace("<td class=" + NameClass + ">", "");
                        int    NameLineCommaIndex = NameLine.IndexOf(',');
                        if (NameLineCommaIndex == -1)
                        {
                            continue;
                        }
                        string   LastName  = NameLine.Substring(0, NameLineCommaIndex);
                        string   FirstName = NameLine.Substring(NameLineCommaIndex + 2, NameLine.Length - LastName.Length - 7);
                        NameData NewName   = NameDatabase.TryAddNewName(FirstName, LastName);
                        NewData.NameId = NewName.Id;

                        AllText.ReadLine();
                        AllText.ReadLine();
                        string PointsLine = AllText.ReadLine().Trim();
                        PointsLine = PointsLine.Replace("<td class=" + PointsClass + ">", "").Replace("</td>", "").Replace(",", ".");
                        float.TryParse(PointsLine, out NewData.RankingPoints);

                        AllPlayers.Add(NewData);
                    }
                }

                RankingsText = "";
                for (int i = 0; i < AllPlayers.Count; ++i)
                {
                    PlayerData Data = AllPlayers[i];
                    RankingsText += NameDatabase.FindInDatabase(Data.NameId).DisplayName + "   " + Data.Rank + "   " + Data.RankingPoints + "\n";
                }

                FetchStatus = "Got " + AllPlayers.Count + " Players Rankings";

                InputTeamsTextChanged = true;
            }

            bWaitingForRankings = false;
        }

        if (InputTeamsTextChanged)
        {
            InputTeamsTextChanged = false;

            ParseTeamsText = "";
            StringReader TeamText = new StringReader(InputTeamsText);
            string       line     = null;
            AllTeams.Clear();
            ErrorList.Clear();
            while ((line = TeamText.ReadLine()) != null)
            {
                TeamData NewTeam = GetTeamFromString(line);
                if (NewTeam != null)
                {
                    AllTeams.Add(NewTeam);
                }
                else
                {
                    char[] BreakCharArray = new char[10];
                    BreakChars.CopyTo(BreakCharArray, 0);
                    string[]  NameArray = line.Split(BreakCharArray);
                    ErrorLine NewError  = new ErrorLine();
                    NewError.OriginalLine = line;
                    foreach (string s in NameArray)
                    {
                        string            NameStr    = s.Trim();
                        List <PlayerData> OutPlayers = new List <PlayerData>();
                        GetPlayersFromString(NameStr, ref OutPlayers);
                        NewError.ErrorList.Add(new ErrorData(NameStr, OutPlayers.Count == 0));
                    }
                    ErrorList.Add(NewError);
                }
            }

            if (bSortTeams)
            {
                AllTeams.Sort(TeamSorter);
            }

            for (int TeamIndex = 0; TeamIndex < AllTeams.Count; ++TeamIndex)
            {
                ParseTeamsText += (TeamIndex + 1) + ". " + AllTeams[TeamIndex].PlayerNames + " : " + AllTeams[TeamIndex].TotalRankPoints + "\n";
            }

            AllPools.Clear();
            if (PoolCount > 0)
            {
                char PoolName = 'A';
                for (int TeamIndex = 0; TeamIndex < AllTeams.Count; ++TeamIndex)
                {
                    if (bSortTeams)
                    {
                        int PoolIndex = TeamIndex % PoolCount;
                        if (PoolIndex >= AllPools.Count)
                        {
                            AllPools.Add(new PoolDataDisplay((PoolName++).ToString()));
                        }

                        AllPools[PoolIndex].Data.Teams.Add(new TeamDataDisplay(AllTeams[TeamIndex]));
                    }
                    else
                    {
                        int TeamsPerPool = AllTeams.Count / PoolCount;
                        int PoolIndex    = TeamIndex / TeamsPerPool;
                        if (PoolIndex >= AllPools.Count)
                        {
                            AllPools.Add(new PoolDataDisplay((PoolName++).ToString()));
                        }

                        AllPools[PoolIndex].Data.Teams.Add(new TeamDataDisplay(AllTeams[TeamIndex]));
                    }
                }
            }

            InputTeamsTextReduced = false;

            //Debug.Log("Parsing pools. Teams: " + AllTeams.Count + "  Pools: " + AllPools.Count);
        }

        if (Input.GetMouseButton(0))
        {
            if (MovingTeam != null)
            {
            }
        }
        else
        {
            if (MovingTeam != null)
            {
                for (int PoolIndex = 0; PoolIndex < AllPools.Count; ++PoolIndex)
                {
                    Vector3 NewMousePos = new Vector3(Input.mousePosition.x, Screen.height - Input.mousePosition.y + ParsedScrollPos.y, 0);
                    if (AllPools[PoolIndex].DisplayRect.Contains(NewMousePos))
                    {
                        MovedTeamBetweenPools(MovingTeam, PoolIndex);
                        break;
                    }
                }
            }

            for (int PoolIndex = 0; PoolIndex < AllPools.Count; ++PoolIndex)
            {
                PoolData PData = AllPools[PoolIndex].Data;
                for (int TeamIndex = 0; TeamIndex < PData.Teams.Count; ++TeamIndex)
                {
                    PData.Teams[TeamIndex].bClickedOn = false;
                }
            }

            MovingTeam = null;
        }
    }