summaryrefslogtreecommitdiffstatshomepage
path: root/src/frontend
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2021-10-21 07:44:34 +1100
committer Vas Crabb <vas@vastheman.com>2021-10-21 07:44:34 +1100
commit3891d424713d11fe4ae1e0d32b60fc66ae53ffdd (patch)
treef9ef522709b5b62c499125c196a42901266fb6f7 /src/frontend
parenta0be1bfba9888725da056cb446e6307443ffb300 (diff)
frontend: Beter provision for plugins with multiple menu levels.
Make it possible for a plugin to specify which item should be selected on repopulate. Also allowed plugins to specify the UI heading flag for menu items. Updated input macro plugin to select sane items when changing menus. Other plugins not updated yet, but may be at some point in the future.
Diffstat (limited to 'src/frontend')
-rw-r--r--src/frontend/mame/luaengine.cpp14
-rw-r--r--src/frontend/mame/luaengine.h8
-rw-r--r--src/frontend/mame/ui/inputmap.cpp4
-rw-r--r--src/frontend/mame/ui/pluginopt.cpp20
4 files changed, 27 insertions, 19 deletions
diff --git a/src/frontend/mame/luaengine.cpp b/src/frontend/mame/luaengine.cpp
index a76c46fb1d5..9169bdc9f50 100644
--- a/src/frontend/mame/luaengine.cpp
+++ b/src/frontend/mame/luaengine.cpp
@@ -432,31 +432,33 @@ sol::object lua_engine::call_plugin(const std::string &name, sol::object in)
return sol::lua_nil;
}
-void lua_engine::menu_populate(const std::string &menu, std::vector<std::tuple<std::string, std::string, std::string>> &menu_list)
+std::optional<long> lua_engine::menu_populate(const std::string &menu, std::vector<std::tuple<std::string, std::string, std::string>> &menu_list)
{
std::string field = "menu_pop_" + menu;
sol::object obj = sol().registry()[field];
- if(obj.is<sol::protected_function>())
+ if (obj.is<sol::protected_function>())
{
auto res = invoke(obj.as<sol::protected_function>());
- if(!res.valid())
+ if (!res.valid())
{
sol::error err = res;
osd_printf_error("[LUA ERROR] in menu_populate: %s\n", err.what());
}
else
{
- sol::table table = res;
- for(auto &entry : table)
+ std::tuple<sol::table, std::optional<long> > table = res;
+ for (auto &entry : std::get<0>(table))
{
- if(entry.second.is<sol::table>())
+ if (entry.second.is<sol::table>())
{
sol::table enttable = entry.second.as<sol::table>();
menu_list.emplace_back(enttable.get<std::string, std::string, std::string>(1, 2, 3));
}
}
+ return std::get<1>(table);
}
}
+ return std::nullopt;
}
bool lua_engine::menu_callback(const std::string &menu, int index, const std::string &event)
diff --git a/src/frontend/mame/luaengine.h b/src/frontend/mame/luaengine.h
index 973dfedfd89..5b945e864c9 100644
--- a/src/frontend/mame/luaengine.h
+++ b/src/frontend/mame/luaengine.h
@@ -16,13 +16,11 @@
#include <functional>
#include <map>
#include <memory>
+#include <optional>
#include <string>
+#include <tuple>
#include <vector>
-#if defined(__GNUC__) && (__GNUC__ > 6)
-#pragma GCC diagnostic ignored "-Wnoexcept-type"
-#endif
-
#define SOL_SAFE_USERTYPE 1
#include "sol/sol.hpp"
@@ -50,7 +48,7 @@ public:
bool frame_hook();
- void menu_populate(const std::string &menu, std::vector<std::tuple<std::string, std::string, std::string>> &menu_list);
+ std::optional<long> menu_populate(const std::string &menu, std::vector<std::tuple<std::string, std::string, std::string>> &menu_list);
bool menu_callback(const std::string &menu, int index, const std::string &event);
void set_machine(running_machine *machine);
diff --git a/src/frontend/mame/ui/inputmap.cpp b/src/frontend/mame/ui/inputmap.cpp
index 08cbab0facc..5ddf7864adf 100644
--- a/src/frontend/mame/ui/inputmap.cpp
+++ b/src/frontend/mame/ui/inputmap.cpp
@@ -481,9 +481,9 @@ void menu_input::populate_sorted(float &customtop, float &custombottom)
else
item_append(menu_item_type::SEPARATOR);
if (item.owner->owner())
- item_append(string_format(_("%1$s [root%2$s]"), item.owner->type().fullname(), item.owner->tag()), 0, nullptr);
+ item_append(string_format(_("%1$s [root%2$s]"), item.owner->type().fullname(), item.owner->tag()), FLAG_UI_HEADING | FLAG_DISABLE, nullptr);
else
- item_append(string_format(_("[root%1$s]"), item.owner->tag()), 0, nullptr);
+ item_append(string_format(_("[root%1$s]"), item.owner->tag()), FLAG_UI_HEADING | FLAG_DISABLE, nullptr);
prev_owner = item.owner;
}
diff --git a/src/frontend/mame/ui/pluginopt.cpp b/src/frontend/mame/ui/pluginopt.cpp
index d36503cdcee..e065582103b 100644
--- a/src/frontend/mame/ui/pluginopt.cpp
+++ b/src/frontend/mame/ui/pluginopt.cpp
@@ -117,7 +117,8 @@ void menu_plugin_opt::handle()
void menu_plugin_opt::populate(float &customtop, float &custombottom)
{
std::vector<std::tuple<std::string, std::string, std::string>> menu_list;
- mame_machine_manager::instance()->lua()->menu_populate(m_menu, menu_list);
+ auto const sel = mame_machine_manager::instance()->lua()->menu_populate(m_menu, menu_list);
+
uintptr_t i = 1;
for(auto &item : menu_list)
{
@@ -126,13 +127,15 @@ void menu_plugin_opt::populate(float &customtop, float &custombottom)
const std::string &tflags = std::get<2>(item);
uint32_t flags = 0;
- if(tflags == "off")
+ if (tflags == "off")
flags = FLAG_DISABLE;
- else if(tflags == "l")
+ else if (tflags == "heading")
+ flags = FLAG_DISABLE | FLAG_UI_HEADING;
+ else if (tflags == "l")
flags = FLAG_LEFT_ARROW;
- else if(tflags == "r")
+ else if (tflags == "r")
flags = FLAG_RIGHT_ARROW;
- else if(tflags == "lr")
+ else if (tflags == "lr")
flags = FLAG_RIGHT_ARROW | FLAG_LEFT_ARROW;
if(text == "---")
@@ -141,9 +144,14 @@ void menu_plugin_opt::populate(float &customtop, float &custombottom)
i++;
}
else
- item_append(text, subtext, flags, (void *)i++);
+ {
+ item_append(text, subtext, flags, reinterpret_cast<void *>(i++));
+ }
}
item_append(menu_item_type::SEPARATOR);
+
+ if (sel)
+ set_selection(reinterpret_cast<void *>(uintptr_t(*sel)));
}
menu_plugin_opt::~menu_plugin_opt()