MODULE: Hypertext v1.3 - Change font mid-sentence, web-like pages, Speech bubble

Started by SSH, Fri 08/12/2006 17:07:08

Previous topic - Next topic

SSH

Requires AGS 2.72 or later

Inspired by the discussion in this thread, 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.
Code: ags

=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




Download the Hypertext module here
Hypertext module documentation
Hypertext module wiki page




12

GarageGothic

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.

SSH

 :P

You could just ask me yourself... ;)
12

Ali

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?

SSH

Rich is do-able, but I fear that sophisticated is beyond the realms of possibility...  ;)
12

Maverick

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

Kweepa

#6
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
Code: ags

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.
Still waiting for Purity of the Surf II

Rui 'Trovatore' Pires

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?
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Maverick

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
Code: ags

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)

Kweepa

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.
Still waiting for Purity of the Surf II

SSH

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.
12

Maverick

Thank you gentleman.
As you pointed out I did not include a space at then end of the first line of text.

SSH

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!
12

Maverick

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?

SSH

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...
12

Rui 'Trovatore' Pires

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.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

GarageGothic

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.

SSH

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.
12

Rui 'Trovatore' Pires

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.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Dualnames

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.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SSH

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!
12

SSH

Bumped for new version: now works in AGS 3.0 wihtout any faffing about, and should also be a bit faster.
12

Dualnames

Damn , you. Did you have to wait for me to make 56 pages to change it?
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SSH

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.
12

riseryn

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.

SSH

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.
12

riseryn

Im using 3.01 final

I just copy/paste this code from demo game

Code: ags

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 :)

SSH

You need to use:

Code: ags

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

12

riseryn

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

SSH

12

riseryn

Its Lucasart.
But its the same thing with other mode.
bubble appears on top of the screen

SSH

12

riseryn

I have 2 characters

first x=140 y=209

second  x =177   y=209

i just use this code in after fadein

Code: ags

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);





SSH

12

Dualnames

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.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

riseryn

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 :)

Dualnames

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.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SSH

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.
12

FrancoFranchi

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 :)

Sektor 13

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!).

Rocco

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.

SMF spam blocked by CleanTalk