Custom Dialog Placement [SOLVED]

Started by outlander, Wed 03/02/2021 03:43:10

Previous topic - Next topic

outlander

Made an account around an hour ago and I'm already opening my very first Beginner Technical Questions thread!!! How's that for an introduction!!!

Hey everyone, I'll be brief; so what I want to do is display the dialogue (as in, the text over the Character who's speaking):


In specific X and Y coordinates (or preferably, in a GUI window) which in this case, would be at the bottom of the screen. That's right, like an RPG game. Just in case, here's a mock-up of EXACTLY what I want:

... dog*.

I know you can do all sorts of cool things with the way the dialog options are displayed (like attaching them to a GUI and stuff), and I was also considering using a Text GUI window to display dialog and the standard dialog options to display options (:P), but I quite like the way writing default dialog works. It's fast, convenient, and kinda fun, honestly.

This also means that I want the text to be aligned to the right, not the center... If the above is possible, is this also possible?
Thank you very much for your attention, and I promise I won't spam the forums with questions. I'm trying my best on learning how to do things on my own.
> > > 666 KILL CHOP DELUXE 666 < < <

eri0o

#1
I am not sure, but maybe SayAt can work.
https://adventuregamestudio.github.io/ags-manual/Character.html#charactersayat

You can wrap everything in a function to make things easier.

This function can be one that extends the Character struct to add a new method to it.

It would be something like this:

Code: ags
function MySay(this Character*, const string message) {
  // Handle message how you want
  this.SayAt(20, 140, 200 /* width */, message)
}


Untested code, so please test if it behaves like you want.

Edit: oh, right, that code you can create a script module (a script and header pair) for it on the project explorer, or you can put into the global script.

Whatever you do, don't forget to import it on the header or it won't show up elsewhere.

On the matching header, do:
Code: ags
import function MySay(this Character*, const string message);


Now when you need it, you can do things like cHero.MySay("Hello dog!");

outlander

#2
Quote from: eri0o on Wed 03/02/2021 11:27:07
I am not sure, but maybe SayAt can work.

Sorry for such a late response, but it works! Thank you! However, there's one thing that's bothering me:


This is what happens when the dialog is 3 lines long.


This is what happens when the dialog is 1 line long. This is how I want it to look like, with other lines being added below.

I don't know the technicality of it, but the way I see it, text is "drawn" like this:

I don't know if I'm explaining my self well... It's like, the more lines are at a given time, they get added on top of the initial line. I want them to get added below. Does that make sense?

(Also yeah! I added stuff to the script to align it to align the text to the left and draw a GUI to act as a text box. Go me!)

> > > 666 KILL CHOP DELUXE 666 < < <

eri0o

Can you show me the code?

And I have a feeling that it will work if you remove the GUI.

outlander

Quote from: eri0o on Thu 04/02/2021 11:36:32
Can you show me the code?

Sure thing:
Code: ags
//RPG text box thingy.
    function BottomSay(this Character*, const string message)
    {
        Speech.TextAlignment = eAlignLeft; //Align text to the left & wait for mouse.
        Speech.SkipStyle = eSkipKeyMouse; 
        
        gBotText.Visible = true;
       
        this.SayAt(16, 137, 286, message);
        
        gBotText.Visible = false;
      }


As you can see, it's exactly what you recommended, except I added the two Speech. parameters and the gBotText. parameters. I tried removing the GUI stuff, but it keeps happening, just, you know, without the box drawn behind.

I was thinking last night, this might come off as a hacky solution but can't I just make two more custom functions, only changing the X coordinates in the "this.SayAt"? so I would have three custom functions which I would use depending on the lines in the current dialog...
> > > 666 KILL CHOP DELUXE 666 < < <

eri0o

One hack could be using a transparent font on speech and using a label on the GUI to actually render the text there.

outlander

Quote from: eri0o on Thu 04/02/2021 14:13:40
One hack could be using a transparent font on speech and using a label on the GUI to actually render the text there.

Alright, I know how to add a Label to a GUI, but, how do I tell the label to render whatever is inside the "message" string? I'm so sorry, it's my first time messing with code in general, I swear I'm not doing this on purpose  :(
> > > 666 KILL CHOP DELUXE 666 < < <

eri0o

#7
So you load the GUI Editor and pickup the label from the toolbar and place it on the GUI you have created.

In the property menu, you can set a label name, say my_box_label and then on script you can access my_box_label.Text and set the value to be the string message.

https://adventuregamestudio.github.io/ags-manual/Label.html#labeltext

Btw, this is just one idea to work what you want to do, there are numerous ways to get a box with text. Once you have made your own function for making the characters talk this is easy to change later since you will only change that function and not all your game dialog.

Also please, keep asking questions, it's alright to ask questions and if people knows the answers they will help. At minimum it will help you to formulate what problem you have and may help you think just by asking.

outlander

#8
Ooh, I see what you mean now:


(yeah, gotta use an invisible Say font).

However, the idea of deleting/setting the Say font to an invisible one kinda alarms me, for some reason. I also came up with this, after brainstorming for like two hours with my tiny little brain, please tell me if it is valid;

Code: ags
    function BottomSay(this Character*, const string message)
    {
      
        Speech.TextAlignment = eAlignLeft; //Align text to the left.
        Speech.SkipStyle = eSkipKeyMouse;  //Text doesn't run out, it waits for mouse click.
        
        gBotText.Visible = true;
        
        if (DLIN==1)
        { 
          this.SayAt(16, 139, 286, message);
        }
        else if (DLIN==2)
        {
          this.SayAt(16, 148, 286, message);
        }
        else if (DLIN==3)
        {
          this.SayAt(16, 157, 286, message);
        }
        
        gBotText.Visible = false;
               }


That uses a global variable called "DLIN". Then, in the room script, while the characters are talking, I change it to be either 1, 2 or 3, each will display a SayAt thing with a different Y coordinate, representing the lines of text:

Code: ags
DLIN=1;
  cRoger.BottomSay("Here's a lonely single line, using DLIN==1.");
  
  DLIN=2;
  cRoger.BottomSay("And here's a pair of lines, using DLIN==2. They help each other in trying times.");

   //etc.


Looks like this:

... and:

... and so on.

I get the feeling that my method might be a bad idea. I mean I can live with the tedium of writing "DLIN" over and over, but I don't know, I got this gut feeling telling me something's deeply wrong with it. Am I right, or is it like, OK?

Also, thank you very much for your help, eri0o, and for your patience. You taught me about labels and functions I wasn't aware about and pretty much gave me a practical example on how importing functions works. I owe you a big one  :-D
> > > 666 KILL CHOP DELUXE 666 < < <

eri0o

If you want to go that way, then it's better to use an already calculated text height:

https://adventuregamestudio.github.io/ags-manual/Globalfunctions_General.html#gettextheight

I am not sure though if the behavior you are seeing is the one that should happen or if it's a bug.

The use of a transparent font is actually a sort of known hack, the speech bubble module also has an option to use it: https://www.adventuregamestudio.co.uk/forums/index.php?topic=55542.0

Link to a transparent font: http://www.angelfire.com/pr/pgpf/if.html

outlander

Quote from: eri0o on Thu 04/02/2021 19:09:55
Link to a transparent font: http://www.angelfire.com/pr/pgpf/if.html

Interesting stuff. For now, I guess I got two methods to go about what I want to do. Guess this is solved!
Thanks again for everything eri0o :-D
> > > 666 KILL CHOP DELUXE 666 < < <

SMF spam blocked by CleanTalk