-
Notifications
You must be signed in to change notification settings - Fork 2
tutorial.basic.11
Windows! Finally. A pretty nice and useful feature to use in uiz.
Creating windows exists out of multiple parts:
- Creating your window and defining itβs size.
- Customizing your window (backgrounds, colors)
- Fixing your window
- Putting stuff in your window
Those are a lot of steps, but we are going to run you through them one a time.
Creating your window is fairly easy, you can use either uiz_window_create, or use uiz_window_create_animation. Look up these functions in the manual. In the sidebar there is a entry called "windows (uiZ)". There is also "windows (os)", but you won't need those as they are functions only applicable to Microsoft Windows. We want to use the uiZ built in windows.
EXAMPLE 40a:
//initializing uiz
uiz_init();
//creating window
window=uiz_window_create_animation(3,dp,3,dp,uiz_anticipate_in,uiz_anticipate_out,uiz_one,1);
//fixing window
uiz_fix(window);
This creates an empty window:
IMAGE 53aTo put stuff inside this window, you don't actually need to learn anything new. Putting things inside a window is handled by uiZ's parenting system from tutorial 2.
EXAMPLE 40b:
//initializing uiz
uiz_init()
//creating window
window=uiz_window_create_animation(3,dp,3,dp,uiz_anticipate_in,uiz_anticipate_out,uiz_one,1)
//fixing window
uiz_fix(window)
//add gradient
gradient = uiz_c(obj_uiZ_gradientsquare);
uiz_setParent(gradient, window);//put the gradientsquare inside the window
uiz_position_t(gradient, uiz_fill, uiz_fill);//fill the window with the gradient
uiz_fix(gradient);
This yields:
IMAGE 53bTo change the look and feel of the window, it uses the background system as explained in tutorial 8. However, something interesting is going on with the window: it has got two backgrounds. You can see this on the window as one big background, and a second one for the top bar. For the main background, you can use the normal uiz_background_ functions, about which you can read more about in tutorial 8, or on the background documentation page.
However, if you want to change the top bar, you need to use the uiz_background_topbar_ functions. For almost every normal uiz_background_, there exists a _topbar_ variant.
Let's see an example where we change the colors of our window:
IMAGE 53cWell, that's what I call a not so merry christmas! But I'm sure you can come up with styles that do look absolutely fabulous.
Before moving onto the next topic, it must be explained that a window handles it background differently. These states exist in these conditions:
- _normal: The window is not selected.
- _in: The window is selected.
- _over: The window is not selected and the window is maximized.
- _out: The window is selected and the window is maximized.
Go on, take a look at the manual on how to change more window settings. You can change:
- what buttons should show. (enable/disable minimize, maximize and close)
- what buttons should look like. (customize minimize, maximize and close)
- what the backgrounds look like, besides just the color
- Set the window text and customize it
- Set how the top bar is put inside the window
- Set how and if the window can be resized.
- Programmatically minimize of maximize the window.
Besides you being able to completely make your own windows, there are some standard βquick windowsβ to use. For example, you may want to make a quick popup with an βokβ button or something. Well, There are pre made scripts that do just that in uiz!
Here is a list of them:
- Uiz_popup_ok
- Uiz_popup_yesno
- Uiz_popup_string
They are very easy to use, just look at an example:
EXAMPLE 41:
//init uiz
uiz_init()
//create popup window
window=uiz_popup_ok("This is a test popup","A window!",true)//we will need to store window for later usage
//no fixing or anything else is needed
To find these functions in the manual, open up the popup section of the wiki sidebar. Click on the uiz_popup_ok entry to see what this function does.
Now the βblock backgroundβ argument in the function is kind of interesting. It allows you to make everything in the background unclickable and forces the user to put all attention on your popup. Enabling this function will βgray outβ everything behind the message. This argument is set to true in the example above. How to get if the ok button has been pressed? Well, you have to check if the window still exists. You can easily do this by checking:
If !instance_exists(window) then{
//execute code
}
I would recommend putting the code into your step event if you are doing some process that has been interrupted to show the user a message. In the upcoming updates, the handling should be changed to something event based. For now, this is not the case.
Next window, The yes/no window. You can create it in very much the same style:
EXAMPLE 42:
//init uiz
uiz_init()
//create popup window
r=uiz_popup_yesno("Do you like uiz?","Important question!",false)
//no fixing or anything else is needed
So how do I get the answer of this box? Well itβs a little big more complicated. First because game maker can only return a single value, the local object variables: βuizreturnyesβ, βuizreturnnoβ and βuizreturnwindowβ will be created after you run the script.
Uizreturnyes now has a instance_id referring to the yes button and uizreturnno has a instance id referring to the no button. Also why have a uizreturnwindow variable? Well, the function uiz_popup_yesno doesnβt always return a window instance id. Normally it should return a window instance id, but when a "block background" is set to true, then it will return the instance id of a obj_uiZ_square which overlays the entire screen. (This is also true for the normal uiz_popup_ok, but it doesnβt really matter there)
Another way of getting the buttons is by accessing βyesbuttonβ and βnobuttonβ on whatever uiz_popup_yesno returns. This will work whether the script returns a window or a square.
Knowing all of this, the following code can be used to get the answer of a popup_yesno, where r refers to a value previously gotten in example 42 :
if instance_exists(r.yesbutton) and r.yesbutton.kmouseover == uiz_mouseclick then{
//yes!
}else{
if instance_exists(r.nobutton) and r.nobutton.kmouseover == uiz_mouseclick then{ //no!
}
}
In later versions of uiZ, this code will be cleared up to be more event based.
Donβt worry if you donβt understand every little bit of code in there but it is useful to know what kmouseover does, which you will learn in the next tutorial. This code though, does need to be in a step event to constantly check if you want to know the answer. The β//yes!β and β//no!β parts only fire for 1 step long.
And last but not least, string input windows. This also works very similar to other popup scripts:
EXAMPLE 43:
//init uiz
uiz_init()
//create popup window
window=uiz_popup_string("what is your name?","Something...", true, "david")
//no fixing or anything else is needed
Now we can "get" the string using:
if instance_exists(r) and r.indestroy=1 then{ string=r.str;}
I hope this tutorial was useful to you. Personally I'm not to happy with it because the way to use the popups is convoluted and bad programming practice. The popup system needs a big overhaul, but for now you unfortunately need to live with the current system.
In this tutorial you learned:
- How to create a window
- How to put stuff into windows
- How to read the documentation for windows
- How a background has multiple backgrounds
- How to change the background (color) of windows
- How to create an ok popup
- How to create an yes/no popup
- How to create an string popup
Next time weβll cover using the mouse and Iβll teach you how to make scroll bars.
πTutorials
Basics 1: Basic positioning
Basics 2: Parenting system
Basics 3: Advanced positioning
Basics 4: Advanced sizing and set point
Basics 5: Canvas and containment
Basics 6: Alpha and depth
Basics 7: Using the manual and Animations
Basics 8: Object backgrounds
Basics 9: Grids
Basics 10: Framesets
Basics 11: Windows
Basics 12: Scroll bars
βοΈ Positioning
π Depth
π Structures
π Objects
obj_uiZ_3waybutton
obj_uiZ_button
obj_uiZ_checkbox
obj_uiZ_clock
obj_uiZ_colorbox
obj_uiZ_cover
obj_uiZ_drawdslist
obj_uiZ_dropdown
obj_uiZ_easybutton
obj_uiZ_frame
obj_uiZ_framescrollbar
obj_uiZ_functionbar
obj_uiZ_gradientsquare
obj_uiZ_gradientroundrect
obj_uiZ_gridlist
obj_uiZ_huesquare
obj_uiZ_loadingbar
obj_uiZ_loadingcircle
obj_uiZ_menubutton
obj_uiZ_mousemenu
obj_uiZ_radiobox
obj_uiZ_rotator
obj_uiZ_slider
obj_uiZ_scrollbar
obj_uiZ_slider_2col
obj_uiZ_slickslider
obj_uiZ_slideframe
obj_uiZ_sprbutton
obj_uiZ_spriteanimationbutton
obj_uiZ_spritecounter
obj_uiZ_stringbox
obj_uiZ_sliderstruct
obj_uiZ_surfacecanvas
obj_uiZ_sprite
obj_uiZ_square
obj_uiZ_squarebutton
obj_uiZ_swipicon
obj_uiZ_switch
obj_uiZ_tabslider
obj_uiZ_tabs
obj_uiZ_treelist
obj_uiZ_text
obj_uiZ_text_background
obj_uiZ_textarea
obj_uiZ_valuebox
π Strings
uiz_addChar
uiz_changechar
uiz_charCanHaveAddon
uiz_returnCharAddon
uiz_charIsNumber
uiz_charIsNumberOrText
uiz_getlines
uiz_gettext_contained
uiz_gettextlines_contained
uiz_getValidVariableName
uiz_isSpaceChar
uiz_lastStringChars
uiz_removeChar
uiz_replaceChars_
uiz_string_copy
uiz_string_digits
uiz_string_format
uiz_string_fromReal
uiz_string_real_getFracLength
uiz_string_real_getIntLength
uiz_string_repeat
uiz_string_replace
uiz_string_pos_at
uiz_stringUntilNewline