Wiki

Clone wiki

menuhelperhelper / Example of use

1.jpg

menumanager.lua

#!lua

if not MenuHelperHelper then return end

Profile_menu = {
    name = 'John Smith',
    age = 35,
    more = {
          height = 180,
          weight = 85
        },
    sex = { 'male', 'female', 'other', value = 1},
    married = true,
    notes = function(item)
        QuickMenu:new(
                'Notes', 
                'No notes attached.',
                 {{text = 'OK', is_cancel_button = true}}   
            ):Show()
    end
}

MenuHelperHelper._tweaks = {
    name = { priority = 10 },
    age = {slider_min = 0, slider_max = 120},
    height = {slider_min = 50, slider_max = 220},
    weight = {slider_min = 30, slider_max = 150}
}

MenuHelperHelper:CreateMenu(Profile_menu, 'profile_menu', 'Profile.txt', function(settings) 
    Profile_menu = settings
end)


-- This below is used to load the localization file
-- This is not a part of the example
local thisPath
local thisDir
local function Dirs()
    thisPath = debug.getinfo(2, "S").source:sub(2)
    thisDir = string.match(thisPath, '.*/')
end
Dirs()
Dirs = nil

Hooks:Add("LocalizationManagerPostInit", "ProfileMenu", function(loc)
    LocalizationManager:load_localization_file(thisDir..'loc.json')
end)

loc.json

#!json
{
    "profile_menu": ">>>>> Profile <<<<<",
    "profile_menu_desc": " ",

    "profile_menu_notes": "Notes",
    "profile_menu_notes_desc": "Display any notes",

    "profile_menu_sex": "Sex",
    "profile_menu_sex_desc": "Set sex",
    "profile_menu_sex_male": "M",
    "profile_menu_sex_female": "F",
    "profile_menu_sex_other": "Other",

    "profile_menu_more": "More info",
    "profile_menu_more_desc": " ",

    "profile_menu_more_height": "Height",
    "profile_menu_more_height_desc": "Set height",

    "profile_menu_more_weight": "Weight",
    "profile_menu_more_weight_desc": "Set weight",

    "profile_menu_age": "Age",
    "profile_menu_age_desc": "Set age",

    "profile_menu_name": "Name",
    "profile_menu_name_desc": "Enter name",

    "profile_menu_married": "Married",
    "profile_menu_married_desc": "Set marital status"
}

mod.txt

#!json
{
    "name": "MenuHelperHelper Example",
    "description": " ",
    "author": "andole",
    "version": "1",
    "blt_version" : 2.0,
    "color" : "0.6 0.3 0.5",
    "contact": "\n http://steamcommunity.com/id/andole/",

    "hooks": [
        {
            "hook_id": "lib/managers/menumanager",
            "script_path": "menumanager.lua"
        }
    ]
}

Updated