Creating own speech gui

Started by imsomnia212, Wed 20/05/2020 06:05:07

Previous topic - Next topic

imsomnia212

Hi, I was trying to create my own function to write the speech on a gui, this function works perfect drawing the text on the gui, but the only problem is that the player can walk while and interact while the speech is draw in the gui (something like SayBackground) and the speech can't be skipped. Searching in the help menu of ags I found that you can use GUI.AsTextWindow but I can't get to work it. I use the thumbleweed script and the AGS version is the latest version.

I tried to add a timer to "Block" the interactions while the speech is on screen but doesn't work.

Code: ags
// new module script
DynamicSprite*messagetext;

#define GWIDTH 300
#define GHEIGHT 30
#define GTIMER 1
#define TEST 1

void MySay(this Character*, String message) {
  if (messagetext == null) messagetext = DynamicSprite.Create(GWIDTH, GHEIGHT); 
  DrawingSurface*ds = messagetext.GetDrawingSurface();
  ds.Clear();
  ds.DrawingColor = this.SpeechColor;
  int w = GWIDTH - 20;
  int wt = GetTextWidth(message, Game.SpeechFont) + 5;
  if (wt < w) w = wt;
  gSpeech.Width = w + 20;
  gSpeech.X = (Screen.Width - w - 20) / 2; 
  int y = (GHEIGHT - GetTextHeight(message, Game.SpeechFont, w)) / 2;
  ds.DrawStringWrapped(10, y, w, Game.SpeechFont, eAlignCenter, message);
  ds.Release();
  gSpeech.BackgroundGraphic = messagetext.Graphic;
  gSpeech.Visible = true;
  SetTimer(TEST, (message.Length / game.text_speed));
  SetTimer(GTIMER, ((message.Length / game.text_speed) + 1) * GetGameSpeed());
}

function repeatedly_execute() { //this was supposed to work like "Blocking" but don't work
  if (gSpeech.Visible) {
    Wait(TEST);
  }
}

function repeatedly_execute_always() {
  GUI*g = gSpeech;
  gBlack.Visible = g.Visible;
  if (g.Visible) {
    gBlack.SetPosition(g.X, g.Y);
    gBlack.SetSize(g.Width, g.Height);
  }

 if (IsTimerExpired(GTIMER)) gSpeech.Visible = false;

}
Are u a tuna?

Khris

I'm pretty sure you can simply  Wait(((message.Length / game.text_speed) + 1) * GetGameSpeed());  at the end of the MySay function?

imsomnia212

Oh I didn't know that will work, thanks. But now I can't get how to make the speech skippable
Are u a tuna?

Khris

Use WaitMouseKey() instead.

imsomnia212

I tried that but nothing happen
Are u a tuna?

Khris

Can you be a bit more specific? And maybe post the code you're currently using?

imsomnia212

The code is this:
Code: ags
// new module script
DynamicSprite*messagetext;

#define GWIDTH 300
#define GHEIGHT 30
#define GTIMER 1

void MySay(this Character*, String message) {
  if (messagetext == null) messagetext = DynamicSprite.Create(GWIDTH, GHEIGHT); 
  DrawingSurface*ds = messagetext.GetDrawingSurface();
  ds.Clear();
  ds.DrawingColor = this.SpeechColor;
  int w = GWIDTH - 20;
  int wt = GetTextWidth(message, Game.SpeechFont) + 5;
  if (wt < w) w = wt;
  gSpeech.Width = w + 20;
  gSpeech.X = (Screen.Width - w - 20) / 2; 
  int y = (GHEIGHT - GetTextHeight(message, Game.SpeechFont, w)) / 2;
  ds.DrawStringWrapped(10, y, w, Game.SpeechFont, eAlignCenter, message);
  ds.Release();
  gSpeech.BackgroundGraphic = messagetext.Graphic;
  gSpeech.Visible = true;
  SetTimer(GTIMER, ((message.Length / game.text_speed) + 1) * GetGameSpeed());
  WaitMouseKey(((message.Length / game.text_speed) + 1) * GetGameSpeed()); //I added this but doesn't work
}

function repeatedly_execute_always() {
  GUI*g = gSpeech;
  gBlack.Visible = g.Visible;
  if (g.Visible) {
    gBlack.SetPosition(g.X, g.Y);
    gBlack.SetSize(g.Width, g.Height);
  }

 if (IsTimerExpired(GTIMER)) gSpeech.Visible = false;

}
Are u a tuna?

Khris

Remove the timer code, and again, please describe how the code fails.
"Doesn't work" is a useless problem description. We know it doesn't work.

imsomnia212

Oh, sorry my bad. What I mean with that is the code works fine if I use only the wait function, the speech draws and I only can interact when it finishes, but if I use the waitmousekey the speech draws fine, I can interact but the speech is still draw on the screen (doesn't skipped with the click).
Are u a tuna?

Crimson Wizard

#9
I think you are missing "gSpeech.Visible = false;" after WaitMouseKey.
(and remove "if (IsTimerExpired(GTIMER)) gSpeech.Visible = false;" from rep-exec of course)

The blocking speech algorithm is simple:
* display speech
* call wait
* hide speech

imsomnia212

Ooooh thank you so much! It worked perfectly now.
Are u a tuna?

SMF spam blocked by CleanTalk