1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GMS 2 I need tips in creating a GUI library.

Discussion in 'Programming' started by StardragonEX, Jul 18, 2019.

  1. StardragonEX

    StardragonEX Member

    Joined:
    Apr 3, 2018
    Posts:
    6
    Hello there, I'm new to taking GMS2 seriously for game making and I want to make a Shmup/RPG, but I realized I need a good GUI system for what I have in mind and GML doesn't have gui functions to create buttons, scroll panes, radio buttons, etc., so I want to create a GUI system to do so or use one that is already created, and I would like some tips or library recommendations.

    So, I'm wondering if someone knows a good gui system already created that wants to recommend it to me or if someone knows how to create one and could give me some tips in how to create it.

    I don't know if I should use GMS2 objects with mouse click events like most people use for buttons and things like that, or only use draw functions, window_mouse_get_x() and window_mouse_get_y() to detect what I'm pressing and build it from the ground up with that.
     
    Last edited: Jul 18, 2019
  2. StardragonEX

    StardragonEX Member

    Joined:
    Apr 3, 2018
    Posts:
    6
  3. Anixias

    Anixias Member

    Joined:
    Jun 27, 2016
    Posts:
    204
    I've always created GUIs directly in the Draw GUI event using draw functions and window_mouse_get_* functions. I also store form values such as radios and text fields in the Create event.

    If you would like to create a library, I suggest you use scripts that simply store forms and other info in the object calling the script. For example, for a radio creation script, I would simply return a data structure or array of some kind. Then, treat that as a radio field. The first two values in the array could be an x and y to draw the first radio at, followed by the third being the vertical distance between each radio. Next, create a radio_add script that simply appends a label onto the array. I would also suggest appending a fourth value into the array that stores which radio is selected, with it defaulting to -1 (no radio selected).

    I would also create a form_create script that returns an empty ds_list, ds_grid, or 2D array. Create a script called form_add that takes in the value returned by radio_create, and other similar functions (text_field_create, button_create, etc.) as well as the x and y position to draw each form_add at. I would then create a form_draw script that goes through the elements in the form and draws them at the given x and y offset + the x and y of each part of that element (so, create a script called radio_draw(x,y), text_field_draw(x,y), etc. Feel free to add other scripts like text_field_draw_ext(x,y,background color,font,font color) and other useful stuff).

    You would also need some scripts that detect user input. You need to have a single variable in the forms that stores which element in the form (provided via form_add) is currently focused. Then, whichever is focused, call something like element_update(elementid) which would act differently depending on the element type. You should also create a script called element_get_type(elementid). In the element create scripts (radio_create, text_field_create), I would store what kind of element it is in the actual data of that element.

    I've been moderately vague with this answer but hopefully it should spark some ideas so that you could create your own library. I have never made these scripts myself, as I never need forms or radios or anything, but this should be a good starting point.

    Other form types to consider:
    -Radio
    -Text Field
    -Multi-line Text Field
    -Button
    -Checkbox
    -Slider
     
  4. StardragonEX

    StardragonEX Member

    Joined:
    Apr 3, 2018
    Posts:
    6
    Hey, thanks for the response, yeah, that could work, it would work a little more like Java Swing that way I think.

    I also been seeing the code of some free gui libraries in the marketplace. All of the ones I've seen use GMS2's objects to make the windows and buttons. I'm still trying to find a way to start. Maybe I should just start and make code for both ways and see what is better in performance wise and customizable wise.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice