Jump to content
juleshuxley

Hello World RscText

Recommended Posts

I'm having real difficulty with UI's as there isn't much documentation.
I've been able to use ctrlCreate to create a RscText box and change it's position and color with commands such as ctrlSetPosition and ctrlSetBackgroundColor.

My mission folder contains three folders:

  • config.cpp
  • init.sqf
  • mission.sqm
     

config.cpp:

class RscText {
  access = 0;
  type = CT_STATIC;
  idc = -1;
  style = ST_LEFT;
  w = 0.1; h = 0.05;
  //x and y are not part of a global class since each rsctext will be positioned 'somewhere'
  font = "TahomaB";
  sizeEx = 0.04;
  colorBackground[] = {0,0.9,0,0};
  colorText[] = {1,1,1,1};
  text = "HELLO WORLD";
  fixedWidth = 0;
  shadow = 0;
};

 

init.sqf

"someLayer" cutRsc ["RscTitleDisplayEmpty", "PLAIN"];

disableSerialization;
_display = uiNamespace getVariable "RscTitleDisplayEmpty";

_columnWidth = 0.015;
_rowHeight = 0.02;

_currentRow = uiNamespace getVariable ["currentRow",safeZoneY];

_font = "EtelkaMonospacePro";
//_text = "A";
_item = _display ctrlCreate ["RscText", -1];

_currentColumn = safeZoneX + (1 * _columnWidth);

_item ctrlSetPosition [_currentColumn,_currentRow,_columnWidth,_rowHeight];
_item ctrlSetFontHeight _rowHeight; 
//_item ctrlSetBackgroundColor [0.0,0.0,0.0,1.0];
//_item ctrlSetText _text;
_item ctrlCommit 0;
_item ctrlSetTextColor [1.0,1.0,1.0,1.0];

So I'd expect this code to create a RscText on the screen, containing the text "HELLO WORLD" and with a green background. But no, nothing. It doesn't seem to pick up on my classes in config.cpp.

Main question: So how should I create a custom RscText class?

Side question: nothing is displayed if I don't have this line at the top of my code:

"someLayer" cutRsc ["RscTitleDisplayEmpty", "PLAIN"];

How does ctrlCreate know to attach my RscText to someLayer? Does it just look for an empty layer?

And why is disableSerialization needed?

Tanks a lot

Share this post


Link to post
Share on other sites
2 hours ago, juleshuxley said:

But no, nothing. It doesn't seem to pick up on my classes in config.cpp.

As you have not explicitly told it to load your config.cpp. The base config for missions( missionConfigFile ) is the description.ext ( config.cpp is the entry point for a mod/addon ).

So either place your class RscText in description.ext or include config.cpp from your description.ext.

 

As a side note I would recommend never using BI control names but instead inherit from BI's version and make your changes to your own.

Spoiler

//description.ext

#include "BaseDefines.hpp"
#include "MyUIControls.hpp"

//baseDefines.hpp

//BI's Base structure needed for RscText
//See BIS_fnc_exportGUIBaseClasses

#define CT_STATIC			0
#define ST_LEFT				0x00

#define GUI_GRID_WAbs		((safezoneW / safezoneH) min 1.2)
#define GUI_GRID_HAbs		(GUI_GRID_WAbs / 1.2)
#define GUI_GRID_H			(GUI_GRID_HAbs / 25)

#define GUI_TEXT_SIZE_MEDIUM	(GUI_GRID_H * 1)

class RscText
{
	deletable = 0;
	fade = 0;
	access = 0;
	type = CT_STATIC;
	idc = -1;
	colorBackground[] = {0,0,0,0};
	colorText[] = {1,1,1,1};
	text = "";
	fixedWidth = 0;
	x = 0;
	y = 0;
	h = 0.037;
	w = 0.3;
	style = ST_LEFT;
	shadow = 1;
	colorShadow[] = {0,0,0,0.5};
	font = "RobotoCondensed";
	SizeEx = GUI_TEXT_SIZE_MEDIUM;
	linespacing = 1;
	tooltipColorText[] = {1,1,1,1};
	tooltipColorBox[] = {1,1,1,1};
	tooltipColorShade[] = {0,0,0,0.65};
};

//MyUIControls.hpp

//Your text control, inherits from RscText only changing the members that are specific to your control
class MyTextControl : RscText {
	w = 0.1;
	h = 0.05;
	font = "TahomaB";
	sizeEx = 0.04;
	colorBackground[] = {0,0.9,0,0};
	text = "HELLO WORLD";
	shadow = 0;
};

 

You then refer to your class as MyTextControl in your scripts rather than RscText.

 

 

2 hours ago, juleshuxley said:

How does ctrlCreate know to attach my RscText to someLayer?

As you are specifically placing it there.

You cut a resource of "RscTitleDisplayEmpty".

2 hours ago, juleshuxley said:

"someLayer" cutRsc ["RscTitleDisplayEmpty", "PLAIN"];

This resource uses onLoad EH which adds a variable to uiNamespace named RscTitleDisplayEmpty that holds a reference to this display...

class RscTitleDisplayEmpty: RscDisplayEmpty
{
  fadeIn=0;
  fadeOut=0;
  duration=9.9999998e+010;
  onLoad="uiNamespace setVariable ['RscTitleDisplayEmpty',_this select 0]"; //<<- When this display is created store reference
};

Which you get in the line...

2 hours ago, juleshuxley said:

_display = uiNamespace getVariable "RscTitleDisplayEmpty";

You then create the ctrl on the display.

2 hours ago, juleshuxley said:

_display ctrlCreate ["RscText", -1];

 

 

2 hours ago, juleshuxley said:

And why is disableSerialization needed

As UI elements( displays, controls ) are not serialisable. When a running mission is saved, all scripts, their variables and contents, and their current execution positions are saved. As UI elements are not serialisable any scripts that have variables that reference UI elements will cause errors. So you use disableSerialization to mark the script as not to be serialised( saved ). In some cases you can avoid needing to disableSerialization by making sure not to store ui element references in variables in missionNamespace.

https://community.bistudio.com/wiki/Namespace#Namespace_serialization

  • Like 1

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

×