Adventure Game Studio

AGS Support => Modules, Plugins & Tools => Topic started by: SSH on Fri 08/12/2006 17:07:08

Title: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bubble
Post by: SSH on Fri 08/12/2006 17:07:08
Requires AGS 2.72 or later

Inspired by the discussion in this thread (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=29281), I have created a module that allows you to display marked-up text that can change font or colour in the middle and back again, also with Hyperlinks. v1.1 includes support for functions that work like character.Say() and Display(). Also, new strikethrough, bold, overline, etc. special effects. v1.2 fixes some bugs and adds speech bubbles. v1.21 fixes a problem where a GUI used for hypertext Display had to be set to non-Clickable. v1.3 works swimmingly with AGS 3.0+

e.g.

=Hypertext=[This is some cool hypertext, with *bold,* /italics/ and _index|links_


rendering as something like:


Hypertext
This is some cool hypertext, with bold, italics and links (http://index)




Download the Hypertext module here (http://ssh.me.uk/modules/Hypertext.zip)
Hypertext module documentation (http://ssh.me.uk/moddoc/Hypertext)
Hypertext module wiki page (http://americangirlscouts.org/agswiki/Hypertext)



(http://ssh.me.uk/images/htss1.png)(http://ssh.me.uk/images/htss2.png)(http://ssh.me.uk/images/htss3.png)
Title: Re: MODULE: Hypertext v1.0
Post by: GarageGothic on Fri 08/12/2006 17:31:34
SSH, you're really becoming my arch nemesis. Every time I spend months and months on scripting something cool, someone pops up in the beginners forum asking for that particular functionality, and you whip something up in a day or two. Cursed be the day that CJ introduced modular scripting.

On a more upbeat note, cheers for another job well done.
Title: Re: MODULE: Hypertext v1.0
Post by: SSH on Fri 08/12/2006 18:10:33
 :P

You could just ask me yourself... ;)
Title: Re: MODULE: Hypertext v1.0
Post by: Ali on Sat 09/12/2006 10:19:12
This looks really useful! By the time I realised AGS lacked this feature, you'd already made a module for it.

If I complained being poor and unkempt in the technical forum, how long would I have to wait before 'SSH's Make Ali Rich and Sophisticated Module' was released?
Title: Re: MODULE: Hypertext v1.0
Post by: SSH on Sat 09/12/2006 11:30:50
Rich is do-able, but I fear that sophisticated is beyond the realms of possibility...  ;)
Title: Re: MODULE: Hypertext v1.0
Post by: Maverick on Sat 09/12/2006 17:16:25
Another excellent module.

I played around with the demo a bit and get a warning when I exit the game
(room1): Dynamic sprite 7 was never deleted
(room1):Dynamic sprite 8 was never deleted

Also if you do the mark up for hypertext using the last word in a string it wraps around to the next string and the whole block of text becomes the hyperlink.
Example:

Hypertext.Add("Test", "John and Joe played _Fred|Tic-Tac-Toe_.");
Hypertext.Add("Test", "After 10 games the score was tied at 5 each. ");

Renders as:

John and Joe played Tic-Tac-Toe_. After 10 games the score was tied at 5 each.

not as:

John and Joe played Tic-Tac-Toe. After 10 games the score was tied at 5 each.

I suppose you can always plan your text in such a way that you never use the last word in a string to create the hyperlink. Not a big issue.

Thanks again for your time and effortÃ,  ;D
Title: Re: MODULE: Hypertext v1.0
Post by: Kweepa on Sat 09/12/2006 18:08:23
Quote from: Maverick on Sat 09/12/2006 17:16:25
Also if you do the mark up for hypertext using the last word in a string it wraps around to the next string and the whole block of text becomes the hyperlink.
Actually, it's the character after the underscore that causes the problem. If you write

Hypertext.Add("Test", "John and Joe played _Fred|Tic-Tac-Toe._ ");
Hypertext.Add("Test", "After 10 games the score was tied at 5 each. ");

it works fine.

Very cool module! I particularly like that the page history works.

[EDIT]
One feature that would be useful that wasn't in the TODO list (I think) would be a function to get the current page name. That way you could trigger game events from it, display images in a separate GUI, play music, end the game...
It might also be useful to be able to clear a page, so it can be altered slightly.
Title: Re: MODULE: Hypertext v1.0
Post by: Rui 'Trovatore' Pires on Sat 09/12/2006 20:10:55
Out of curiosity (and it's easy to see in the module, but it would be nice if it were mentioned here as well), are we talking about about Display messages, GUI labels, or both?
Title: Re: MODULE: Hypertext v1.0
Post by: Maverick on Sat 09/12/2006 20:38:15
Quote from: SteveMcCrea on Sat 09/12/2006 18:08:23
actually, it's the character after the underscore that causes the problem. If you write

Hypertext.Add("Test", "John and Joe played _Fred|Tic-Tac-Toe._ ");
Hypertext.Add("Test", "After 10 games the score was tied at 5 each. ");

it works fine.

Steve ,
I tried it and the problem is still the same (AGS version 2.72)
Title: Re: MODULE: Hypertext v1.0
Post by: Kweepa on Sat 09/12/2006 20:57:39
Quote from: Maverick on Sat 09/12/2006 20:38:15
I tried it and the problem is still the same (AGS version 2.72)
You probably didn't put a space at the end of the first line, after the underscore.
The underscore (or asterisk, etc) has to be the last character in a word - the words are separated by spaces only.
Title: Re: MODULE: Hypertext v1.0
Post by: SSH on Sat 09/12/2006 21:25:38
Indeed, as Steve says, you have to remember to put the closing markup AFTER any punctuation for it to work.

If you do keep having a problem, though, Maverick, please upload your game directory as a zip and I'll take a look and try and sort it out.
Title: Re: MODULE: Hypertext v1.0
Post by: Maverick on Sun 10/12/2006 09:49:20
Thank you gentleman.
As you pointed out I did not include a space at then end of the first line of text.
Title: Re: MODULE: Hypertext v1.2
Post by: SSH on Thu 14/12/2006 13:16:38
Just a bump to highlight that I've added Speech bubbles to this. Look at the first post for screenshots of Roger and Mika's steamy conversation!
Title: Re: MODULE: Hypertext v1.2 - Change font mid-sentence
Post by: Maverick on Mon 05/02/2007 20:01:57
Wow! This is getting better all the time. What are the chances of including images (like thumbnails on a web page) so it behaves like a "real" web page?
Title: Re: MODULE: Hypertext v1.21 - Change font mid-sentence
Post by: SSH on Fri 16/02/2007 09:44:11
Updated to fix a bug Maverick found.

As for images, I do want to add it sometime, but I'm not sure when I'll have time...
Title: Re: MODULE: Hypertext v1.21 - Change font mid-sentence
Post by: Rui 'Trovatore' Pires on Fri 16/02/2007 10:16:45
I'm still not sure I've undertood completely about this module, but anyway, SSH, tell me - is it possible to use it to change the colour of certain items in a Listbox? Just that - write something in a different colour, and then write back in a normal colour.
Title: Re: MODULE: Hypertext v1.21 - Change font mid-sentence
Post by: GarageGothic on Fri 16/02/2007 10:36:00
I haven't used SSH's module, but as I understand it (and if it's anything similar to my own html module), all the handling of mouseovers and links is handled by the module itself, without any GUI objects such as listboxes. Thus, you can't change the color of a Listbox item, but you can achieve a similar effect by creating a list of links similar to a listbox. Of course this means that some of the listbox specific commands related to savegames etc. can't be applied.
Title: Re: MODULE: Hypertext v1.21 - Change font mid-sentence
Post by: SSH on Fri 16/02/2007 10:49:17
Yes, you're right GG.

If you tell me EXACTLY what you're trying to achieve, Rui, I can tell you the best way to do it or perhaps make a small change to the module to make it easier.
Title: Re: MODULE: Hypertext v1.21 - Change font mid-sentence
Post by: Rui 'Trovatore' Pires on Sat 17/02/2007 00:13:55
Ah, no, nevermind then, thanks. I made, for a game, a text system similar to the one in SQ6 - all text gets displayed in a box at the bottom of the screen, and you can scroll up to see old messages. I used a listbox, and I was musing on changing the colour for when a character speaks.

Doesn't matter all that much anyway, I can change the colour when the character speaks, change it back afterwards and leave it "on record", as it were, in a normal colour - the player will have already seen it in a different colour during the conversation, which is where it matters.
Title: Re: MODULE: Hypertext v1.21 - Change font mid-sentence
Post by: Dualnames on Tue 11/03/2008 10:50:00
Kill me for digging this but it's very important if someone cares to use it for AGS 3.0

First if new-strings is set to true it means that you have to replace a lot of functions in the module. 780 lines is a lot..

Secondly when you add pages you have to make sure that the line of code isn;t bigger than 500.

Don;t do this:
Hypertext.Add("mypage","Get dead really
fast.");

Just make more pages and add more links.
Also the name of a page shouldn't contain any gaps for your personal convinience.You can;t link it like this _my page|more_.
Also leave a gap before each _ and after one_
ex:
Get dead or what _my page_ .


If you don;t folllow my advice you'll get a message I got. AGS failed in drawing... and some stuff.
Title: Re: MODULE: Hypertext v1.21 - Change font mid-sentence
Post by: SSH on Tue 11/03/2008 12:17:41
Quote from: Dualnames on Tue 11/03/2008 10:50:00
Kill me for digging this but it's very important if someone cares to use it for AGS 3.0

First if new-strings is set to true it means that you have to replace a lot of functions in the module. 780 lines is a lot..
Yes, this module only works in AGS3.0+ if you turn of the strict settings, to allow the old RawDraw functions to work. Upgrading my modules to 3.0 is on my todo list!

Quote
Secondly when you add pages you have to make sure that the line of code isn;t bigger than 500.

Yes, AGS scripts have a line length restriction, but you can Add to the same page repeatedly and the new text gets added to the end.

Quote
Don;t do this:
Hypertext.Add("mypage","Get dead really
fast.");

Yes, AGS doesn't allow newlines in strings, but you can use the "[" character, like in normal AGS speech to insert a Line Break

Quote
Also the name of a page shouldn't contain any gaps for your personal convinience.You can;t link it like this _my page|more_.

Page names can contain gaps, but not when used with aliased links like you say. This isn't easy to workaround given the current code. If you want to use a lot of aliased links, try using underscores, dots, or CamelCase in your page names, instead of spaces.

Quote
Also leave a gap before each _ and after one_
ex:
Get dead or what _my page_ .
Or put the full stop inside the '_'s

Quote
If you don;t folllow my advice you'll get a message I got. AGS failed in drawing... and some stuff.

If you get an error, you can post it here and I can sort out the problems! But vague references don't really help!
Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bu
Post by: SSH on Fri 21/03/2008 14:26:05
Bumped for new version: now works in AGS 3.0 wihtout any faffing about, and should also be a bit faster.
Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bubble
Post by: Dualnames on Fri 21/03/2008 15:25:55
Damn , you. Did you have to wait for me to make 56 pages to change it?
Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bu
Post by: SSH on Fri 21/03/2008 15:37:38
But you can just remove the current module and load in the new one. It shouldn't change the pages you've made at all.
Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bu
Post by: riseryn on Thu 10/04/2008 22:59:51
Hi
thanks for your work :)

I tried to use your module to have speech in bubble.
I have copy/paste example code in a room script(after fadein).
no error at compile time but not bubble although.

Could you please explain how to do this?
I read documentation and this thread but cant manage to understand how to do.
Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bubble
Post by: SSH on Fri 11/04/2008 10:39:09
Please post the code you used and teh AGS version you are using. Also, try putting some other code (e.g.a Display) in the function to make sure it is working.
Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bu
Post by: riseryn on Fri 11/04/2008 13:11:01
Im using 3.01 final

I just copy/paste this code from demo game


function room_AfterFadeIn()
{
Hypertext.SetPrefixStyle(HYPERTEXT_NORMAL, 4, eHypertextSpecial_None, 0, 0, 0);
Hypertext.SetPrefixStyle(HYPERTEXT_LINK, HYPERTEXT_KEEP, eHypertextSpecial_Underline, 240, 0, 40);
Hypertext.SetPrefixStyle(HYPERTEXT_VISITED, HYPERTEXT_KEEP, eHypertextSpecial_Overline, 180, 40, 0);
Hypertext.SetPrefixStyle('=', 8, eHypertextSpecial_Box, 0, 0, 0);
Hypertext.SetPrefixStyle('^', HYPERTEXT_KEEP, eHypertextSpecial_Strikethrough, 255, 255, 255, 0,60,0);
Hypertext.SetPrefixStyle('*', 4, eHypertextSpecial_Bold);
Hypertext.SetPrefixStyle('/', 6);
Hypertext.SetPrefixStyle('+', 7, eHypertextSpecial_Crossout); 
Hypertext.SetPrefixStyle('_', 3, eHypertextSpecial_None, 255, 0, 0);
Hypertext.SetBubbleColour(255, 255, 255, 0, 0, 0);
Hypertext.SetBubble(3, 3, 8, 5, 5, 5);


player.Say("hello");
}


I notice that in demo game code is in hotspot interaction.
Is it mandatory?


Thanks for your answer :)
Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bubble
Post by: SSH on Fri 11/04/2008 16:06:30
You need to use:


Hypertext.Say(player, "Hello")
// not player.Say...

Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bu
Post by: riseryn on Fri 11/04/2008 18:48:13
Thanks 
I now have speech in bubble, however bubble appears top of the screen instead above character head.

My game is 800x600 32bits colour depth direct 3d 9 graphics driver
Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bu
Post by: SSH on Fri 11/04/2008 19:37:07
What speech mode have you set? Sierra? Lucasarts?
Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bu
Post by: riseryn on Fri 11/04/2008 19:52:45
Its Lucasart.
But its the same thing with other mode.
bubble appears on top of the screen
Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bu
Post by: SSH on Fri 11/04/2008 19:55:30
What are the X and Y coordinates of your player character?
Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bu
Post by: riseryn on Fri 11/04/2008 20:53:05
I have 2 characters

first x=140 y=209

second  x =177   y=209

i just use this code in after fadein


Hypertext.SetPrefixStyle(HYPERTEXT_NORMAL, 1, eHypertextSpecial_None, 0, 0, 0);
Hypertext.SetBubbleColour(0, 0, 0, 255, 255, 255);
Hypertext.SetBubble(3, 3, 8, 5, 5, 5);




Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bu
Post by: SSH on Fri 11/04/2008 22:04:55
Can you upload a sample game?
Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bubble
Post by: Dualnames on Fri 11/04/2008 22:14:33
I actually have lucas arts style and it;'s working good. You probably haven't set the module's settings to work the right way.
Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bu
Post by: riseryn on Fri 11/04/2008 22:53:50
Quote
You probably haven't set the module's settings to work the right way.
yes  thats all my problem I guess.

Can you give me an example of a proper setting?

EDIT
ok problem solved.
It was caused by scaling level.

SSH will give us a fix soon :)
Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bubble
Post by: Dualnames on Sat 12/04/2008 14:45:00
well, I'm replying either ways. There's a part at the module script(asc) that has at the function game start a list of setting for the Hypertext. Which are default if you don;t put your own.
Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bu
Post by: SSH on Sat 12/04/2008 16:36:03
The problem was that I didn't take scaling into account in calculating where "above a character" was, so when a character was scaled down small, like riseryn's, the module placed the text above his head as if he were unscaled, meaning a huge gap. Its an easy fix, but I ain't got the code on this computer easily to hand.
Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bubble
Post by: FrancoFranchi on Sun 02/10/2011 13:40:32
Sorry for bumping this, but I've been fiddling around with the demo-game and re-reading the documentation but I'm not sure how to deal with this (seemingly basic) question:

How can you call a function after a user has clicked on a specific hypertext link?

I've got the pages set up on a GUI button, that the player needs to click through; once they reach the relevant entry, I need to add an inventory item.  As you call all the Hypertext pages with the 'Add' function at the room load, I'm not sure what you'd use to indicate exactly when a user has reached the right link? I'm sure it's straight-forward but I've hit a stumbling block as a beginner. 

Any help appreciated :)
Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bubble
Post by: Sektor 13 on Tue 25/10/2011 09:11:29
So it is not possible to display bubble over "player.say()" ?

This could be usefull module, but i have a lot of text already written. I don't want to go back and rewrite it all (i am too lazy!).
Title: Re: MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bubble
Post by: Rocco on Fri 11/05/2012 19:49:16
I would need nonblocking speechbubbles, instead of the saybackground command.
Can this module do that?
I noticed the Hypertext.Say function in the documtation, i suspect this works with blocking.