Skip to content
Merged
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
58 changes: 32 additions & 26 deletions features/gui/autofill.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ local Color = require 'resources.color_presets'
local enabled_style = 'working_weapon_button'
local disabled_style = 'not_working_weapon_button'

local style_map = {[true] = enabled_style, [false] = disabled_style}
local enabled_locale_map = {[true] = {'common.enabled'}, [false] = {'common.disabled'}}
local style_map = { [true] = enabled_style, [false] = disabled_style }
local enabled_locale_map = { [true] = { 'common.enabled' }, [false] = { 'common.disabled' } }

local main_button_name = Gui.uid_name()
local main_frame_name = Gui.uid_name()
Expand All @@ -26,15 +26,15 @@ local function player_created(event)
type = 'sprite-button',
name = main_button_name,
sprite = 'item/piercing-rounds-magazine',
tooltip = {'autofill.main_button_tooltip'},
tooltip = { 'autofill.main_button_tooltip' },
auto_toggle = true,
})
end

local function update_ammo_button(button, name, enabled)
local locale_name = Autofill.ammo_locales[name]
local style = style_map[enabled]
local tooltip = {'', locale_name, ' ', enabled_locale_map[enabled]}
local tooltip = { '', locale_name, ' ', enabled_locale_map[enabled] }

button.style = style
button.tooltip = tooltip
Expand All @@ -50,37 +50,43 @@ local function toggle_main_frame(event)
local main_button = Gui.get_top_element(player, main_button_name)
main_button.toggled = false
else
frame = Gui.add_left_element(player, { type = 'frame', name = main_frame_name, caption = {'autofill.frame_name'}, direction = 'vertical' })
frame = Gui.add_left_element(player, { type = 'frame', name = main_frame_name, caption = { 'autofill.frame_name' }, direction = 'vertical' })
Gui.set_style(frame, { width = 376 })

local enabled_checkbox =
frame.add {
local inner = frame.add { type = 'frame', style = 'inside_shallow_frame', direction = 'vertical' }
Gui.set_style(inner, { padding = 8 })

local enabled_checkbox = inner.add {
type = 'checkbox',
name = enabled_checkbox_name,
caption = {'autofill.enable'},
state = Autofill.get_enabled(player_index)
caption = { 'autofill.enable' },
state = Autofill.get_enabled(player_index),
}

local ammo_count_flow = frame.add {type = 'flow', direction = 'horizontal'}
local ammo_count_label = ammo_count_flow.add {type = 'label', caption = {'autofill.ammo_count'}}
local ammo_count_textfield =
ammo_count_flow.add {
local ammo_count_flow = inner.add { type = 'flow', direction = 'horizontal' }
local ammo_count_label = ammo_count_flow.add { type = 'label', caption = { 'autofill.ammo_count' } }
Gui.set_style(ammo_count_label, { minimal_width = 140 })
local ammo_count_textfield = ammo_count_flow.add {
type = 'textfield',
name = ammo_count_name,
text = tostring(Autofill.get_ammo_count(player_index))
text = tostring(Autofill.get_ammo_count(player_index)),
numeric = true,
allow_decimal = false,
allow_negative = false,
Comment on lines +73 to +75
Copy link
Contributor Author

@RedRafe RedRafe Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added native input sanitization for ammo count (the parsing logis was kept still, but this should give the user even more feedbacks as letters/commas cannot be used at all).
I havent checked if RedMew settings could use more of those but I havent heavily refactored that module (yet, dunno if it is needed) so maybe I'll come back to it in the future.
Next will be poll/player_list

}

local enabled_ammos_flow = frame.add {type = 'flow', direction = 'horizontal'}
enabled_ammos_flow.add {type = 'label', caption = {'autofill.enabled_ammos'}}
local enabled_ammos_flow = inner.add { type = 'flow', direction = 'horizontal' }
local enabled_ammos_label = enabled_ammos_flow.add { type = 'label', caption = { 'autofill.enabled_ammos' } }
Gui.set_style(enabled_ammos_label, { minimal_width = 140 })

local grid = enabled_ammos_flow.add { type = 'scroll-pane', style = 'deep_slots_scroll_pane' }.add { type = 'table', column_count = 5, style = 'filter_slot_table' }

for name, enabled in pairs(Autofill.get_player_ammos(player_index)) do
local button =
enabled_ammos_flow.add({type = 'flow'}).add(
{
type = 'sprite-button',
name = enabled_ammo_button,
sprite = 'item/' .. name
}
)
local button = grid.add({ type = 'flow' }).add({
type = 'sprite-button',
name = enabled_ammo_button,
sprite = 'item/' .. name,
})
update_ammo_button(button, name, enabled)

Gui.set_data(button, name)
Expand All @@ -91,7 +97,7 @@ local function toggle_main_frame(event)
local data = {
enabled_checkbox = enabled_checkbox,
ammo_count_label = ammo_count_label,
ammo_count_textfield = ammo_count_textfield
ammo_count_textfield = ammo_count_textfield,
}

Gui.set_data(frame, data)
Expand All @@ -112,7 +118,7 @@ local function set_ammo_count_elements_validation(textfield, label, valid)
else
color = Color.red
label_color = Color.red
tooltip = {'autofill.invalid_ammo_count'}
tooltip = { 'autofill.invalid_ammo_count' }
end

textfield.style.font_color = color
Expand Down
Loading