Example #1
0
 void initTextsTable()
 {
     textsTable.init(new string[] { "WPM", "HiWPM", "LoWPM", "Acc %", "Time", "Text" }, 7, 18);
     textsTable.PrimarySortCol = WpmCol;
     primaryTextSort           = columnToSortType(textsTable.PrimarySortCol);
     textsTable.Sort          += Table_Sort;
     for (int r = 0; r < Rows; r++)
     {
         textsTable.addRow();
         for (int c = 0; c < Columns; c++)
         {
             //if (c == WpmCol)
             //{
             //	cell.FontWeight = FontWeights.Bold;
             //}
             if (c == TextCol || c == HighWpmCol || c == MinWpmCol)
             {
                 var cell = new HyperlinkButton();
                 //Duplicate init code---------
                 cell.HorizontalAlignment = c == TextCol ? HorizontalAlignment.Left : HorizontalAlignment.Right;
                 cell.VerticalAlignment   = VerticalAlignment.Center;
                 cell.Padding             = new Thickness(20, 5, 7, 5);
                 if (c == TextCol)
                 {
                     cell.Padding = new Thickness(7, 5, 7, 5);
                 }
                 cell.FontSize = 18;
                 //----------------------------
                 cell.Click += textRecordsBtn_Click;
                 textsTable.addCell(cell);
             }
             else
             {
                 var cell = new TextBlock();
                 //Duplicate init code---------
                 cell.HorizontalAlignment = HorizontalAlignment.Right;
                 cell.TextAlignment       = TextAlignment.Right;
                 cell.VerticalAlignment   = VerticalAlignment.Center;
                 cell.Padding             = new Thickness(20, 5, 7, 5);
                 cell.FontSize            = 18;
                 //----------------------------
                 setCellWidth(c, cell);
                 cell.Foreground = new SolidColorBrush(Colors.White);
                 textsTable.addCell(cell);
             }
         }
     }
     textsTable.applyStyle();
 }
Example #2
0
        //removeHidden == true searches for a record that is guaranteed to not be visible regardless of primary sort column.
        //More Specifically it searches for a record whose max/min/avg wpm are all below top ten for the current text.
        //Pass false for better performanc if loading records from file.
        public void addRecord(Record newRecord, bool removeHidden)
        {
            userData.Records.Add(newRecord);
            var currentTextRecords = getRecordsOfText(newRecord.TextTitle);

            if (currentTextRecords.Length <= MaxRecords)
            {
                return;
            }

            //Create record lists sorted after every primary sort type
            var sortedRecords = new Record[Enum.GetValues(typeof(Record.PrimarySortType)).Length][];

            for (int i = 0; i < sortedRecords.Length; i++)
            {
                sortedRecords[i] = new Record[currentTextRecords.Length];
                Array.Copy(currentTextRecords, 0, sortedRecords[i], 0, currentTextRecords.Length);
                Record.sort(sortedRecords[i], (Record.PrimarySortType)i, false);
            }

            //Search for a record to remove
            foreach (var record in currentTextRecords)
            {
                bool removeRecord = true;
                for (int i = 0; i < Enum.GetValues(typeof(Record.PrimarySortType)).Length; i++)
                {
                    //If record is higher than the MaxRecords first it can stay.
                    //eg., if there are 11 records and MaxRecords == 10, check if it's higher than [9] (descending sort)
                    //It can also stay if it IS [9]
                    Record lowestHighRecord = sortedRecords[i][MaxRecords - 1];
                    Record.PrimarySortType typeToCompare = (Record.PrimarySortType)i;
                    if (record.Id == lowestHighRecord.Id || record.primarySortTypeIsGreaterThan(lowestHighRecord, typeToCompare))
                    {
                        removeRecord = false;
                        break;
                    }
                }
                if (removeRecord)
                {
                    userData.Records.Remove(record);
                    return;
                }
            }
        }
Example #3
0
        public Record[] getRecords(RecordSortMethod sortMethod, Record.PrimarySortType primarySort, int count = 0)
        {
            Record[] records = new Record[userData.Records.Count];
            userData.Records.CopyTo(records);
            Record.sort(records, primarySort, false);

            if (sortMethod != RecordSortMethod.FastestSessions)
            {
                var dict = new Dictionary <string, Record>();
                foreach (var rec in records)
                {
                    //Add record to dictionary if it doesn't already contain a record with this text title
                    if (!dict.ContainsKey(rec.TextTitle))
                    {
                        dict[rec.TextTitle] = rec;
                    }
                }
                records = new Record[dict.Count].ToArray();
                int i = 0;
                foreach (var rec in dict)
                {
                    records[i++] = rec.Value;
                }
                Record.sort(records, primarySort, sortMethod == RecordSortMethod.SlowestTexts);
            }
            var subArray = records;

            if (count > 0)
            {
                int actualCount = Math.Min(count, records.Length);                 //There may be fewer available items than requested. In that case return all availabLe items.
                subArray = new Record[actualCount];
                for (int i = 0; i < actualCount; i++)
                {
                    subArray[i] = records[i];
                }
            }
            return(subArray);
        }
Example #4
0
 private void Table_Sort(object sender, SortEventArgs e)
 {
     primaryTextSort = columnToSortType(e.Column);
     syncData();
 }