private void ResetSortDirectionState() { _sortDirection = SortDirection.Descending; _lastSortTopic = SortTopic.None; _lastSortDirection = SortDirection.Descending; }
protected int CompareDefensiveStrength(Transform rowA, Transform rowB) { _lastSortTopic = SortTopic.DefensiveStrength; var rowAStrengthElement = GetGuiElement(rowA, GuiElementID.DefensiveStrength) as GuiStrengthElement; var rowBStrengthElement = GetGuiElement(rowB, GuiElementID.DefensiveStrength) as GuiStrengthElement; return CompareStrength(rowAStrengthElement, rowBStrengthElement); }
/// <summary> /// Assesses the sort direction needed and returns it. Records any /// resulting sorting state changes in prep for the next query. /// </summary> /// <param name="sortTopic">The current sort topic.</param> /// <returns></returns> private SortDirection DetermineSortDirection(SortTopic sortTopic) { SortDirection sortDirection; if (_lastSortTopic != sortTopic) { // new sort topic so direction should be descending sortDirection = SortDirection.Descending; //_lastSortTopic = sortTopic; // now set in Comparison method as the comparison method is called by UITable on Start } else { // same sort topic so direction should be the 'other' direction sortDirection = ToggleSortDirection(); } _lastSortDirection = sortDirection; //D.Log("{0}.AssessSortDirection(Topic: {1}): Direction: {2}, Value: {3}.", GetType().Name, sortTopic.GetName(), sortDirection.GetName(), (int)sortDirection); return sortDirection; }
protected int CompareSpeed(Transform rowA, Transform rowB) { _lastSortTopic = SortTopic.Speed; var rowASpeedLabel = GetLabel(rowA, GuiElementID.SpeedLabel); var rowBSpeedLabel = GetLabel(rowB, GuiElementID.SpeedLabel); return (int)_sortDirection * rowASpeedLabel.text.CompareTo(rowBSpeedLabel.text); }
protected int CompareComposition(Transform rowA, Transform rowB) { _lastSortTopic = SortTopic.Composition; var rowACompositionLabel = GetLabel(rowA, GuiElementID.CompositionLabel); var rowBCompositionLabel = GetLabel(rowB, GuiElementID.CompositionLabel); return (int)_sortDirection * rowACompositionLabel.text.CompareTo(rowBCompositionLabel.text); }
protected int CompareHealth(Transform rowA, Transform rowB) { _lastSortTopic = SortTopic.Health; var rowAHealthElement = GetGuiElement(rowA, GuiElementID.Health) as HealthGuiElement; var rowBHealthElement = GetGuiElement(rowB, GuiElementID.Health) as HealthGuiElement; return (int)_sortDirection * rowAHealthElement.CompareTo(rowBHealthElement); }
protected int CompareSize(Transform rowA, Transform rowB) { _lastSortTopic = SortTopic.Size; var rowASizeElement = GetGuiElement(rowA, GuiElementID.Size) as GuiSizeElement; var rowBSizeElement = GetGuiElement(rowB, GuiElementID.Size) as GuiSizeElement; return (int)_sortDirection * rowASizeElement.CompareTo(rowBSizeElement); }
protected int CompareLocation(Transform rowA, Transform rowB) { _lastSortTopic = SortTopic.Location; var rowALocationElement = GetGuiElement(rowA, GuiElementID.Location) as GuiLocationElement; var rowBLocationElement = GetGuiElement(rowB, GuiElementID.Location) as GuiLocationElement; return (int)_sortDirection * rowALocationElement.CompareTo(rowBLocationElement); }
protected int CompareOwner(Transform rowA, Transform rowB) { _lastSortTopic = SortTopic.Owner; var rowAOwnerElement = GetGuiElement(rowA, GuiElementID.Owner) as OwnerGuiElement; var rowBOwnerElement = GetGuiElement(rowB, GuiElementID.Owner) as OwnerGuiElement; return (int)_sortDirection * rowAOwnerElement.CompareTo(rowBOwnerElement); }
// Note: These comparison algorithms will be called multiple times when doing the sort so _sortDirection must be setup outside before sorting starts protected int CompareName(Transform rowA, Transform rowB) { //D.Log("{0}.CompareName() called.", GetType().Name); _lastSortTopic = SortTopic.Name; var rowANameLabel = GetLabel(rowA, GuiElementID.ItemNameLabel); var rowBNameLabel = GetLabel(rowB, GuiElementID.ItemNameLabel); return (int)_sortDirection * rowANameLabel.text.CompareTo(rowBNameLabel.text); }