X2CommunityCore / X2WOTCCommunityHighlander

https://steamcommunity.com/workshop/filedetails/?id=1134256495
MIT License
60 stars 68 forks source link

Add OnSortFinished to UIPersonnel #402

Closed Onidotmoe closed 5 years ago

Onidotmoe commented 5 years ago

When the UIPersonnel is done sorting a delegate should be called, this is to allow easier access to disable rows that i don't want enabled, changing m_arrSoldiers does nothing as it gets ignored on the next sort.

Would do this myself but the game crashes when i try to do anything with my own modded Highlander.

Anyhow, there should be no issue with this once implement.

Here's the code that needs changing(in UIPersonnel.uc) :

// Delegates
var bool m_bRemoveWhenUnitSelected;
var public delegate<OnPersonnelSelected> onSelectedDelegate;

delegate OnPersonnelSelected(StateObjectReference selectedUnitRef);
delegate OnButtonClickedDelegate(UIButton ButtonControl);
delegate int SortDelegate(StateObjectReference A, StateObjectReference B);

To :

// Delegates
var bool m_bRemoveWhenUnitSelected;
var public delegate<OnPersonnelSelected> onSelectedDelegate;
var public delegate<OnSortFinishedCallBack> OnSortFinished;

delegate OnPersonnelSelected(StateObjectReference selectedUnitRef);
delegate OnButtonClickedDelegate(UIButton ButtonControl);
delegate int SortDelegate(StateObjectReference A, StateObjectReference B);

delegate OnSortFinishedCallBack();

Do note that the new delegate has to be after all the "var" values

Change this :

function SortData()
{
    switch( m_eSortType )
    {
    case ePersonnelSoldierSortType_Name:     SortCurrentData(SortByName);      break;
    case ePersonnelSoldierSortType_Location: SortCurrentData(SortByLocation);  break;
    case ePersonnelSoldierSortType_Rank:     SortCurrentData(SortByRank);      break;
    case ePersonnelSoldierSortType_Class:    SortCurrentData(SortByClass);     break;
    case ePersonnelSoldierSortType_Status:   SortCurrentData(SortByStatus);    break;
    case ePersonnelSoldierSortType_Kills:    SortCurrentData(SortByKills);    break;
    case ePersonnelSoldierSortType_Missions:     SortCurrentData(SortByMissions);    break;
    case ePersonnelSoldierSortType_Operations:   SortCurrentData(SortByOperation);    break;
    case ePersonnelSoldierSortType_Time:     SortCurrentData(SortByTime);    break;
    }

    m_bDirtySortHeaders = false;
    UpdateSortHeaders();
}

To this :

function SortData()
{
    switch( m_eSortType )
    {
    case ePersonnelSoldierSortType_Name:     SortCurrentData(SortByName);      break;
    case ePersonnelSoldierSortType_Location: SortCurrentData(SortByLocation);  break;
    case ePersonnelSoldierSortType_Rank:     SortCurrentData(SortByRank);      break;
    case ePersonnelSoldierSortType_Class:    SortCurrentData(SortByClass);     break;
    case ePersonnelSoldierSortType_Status:   SortCurrentData(SortByStatus);    break;
    case ePersonnelSoldierSortType_Kills:    SortCurrentData(SortByKills);    break;
    case ePersonnelSoldierSortType_Missions:     SortCurrentData(SortByMissions);    break;
    case ePersonnelSoldierSortType_Operations:   SortCurrentData(SortByOperation);    break;
    case ePersonnelSoldierSortType_Time:     SortCurrentData(SortByTime);    break;
    }

    m_bDirtySortHeaders = false;
    UpdateSortHeaders();
    OnSortFinished();
}

Adding our callback last to notify any outside function when the player has sorted the list.

Adding this to the base UIPersonnel instead of making a new one would ensure players can still use their own modded UIPersonnel without any issues.

Xymanek commented 5 years ago

Wouldn't a UIPersonnelSortFinished event be simpler?

Onidotmoe commented 5 years ago

Wouldn't a UIPersonnelSortFinished event be simpler? I think the above fits better in with how the rest of the game is coded and doesn't add more to the listening system.

Onidotmoe commented 5 years ago

Done : https://github.com/X2CommunityCore/X2WOTCCommunityHighlander/pull/422

Onidotmoe commented 5 years ago

This has been done at #591 This pull request should just be deleted it adds too much confusion, sorry about that.