Jump to content

Recommended Posts

Posted

I am looking for information if the same system of leadwerks 4 exists to store information of the configurations for example of a menu. Does it exist or do I have to create it manually with the read and write file commands?

image.thumb.png.340d777e904d3120eadc846c25f967d5.png

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games

  • Solution
Posted

This is the code I use to do it. You can customize it to work the way you want:

#include "UltraEngine.h"
#include "LoadMenu.h"

namespace UltraEngine
{
    shared_ptr<Widget> LoadSubmenu(nlohmann::json& j3, shared_ptr<Widget> parent)
    {
        if (not j3.is_object()) return NULL;
        KeyCode hotkey = KeyCode(0);
        Modifier mods = Modifier(0);
        WString name = WString(j3["name"]).Trim();
        if (j3["hotkey"].is_number_unsigned()) hotkey = j3["hotkey"];
        if (j3["mods"].is_number_unsigned()) mods = j3["mods"];
        auto menu = CreateMenu(name, parent, hotkey, mods);
        name = name.Replace("/", "");
        if (j3["showicon"].is_boolean() == false or j3["showicon"] == true)
        {
            if (FileType(AppDir() + "/UI/Icons/Menus/" + name.Lower() + ".svg") == 1)
            {
                auto icon = LoadIcon(AppDir() + "/UI/Icons/Menus/" + name.Lower() + ".svg");
                menu->SetIcon(icon);
            }
        }
        if (j3["enabled"].is_boolean())
        {
            if (bool(j3["enabled"]))
            {
                menu->Enable();
            }
            else
            {
                menu->Disable();
            }
        }
        if (j3["state"].is_boolean())
        {
            menu->SetState(bool(j3["state"]));
        }
        if (j3["kids"].is_array())
        {
            for (int n = 0; n < j3["kids"].size(); ++n)
            {
                LoadSubmenu(j3["kids"][n], menu->As<Menu>());
            }
        }
        return menu;
    }

    shared_ptr<Widget> LoadMenu(const WString& path, shared_ptr<Widget> parent)
    {
        auto j3 = LoadJson(path);
        if (not j3.is_object()) return NULL;
        if (not j3["menu"].is_object()) return NULL;
        return LoadSubmenu(j3["menu"], parent);
    }

    shared_ptr<Widget> LoadMenu(nlohmann::json& j3, shared_ptr<Widget> parent)
    {
        if (not j3.is_object()) return NULL;
        if (not j3["menu"].is_object()) return NULL;
        return LoadSubmenu(j3["menu"], parent);
    }
}

I create my menus for the editor in JSON like this:

{
    "menu":
    {
        "kids":
        [
            {
                "name": "File",
                "kids":
                [
                    {
                        "name": "Save",
                        "hotkey": 83,
                        "mods": 1
                    },
                    {
                        "name": "Save As"
                    },
                    {},
                    {
                        "name": "Close"
                    }
                ]
            },
            {
                "name": "Tools",
                "kids":
                [
                    {
                        "name": "Build Mipmaps"
                    },
                    {},
                    {
                        "name": "Generate Normal Map"
                    },
                    {
                        "name": "Flip Normal Map U"
                    },
                    {
                        "name": "Flip Normal Map V"
                    }
                ]
            },
            {
                "name": "Help",
                "kids":
                [
                    {
                        "name": "Ultra Engine Documentation",
                        "hotkey": 112
                    },
                    {},
                    {
                        "name": "Support Forum"
                    },
                    {
                        "name": "Ask a question"
                    },
                    {
                        "name": "Suggest a feature"
                    },
                    {
                        "name": "Report a problem"
                    },
                    {},
                    {
                        "name": "About"
                    }
                ]
            }
        ]
    }
}

 

  • Like 1

Let's build cool stuff and have fun. :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...