Merge pull request #602 from vasilvv/master

Allow load/save state slots to be bound to joystick buttons
This commit is contained in:
Vas Crabb 2016-02-04 02:07:41 +11:00
commit cfb1b36152
4 changed files with 59 additions and 4 deletions

View File

@ -37,6 +37,8 @@ enum
LOADSAVE_SAVE
};
#define MAX_SAVED_STATE_JOYSTICK 4
/***************************************************************************
LOCAL VARIABLES
@ -242,6 +244,7 @@ ui_manager::ui_manager(running_machine &machine)
m_popup_text_end = 0;
m_use_natural_keyboard = false;
m_mouse_arrow_texture = nullptr;
m_load_save_hold = false;
// more initialization
set_handler(handler_messagebox, 0);
@ -1625,6 +1628,7 @@ UINT32 ui_manager::handler_ingame(running_machine &machine, render_container *co
if (machine.ui_input().pressed(IPT_UI_SAVE_STATE))
{
machine.pause();
machine.ui().m_load_save_hold = true;
return machine.ui().set_handler(handler_load_save, LOADSAVE_SAVE);
}
@ -1632,6 +1636,7 @@ UINT32 ui_manager::handler_ingame(running_machine &machine, render_container *co
if (machine.ui_input().pressed(IPT_UI_LOAD_STATE))
{
machine.pause();
machine.ui().m_load_save_hold = true;
return machine.ui().set_handler(handler_load_save, LOADSAVE_LOAD);
}
@ -1713,6 +1718,23 @@ UINT32 ui_manager::handler_load_save(running_machine &machine, render_container
else
machine.ui().draw_message_window(container, "Select position to load from");
// if load/save state sequence is still being pressed, do not read the filename yet
if (machine.ui().m_load_save_hold) {
bool seq_in_progress = false;
const input_seq &load_save_seq = state == LOADSAVE_SAVE ?
machine.ioport().type_seq(IPT_UI_SAVE_STATE) :
machine.ioport().type_seq(IPT_UI_LOAD_STATE);
for (int i = 0; i < load_save_seq.length(); i++)
if (machine.input().code_pressed_once(load_save_seq[i]))
seq_in_progress = true;
if (seq_in_progress)
return state;
else
machine.ui().m_load_save_hold = false;
}
// check for cancel key
if (machine.ui_input().pressed(IPT_UI_CANCEL))
{
@ -1740,21 +1762,41 @@ UINT32 ui_manager::handler_load_save(running_machine &machine, render_container
if (machine.input().code_pressed_once(input_code(DEVICE_CLASS_KEYBOARD, 0, ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, id)))
file = id - ITEM_ID_0_PAD + '0';
if (file == 0)
return state;
{
bool found = false;
for (int joy_index = 0; joy_index <= MAX_SAVED_STATE_JOYSTICK; joy_index++)
for (input_item_id id = ITEM_ID_BUTTON1; id <= ITEM_ID_BUTTON32; ++id)
if (machine.input().code_pressed_once(input_code(DEVICE_CLASS_JOYSTICK, joy_index, ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, id)))
{
snprintf(filename, sizeof(filename), "joy%i-%i", joy_index, id - ITEM_ID_BUTTON1 + 1);
found = true;
break;
}
if (!found)
return state;
}
else
{
sprintf(filename, "%c", file);
}
// display a popup indicating that the save will proceed
sprintf(filename, "%c", file);
if (state == LOADSAVE_SAVE)
{
machine.popmessage("Save to position %c", file);
machine.popmessage("Save to position %s", filename);
machine.schedule_save(filename);
}
else
{
machine.popmessage("Load from position %c", file);
machine.popmessage("Load from position %s", filename);
machine.schedule_load(filename);
}
// avoid handling the name of the save state slot as a seperate input
machine.ui_input().mark_all_as_pressed();
// remove the pause and reset the state
machine.resume();
return UI_HANDLER_CANCEL;

View File

@ -182,6 +182,7 @@ private:
std::unique_ptr<UINT8[]> m_non_char_keys_down;
render_texture * m_mouse_arrow_texture;
bool m_mouse_show;
bool m_load_save_hold;
// text generators
std::string &disclaimer_string(std::string &buffer);

View File

@ -324,3 +324,13 @@ void ui_input_manager::push_char_event(render_target* target, unicode_char ch)
event.ch = ch;
push_event(event);
}
/*-------------------------------------------------
mark_all_as_pressed - marks all buttons
as if they were already pressed once
-------------------------------------------------*/
void ui_input_manager::mark_all_as_pressed()
{
for (int code = IPT_UI_FIRST + 1; code < IPT_UI_LAST; code++)
m_next_repeat[code] = osd_ticks();
}

View File

@ -86,6 +86,8 @@ public:
void push_mouse_double_click_event(render_target* target, INT32 x, INT32 y);
void push_char_event(render_target* target, unicode_char ch);
void mark_all_as_pressed();
private:
// internal state