summaryrefslogtreecommitdiffstatshomepage
path: root/src/frontend/mame/ui/pluginopt.cpp
blob: d6037af438bbbb145382ee168fa4f06bcbd8480d (plain) (blame)
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
// 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 "ui/pluginopt.h"

#include "mame.h"
#include "luaengine.h"


namespace ui {
void menu_plugin::handle()
{
	const event *menu_event = process(0);

	if (menu_event != nullptr && menu_event->itemref != nullptr)
	{
		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()
{
	for (auto &curplugin : m_plugins)
		item_append(curplugin, "", 0, (void *)curplugin.c_str());
	item_append(menu_item_type::SEPARATOR);
}

menu_plugin::~menu_plugin()
{
}

menu_plugin_opt::menu_plugin_opt(mame_ui_manager &mui, render_container &container, char *menu) :
		ui::menu(mui, container),
		m_menu(menu)
{
}

void menu_plugin_opt::handle()
{
	const event *menu_event = process(0);

	if (menu_event != nullptr && (FPTR)menu_event->itemref)
	{
		std::string key;
		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;
			default:
				return;
		}
		if(mame_machine_manager::instance()->lua()->menu_callback(m_menu, (FPTR)menu_event->itemref, key))
			reset(reset_options::REMEMBER_REF);
	}
}

void menu_plugin_opt::populate()
{
	std::vector<lua_engine::menu_item> menu_list;
	mame_machine_manager::instance()->lua()->menu_populate(m_menu, menu_list);
	FPTR i = 1;
	for(auto &item : menu_list)
	{
		UINT32 flags = 0;
		if(item.flags == "off")
			flags = FLAG_DISABLE;
		else if(item.flags == "l")
			flags = FLAG_LEFT_ARROW;
		else if(item.flags == "r")
			flags = FLAG_RIGHT_ARROW;
		else if(item.flags == "lr")
			flags = FLAG_RIGHT_ARROW | FLAG_LEFT_ARROW;

		if(item.text == "---")
		{
			item_append(menu_item_type::SEPARATOR);
			i++;
		}
		else
			item_append(item.text, item.subtext, flags, (void *)i++);
	}
	item_append(menu_item_type::SEPARATOR);
}

menu_plugin_opt::~menu_plugin_opt()
{
}

} // namespace ui