Help with the menu (ds_map)

Help me how to change the window mode in the menu?

GML:
#macro MAIN            0
#macro SETTINGS    1

global.dsm_settings = ds_map_create();
#macro set        global.dsm_settings
ds_map_add(set, "sound", [5,  [0, 10]]);
ds_map_add(set, "music" , [5,  [0, 10]]);
ds_map_add(set, "window mode" , [0, ["Window", "Fullscreen"]]);
ds_map_add(set, "window size" , [1, ["x2", "x3", "x4"]]);

//Главное.  Submenu 0.
menu[MAIN][0] = "Start Game";
menu[MAIN][1] = "Settings";
menu[MAIN][2] = "Exit";

//Submenu 1.
menu[SETTINGS][0] = ["Sound ", "sound"];
menu[SETTINGS][1] = ["Music ", "music"];
menu[SETTINGS][2] = ["Window mode ", "window mode"];
menu[SETTINGS][3] = ["Window size ", "window size"];
menu[SETTINGS][4] = "Back";

index = 0;
sub_menu= 0;
menu_size = 0;

Here I do not understand how to write correctly.

GML:
 //Window mode.
                    case 2:
                        change_menu(_h_move, "window mode");
                        var _window_mode = global.dsm_settings[? "window mode"];;
                        if (_window_mode = "Fullscreen") {
                            window_set_fullscreen(true);
                        }else{
                            window_set_fullscreen(false);
                        }
GML:
#region function change_menu
    function change_menu(_move, _key) {
        ///@desc            change the ds map key entry by the move value passed
        ///@move        real which way to move the selection
        ///@key            string ds_map key for this selection
       
        //get the allowed limits for this selection
        //get map array
        var _map_arr = set[? _key];
        //get the limits array
        var _limits_arr = _map_arr[1];
       
        if (is_real(_limits_arr[0])) {
   
            var _min = _limits_arr[0];
            var _max = _limits_arr[1];
        } else {
       
        var _min = 0;
        var _max = array_length(_limits_arr) - 1;
        }

            _map_arr[@ 0] = clamp(_move + _map_arr[0], _min, _max);
}
#endregion
 

chamaeleon

Member
GML:
var _window_mode = global.dsm_settings[? "window mode"];;
_windw_mode should now contain the array [0, ["Window", "Fullscreen"]].
GML:
if (_window_mode = "Fullscreen") {
...
}
_window_mode does not contain a string to compare against

So maybe this is what you want, given the current data structure definition
GML:
var _window_mode = global.dsm_settings[? "window mode"];;
if (_window_mode[1][_window_mode[0]] = "Fullscreen") {
    window_set_fullscreen(true);
} else {
    window_set_fullscreen(false);
}
But it seems very ugly. _window_mode[0] should contain a value that is directly comparable to something, perhaps an enum that contains Window and Fullscreen as entries.
GML:
enum WindowMode {
    Window,
    FullScreen
};
...
ds_map_add(set, "window mode" , [WindowMode.Window, ["Window", "Fullscreen"]]);
...
var _window_mode = global.dsm_settings[? "window mode"][0];;
if (_window_mode = WindowMode.FullScreen) {
    window_set_fullscreen(true);
} else {
    window_set_fullscreen(false);
}
Or use macros instead of enums, if enums seems like too much typing.
 
Thanks! It works!
What is the best way to add a window scale change to the menu?

This is how I made a camera:
GML:
enum RES {
    WIDTH = 640,
    HEIGHT = 360,
    SCALE = 2 //Zoom.
}
//---------------------------------------------------------------------------------------------------------

global.CAMERA = camera_create_view(0, 0, RES.WIDTH, RES.HEIGHT, 0, -1, -1, -1, _x_border, _y_border);

global.CAMERA = view_camera[0];

var _width = RES.WIDTH * RES.SCALE;
var _height = RES.HEIGHT * RES.SCALE;

surface_resize(application_surface, _width , _height );

window_set_size(_width, _height);

display_set_gui_size(RES.WIDTH,  RES.HEIGHT);
in o_menu:
GML:
...
ds_map_add(set, "window size" , [1, ["x2", "x3", "x4"]]);
...

//Window size.
    case 3:
    change_menu(_h_move, "window size");
    var _window_size = global.dsm_settings[? "window size"][0];
    show_debug_message( _window_size);
    switch (_window_size) {
    case 0:  ????    break;
    case 1:  ????    break;
    case 2:  ????    break;
    }
 

chamaeleon

Member
GML:
enum RES {
    WIDTH = 640,
    HEIGHT = 360,
    SCALE = 2 //Zoom.
}
Enum is not good choice for independent scalar values that in theory could be the same (you wouldn't be able to specify a square area for instance with the same width and height). Just make those macros.

As for code required for setting the various window sizes, I have no quick answer for you. It's a matter setting the window size, the application surface size, and any relevant view port sizes, etc., using the functions available for these tasks.
 
Top