Main Text GUI display issues

Started by Demicrusaius, Sun 03/02/2013 21:32:40

Previous topic - Next topic

Demicrusaius

Hello, I have only been using AGS for one week, but I am really loving it so far!
I'm using the "blank game" template to learn how to script and I must say, I have encountered dozens of problems that have all been solved by referring to five year old forum posts and the manual, however, despite my attempts to find my own answer, I am having problems with the main text box GUI I designed.

Everything looks good, but I can't control the position of the box.
My GUI is called gTextDisplay and commands like gTextDisplay.Displayat and gTextDisplay.DisplayatY work for one instance of a message, but I was hoping to set the GUI position to the bottom once and not have to use it again.
So, I tried gTextDisplay.SetPosition(int x, int y) but that doesn't move it at all, I also tried gTextDisplay.Y = int; but it doesn't seem to do anything.
Does this have something to do with the position of the controls for the eight edge pieces?
I feel like this has a really easy answer, but I'm not finding it on my own.
It is better to light one small candle than to curse the darkness.

MurrayL

#1
I may be wrong, and I hope someone will correct me if I am, but I don't think you can permanently move where a text GUI displays by default.

The fastest solution would be to make your own little wrapper function that moves the text box every time, but this really isn't that much faster than just manually typing gTextDisplay.DisplayatY(200, "hi").

In globalscript.asc:
Code: AGS

function ShowMessage(String msg){
    DisplayAtY(200, msg);
}


In globalscript.ash:
Code: AGS

import function ShowMessage(String msg);


By 'importing' the function in the global header file (the .ash), the engine makes it available to every other script in your game. Now you can just use ShowMessage("bla bla bla"); and it'll stick it in the right place without you needing to specify any coordinates.
The disadvantage, of course, is that it will always show up at 200y. You can experiment with other values, but be wary of accidentally moving the text display off the bottom of the screen - especially with longer messages!
It would be much better if we could position the text box using its bottom co-ordinate, but there's no way to do that.

If you want a little experiment, you could add some code to the ShowMessage function (before the message is displayed) which checks the length of msg, and adjusts the y value accordingly, e.g.

Code: AGS

function ShowMessage(String msg){
    int y = 300 - msg.Length;
    DisplayAtY(y, msg);
}


Some trial and error will be required to get the right values in there.

Khris

Just for reference, there's neither a GUI.DisplayAt command nor a GUI.DisplayAtY command.

MurrayL

Quote from: Khris on Sun 03/02/2013 22:06:35
Just for reference, there's neither a GUI.DisplayAt command nor a GUI.DisplayAtY command.

Whoops - you're right, they're static commands. I've updated my post to reflect that. This is what happens when I do most of my forum posts without AGS open ;)

Slasher

QuoteI may be wrong, and I hope someone will correct me if I am, but I don't think you can permanently move where a text GUI displays by default.

Text GUI's are hardcoded and can't be moved. Making a normal GUI to display text is what we generally do because that way we can set it's position. However, it will not 'stretch' to accomodate text like normal Text GUI's do so its a little resticted afaik.

I would have thought you would have used the default template, that way you could play around with exsisting GUI'S whilst learning.

Anyhow, hope you sort this out.




Demicrusaius

Actually, using the empty template has been great for learning! When I first started using the default templates, altering script was confusing, but building it up from scratch has been a tremendous learning experience because I can see how everything works together. Though, I occasionally reference the default templates.

In other news, I understand my problem now. The Text GUI's can't be moved, but I can work around it by diverting the string of text to a different non-text GUI that has a text box. This isn't too bad because it means the top line of text will always be displayed at the same place, I just need to find out how many characters it can hold before getting cut off.

This is good and bad, however, because for tiny short messages the huge text box will still appear.
These are things to consider. I'm not sure which I like better!

Thanks for the quick replies. This site has been great.
It is better to light one small candle than to curse the darkness.

Khris

#6
If you put a label on the GUI, text is wrapped automatically:

Code: ags
// add this to GlobalScript.asc
void Talk(this Character*, String message) {
  lblTalk.Text = message;   // label's script name: lblTalk
  gTalk.Visible = true;       // GUI's script name: gTalk
  int delay = (message.Length * GetGameSpeed()) / Game.TextReadingSpeed;
  int min_delay = (Game.MinimumTextDisplayTimeMs * GetGameSpeed()) / 1000;
  if (delay < min_delay) delay = min_delay;
  int ignore_delay = (Game.IgnoreUserInputAfterTextTimeoutMs * GetGameSpeed()) / 1000;
  mouse.Visible = false;
  Wait(ignore_delay);
  delay -= ignore_delay;
  if (delay > 0) WaitMouseKey(delay);
  mouse.Visible = true;
  gTalk.Visible = false;
}

// add this to GlobalScript.ash
import void Talk(this Character*, String message);

// use like this:
  player.Talk("Hello there.");


Not tested!

Edit: Did test it, seems to work ok.

Slasher

That code's good, thanks Khris... now, if we can just get player to speech animate  8-)

Woten

Hi there.
This Gui works great, I just have one question.

Is there any way for it to be in the center of the screen instead of in the top right corner?

Khris

I'm not sure what exactly you're referring to here. If you're using my code, just move the GUI and label to where you want them to be.
It works best for a text area that has a fixed upper-left corner, but you can of course use a bigger GUI and reposition the label based on the amount of text, using either message.Length or GetTextHeight().

SMF spam blocked by CleanTalk