Home   Help Search Login Register  

Author Topic: How to update a dialog in real time  (Read 2346 times)

0 Members and 1 Guest are viewing this topic.

Offline GameAdd1cted

  • Members
  • *
How to update a dialog in real time
« on: 17 Jan 2010, 00:19:23 »
Hi again, got stuck again  >:(

I have a dialog and 2 combobox controls on it.

Combobox 1 (idc 1701) has the following items: [A, B, C]
Based on the selection the player makes, the second combobox  (idc 1702) displays an according list
(e.g.
If A was selected, the second combo list woud be A1, A2, A3...
If B was selected, the second combo list woud be B1, B2, B3...)

I managed to do this, but if the player changes again the first list, the second one doesn't update.
Maybe LBSelChanged is the solution, but I am clueless with ctrlSetEventHandler.

Here it is the code:
Code: [Select]
_ok = createDialog "GadCreateEnemyDialog";

// Seleccionador de tipo de unidades a crear (infanterĂ­a, grupos, vehĂ­culos, etc.)
for [{_i = 0}, {_i < count GadTypeToSpawnArray}, {_i = _i + 1}] do {
_item = GadTypeToSpawnArray select _i;
_index = lbadd [1701,_item];
};

waitUntil {lbcursel 1701 != -1;};
currentType = lbcursel 1701;

switch (lbcursel 1701) do {
case 0: {GadElementsToSpawnArray = GadInfantryToSpawnArray;};
case 1: {GadElementsToSpawnArray = GadGruposToSpawnArray;};
case 2: {GadElementsToSpawnArray = GadVehiclesToSpawnArray;};
};

for [{_i = 0}, {_i < count GadElementsToSpawnArray}, {_i = _i + 1}] do {
_item = GadElementsToSpawnArray select _i;
_index = lbadd [1702,_item];
};
« Last Edit: 17 Jan 2010, 00:39:53 by GameAdd1cted »

Offline i0n0s

  • Moderator
  • *****
Re: How to update a dialog in real time
« Reply #1 on: 17 Jan 2010, 02:04:53 »
Define OnLBSelChanged with the code which should run when you change the combobox.
The definition has to be within the dialogue definition.
Take a look here:
http://community.bistudio.com/wiki/User_Interface_Event_Handlers

Offline GameAdd1cted

  • Members
  • *
Re: How to update a dialog in real time
« Reply #2 on: 17 Jan 2010, 17:22:41 »
i0n0s,

Thank you, got it working :)
The event handlers look intimidating, but as there is no other solution... :)

Anyways, just in case somebody has the same issue:

In the dialog definition file:
Code: [Select]
class GadComboTypeSelection : GadCombo {
idc = 1701;
x = 0.1;
y = 0.1;
onLBSelChanged = "hint str _this; lbclear 1702; call GadFunctionTest;";
};

I defined the GadFunctionTest in the init.sqf
Code: [Select]
GadFunctionTest = {nul = [] execVM "GadDialog.sqf";};
The GadDialog.sqf

Code: [Select]
lbclear 1702;

switch (lbcursel 1701) do {
case 0: {GadElementsToSpawnArray = GadInfantryToSpawnArray;};
case 1: {GadElementsToSpawnArray = GadGruposToSpawnArray;};
case 2: {GadElementsToSpawnArray = GadVehiclesToSpawnArray;};
};

for [{_i = 0}, {_i < count GadElementsToSpawnArray}, {_i = _i + 1}] do {
_item = GadElementsToSpawnArray select _i;
_index = lbadd [1702,_item];
};