1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
// license:BSD-3-Clause
// copyright-holders:Nicola Salmoria, Aaron Giles, Nathan Woods
/*********************************************************************
ui/pluginopt.cpp
Internal menu for the plugin interface.
*********************************************************************/
#include "emu.h"
#include "pluginopt.h"
#include "ui/utils.h"
#include "luaengine.h"
#include "mame.h"
namespace ui {
void menu_plugin::handle()
{
const event *menu_event = process(0);
if (menu_event && menu_event->itemref)
{
if (menu_event->iptkey == IPT_UI_SELECT)
menu::stack_push<menu_plugin_opt>(ui(), container(), (char *)menu_event->itemref);
}
}
menu_plugin::menu_plugin(mame_ui_manager &mui, render_container &container) :
menu(mui, container),
m_plugins(mame_machine_manager::instance()->lua()->get_menu())
{
}
void menu_plugin::populate(float &customtop, float &custombottom)
{
for (auto &curplugin : m_plugins)
item_append(curplugin, 0, (void *)curplugin.c_str());
item_append(menu_item_type::SEPARATOR);
}
void menu_plugin::show_menu(mame_ui_manager &mui, render_container &container, char *menu)
{
// reset the menu stack
menu::stack_reset(mui.machine());
// add the plugin menu entry
menu::stack_push<menu_plugin_opt>(mui, container, menu);
// force the menus on
mui.show_menu();
// make sure MAME is paused
mui.machine().pause();
}
menu_plugin::~menu_plugin()
{
}
menu_plugin_opt::menu_plugin_opt(mame_ui_manager &mui, render_container &container, std::string_view menu) :
ui::menu(mui, container),
m_menu(menu),
m_process_flags(0U),
m_need_idle(false)
{
}
void menu_plugin_opt::handle()
{
event const *const menu_event = process(m_process_flags);
void *const itemref = menu_event ? menu_event->itemref : get_selection_ref();
std::string key;
if (menu_event)
{
switch (menu_event->iptkey)
{
case IPT_UI_UP:
key = "up";
break;
case IPT_UI_DOWN:
key = "down";
break;
case IPT_UI_LEFT:
key = "left";
break;
case IPT_UI_RIGHT:
key = "right";
break;
case IPT_UI_SELECT:
key = "select";
break;
case IPT_UI_DISPLAY_COMMENT:
key = "comment";
break;
case IPT_UI_CLEAR:
key = "clear";
break;
case IPT_UI_CANCEL:
key = "cancel";
break;
case IPT_SPECIAL:
key = std::to_string((u32)menu_event->unichar);
break;
default:
break;
}
}
if (!key.empty() || m_need_idle)
{
auto const result = mame_machine_manager::instance()->lua()->menu_callback(m_menu, uintptr_t(itemref), key);
if (result.second)
set_selection(reinterpret_cast<void *>(uintptr_t(*result.second)));
if (result.first)
reset(reset_options::REMEMBER_REF);
else if (menu_event && (menu_event->iptkey == IPT_UI_CANCEL))
stack_pop();
}
}
void menu_plugin_opt::populate(float &customtop, float &custombottom)
{
std::vector<std::tuple<std::string, std::string, std::string>> menu_list;
std::string flags;
auto const sel = mame_machine_manager::instance()->lua()->menu_populate(m_menu, menu_list, flags);
uintptr_t i = 1;
for (auto &item : menu_list)
{
std::string &text = std::get<0>(item);
std::string &subtext = std::get<1>(item);
std::string_view tflags = std::get<2>(item);
uint32_t item_flags_or = uint32_t(0);
uint32_t item_flags_and = ~uint32_t(0);
auto flag_start = tflags.find_first_not_of(' ');
while (std::string_view::npos != flag_start)
{
tflags.remove_prefix(flag_start);
auto const flag_end = tflags.find(' ');
auto const flag = tflags.substr(0, flag_end);
tflags.remove_prefix(flag.length());
flag_start = tflags.find_first_not_of(' ');
if (flag == "off")
item_flags_or |= FLAG_DISABLE;
else if (flag == "on")
item_flags_and &= ~FLAG_DISABLE;
else if (flag == "l")
item_flags_or |= FLAG_LEFT_ARROW;
else if (flag == "r")
item_flags_or |= FLAG_RIGHT_ARROW;
else if (flag == "lr")
item_flags_or |= FLAG_RIGHT_ARROW | FLAG_LEFT_ARROW;
else if (flag == "invert")
item_flags_or |= FLAG_INVERT;
else if (flag == "heading")
item_flags_or |= FLAG_DISABLE | FLAG_UI_HEADING;
}
if (text == "---")
item_append(menu_item_type::SEPARATOR);
else
item_append(std::move(text), std::move(subtext), item_flags_or & item_flags_and, reinterpret_cast<void *>(i));
++i;
}
item_append(menu_item_type::SEPARATOR);
if (sel)
set_selection(reinterpret_cast<void *>(uintptr_t(*sel)));
m_process_flags = 0U;
m_need_idle = false;
if (!flags.empty())
{
std::string_view mflags = flags;
auto flag_start = mflags.find_first_not_of(' ');
while (std::string_view::npos != flag_start)
{
mflags.remove_prefix(flag_start);
auto const flag_end = mflags.find(' ');
auto const flag = mflags.substr(0, flag_end);
mflags.remove_prefix(flag.length());
flag_start = mflags.find_first_not_of(' ');
if (flag == "lralways")
m_process_flags |= PROCESS_LR_ALWAYS;
else if (flag == "lrrepeat")
m_process_flags |= PROCESS_LR_REPEAT;
else if (flag == "customnav")
m_process_flags |= PROCESS_CUSTOM_NAV;
else if (flag == "idle")
m_need_idle = true;
}
}
}
menu_plugin_opt::~menu_plugin_opt()
{
}
} // namespace ui
|