Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion docs/source/plugins/autofire.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ may need higher numbers than 1 for the system to recognise the button being
released and pressed again (e.g. 2 on frames and 2 off frames works for Alcon).
Experiment with different values to get the best effect.

Select **Toggle hotkey** to set a control to enable/disable autofire on the
button. This is optional, and may be skipped if not needed. Press the UI Clear
key or select the **Unset toggle hotkey** menu item (which appears when the
toggle hotkey is set) to remove the hotkey. When the toggle hotkey is set,
pressing it turns off autofire on the button, making it behave like a
non-autofire button (holding the hotkey keeps the button pressed). Pressing the
toggle hotkey again turns autofire back on. This is useful if you want to
switch between autofire and non-autofire behavior without having separate
buttons for the two.

When adding a new autofire button, there is a **Cancel** option that changes to
**Create** after you set the input and hotkey. Select **Create** to finish
creating the autofire button and return to the list of autofire buttons. The
Expand Down Expand Up @@ -112,4 +122,5 @@ levels will only produce a single beam, greatly reducing the weapon’s
effectiveness. The fire button must be held down to produce all beams. Some
shooting games (e.g. Raiden Fighters) require the primary fire button to be held
down for a charged special attack. This means it’s often necessary to have a
non-autofire input for the primary fire button assigned to play effectively.
non-autofire input for the primary fire button assigned to play effectively, or
a toggle hotkey assigned to switch between autofire and non-autofire.
49 changes: 48 additions & 1 deletion plugins/autofire/autofire_menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ local configure_selection_save
-- Helper for polling for hotkeys
local hotkey_poller

-- Helper for polling for toggle hotkeys
local toggle_hotkey_poller

-- Button being created/edited
local current_button = {}

Expand All @@ -57,7 +60,8 @@ local function create_new_button()
return {
on_frames = 1,
off_frames = 1,
counter = 0
counter = 0,
enabled = true
}
end

Expand Down Expand Up @@ -153,13 +157,18 @@ local function populate_configure_menu(menu)
button_name = _p('plugin-autofire', '[not set]')
end
local key_name = current_button.key and manager.machine.input:seq_name(current_button.key) or _p('plugin-autofire', '[not set]')
local toggle_key_name = current_button.toggle_key and manager.machine.input:seq_name(current_button.toggle_key) or _p('plugin-autofire', '[not set]')
table.insert(menu, {_p('plugin-autofire', 'Input'), button_name, ''})
if not (configure_menu_active or configure_selection_save) then
configure_selection_save = #menu
end
table.insert(menu, {_p('plugin-autofire', 'Hotkey'), key_name, hotkey_poller and 'lr' or ''})
table.insert(menu, {_p('plugin-autofire', 'On frames'), tostring(current_button.on_frames), current_button.on_frames > 1 and 'lr' or 'r'})
table.insert(menu, {_p('plugin-autofire', 'Off frames'), tostring(current_button.off_frames), current_button.off_frames > 1 and 'lr' or 'r'})
table.insert(menu, {_p('plugin-autofire', 'Toggle hotkey'), toggle_key_name, toggle_hotkey_poller and 'lr' or ''})
if current_button.toggle_key then
table.insert(menu, {_p('plugin-autofire', 'Unset toggle hotkey'), '', ''})
end
configure_menu_active = true
end

Expand All @@ -177,6 +186,19 @@ local function handle_configure_menu(index, event)
return false
end

if toggle_hotkey_poller then
-- special handling for polling for toggle hotkey
if toggle_hotkey_poller:poll() then
if toggle_hotkey_poller.sequence then
current_button.toggle_key = toggle_hotkey_poller.sequence
current_button.toggle_key_cfg = manager.machine.input:seq_to_tokens(toggle_hotkey_poller.sequence)
end
toggle_hotkey_poller = nil
return true
end
return false
end

if index == 1 then
-- Input
if event == 'select' then
Expand Down Expand Up @@ -222,6 +244,27 @@ local function handle_configure_menu(index, event)
current_button.off_frames = 1
return true
end
elseif index == 5 then
-- Toggle hotkey
manager.machine:popmessage(_p('plugin-autofire', 'Hotkey to enable/disable autofire for this button'))
if event == 'select' then
if not commonui then
commonui = require('commonui')
end
toggle_hotkey_poller = commonui.switch_polling_helper()
return true
elseif event == 'clear' then
current_button.toggle_key = nil
current_button.toggle_key_cfg = nil
return true
end
elseif index == 6 then
-- Unset toggle hotkey
if event == 'select' then
current_button.toggle_key = nil
current_button.toggle_key_cfg = nil
return true
end
end
return false
end
Expand All @@ -245,6 +288,8 @@ local function populate_edit_menu()
configure_selection_save = nil
if hotkey_poller then
return hotkey_poller:overlay(menu, selection, 'lrrepeat')
elseif toggle_hotkey_poller then
return toggle_hotkey_poller:overlay(menu, selection, 'lrrepeat')
else
return menu, selection, 'lrrepeat'
end
Expand Down Expand Up @@ -292,6 +337,8 @@ local function populate_add_menu()
configure_selection_save = nil
if hotkey_poller then
return hotkey_poller:overlay(menu, selection, 'lrrepeat')
elseif toggle_hotkey_poller then
return toggle_hotkey_poller:overlay(menu, selection, 'lrrepeat')
else
return menu, selection, 'lrrepeat'
end
Expand Down
8 changes: 6 additions & 2 deletions plugins/autofire/autofire_save.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ local function initialize_button(settings)
key_cfg = settings.key,
on_frames = settings.on_frames,
off_frames = settings.off_frames,
counter = 0
counter = 0,
enabled = true,
toggle_key = settings.toggle_key and manager.machine.input:seq_from_tokens(settings.toggle_key),
toggle_key_cfg = settings.toggle_key
}
local port = ioport.ports[settings.port]
if port then
Expand All @@ -42,7 +45,8 @@ local function serialize_settings(button_list)
type = manager.machine.ioport:input_type_to_token(button.type),
key = button.key_cfg,
on_frames = button.on_frames,
off_frames = button.off_frames
off_frames = button.off_frames,
toggle_key = button.toggle_key_cfg
}
table.insert(settings, setting)
end
Expand Down
23 changes: 19 additions & 4 deletions plugins/autofire/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- copyright-holders:Jack Li
local exports = {
name = 'autofire',
version = '0.0.4',
version = '0.0.5',
description = 'Autofire plugin',
license = 'BSD-3-Clause',
author = { name = 'Jack Li' } }
Expand All @@ -23,6 +23,10 @@ function autofire.startplugin()
-- 'off_frames' - number of frames button is released
-- 'button' - reference to ioport_field
-- 'counter' - position in autofire cycle
-- 'enabled' - autofire enabled/disabled
-- 'toggle_key' - input_seq of the toggle keybinding
-- 'toggle_key_cfg' - configuration string for the toggle keybinding
-- 'toggle_key_pressed' - whether the toggle key is currently being pressed
local buttons = {}

local input_manager
Expand All @@ -31,10 +35,21 @@ function autofire.startplugin()
local function process_frame()
local function process_button(button)
local pressed = input_manager:seq_pressed(button.key)
local new_toggle_pressed = button.toggle_key and input_manager:seq_pressed(button.toggle_key)
local toggled = new_toggle_pressed and not button.toggle_key_pressed and not manager.ui.menu_active
button.toggle_key_pressed = new_toggle_pressed
if toggled then
button.enabled = not button.enabled
button.counter = 0
end
if pressed then
local state = button.counter < button.on_frames and 1 or 0
button.counter = (button.counter + 1) % (button.on_frames + button.off_frames)
return state
if button.enabled then
local state = button.counter < button.on_frames and 1 or 0
button.counter = (button.counter + 1) % (button.on_frames + button.off_frames)
return state
else -- Behave like a normal button when autofire is disabled
return 1
end
else
button.counter = 0
return 0
Expand Down
2 changes: 1 addition & 1 deletion plugins/autofire/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"plugin": {
"name": "autofire",
"description": "Autofire plugin",
"version": "0.0.4",
"version": "0.0.5",
"author": "Jack Li",
"type": "plugin",
"start": "false"
Expand Down