Jibble

Author Topic: MODULE: ChatDisplay (show a WhatsApp-like dialogue on GUI Button)  (Read 2112 times)

DOWNLOAD: https://drive.google.com/file/d/1sklK7U1ZNEz_lSmtUxCcwBAPculqVQCt/view?usp=sharing

To use the module, put a button on a GUI, then create a new chat instance:
Code: [Select]
  globalHandleInt = Chat.Create(btnChat, eFontWestwood [, bgSprite, width, height]);bgSprite is a sprite slot for the background, it gets auto-tiled if it's smaller than the button. You can also state width and height, in that case the button is resized to those dimensions.

Optionally add sound:
Code: [Select]
  Chat.SetSound(globalHandleInt, aBlip);Pass null to disable sound.

To add a message, just call:
Code: [Select]
  Chat.Add(globalHandleInt, "The message", "sender" [, hour, minute]);If you put an asterisk at the start of the sender, like "*Alice", the message appears on the right. You can optionally state a timestamp, or omit for user's local time.

Adding a message makes the chat scroll down automatically. You can also scroll using the mousewheel, while hovering over the chat.

The chat is automatically drawn and scrolled if the GUI and button are visible.

It's also possible to prepare multiple messages, just call Chat.Prepare() instead. Show them one by one using Chat.Advance(globalHandleInt); or all at once using Chat.ShowAllPrepared(globalHandleInt);.
(Calling .Add() will simply call .Prepare(), then .Advance(), so make sure you have advanced over all prepared messages before using .Add(), or you will get unexpected results ;) )

It is recommended to call Chat.CleanUp() upon quitting the game, this will delete all the DynamicSprites, avoiding a warnings log in the game folder.

Given that most people will probably want to customize the look of the chat, I've moved the function that draws a message to the very top of the module script.
It gets passed all relevant parameters:
Code: [Select]
DynamicSprite *CustomMessage(int chatWidth, Alignment align, String author, int hour, int minute, String text, FontType font) and must return a new DynamicSprite containing the message.

Preview of default look:
Spoiler: ShowHide

My example room script: http://pastebin.com/raw/BvruHqr7
« Last Edit: 21 Jun 2019, 10:08 by Khris »
Fail at Floaty Rog' now!  still having to deal with what games are going through

Hi Khris.
I would like to say that, in my opinion, it's truely amazing the work you have done with this module, really.
Later I have done a quickly basic test to try it out :
http://www.fileconvoy.com/dfl.php?id=gbb02b56387dd286a999940942fd5c255f26ad0a41

Suddenly, I would like to ask you if there is a way to do those extra stuff inside your module so far...

- Add emoticon 'graphic' at the end of the text message lenght if a "needle emoticon" was found inside a string.
- Mouse click at the scrolling bar to make it scroll and visible like how it is working for (mouse wheel support)
- "Drag and drop" the btnFirstChat to make it scroll like how it is working for (mouse wheel support)
- A way to open our computer folders and to select an image to send in the text message (eventually it get resize to a default value to fill well into the text message)

Let me know, if you want, what do you think about those ideas.
Thank you in advance again for reading this message.

Hi Vincent,

I've already thought about adding emoticons; right now the text is created using DrawStringWrapped() but I wanted to implement links, so I'd have to pick apart and reassemble the bubble text anyway. It's more work than writing the entire current module though, so maybe at some point.

Dragging the scroll bar using the mouse it much more easy to implement; I might also add that, yes. Dragging and dropping the button however is pretty easy and unrelated to the module. Just look up code for dragging GUI buttons or objects and implement it in your game.

As for opening a file selection window, not possible. You can populate a listbox with filtered content of your game folder, but you cannot browse the hard drive. You can select and load an image file in the same folder as the game though.
Fail at Floaty Rog' now!  still having to deal with what games are going through

Hi Vincent,

I've already thought about adding emoticons; right now the text is created using DrawStringWrapped() but I wanted to implement links, so I'd have to pick apart and reassemble the bubble text anyway.

Hi Khris.
I have try to reassemble so far the bubble text and adding an emoticon graphic in it but it didn't work at all.
I was just able to show the emoticon graphic outside the bubble text which it's not looking very well..


Dragging and dropping the button however is pretty easy and unrelated to the module. Just look up code for dragging GUI buttons or objects and implement it in your game.

I apologize if I misspoke about the dragging and dropping question.
I meant to say to use the dragging and dropping method (to the btnFirstChat) to make scroll the messages history (as it's working for the mouse wheel) but without dragging and dropping the button itself just to use the dragging and dropping method to scroll the messages if possible..
I hope you understand what I mean.

As for opening a file selection window, not possible. You can populate a listbox with filtered content of your game folder, but you cannot browse the hard drive. You can select and load an image file in the same folder as the game though.

I'm not sure what I'm about to say but if I remember correctly there's a module made by Wyz "TilemapConv1.0.0" which does exactly a browse to our hard drive to find a folder containing a TMX files..
Anytime we select '..' inside the listbox then it move to the parent directory.


Ps: Everything you're going to implement it sounds fantastic !!! :)


:EDIT:
if I remember correctly there's a module made by Wyz

It's actually an executable.

« Last Edit: 17 Mar 2017, 13:34 by Vincent »

I am sorry to necroposting this thread. Actually I noticed that all the text which are processed into the static bool Chat::Prepare are not translated into the .trs file.
I edited the static bool Chat::Prepare to look in this way now:

Code: Adventure Game Studio
  1. message[messages].text = GetTranslation(text);
  2.  

Actually this is working well and it get the translation just properly fine.

Thanks Vincent, nice catch! I updated the module and the download link in the first post.
Fail at Floaty Rog' now!  still having to deal with what games are going through

Thanks you are welcome!

Sorry to revive the thread. This plugin has been enormously useful to me, but I haven't been able to figure out how to use it in skippable cutscenes. The game inevitably freezes if I try to skip any Chatdisplay content. I've tried to use if (!Game.SkippingCutscene) to bypass the Chat code, but no luck.

Any thoughts would be greatly appreciated. Either way it's a terrific module!