Announcement

Collapse
No announcement yet.

Filling UI ComboBox with players from the current game?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Filling UI ComboBox with players from the current game?

    I'm currently working on a mutator with a custom menu. That menu contains a combo-box where the players can be selected. I want to fill this combo-box with the list of players of the current game. Several menu elements do use the DataStore logic to provide data. You specify the DataStoreMarkup for an element to say which data this element should use.

    For intance, if you have a combobox and set the DataStoreMarkup to "<UTStringList:ScreenResolution>" the combobox is filled with resolutions automatically (on runtime or designtime). This works well for my current UI scene:
    Click image for larger version

Name:	UIDatastore_CurrentGame_ComboBox.jpg
Views:	1
Size:	67.2 KB
ID:	3253911

    However, as said, I need a list of current players. There is the the datastore CurrentGameDataStore which stores its data behind the name of CurrentGame (like UTUIDataStore_StringList stores its data behind UTStringList). CurrentGame has a registered DataProvider PlayerDataProvider which stores the players' data for the UI. The provider is stored behind the tag Players.

    I was assuming that the DataStoreMarkup of "<CurrentGame.Players>" will create a list of the current players. The problem with this, the Players provider has several sub properties like "PlayerName", "Score" etc.. It's not working with that markup. I also tried "<CurrentGame.Players.PlayerName>" to get a list of all players' name. No success.

    I tried to understand the DataStore better by checking the documenation for it here:
    http://udn.epicgames.com/Three/UIDataStore.html
    http://udn.epicgames.com/Three/UILists.html

    But it didn't help for me. So here is my question:
    Does anyone have experience with UI elements (like UIComboBox) and the use of the CurrentGame datastore to fill UI elements?
    I'm able to fill the data manually, asign a notify delegate for datastore changes but this involves several code lines. Using DataStore markup is only a single line of code and updates automatically.

    #2
    I ended up using a custom approach of adding elements to the ComboBox by creating a list in the 2D-StringList datastore (UTUIDataStore_2DStringList), filling the items manually when a player connects/disconnects and referencing that list by a dynamically created markup string.

    Code:
    var transient UTUIDataStore_2DStringList StringDatastore;
    var transient class<UTUIDataStore_2DStringList> StringDatastoreClass;
    
    function string CreateDataStoreStringList(name listname, array<string> entries)
    {
        local DataStoreClient DSC;
        local string fieldstr, ret;
        local name fieldname;
        local int i;
    
        // Get a reference to (or create) a 2D string list data store
        DSC = Class'UIInteraction'.static.GetDataStoreClient();
    
        if (StringDatastore == none)
        {
            StringDatastore = UTUIDataStore_2DStringList(DSC.FindDataStore(StringDatastoreClass.default.Tag));
            if (StringDatastore == none)
            {
                StringDatastore = DSC.CreateDataStore(StringDatastoreClass);
                DSC.RegisterDataStore(StringDatastore);
            }
        }
    
        // create unique names
        fieldstr = DataFieldPrefix$listname;
        fieldname = name(fieldstr);
    
        // Setup the list if it's not already set
        i = StringDatastore.GetFieldIndex(fieldname);
        if (i == INDEX_None)
        {
            i = StringDataStore.AddField(fieldname);
    
            // store the current fieldname to remove the list on destruction of the scene
            RegisteredDatafields.AddItem(fieldname);
        }
        else
        {
            // clear list and add all new entries if the list already exists
            StringDatastore.EmptyFieldLists(fieldname);
        }
    
        // fill the data fields within the data store 
        StringDatastore.AddFieldList(i, listname);
        StringDataStore.UpdateFieldList(i, listname, entries);
    
        ret = "<"$StringDatastore.Tag$":"$fieldname$">";
        return ret;
    }
    
    defaultproperties
    {
        StringDatastoreClass=class'UTUIDataStore_2DStringList'
        DataFieldPrefix="MyDataTag_"
    }
    The combo-box is filled with the following code for example.
    Code:
    function FillCombo(UIComboBox combo)
    {
        local array<string> players;
        local string str;
    
        // fill 'players' array with player names
        //... 
    
        str = CreateDataStoreStringList('CurrentPlayers', players);
        combo.ComboList.SetDataStoreBinding(str);
        combo.ComboList.RefreshSubscriberValue();
    }



    If anyone finds out how to use the CurrentGame datastore (CurrentGameDataStore) and use the Players data provider (<CurrentGame.Players>) to be used for a combo box (UIList), let me know.

    Comment

    Working...
    X