Data Bindings: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 52: | Line 52: | ||
+ _yourNewBinding->Set(42); | + _yourNewBinding->Set(42); | ||
</pre> | </pre> | ||
* Your new binding should now show up in the <code>emp_bindings_list</code> command in the Empires console. | * Your new binding should now show up in the <code>emp_bindings_list</code> [[Console_commands|command]] in the Empires console. | ||
=== Choosing a Type === | |||
* For values that are strings or booleans the choice is simple, use the same type as the original value. | |||
* If your original type is a number and it changes very frequently (multiple times per second), try to use an int if that doesn't cause big artifacts on the [[HUD]]. This makes the HUD update less often resulting in a smoother game. | |||
* If the value changes less often or you actually need the extra precision, use a float. | |||
[[Category:VGUI]] | [[Category:VGUI]] |
Revision as of 23:49, 8 August 2017
The game exposes values to the HUD using Bindings. The HUD elements can register to a binding and receive a callback when the value changes. Bindings are indexed using a name and a type. The type is currently one of: int, string, float or bool.
Registering to a Bind
You can register a function to get called when a value gets changed. This is an example from the ammo hud panel:
bind.register("player_ammo_total", "int", function(value) { ammoTotalLabel.text = value; });
Existing Binds
This is an overview of the bindings available in Empires. You can get an up to date list by typing emp_binding_list
in your console.
Int
- player_mines_deployed - The amount of mines currently placed by the player
- player_ammo_current - The amount of ammo in the clip of the current weapon
- player_ammo_total - The amount of ammo in total
- player_mines_max - The maximum amount of mines the player can place
- player_ammo_clipsize - The maximum amount of ammo in a clip
- player_stamina - The stamina of the player from 0 to 100
- player_health_max - The maximum health of the player, normally 100.
- player_ammo_type - The type of ammo currently held.
- player_health - The current health of the player
- player_wages - The amount of wages the current player has.
- team_tickets - The amount of tickets the team of the player has
- team_res_total - The amount of resources the team of the player has
- team_res_income - The resource income per second for the team of the player
- team_tanks - The amount of vehicles the current team has on the field.
- team_tanks_max - The amount of vehicles the current team can place on the field.
- game_seconds_left - The amount of seconds left in the game.
- enemy_tickets - The amount of tickets of the enemy team (if applicable)
Adding a bind in C++ code
Binds usually live in either the C_EmpPlayer class, the C_EmpTeam class or the GameRules class. To create a new bind in the Player class, perform the following steps:
- Add a new bind member variable to the emp_player.h file:
std::shared_ptr< EmpDataBinding<int> > _healthBinding; std::shared_ptr< EmpDataBinding<int> > _staminaBinding; + std::shared_ptr< EmpDataBinding<int> > _yourNewBinding;
- In the constructor implementation of the player class, create the actual binding:
_healthBinding = EmpDataBindingManager<int>::GetBinding("player_health"); _staminaBinding = EmpDataBindingManager<int>::GetBinding("player_stamina"); + _yourNewBinding = EmpDataBindingManager<int>::GetBinding("your_new_binding");
- In the UpdateDataBindings function, set the actual value the bind is supposed to have:
_healthMaxBinding->Set(GetMaxHealth()); _staminaBinding->Set(GetStamina()); + _yourNewBinding->Set(42);
- Your new binding should now show up in the
emp_bindings_list
command in the Empires console.
Choosing a Type
- For values that are strings or booleans the choice is simple, use the same type as the original value.
- If your original type is a number and it changes very frequently (multiple times per second), try to use an int if that doesn't cause big artifacts on the HUD. This makes the HUD update less often resulting in a smoother game.
- If the value changes less often or you actually need the extra precision, use a float.