Jump to content
Sign in to follow this  
UltimateBawb

Calling a dialog box directly from addAction

Recommended Posts

Is it possible to call a class from addAction? I don't want to make a new .sqf for every dialog call.

Share this post


Link to post
Share on other sites

addAction calls a script. That's what it does. :) Make a menu dialog called from a script and put the rest of your dialog calls in there.

Share this post


Link to post
Share on other sites

But once I call the .sqf file that holds every script, how would I determine which class to call? Sorry if I'm not getting this.

Share this post


Link to post
Share on other sites

Have a unit with an action that will open up a dialog box. But there will be multiple units each with their own dialog.

Share this post


Link to post
Share on other sites

That's unhelpful. :) You've already established that. What does the dialog box contain, say and do? What does each unit see? What is this action supposed to do exactly?

Share this post


Link to post
Share on other sites

You always can pass arguments into sqf script with addAction so you can open dialog depending on which argument was passed and have only one sqf for all dialogs. Read: addAction

Share this post


Link to post
Share on other sites

Just like they said above you can pass arguments with addAction.

//init.sqf
waitUntil {isDedicated || (!isNull player)};
if (local player) then {
 if (!isNil "unit1") then {
   if (player == unit1) then 
   {
     player addAction ["Dialog","dialog.sqf",1];
   };
 };
//etc
};

Notice the number at the end

If you have respawn you might have to add the action again after the player has respawned. If you're using CBA you can use this

// dialog.sqf
_nr = _this select 3;

switch _nr do 
{
 case 1: {createDialog "myDialog1"};
 case 2: {createDialog "myDialog2"};
 default {hint "houston my switch is borke"};
};

Edited by cuel

Share this post


Link to post
Share on other sites
That's unhelpful. :) You've already established that. What does the dialog box contain, say and do? What does each unit see? What is this action supposed to do exactly?

Ok, sorry.

The dialogue is essentially a shop, consisting mainly of buttons. When a button is pressed, the selected weapon is changed to the corresponding weapon, and the buy button causes that weapon to be spawned. Only the unit who activates the addAction will see the dialog.

Share this post


Link to post
Share on other sites

Does the weapons available change based on the unit or something? I don't see why you couldn't call that from a script?

Share this post


Link to post
Share on other sites

YES. Sorry I didn't mention that. That's why I need to distinguish between scripts and classes.

Share this post


Link to post
Share on other sites

This is why I asked what exactly it does. :) As we've mentioned before in this thread, you can feed addAction scripts anything you want as _this select 3 which you can than use to change what gets displayed. Post your mission please and I'm sure we'll find an elegant way for this to work.

Share this post


Link to post
Share on other sites

This is the code that is involved in the dialog making, would be great if you could help. I left the fields of the addActions empty for obvious reasons.

init.sqf:

execVM "initActions";

initActions.sqf:

shopWest addAction ["Buy Weapons and Equipment", ""];
shopEast addAction ["Buy Weapons and Equipment", ""];

description.ext:

#include "Defines.hpp"
#include "Dialogs.hpp"

Defines.hpp:

class Button {
type                      = CT_BUTTON;
idc                       = -1;
style                     = ST_LEFT;
colorText[]               = {0, 0, 0, 1};
font                      = FontM;
text 					  = ""
sizeEx                    = 0.025;
default                   = false;
colorActive[]             = {0, 0, 0, 0};
colorDisabled[]           = {0, 0, 0, 0.1};
colorBackground[]         = {0.8,0.8,0.8,0.3};
colorBackgroundActive[]   = {0.7,0.7,0.7,1};
colorBackgroundDisabled[] = {1,1,1,0.3};
colorFocused[]            = {0.84,1,0.55,1};
colorShadow[]             = {0, 0, 0, 0.1};
colorBorder[]             = {1, 1, 1, 1};
soundEnter[]              = {"", 0.15, 1};
};

Dialogs.hpp:

class shopWest
{
idd = -1;			
movingEnable = true;	
controlsBackground[] = {Background};		
objects[] = { };							
controls[] = { M4A1};	

class Background {
	colorBackground[] = { 0.40, 0.33, 0.19, 0.95 };
	style = ST_BACKGROUND;
	x = 0.06;
	y = 0.15;
	w = 0.372;
	h = 0.4;
};

class M4A1: Button {
	x = 0.068;
	y = 0.19;
	w = 0.353;
	h = 0.04;
	text = "1: M4A1 Carbine"
};
};

class shopEast
{
idd = -1;			
movingEnable = true;	
controlsBackground[] = {Background};		
objects[] = { };							
controls[] = { AKM};	

class Background {
	colorBackground[] = { 0.40, 0.33, 0.19, 0.95 };
	style = ST_BACKGROUND;
	x = 0.06;
	y = 0.15;
	w = 0.372;
	h = 0.4;
};

class AKM: Button {
	x = 0.068;
	y = 0.19;
	w = 0.353;
	h = 0.04;
	text = "1: AKM"
};
};

Share this post


Link to post
Share on other sites

That's not the mission, you're still missing a lot. For instance all your defines for those dialogs so that code doesn't really help much. You're also reinventing the wheel, try this.

Share this post


Link to post
Share on other sites

Wow, that script really helps, thanks :)

I did define those in Defines.hpp, but figured posting them would be unnecessary. Thanks for the help, I should be able to work with what you've given me.

Share this post


Link to post
Share on other sites

I was on the verge of making that script work with selected weapons instead of any weapons, but got dragged into a big fight. I'll try it later though. :)

Here's the script edited to allow you to limit which weapons should be allowed by side. Should be able to call it directly from addAction. The main problems with this is that it aggressively removes your weapons and magazines completely and gives you the full selection of possibly mags for whatever weapon you pick. Which could be neat depending.

#include "def_wepsel.hpp"
private["_wepsel"];

// Limit weapons available by side.
_OKlist = switch (side player) do {
case west: {["M1014", "M40A3", "M24", "M249_EP1"]};
case east: {["FN_FAL", "AKS_74", "SVD_des_EP1", "PK"]};
case default {["M9"]};
};

_weaponsList = [];
_namelist = [];
_cfgweapons = configFile >> "cfgWeapons";

for "_i" from 0 to (count _cfgweapons)-1 do {
_weapon = _cfgweapons select _i;
if (isClass _weapon) then {
	_wCName = configName(_weapon);
	if (!(_wCname in _OKlist)) exitWith{};
	_wDName = getText(configFile >> "cfgWeapons" >> _wCName >> "displayName");
	_wModel = getText(configFile >> "cfgWeapons" >> _wCName >> "model");
	_wType = getNumber(configFile >> "cfgWeapons" >> _wCName >> "type");
	_wPic =  getText(configFile >> "cfgWeapons" >> _wCName >> "picture");
	_wDesc = getText(configFile >> "cfgWeapons" >> _wCName >> "Library" >> "libTextDesc");		

	_isFake = false;
	_wHits=0;
	_mags=[];
	_muzzles = getArray(configfile >> "cfgWeapons" >> _wCName >> "muzzles");
	if ((_muzzles select 0)=="this") then {
		_muzzles=[_wCName];
		_mags = getArray(configfile >> "cfgWeapons" >> _wCName >> "magazines");
	} else {
		{
			_muzzle=_x;
			_mags = getArray(configfile >> "cfgWeapons" >> _wCName >> _muzzle >> "magazines");
		}forEach _muzzles;
	};
	{
		_ammo = getText(configfile >> "cfgMagazines" >> _x >> "ammo");
		_hit = getNumber(configfile >> "cfgAmmo" >> _ammo >> "hit");
		_wHits = _wHits + _hit;
	}forEach _mags;
	if ("vbs2_mag_canon_xl1" in _mags) then {_wCName=""};	// can't catch the video camera any other way...
	if ((_wCName!="") && (_wDName!="") && (_wModel!="") && (_wType<6) && (_wHits>1) && !("fake" in _mags)) then {
		if !(_wDName in _namelist) then {
			_weaponsList = _weaponsList + [[_wCName,_wDName,_wPic,_wDesc]];
				_namelist = _namelist + [_wDName];
		};
	};
};
if (_i % 10==0) then {
	hintSilent format["Loading Weapons List... (%1)",count _weaponsList];
	sleep .0001;
};
};
hint "";
_namelist=nil;

doEquip = {
// equip player with selected weapon, and all compatible mags
KRON_MAGS=[];
{player removeMagazine _x} forEach magazines player;
_muzzles = getArray(configfile >> "cfgWeapons" >> _wepsel >> "muzzles");
{
	if (_x=="this") then {
		_mags = getArray(configfile >> "cfgWeapons" >> _wepsel >> "magazines");
		{
			KRON_MAGS=KRON_MAGS+[_x];
			player addMagazine _x;
		}forEach _mags;
	} else {
		_mags = getArray(configfile >> "cfgWeapons" >> _wepsel >> _x >> "magazines");
		{
			KRON_MAGS=KRON_MAGS+[_x];
			player addMagazine _x;
		}forEach _mags;
	};
} forEach _muzzles;

player addWeapon _wepsel;
{if (_x!=_wepsel) then {player removeWeapon _x}} forEach weapons player;
};


#ifndef VBS
disableSerialization;
#endif

// fill dialog with weapon names
createDialog "SelectWeapon";
sleep .1;
_ctrlList = findDisplay DLG_WEP_IDD displayCtrl DLG_WEP_LIST;

for "_i" from 0 to (count _weaponsList)-1 do {
_weapon = _weaponsList select _i;
lbAdd [DLG_WEP_LIST,format["%1",_weapon select 1]];
lbSetPicture [DLG_WEP_LIST, _i, _weapon select 2];
lbSetValue [DLG_WEP_LIST, _i, _i];
};
lbSort (findDisplay DLG_WEP_IDD displayCtrl DLG_WEP_LIST); 

// highlight player's current one
_index=0;
for "_i" from 0 to (lbSize DLG_WEP_LIST)-1 do {
lbSetCurSel [DLG_WEP_LIST,_i];
if (_index==0) then {
	{
		if ((_weaponsList select lbValue [DLG_WEP_LIST, _i]) select 0==_x) then {
			_index=_i;
		};
	}forEach weapons player;
};
};
// put the selection somewhat in the middle of the displayed listing
_i=(_index -9) max 0;
lbSetCurSel [DLG_WEP_LIST, _i];
lbSetCurSel [DLG_WEP_LIST, _index];

// preview controls
_ctrlPic = findDisplay DLG_WEP_IDD displayCtrl DLG_WEP_PIC;
_ctrlName = findDisplay DLG_WEP_IDD displayCtrl DLG_WEP_NAME;
_ctrlDesc = findDisplay DLG_WEP_IDD displayCtrl DLG_WEP_DESC;

_wepidx=lbValue [DLG_WEP_LIST, _index];
_lstidx=_index;
_lstpos=-1;
DLG_WEP_SELECTED=false;
while {ctrlVisible DLG_WEP_LIST} do {
_index = lbCurSel DLG_WEP_LIST;
_posidx = _index;
#ifdef VBS	
if !(isNil "DLG_WEP_SEL") then {
	if (DLG_WEP_SEL select 3) then {
		_posidx = _ctrlList lbPosIndex [DLG_WEP_SEL select 1,DLG_WEP_SEL select 2];
	};
};
#endif	
if (DLG_WEP_SELECTED) then {
	_wepidx=lbValue [DLG_WEP_LIST, _index];
	closeDialog DLG_WEP_IDD;
	_wepsel=(_weaponsList select _wepidx) select 0;
	call doEquip;
};
if (_posidx==-1) then {
	_posidx = _index;
};
if (_lstpos!=_posidx) then {
	_lbidx = lbValue [DLG_WEP_LIST, _posidx];
	_wDName = (_weaponsList select _lbidx) select 1;
	_wPic = (_weaponsList select _lbidx) select 2;
	_wDesc = (_weaponsList select _lbidx) select 3;
	_ctrlPic ctrlSetText _wPic;
	_ctrlName ctrlSetText _wDName;
	_ctrlDesc ctrlSetStructuredText parseText (_wDesc);
	_lstpos=_posidx;
};
sleep .1;
};

Edited by kylania
Fixed

Share this post


Link to post
Share on other sites

Thank you so much! I was just struggling to get that working myself, but I used arrays to create an "okList" instead of classes. You're truly awesome. +1

Share this post


Link to post
Share on other sites

Actually, I'm still having problems. You said it would be compatible with addAction. How?

Share this post


Link to post
Share on other sites

What problems are you having? The demo I tested that code with is at home so I'll double check later, but all I did was run that script from an addAction.

Share this post


Link to post
Share on other sites

Oh, I forgot to mention I originally didn't plan for it to be based on which side you're on. I'm trying to make it run based on what variable "Shop" equals.

Share this post


Link to post
Share on other sites

// Limit weapons available by side.
_OKlist = switch (player getVariable "shop") do {
case "ScopedGuns": {["M40A3", "SVD_des_EP1", "M24"]};
case "ShotgunGuns": {["M1014"]};
case "LMGGuns": {["M249_EP1", "PK"]};
case "GenericGuns": {["FN_FAL", "AKS_74"]};
case default {["M9"]};
};

or to filter by what's in the addAction call:

// this addAction ["Buy Scoped Weapon", "wepsel.sqf","ScopedGuns"];
// Limit weapons available by side.
_OKlist = switch (_this select 3) do {
...

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×