An easier way to create the LEC style statusline

Started by Ishmael, Sat 24/05/2003 17:27:32

Previous topic - Next topic

Ishmael

I posted this here beacuse those new AGSers who come to ask how to get the LEC statusline to work. The LEC GUI that comes with AGS uses scritp like this:

if (GetLocationType(mouse.x,mouse.y)>0) { // or whatever like that
Ã, GetLocationName(mouse.x,mouse.y);
Ã, //someting
Ã, SetLabelText(0,0,"Walk to...");
}

etc.

But I found an easier way. I dont know how many people have thought of this, and if this is allready posted somewhere in the forum, but anyway:

All the GetThisAt and GetThatName can be replaced with @OVERHOTSPOT@, right?

So, make a new GUI, put it where you want the statusline to be, create a label on it and set the size and position. (In this script the statusline is GUI 0 and the label is object 0.)

Then, put into the global script repeadetly execute function: (add teh stuff beween the line starting "function" and the last })

function repeadetly_execute() {
Ã, // the comment line here
Ã, if (GetCursorMode()==0) SetLabelText(0,0,"Walk to @OVERHOTSPOT@");
Ã, if (GetCursorMode()==1) SetLabelText(0,0,"Look at @OVERHOTSPOT@");
Ã, if (GetCursorMode()==2) SetLabelText(0,0,"Interact with @OVERHOTSPOT@");
Ã, if (GetCursorMode()==3) SetLabelText(0,0,"Talk to @OVERHOTSPOT@");
Ã, if (GetCursorMode()==4) {
Ã,  Ã, string usinginv;
Ã,  Ã, string useinvtxt;
Ã,  Ã, StrCopy (useinvtxt, "Use ");
Ã,  Ã, GetInvName(character[GetPlayerCharacter()].activeinv,usinginv);
Ã,  Ã, StrCat (useinvtxt,usinginv);
Ã,  Ã, StrCat (useinvtxt," with ");
Ã,  Ã, StrCat (useinvtxt,"@OVERHOTSPOT@");
Ã,  Ã, SetLabelText(0,0,useinvtxt);
Ã, }
}

Quote
Ã,  Ã, StrCat (useinvtxt,usinginv);
Ã,  Ã, StrCat (useinvtxt," with ");
Ã,  Ã, StrCat (useinvtxt,"@OVERHOTSPOT@");

Is because when there is no hotspot or char under the mouse, it says "Use XXX with ". This can ofcourse be changed very easy:

Ã,  Ã, StrCat (useinvtxt,usinginv);
Ã,  Ã, StrCat (useinvtxt," with @OVERHOTSPOT@");

Would make it say just the "Use XXX".

Sorry if I cause any trouble to ya all nice moderators, but this just popped into my head and I couldn't hold it all just by myself. Ã, ;)

THIS CODE CAN BE USED BY ANYBODY WHO NEEDS, in case it works.
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

fanton

ok. i ask you this:

how can I use StrLen with any hotspot name. for example, if I have my mouse over a door "Door" right? I would like to have a StrLen("@overhotspot@") which should give 5 and use that number to adjust a gui, label using almost the same principle. e.g.

repeadedly_execute
{
   len_gui = StrLen("@overhotspot") ;
   //which does not work
   SetGuiPosition(GUI,mouse.x,mouse.y);
   SetGuiSize(len_gui * 10, 9);
}

or

if(GetLocationType(mouse.x,mouse.y)>0)
{
StrLen(GetLocationName(mouse.x,mouse.y));
}

which does not work. code problem i guess.

SSH

a) You're closer with the second one, but you need to assign the result of strlen into a variable
b) The fonts are not fixed-width, so stelen is maybe not what you need

SO...
int len_gui;
string guistr;

guistr = GetLocationName(mouse.x, mouse.y);
len_gui = GetTextWidth(guistr, FONT_YOU_ARE_USING);
SetGuiPosition(GUI, mouse.x, mouse.y);
SetGuiSize(len_gui+MARGIN, 9);
12

Simonsez128

#3
I just wanted to post a little something I put together for my GUI as help for anyone who looks for something like this. I think this post is closest to what I scripted.

I wanted a status line right next to the mousepointer which displays the name of any hotspot, region, character and object. Additionally I wanted it to display any actions you could take interacting with them according to the current mousepointer mode. This way the whole thing would seem more intelligent since the actions you can take would depend on the current object your mouse is pointing at.

First I created a simply GUI called MOUSEDESCR with a width of 320x200. It should be normally visible and non-clickable. I created a text-tag field in this GUI (0).

Next I set up a property value I could use for all kinds of objects, characters etc. I called itÃ, UseInteract and set it as an integer value. Default value is 1. It may require setting up this property for each object according to what you could do with it. For example, I wanted the value 1 to correspond with "Pick up" for any object, thus the setting for everything you can pick up would be 1. The advantage is that you can easily adapt this system to your individual needs.

In the rep-ex part of the global script I scripted the following:

Code: ags

SetGUIObjectPosition(MOUSEDESCR, 0, mouse.x + 5,mouse.y + 5);Ã, 
if (GetCursorMode() == 1)
{
	StrCopy (label_text,"Look at ");

	StrCat (label_text,"@OVERHOTSPOT@");	
Ã,  Ã,  
	if (GetLocationType(mouse.x,mouse.y) != 0)
	{
		SetLabelText(2,0, label_text);
	}
	else 
	{
		SetLabelText(2,0, " ");
	}
}
else if (GetCursorMode() == 4)
{
	GetInvName (character[EGO].activeinv, inv_item);
	StrCopy (label_text,"Use ");
	StrCat (label_text,inv_item);
	StrCat (label_text," with @OVERHOTSPOT@");

	if (GetLocationType(mouse.x,mouse.y) != 0)
	{
		SetLabelText(2,0, label_text);
	}
	else
	{
		SetLabelText(2,0, " ");
	}
}
else if (GetCursorMode() == 2)
{
	if (GetLocationType(mouse.x,mouse.y) != 0)
	{
		if (GetLocationType(mouse.x,mouse.y) == 1)
		{
			currentlocation = GetHotspotAt (mouse.x, mouse.y);
			if (GetHotspotProperty(currentlocation, "UseInteract") == 4)
				InteractText ("Touch");
			if (GetHotspotProperty(currentlocation, "UseInteract") == 1)
				InteractText ("Use");
			if (GetHotspotProperty(currentlocation, "UseInteract") == 2)
				InteractText ("Open");
			if (GetHotspotProperty(currentlocation, "UseInteract") == 3)
				InteractText ("Move");
		}
		else if (GetLocationType(mouse.x,mouse.y) == 2)
		{
			currentlocation = GetCharacterAt (mouse.x, mouse.y);
			if (GetCharacterProperty(currentlocation, "UseInteract") == 1)
				InteractText ("Touch");
			if (GetCharacterProperty(currentlocation, "UseInteract") == 2)
				InteractText ("Push");
			if (GetCharacterProperty(currentlocation, "UseInteract") == 3)
				InteractText ("Pull");
		}
		else if (GetLocationType(mouse.x,mouse.y) == 3)
		{ 
			currentlocation = GetObjectAt (mouse.x, mouse.y);
			if (GetObjectProperty(currentlocation, "UseInteract") == 1)
				InteractText ("Pick up");
			if (GetObjectProperty(currentlocation, "UseInteract") == 2)
				InteractText ("Touch");
			if (GetObjectProperty(currentlocation, "UseInteract") == 3)
				InteractText ("Move");
		}

		SetLabelText(2,0, label_text); 
	}
	else 
	{
		SetLabelText(2,0, " ");
	}
}
else if (GetCursorMode() == 3)
{
	StrCopy (label_text,"Talk to @OVERHOTSPOT@");
	if (GetLocationType(mouse.x,mouse.y) != 0)
	{
		SetLabelText(2,0, label_text);
	}
	else
	{
		SetLabelText(2,0, " ");
	}
}
else
{
	SetLabelText(2,0, "@OVERHOTSPOT");
}


Additionally I had to define the function InteractText and some variables which I did in the global script body:

Code: ags

string inv_item;
string label_text;
int currentlocation;

function InteractText (string action) {
	StrCopy (label_text,action);
	StrCat (label_text, " @OVERHOTSPOT@");Ã, 
}


Hope it was ok to post this here. I'm glad if I could help someone with this!

[edit by scorpiorus to fix width]

I've given a million ladies a million footmassages - and they all meant something! - Vincent Vega

BorisZ

But what happens when blocking action is activated? GUI is still on and showing hotspot string. How do you get rid of string while blocking action is occuring?

Rui 'Trovatore' Pires

Well, then your best bet might be to use rep_exec_always instead.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

BorisZ

Quote from: Rui "Brisby" Pires on Thu 02/06/2005 17:57:44
Well, then your best bet might be to use rep_exec_always instead.

Wouldn't it be useless? It would still look for mouse coordinates and show hotspot string, even when blocking action is occuring. Or...?

Gilbert

I didn't read much of it but what I guess you'll need is just simple solution like this:

Define a global variable (or use GlobalInt instead) called, say:
int statusdisabled;

Whenever you want the status line to be disabled, like say,before a blocking action, or a cutscene:
statusdisabled=1;

After that, when it's to be enabled again:
statusdisabled=0;

Then in repeated_execute_always(), the part where you set the status line, do something like:

if (statusdisabled==1) SetLabelText(0,0,"");
else {
  //put whatever code about the status line into here
  }

monkey0506

On that note it might be easier to use a bool versus an integer.

BorisZ

There is not much difference then in closing gui each time blocking action is run (since you have to define variable anyway).

Scorpiorus

In that case the IsInterfaceEnabled function may come in handy:

if (IsInterfaceEnabled()==0) SetLabelText(0,0,"");
else {
  //put whatever code about the status line into here
}

BorisZ

Yep,  that's it.
Why didn't come out with this before I finished my last game? %$"%%$"%&

Ishmael

Just as a side note, when using the statusline in my own games it worked well enough for me. When a cutscene started or something I just turned the GUI off, and back on afterwards.

But yeah, it needs some adjusting and optimising... I should look into it, atleast when I get to the GUI phase of this new little project of mine... Maybe I'll just write a completely new one and release it. Hmm... Time will tell.
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Sythe

I know this is an old topic but I dug it up while having the same problem.

A simple solution i came up with is to make a character which has no animations, just a 1x1 transparent pixel which isnt clickable and doesnt start in any room. Then when you want to display text use cStatus.SatAt(0,185,text); you can make a global function to do it etc.

It just seems far easier to make sure of the precoded centering the character talk uses.

SMF spam blocked by CleanTalk