Jump to content

Recommended Posts

Hey guys,

I've just registered so, many greets to you all:D

Allright, here's the idea: Last night I was bored and played some Tropico, then I thought: How about implementing some small economy to the different locations like the lumberjack camps or banana plantations on Tanoa to hire some guys to work for your Team and earn some money with it. It could lead to a persistent rebell mission where you have to buy new weapons and stuff and defend your economy against the local government or something, don't know exactly, just been playing around, but here is my point:

 

I have set up a first dialog that opens at a laptop at the plantation office like this:

Ml1vsL7.jpg?1

If you klick on the different inactive buttons (in fact these are pictures, but I will call them buttons from here on), the script will hire some workers, pay them as you want and you will need some trucks to move the stuff your guys harvestet.

OzVTrpa.jpg

Example: If no budget button is active, they all have transparency 0.2. If you just hover over it, transparency is set to 1 to indicate to the player that he can click something. In the case of no active buttons, if player for example clicks on budget button #3, all buttons left from #3 including #3 will switch to active, color transparency changes from 0.2 to 1, colorActive transparency switches from 1 to 0.2. Now you are paying some money, right;D If player now clicks on maybe button #2, buttons #2 and #3 will "deactivate" and change transparency back again.

 

Everything is working fine so far, you get the idea, right? So here are the problems, finally:

 

I need a method that allows me to create just one class (inside controls in dialog.hpp) for the "budget buttons", one for the "worker buttons" and just one for "trucks buttons", wich I can access dynamically via some script to set their position and transparency.

Right now, every single button has its own class, so just for this dialog i needed to write 17 classes RscActiveText. I did this because I needed to change the transparency of  "color[] = ...." and "colorActive[]=..." every time you click on a button and for this I declared three unique variables for every button, makes 51 global variables in total just to change transparency. First one to let the script know if the button is already clicked, and the two other ones to change the transparency of color and colorActive back and forth, depending on the state of the button. Heres a little summary of a part of the dialog.hpp and the script activated by clicking the buttons. The 51 global variables (and more) ar predefined after init.

 

dialog.hpp:

class budg_bttn1: RscActiveText
        {
            idc = 1601;
            text = "pics\moneyPile.paa"; 
            x = 0.840312 * safezoneW + safezoneX;
            y = 0.258 * safezoneH + safezoneY;
            w = 0.0154688 * safezoneW;
            h = 0.022 * safezoneH;
            color[] = {1, 1, 1, missionNamespace getVariable "bttn_col1"}; //global variable#1 for transparency
	        colorActive[] = {1, 1, 1, missionNamespace getVariable "bttn_actCol1"}; //global variable#2 for transparency
            onMouseButtonClick = "[_this] execVM 'oumere_plantations\moneyBttns.sqf';";
        };
        class budg_bttn2: RscActiveText
        {
            idc = 1602;
            text = "pics\moneyPile.paa"; 
            x = 0.87125 * safezoneW + safezoneX;
            y = 0.258 * safezoneH + safezoneY;
            w = 0.0154688 * safezoneW;
            h = 0.022 * safezoneH;
            color[] = {1, 1, 1, missionNamespace getVariable 'bttn_Col2'};
	        colorActive[] = {1, 1, 1, missionNamespace getVariable 'bttn_actCol2'};
            onMouseButtonClick = "[_this] execVM 'oumere_plantations\moneyBttns.sqf';";
        };
        class budg_bttn3: RscActiveText
        {
            idc = 1603;
            text = "pics\moneyPile.paa"; 
            x = 0.902187 * safezoneW + safezoneX;
            y = 0.258 * safezoneH + safezoneY;
            w = 0.0154688 * safezoneW;
            h = 0.022 * safezoneH;
            color[] = {1, 1, 1, missionNamespace getVariable 'bttn_Col3'};
	        colorActive[] = {1, 1, 1,  missionNamespace getVariable 'bttn_actCol3'};
            onMouseButtonClick = "[_this] execVM 'oumere_plantations\moneyBttns.sqf';";
        //..........etc. etc.

moneyBttns.sqf:


disableSerialization;

_display = findDisplay 5000;
_control = (_this select 0) select 0;
_controls = [_display displayCtrl 1601, _display displayCtrl 1602, _display displayCtrl 1603, _display displayCtrl 1604, _display displayCtrl 1605];
//_activeButtons = [];
//_inacitveButtons = [];

switch (ctrlIDC _control) do {
	case 1601: //checks wich button is clicked on
	{
		switch (bttn_active1) do //checks, if button is already active. bttn_active1 switches between 0 and 1
		{
			case 0:
			{
				missionNamespace setVariable ["plantationIndex", 1, true]; //plantationIndex tells how many buttons are active in total
				missionNamespace setVariable [format ["bttn_active%1", 1], 1, true];//sets the buttons active state
				missionNamespace setVariable [format ["bttn_Col%1", 1], 1, true];//changing of transparency, in this case, button will..
				missionNamespace setVariable [format ["bttn_actCol%1", 1], 0.2, true];//...appear with transp. if you hover over it
				(_controls select 0) ctrlSetTextColor [1,1,1, bttn_Col1];//sending transparency state to class
				(_controls select 0) ctrlSetActiveColor [1,1,1, bttn_actCol1];
				if (debug) then {systemChat format ["PlantationIndex = %1", plantationIndex];};
			};
			case 1:
			{
				plantationIndex = 0; 
				missionNamespace setVariable [format ["bttn_active%1", 1], 0, true];
				missionNamespace setVariable [format ["bttn_Col%1", 1], 0.2, true];
				missionNamespace setVariable [format ["bttn_actCol%1", 1],1, true];
				(_controls select 0) ctrlSetTextColor [1,1,1, bttn_Col1];
				(_controls select 0) ctrlSetActiveColor [1,1,1, bttn_actCol1];
				for "_i" from 1 to 5 do 
				{
					missionNamespace setVariable [format ["bttn_active%1", _i], 0, true];
					missionNamespace setVariable [format ["bttn_Col%1", _i], 0.2, true];
					missionNamespace setVariable [format ["bttn_actCol%1", _i], 1, true];
					
					(_controls select (_i-1)) ctrlSetActiveColor [1,1,1, call compile format ["bttn_actCol%1", _i]];
					(_controls select (_i-1)) ctrlSetTextColor [1,1,1, call compile format ["bttn_Col%1", _i]];
				};
				if (debug) then {systemChat format ["PlantationIndex = %1", plantationIndex];};
			};
		};
	};
	case 1602: 
	{
		switch (bttn_active2) do 
		{
			case 0:
			{
				plantationIndex = 2;
				for "_i" from 1 to 2 do 
				{
					missionNamespace setVariable [format ["bttn_active%1", _i], 1, true];
					missionNamespace setVariable [format ["bttn_Col%1", _i], 1, true];
					missionNamespace setVariable [format ["bttn_actCol%1", _i], 0.2, true];
					(_controls select (_i-1)) ctrlSetActiveColor [1,1,1, call compile format ["bttn_actCol%1", _i]];
					(_controls select (_i-1)) ctrlSetTextColor [1,1,1, call compile format ["bttn_Col%1", _i]];
				};
				if (debug) then {systemChat format ["PlantationIndex = %1", plantationIndex];};
			};
			case 1:
			{
				plantationIndex = 1;
				for "_i" from 2 to 5 do 
				{
					missionNamespace setVariable [format ["bttn_active%1", _i], 0, true];
					missionNamespace setVariable [format ["bttn_Col%1", _i], 0.2, true];
					missionNamespace setVariable [format ["bttn_actCol%1", _i], 1, true];
					(_controls select (_i-1)) ctrlSetActiveColor [1,1,1, call compile format ["bttn_actCol%1", _i]];
					(_controls select (_i-1)) ctrlSetTextColor [1,1,1, call compile format ["bttn_Col%1", _i]];
				};
				if (debug) then {systemChat format ["PlantationIndex = %1", plantationIndex];};
			};
		};
	};
	case 1603: 
	{ 
		switch (bttn_active3) do
		{
			case 0:
			{
				plantationIndex = 3;
				for "_i" from 1 to 3 do 
				{
					missionNamespace setVariable [format ["bttn_active%1", _i], 1, true];
					missionNamespace setVariable [format ["bttn_Col%1", _i], 1, true];
					missionNamespace setVariable [format ["bttn_actCol%1", _i], 0.2, true];
					(_controls select (_i-1)) ctrlSetActiveColor [1,1,1, call compile format ["bttn_actCol%1", _i]];
					(_controls select (_i-1)) ctrlSetTextColor [1,1,1, call compile format ["bttn_Col%1", _i]];
				};
				if (debug) then {systemChat format ["PlantationIndex = %1", plantationIndex];};
			};
			case 1:
			{
				plantationIndex = 2;
				for "_i" from 3 to 5 do 
				{
					missionNamespace setVariable [format ["bttn_active%1", _i], 0, true];
					missionNamespace setVariable [format ["bttn_Col%1", _i], 0.2, true];
					missionNamespace setVariable [format ["bttn_actCol%1", _i], 1, true];
					(_controls select (_i-1)) ctrlSetActiveColor [1,1,1, call compile format ["bttn_actCol%1", _i]];
					(_controls select (_i-1)) ctrlSetTextColor [1,1,1, call compile format ["bttn_Col%1", _i]];
				};
				if (debug) then {systemChat format ["PlantationIndex = %1", plantationIndex];};
			};	
		};
	};//....etc.etc.

So, can someone imagine a better practice to solve this idea?

As you can imagine, if I want to create more businesses on the island, I need to write a huge amount of classes and variables for every location. The problem is, that If I just use one class using the same global vars for the budget buttons, all buttons change transparency even when I just click a single one.

I don't really unserstand how to refer between classes and variables using uiNamespace, maybe there's a solution in there?

 

I hope I explained this one well enough and any help is highly appreciatet. Greets from Germany;D

 

 

 

Share this post


Link to post
Share on other sites

Rather than storing each plantation's data in missionNamespace, instead pass an Object (i.e the laptop) to store the data for this plantation.

 

Laptop addAction

//laptop init
this addAction [ "Manage Plantation", {
		params [ "_target", "_caller", "_id", "_args" ];
		
		_nul = [ _target ] spawn {
			params[ "_laptop" ];
			
			//open display
			createDialog "myDialog";
			//Wait for display to be shown
			waitUntil { !isNull findDisplay 5000 };
			//Set variable on display of plantation laptop
			findDisplay 5000 setVariable [ "laptop", _laptop ];
		};
		
	},
	[],
	1,
	true,
	true,
	"",
	""
];

 

Dialog with button macro

#define BUDGET( btn_name, btn_idc, btn_column ) \
	class btn_name: RscActiveText \
	{ \
		idc = btn_idc; \
 \
		x = (( 0.840312 * safezoneW + safezoneX ) + ((( 0.0154692 + 0.0154688 ) * safeZoneW ) * btn_column )); \
		y = 0.258 * safezoneH + safezoneY; \
		w = 0.0154688 * safezoneW; \
		h = 0.022 * safezoneH; \
 \
		text = "pics\moneyPile.paa"; \
		color[] = {1, 1, 1, 0.2 }; \
		colorActive[] = {1, 1, 1, 1 }; \
 \
		onMouseButtonClick = "[ 'SELECTED', _this ] execVM 'oumere_plantations\moneyBttns.sqf';"; \
		onLoad = "[ 'INIT', _this ] execVM 'oumere_plantations\moneyBttns.sqf';"; \
	}


class myDialog 
{
	idd = 5000;
	class controls {
		//	class name, idc, column
		BUDGET( budg_bttn1, 1601, 0 );
		BUDGET( budg_bttn2, 1602, 1 );
		BUDGET( budg_bttn3, 1603, 2 );
		BUDGET( budg_bttn4, 1604, 3 );
		BUDGET( budg_bttn5, 1605, 4 );
	};
};

Where each buttons X is

(( 0.840312 * safezoneW + safezoneX ) + ((( 0.0154692 + 0.0154688 ) * safeZoneW ) * btn_column ))

the first buttons start position plus a button width and rough gap (calculated from what you have shown) multiplied by its column number.

So button at column 0 will have an X of ( 0.840312 * safezoneW + safezoneX ) as ((( 0.0154692 + 0.0154688 ) * safeZoneW ) * btn_column ) multiplied by 0 (column) is 0.

Button at column 1 will have an X of (( 0.840312 * safezoneW + safezoneX ) + ((( 0.0154692 + 0.0154688 ) * safeZoneW ) * 1 )) original start X plus one button width and one gap. etc etc

 

oumere_plantations\moneyBttns.sqf

disableSerialization;

_display = findDisplay 5000;
_budgetButtonsIDCs = [ 1601, 1602, 1603, 1604, 1605 ];

//Wait for the display to have its plantation laptop set
waitUntil{ !isNull ( _display getVariable [ "laptop", objNull ] ) };

//from the display get the plantation laptop
_laptop = _display getVariable "laptop";

//from the laptop get the current budget data
_budgetData = _laptop getVariable [ "budgetData", [ 0, 0, 0, 0, 0 ] ]; //all inactive if no data found

params[ "_mode", "_this" ];

switch ( toUpper _mode ) do {
	
	//called when each button is loaded
	case "INIT" : {
		params[ "_btn" ];
		
		//Get button index
		_btnIndex = _budgetButtonsIDCs find ctrlIDC _btn;
		
		//If we have a valid index
		if !( _btnIndex isEqualTo - 1 ) then {
			
			//Get data for button
			_isActive = _budgetData select _btnIndex > 0;
			
			//Set buttons colors based on whether it is active
			_btn ctrlSetTextColor [1,1,1,[ 0.2, 1 ] select _isActive];
			_btn ctrlSetActiveColor [1,1,1,[ 1, 0.2 ] select _isActive];
		};
	};
	
	//called when mouse button is pressed over button
	case "SELECTED" : {
		params[ "_btn", "_mouseButton" ];
		
		//left mouse button was pressed
		if ( _mouseButton isEqualTo 0 ) then {
			
			//Get button index
			_btnIndex = _budgetButtonsIDCs find ctrlIDC _btn;
			
			//If we have a valid index
			if !( _btnIndex isEqualTo -1 ) then {
				
				//Get data for button
				_isActive = _budgetData select _btnIndex > 0;
				
				if ( _isActive ) then {
					//if the button is currently active then
					//all controls from this to last need to be set inActive
					{
						//Get the button from its IDC
						_btn = _display displayCtrl _x;
						
						//Set inActive
						_btn ctrlSetTextColor [1,1,1,0.2];
						_btn ctrlSetActiveColor [1,1,1,1];
						
						//Update data
						_budgetData set[ _btnIndex + _forEachIndex, 0 ];
					}forEach ( _budgetButtonsIDCs select [ _btnIndex, count _budgetButtonsIDCs ] );
				}else{
					//if the button is currently inactive then
					//all controls from start to this need to be set active
					{
						//Get the button from its IDC
						_btn = _display displayCtrl _x;
						
						//Set active
						_btn ctrlSetTextColor [1,1,1,1];
						_btn ctrlSetActiveColor [1,1,1,0.2];
						
						//Update data
						_budgetData set[ _forEachIndex, 1 ];
					}forEach ( _budgetButtonsIDCs select [ 0, _btnIndex + 1 ] );
				};
				
				//Update data stored on laptop
				_laptop setVariable [ "budgetData", _budgetData, true ];
			};
		};
	};	
};

 

  • Like 2

Share this post


Link to post
Share on other sites

Hey Larrow,

sorry for the late answer but I was pretty busy last days.

Thank you very much, this is just the idea i was looking for. I haven't worked with it yet but I will update you when I have the time to test it. On the first look, it seems to work in just the way I need it. Thank you for pushing me into the right direction.

Greets, Crawl

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

×