Misc

← Back Overriding cell button text

Overriding cell button text

There is an extension technique, which can be used for overriding cell button text for button-based fields. You can provide C# class or calculation graph, which can return custom text, based on database values. For example, let's say you have a Weapon table with a nested WeaponDamage table and each row of the nested table has power (int) and damageType (singleRelation) fields. The name field for the nested table is disabled and not used.

The default button text for the nested table is composed of the nested rows names, but since we do not use the name field, the button caption is [2] [no name] | [no name], which is not very informative

The solution for this problem is providing your own C# class (or calculation graph), which can be used for button text calculation. Below is the C# class example, which includes the number of related rows with power and damageType fields values to the button text

The C# code for custom button text provider
using BansheeGz.BGDatabase.Editor;

//this class uses CodeGen addon generated classes
public class WeaponEffectsButtonText : BGButtonTextProviderI
{
    public BGButtonTextResponse GetButtonText(BGButtonTextRequest request)
    {
        var response = new BGButtonTextResponse();
        var entity = (D_Weapon)request.Entity;
        var damageTypes = entity.WeaponDamage;
        if (damageTypes == null || damageTypes.Count == 0) response.Text = "No value";
        else
        {
            response.Text += $"[{damageTypes.Count}] ";
            for (var i = 0; i < damageTypes.Count; i++)
            {
                var damageType = damageTypes[i];
                if (i != 0) response.Text += " | ";
                response.Text += (damageType.damageType?.name ?? "[not set]") + ": " + damageType.power;
            }
        }
        return response;
    }
}

To assign the custom button text provider to your field, use M field's menu and Custom button text provider menu item

← Back to Misc