Making a basic menu

Learn how to make a basic menu with DSS.

Intro

We're going to make a simple menu with an options page featuring an on/off switch, as well as a page where you can heal every player at the click of a button. We'll be storing data using the :SaveData() method of our ModReference.

Setting up your mod

Before we can use DSS, we first need to register our mod in our main.lua file. While we're at it, let's define a couple functions that'll handle saving and loading our mod's data.

DSS expects us to save the menu-related data ourselves. If your mod has its own save manager in it, them use those! Otherwise, you can use the code below.

Setup code
local mod = RegisterMod("Awesome Mod", 1)
local json = require("json")

local saveDataMod = RegisterMod("Awesome Mod Save Data", 1)
saveDataMod.MenuSaveData = nil -- The variable that will hold the save data that DSS uses

function mod.LoadSaveData()
    if not saveDataMod.MenuSaveData then -- If we have no save data loaded
        if mod:HasData() then
            saveDataMod.MenuSaveData = json.decode(mod:LoadData())
        else
            saveDataMod.MenuSaveData = {}
        end
    end

    return saveDataMod.MenuSaveData
end

function mod.StoreSaveData()
    mod:SaveData(json.encode(saveDataMod.MenuSaveData))
end

Setting up DSS

As the developer, you get to choose how your save data is loaded and saved. This means that you need to define the functions DSS uses to save and load its own data. Let's define a table that'll contain all of the aforementioned functions. We'll store this table in a variable named menuProvider. Make sure to customize these functions to suit your mod's save data structure.

Pre-initialization code
-- This variable and all functions contained within it are required for DSS to run.
local menuProvider = {}

function menuProvider.SaveSaveData()
    mod.StoreSaveData()
end

function menuProvider.GetPaletteSetting()
    return mod.LoadSaveData().MenuPalette
end

function menuProvider.SavePaletteSetting(var)
    mod.LoadSaveData().MenuPalette = var
end

function menuProvider.GetHudOffsetSetting()
    if not REPENTANCE then
        return mod.LoadSaveData().HudOffset
    else
        return Options.HUDOffset * 10
    end
end

function menuProvider.SaveHudOffsetSetting(var)
    if not REPENTANCE then
        mod.LoadSaveData().HudOffset = var
    end
end

function menuProvider.GetGamepadToggleSetting()
    return mod.LoadSaveData().GamepadToggle
end

function menuProvider.SaveGamepadToggleSetting(var)
    mod.LoadSaveData().GamepadToggle = var
end

function menuProvider.GetMenuKeybindSetting()
    return mod.LoadSaveData().MenuKeybind
end

function menuProvider.SaveMenuKeybindSetting(var)
    mod.LoadSaveData().MenuKeybind = var
end

function menuProvider.GetMenuHintSetting()
    return mod.LoadSaveData().MenuHint
end

function menuProvider.SaveMenuHintSetting(var)
    mod.LoadSaveData().MenuHint = var
end

function menuProvider.GetMenuBuzzerSetting()
    return mod.LoadSaveData().MenuBuzzer
end

function menuProvider.SaveMenuBuzzerSetting(var)
    mod.LoadSaveData().MenuBuzzer = var
end

function menuProvider.GetMenusNotified()
    return mod.LoadSaveData().MenusNotified
end

function menuProvider.SaveMenusNotified(var)
    mod.LoadSaveData().MenusNotified = var
end

function menuProvider.GetMenusPoppedUp()
    return mod.LoadSaveData().MenusPoppedUp
end

function menuProvider.SaveMenusPoppedUp(var)
    mod.LoadSaveData().MenusPoppedUp = var
end

It's time to initialize DSS. We'll include dssmenucore and use the function it returns to initialize DSS.

Initialization code

Creating your menu's main page

Creating a menu is a simple and intuitive process. Your entire menu will be defined within a main "directory," which is just a table. Let's create our directory, then make the main page that will appear when your menu is opened.

Main page code

Creating a page to heal all players

We're going to define another page in our menu just like before. This page will have only two buttons: one button that will take you to the previous menu, and one that will play a sound effect and heal all players when pressed.

Healing page code

Creating a settings page

The final page of our menu will be the settings page. There will only be one setting, which can either be on or off. To achieve this, we're going to make a settings button. There are many different types of settings buttons. For our purposes, we want to make a multiple choice button that lets us choose either "on" or "off."

Settings page code

Implementing our menu

We're almost done! The last thing we need to do is to actually add our menu to DSS. First, we must make a directory key. This is a table used by DSS and tells it about our directory.

Directory key code

Finally, let's add our menu using the AddMenu function of the DeadSeaScrollsMenu global.

Add menu code

Conclusion

With all of this, you now have your first menu up and running.

Going through the various buttons and pages that we made and showing them functioning correctly
Hooray!

You can download the example mod and inspect how it works below. It includes the code found in the "Adding changelogs" tutorial and the "Adding menu palettes" tutorial.

Awesome Mod download.

Last updated