GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2010-06-16 01:01:45

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

Format your message box the way you want

This method shows how to use message_background with a surface and baground_add so to use gm's show_message_ext using any formating you want. it can be modified so to make show message look just the way you want for your game, in a dynamic way, for example you could redirect your game drawing to the surface call show message ext with no button ("","","","") to make a pause screen. Or draw interesting stuff in each message boxes...

For the example, I just enhanced the text formating.

Expand//show_message_ext2(message,but1,but2,but3)
//see manual for show_message_ext()
//WARNING: resets the fonts, you must re-aply your game font in your game after use
//WARNING: resets the font alignment, you must re-aply your game font alignment in your game after use
//WARNING: This permanently changes the message box specs

//this creates a message box using a font in the font resource
//the message resizes according to the text and the specs below

var bkcolor; bkcolor = c_gray; //back color
var width; width = 400; //fixed width of message box 
var leftedge; leftedge = 20; //left edge
var rightedge; rightedge = 20; //right edge
var topedge; topedge = 20; //top edge
var bottomedge; bottomedge = 60; //bottom edge
var font; font = font0; //the font to use in your resource
var fontcolor; fontcolor = c_white; //font color
var halign; halign = fa_center; //font alignment;

//remember old color
var ocol; ocol = draw_get_color();
//set new font;
draw_set_font(font);
//alignment
draw_set_halign(halign);
//set font color
draw_set_color(fontcolor);

//calculate width 
var w; w = string_width_ext(argument0,-1,width-(leftedge+rightedge)) + leftedge+rightedge
//the height
var h; h = string_height_ext(argument0,-1,width-(leftedge+rightedge)) + bottomedge + topedge;

//to surface
var s; s = surface_create(w,h)
surface_set_target(s);
//clear and color
draw_clear(bkcolor)

//draw the text
var xx,yy;
xx = leftedge;
yy = topedge;
if(halign == fa_center)
{
    xx = w/2;
    yy = topedge;
}
if(halign == fa_right)
{
    xx = w-rightedge;
    yy = topedge;
}
draw_text_ext(xx,yy,argument0,-1,width-(leftedge+rightedge));

//back to normal
surface_reset_target();

//set to a background
var b; b = background_create_from_surface(s,0,0,w,h,0,0,0);
//free surface
surface_free(s);
//set the message size
message_size(w,h);
//set to message background image (the text)
message_background(b);
//figure out the buttons
var but0,but1,but2;
but0 = "";
if(is_string(argument1)) but0 = argument1;
but1 = "";
if(is_string(argument2)) but1 = argument2;
but2 = "";
if(is_string(argument3)) but2 = argument3;
//show the message, sans text
var ret; ret = show_message_ext("",but0,but1,but2);
//message_background(-1);
//frre background
background_delete(b);
//reset what cen be reset
draw_set_color(ocol);

//return result
return ret;

Offline

#2 2010-06-17 14:36:19

xot
Administrator
Registered: 2007-08-18
Posts: 1,239

Re: Format your message box the way you want

I don't quite get this one at first glance. Can you provide one or two examples?


Abusing forum power since 1986.

Offline

#3 2010-06-17 15:07:51

flexaplex
Member
Registered: 2008-12-11
Posts: 72

Re: Format your message box the way you want

Hmm not sure this is best used as a script, think it would suit better as an example in the tutorials forum. I'm interested in seeing an example also, I'm too lazy to even open GM at the moment laugh

You should reset all the fonts yourself though, assign the current settings to variables before it's run then set again when it ends. I think there should be an in-built message_set_default() function in GM.

Offline

#4 2010-06-17 21:50:07

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

Re: Format your message box the way you want

Here is the example

Download ShowMessageExt2.gmk

Basically, this one like the provided script above (Using the _ext2 script now BTW), only shows how to extend the text formating. But you can do much more.

like
screen refresh right after the draw redirect and set the width and height w and h to the room size. call with no buttons, instant pause.

Offline

#5 2010-06-17 22:01:54

flexaplex
Member
Registered: 2008-12-11
Posts: 72

Re: Format your message box the way you want

Yes I go back to my previous point. This is much more an example rather than a script. As you need to edit in script to get the functionality you want it is not flexible as a standalone script.

It is certainly an interesting way of making a pause script. You could technically use the buttons in the show_message to make a basic menu if wanted also. Recalling another show_message based on the button pressed.

Last edited by flexaplex (2010-06-17 22:02:35)

Offline

#6 2010-06-18 02:17:38

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

Re: Format your message box the way you want

flexaplex wrote:

Yes I go back to my previous point. This is much more an example rather than a script. As you need to edit in script to get the functionality you want it is not flexible as a standalone script.

It is certainly an interesting way of making a pause script. You could technically use the buttons in the show_message to make a basic menu if wanted also. Recalling another show_message based on the button pressed.

Well, I could argue that the script as is can be used just for fixing show_message_ext text formating limitation. Yes, I coded values inside which could be passed as argument. But since, from my experience, you tend to stick to one type of message style in a game, i figured it would ease the complexity of the call. Also, gm does NOT have proper gets to reset the changes I make. for example, I can't get the old halign to reset... I also cant reset the dialog box background to default. One would be forced to edit the script to reset everything to his game's defaults.

Using it for a pause script is just an outside the box idea I found cool.

Offline

#7 2010-06-18 09:01:15

flexaplex
Member
Registered: 2008-12-11
Posts: 72

Re: Format your message box the way you want

Well naturally I wouldn't call your script in that way. I would use the following script format:

Expandset_message_background();  //what I would rename your script to
show_message_ext("", but0, but1, but2);
clear_message_background();

I think that is a more logical way of setting this. It allows you to make multiple show_message_ext calls with the same background or change the background script call but still use the same messages.

Last edited by flexaplex (2010-06-18 09:03:25)

Offline

#8 2010-06-18 09:23:22

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

Re: Format your message box the way you want

Good suggestion.

Offline

#9 2010-10-31 13:24:28

Bravo009
Member
Registered: 2010-10-31
Posts: 1

Re: Format your message box the way you want

What a great blog is it! though i am not much familiar with these codes but have a great interest to have the knowledge of it. i hope that more updates will be available in this post to keep us smart.

thanks for nice sharing.  smile

Offline

Board footer

Powered by FluxBB