cheatopt: add the global cheat enable toggle to the menu

This commit is contained in:
hap 2024-02-11 17:07:20 +01:00
parent ddb2a9fb22
commit e4fb63b492
9 changed files with 40 additions and 22 deletions

View File

@ -1098,7 +1098,7 @@ cheat_manager::cheat_manager(running_machine &machine)
// cheat engine
//-------------------------------------------------
void cheat_manager::set_enable(bool enable)
void cheat_manager::set_enable(bool enable, bool show)
{
// if the cheat engine is disabled, we're done
if (!machine().options().cheat())
@ -1114,7 +1114,8 @@ void cheat_manager::set_enable(bool enable)
if (cheat->state() == SCRIPT_STATE_RUN)
cheat->execute_off_script();
}
machine().popmessage("Cheats Disabled");
if (show)
machine().popmessage("Cheats Disabled");
m_disabled = true;
}
else if (m_disabled && enable)
@ -1128,7 +1129,8 @@ void cheat_manager::set_enable(bool enable)
if (cheat->state() == SCRIPT_STATE_RUN)
cheat->execute_on_script();
}
machine().popmessage("Cheats Enabled");
if (show)
machine().popmessage("Cheats Enabled");
}
}

View File

@ -314,7 +314,7 @@ public:
std::vector<std::unique_ptr<cheat_entry>> const &entries() const { return m_cheatlist; }
// setters
void set_enable(bool enable);
void set_enable(bool enable, bool show);
// actions
void reload();

View File

@ -20,9 +20,10 @@
namespace ui {
// itemrefs for key menu items
#define ITEMREF_CHEATS_RESET_ALL ((void *) 0x0001)
#define ITEMREF_CHEATS_RELOAD_ALL ((void *) 0x0002)
#define ITEMREF_CHEATS_FIRST_ITEM ((void *) 0x0003)
#define ITEMREF_CHEATS_ENABLE ((void *) 0x0001)
#define ITEMREF_CHEATS_RESET_ALL ((void *) 0x0002)
#define ITEMREF_CHEATS_RELOAD_ALL ((void *) 0x0003)
#define ITEMREF_CHEATS_FIRST_ITEM ((void *) 0x0004)
/*-------------------------------------------------
@ -39,6 +40,15 @@ bool menu_cheat::handle(event const *ev)
// clear cheat comment on any movement or keypress
machine().popmessage();
if (ev->itemref == ITEMREF_CHEATS_ENABLE)
{
if ((ev->iptkey == IPT_UI_LEFT) || (ev->iptkey == IPT_UI_RIGHT) || (ev->iptkey == IPT_UI_CLEAR))
{
// handle global enable toggle
mame_machine_manager::instance()->cheat().set_enable(ev->iptkey == IPT_UI_RIGHT || (ev->iptkey == IPT_UI_CLEAR), false);
changed = true;
}
}
if ((ev->itemref == ITEMREF_CHEATS_RESET_ALL || ev->itemref == ITEMREF_CHEATS_RELOAD_ALL) && ev->iptkey == IPT_UI_SELECT)
{
// handle reset all + reset all cheats for reload all option
@ -109,17 +119,28 @@ bool menu_cheat::handle(event const *ev)
menu_cheat::menu_cheat(mame_ui_manager &mui, render_container &container) : menu(mui, container)
{
set_heading(_("Cheat Options"));
set_process_flags(PROCESS_LR_REPEAT);
}
void menu_cheat::menu_activated()
{
reset(reset_options::REMEMBER_REF);
}
void menu_cheat::populate()
{
/* iterate over cheats */
// iterate over cheats
std::string text;
std::string subtext;
// add cheats
if (!mame_machine_manager::instance()->cheat().entries().empty()) {
if (!mame_machine_manager::instance()->cheat().entries().empty())
{
// add global enable toggle
item_append_on_off(_("Cheat Engine"), mame_machine_manager::instance()->cheat().enabled(), 0, (void *)ITEMREF_CHEATS_ENABLE);
item_append(menu_item_type::SEPARATOR);
for (auto &curcheat : mame_machine_manager::instance()->cheat().entries())
{
uint32_t flags;
@ -130,15 +151,14 @@ void menu_cheat::populate()
item_append(text, subtext, flags, curcheat.get());
}
/* add a separator */
item_append(menu_item_type::SEPARATOR);
/* add a reset all option */
// add a reset all option
item_append(_("Reset All"), 0, (void *)ITEMREF_CHEATS_RESET_ALL);
/* add a reload all cheats option */
item_append(_("Reload All"), 0, (void *)ITEMREF_CHEATS_RELOAD_ALL);
}
// add a reload all cheats option
item_append(_("Reload All"), 0, (void *)ITEMREF_CHEATS_RELOAD_ALL);
}
menu_cheat::~menu_cheat()

View File

@ -25,6 +25,7 @@ public:
private:
virtual void populate() override;
virtual void menu_activated() override;
virtual bool handle(event const *ev) override;
};

View File

@ -166,7 +166,7 @@ void menu_main::populate()
item_append(_("menu-main", "Crosshair Options"), 0, (void *)CROSSHAIR);
if (machine().options().cheat())
item_append(_("menu-main", "Cheat"), 0, (void *)CHEAT);
item_append(_("menu-main", "Cheat Options"), 0, (void *)CHEAT);
if (machine_phase::RESET <= m_phase)
{

View File

@ -1178,10 +1178,6 @@ void menu::handle_keys(uint32_t flags, int &iptkey)
machine().pause();
}
// handle a toggle cheats request
if (machine().ui_input().pressed_repeat(IPT_UI_TOGGLE_CHEAT, 0))
mame_machine_manager::instance()->cheat().set_enable(!mame_machine_manager::instance()->cheat().enabled());
// see if any other UI keys are pressed
if (iptkey == IPT_INVALID)
{

View File

@ -1659,7 +1659,7 @@ void menu_select_launch::handle_keys(u32 flags, int &iptkey)
// handle a toggle cheats request
if (!m_ui_error && machine().ui_input().pressed_repeat(IPT_UI_TOGGLE_CHEAT, 0))
mame_machine_manager::instance()->cheat().set_enable(!mame_machine_manager::instance()->cheat().enabled());
mame_machine_manager::instance()->cheat().set_enable(!mame_machine_manager::instance()->cheat().enabled(), true);
// handle pasting text into the search
if (exclusive_input_pressed(iptkey, IPT_UI_PASTE, 0))

View File

@ -65,7 +65,6 @@ void menu_sound_options::menu_dismissed()
if (moptions.bool_value(OPTION_SAMPLES) != m_samples)
moptions.set_value(OPTION_SAMPLES, m_samples, OPTION_PRIORITY_CMDLINE);
}
//-------------------------------------------------

View File

@ -1378,7 +1378,7 @@ uint32_t mame_ui_manager::handler_ingame(render_container &container)
// handle a toggle cheats request
if (machine().ui_input().pressed(IPT_UI_TOGGLE_CHEAT))
mame_machine_manager::instance()->cheat().set_enable(!mame_machine_manager::instance()->cheat().enabled());
mame_machine_manager::instance()->cheat().set_enable(!mame_machine_manager::instance()->cheat().enabled(), true);
// toggle MNG recording
if (machine().ui_input().pressed(IPT_UI_RECORD_MNG))