Jump to content
Sign in to follow this  
Rothwell

Structured Text

Recommended Posts

Hi,

I need some help with structured text. Basically, I want to do something like a counter that would be equivalent to: format["time: %1", timeLeft] and display it in the center-top of the screen

1.) I can't figure out how to get it to display! I know I need to get my titlersc to display structured text instead of regular text, but something I'm doing isn't right. I know I need to have this somewhere:

_x = "<t color='#ffff00'>" + format["%1",name player]+"</t>";
_y = "<t color='#00ff00'>" + " is my name"+"</t>";
_z = _x + _y;
//I'm assuming these are the id's i want. probably where i'm wrong
((findDisplay 300) displayCtrl 301) ctrlSetStructuredText parseText _z;

however I dont know where this is supposed to go. Anywhere I want to change the method? init.sqf for testing?

2.) I have only gotten a titlersc to display on the screen, however, when i set y=0, it wasn't at the very top of the screen, how do I get it to be flush with the top of the screen?

here's my description.ext file I'm trying to use

class MyRscStructuredText {
idc = 303;
type = CT_STRUCTURED_TEXT;
style = ST_LEFT;
colorBackground[] = {0,0,0,.5};
x=0.4;
y=0.0;
w=0.2;
h=0.1;
size = 0.018;
text = null;
class Attributes{
	font = "TahomaB";
	color = "#FF0000";
	align = "left";
	valign = "top";
	shadow = false;
	shadowColor = "#ffoooo";
	size = "1";
};
};


class RscTitles
{
titles[]={}; 

class MyRscTitle
{
  	idd=300;
  	movingEnable=0;
  	duration=12;
  	name="title1";
  	controls[]={"text1"};

  	class text1 : MyRscStructuredText
	{
		idc = 301;
	};
};
};

Edited by Rothwell

Share this post


Link to post
Share on other sites

Here is what I came up with given your code:

1) Description.ext uses some constants, are these defined somewhere? I'm assuming you just copied a snippet and not the whole thing.

2) To obtain idd for a display used as a resource, you have to use onLoad to store the variable for future use in uiNamespace. It would have worked without it if it was created using createDialog, but that kinda sets some limitations on a displayed counter :p

3) Use safeZoneY to set it to top portion of anyones screen.

Init.sqf:

[] spawn {
waitUntil {player == player};
cutRsc ["MyRscTitle","PLAIN"];
disableSerialization;
_disp = uiNamespace getVariable "d_MyRscTitle";
while {true} do {
	_msg = "<t color='#00ff00'>" + "Welcome "+"</t>";
	_msg = _msg + "<t color='#ffff00'>" + format["%1",name player]+ "</t>" + "<br/>";
	_msg = _msg + "<t color='#000000'>" + "Time left:"+"</t>";
	_msg = _msg + "<t color='#ff0000'>" + format ["%1",100 - floor time max 0]+"</t>";
	(_disp displayCtrl 301) ctrlSetStructuredText parseText _msg;
	sleep 1;
};
};

Description.ext:

#include "define.hpp"
class MyRscStructuredText {
idc = -1;
type = CT_STRUCTURED_TEXT;
style = ST_LEFT;
colorBackground[] = {0.6,0.7,0.8,1.0};
x=0.4;
y=safeZoneY;
w=0.2;
h=0.1;
size = 0.024;
text = "Yo";
class Attributes{
	font = "TahomaB";
	color = "#FFFFFF";
	align = "left";
	valign = "top";
	shadow = true;
	shadowColor = "#000000";
	underline = false;
	size = "1";
};
};

class RscTitles
{
titles[]={}; 
class MyRscTitle
{
  	idd=-1;
  	movingEnable=0;
  	duration=10e30;
  	name="title1";
	onLoad = "uiNamespace setVariable ['d_MyRscTitle', _this select 0]";
  	controls[]={"text1"};
  	class text1 : MyRscStructuredText
	{
		idc = 301;
	};
};
};

Underline works fine, but I have never been able to get shadow to work. Does it work?

Share this post


Link to post
Share on other sites

So this works... kinda. And I'm willing to bet it's not working how it should because of my shakey at best understanding of these dialogs... is (#include "define.hpp") the only thing I actually put in my description.ext, and make a file named define.hpp with the rest of the code in it? I'm not sure what exactly .hpp files are all about, i'm assuming they're used to keep the description.ext from getting too cluttered... at least this is what I've observed from code others have written.

Aside from that, I say it kinda works because when I'm in-game all it says is "Yo". but when I press esc and pause the game, it shows the structured text.

Share this post


Link to post
Share on other sites

Uhm, ok. Guessing you don't have the defines then. The relevant parts in full, but I don't include all the other stuff I have in my project, which would only confuse:

Part of my define.hpp, relevant parts (used here) in bold:

#define CT_STATIC			0
#define CT_BUTTON			1
#define CT_EDIT				2
#define CT_SLIDER			3
#define CT_COMBO			4
#define CT_LISTBOX			5
#define CT_TOOLBOX			6
#define CT_CHECKBOXES		7
#define CT_PROGRESS			8
#define CT_HTML				9
#define CT_STATIC_SKEW		10
#define CT_ACTIVETEXT		11
#define CT_TREE				12
[b]#define CT_STRUCTURED_TEXT	13[/b] 
#define CT_3DSTATIC			20
#define CT_3DACTIVETEXT		21
#define CT_3DLISTBOX		22
#define CT_3DHTML			23
#define CT_3DSLIDER			24
#define CT_3DEDIT			25
#define CT_OBJECT			80
#define CT_OBJECT_ZOOM		81
#define CT_OBJECT_CONTAINER	82
#define CT_OBJECT_CONT_ANIM	83
#define CT_USER				99
#define ST_HPOS				0x0F
[b]#define ST_LEFT				0[/b]
#define ST_RIGHT			1
#define ST_CENTER			2
#define ST_UP				3
#define ST_DOWN				4
#define ST_VCENTER			5
#define ST_TYPE				0xF0
#define ST_SINGLE			0
#define ST_MULTI			16
#define ST_TITLE_BAR		32
#define ST_PICTURE			48
#define ST_FRAME			64
#define ST_BACKGROUND		80
#define ST_GROUP_BOX		96
#define ST_GROUP_BOX2		112
#define ST_HUD_BACKGROUND	128
#define ST_TILE_PICTURE		144
#define ST_WITH_RECT		160
#define ST_LINE				176
#define ST_SHADOW			256
#define ST_NO_RECT			512
#define ST_TITLE			ST_TITLE_BAR + ST_CENTER

Much stuff removed. Look around, you may find better defines elsewhere.

Description.ext is in fact a .hpp file, regarding its structure defining classes and attributes, except it will be loaded automatically by the game. You create and include .hpp files in order to make description.ext more easy to read, that's all. The #include statement is just a preprocessor command that includes the contents of given files into where it goes, not a big mystery :) You could have all your identities and sound related entries in separate .hpp files if you want.

I find it odd that it displays "Yo" until you hit escape. Doesn't do that with me.

Share this post


Link to post
Share on other sites

Ok, I figured all of those #define lines were if you wanted to set a type or something and then enter a number instead of typing out the name. Like: style = 0;, instead of style = ST_LEFT;.

AHHH... i figured out what was wrong. I had this piece of code left over sitting at the top of my init.sqf that I had overlooked

counter = titlersc["MyRscTitle","PLAIN"];

it works perfectly now! thanks for your help!

EDIT: I meant to say also, i haven't got shadow to work either. not a big deal to me though.

Edited by Rothwell

Share this post


Link to post
Share on other sites

Sorry if this is a stupid question, but using your above example, how do I terminate the display?

I added a handle to the beginning of the spawn like this:

RavenDisplay = [] spawn {               waitUntil {player == player};etc...

And then I set up a radio trigger with this in the activation field:

cutRsc ["","PLAIN"];
terminate "RavenDisplay";

When I execute the radio trigger, it gives me an error "Resource Title Not Found". It ends the script but the display is still present (just not actively calculating things and changing the text).

Share this post


Link to post
Share on other sites

One year old thread? :) Too tired to read through it all, but try:

5 cutRSC ["Default","PLAIN"]; //5 is the layer you want to terminate.

I.e. I use:

5 cutRsc ["D_Oxygenmask","PLAIN"];

to open the display, then

5 cutRSC ["Default","PLAIN"];

to close it.

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  

×