Extract GameSettingsState and tweak popup layout

The settings model now separates generic settings from game‑specific
fields by
introducing `GameSettingsState`. All game‑related fields are moved into
this
struct and `SettingsState` now holds a `game_settings` field.
Initialization in
`GameStates::new` is updated accordingly. The UI popup is rendered
directly
with added padding and a resized rectangle, and the unused `popup_area`
variable is removed.
This commit is contained in:
2026-03-16 10:42:58 +01:00
parent fd0f6defea
commit aacdacadd5
2 changed files with 37 additions and 25 deletions
+20 -13
View File
@@ -40,9 +40,7 @@ pub struct SkillsConfigState {
}
#[derive(Debug, Clone, PartialEq)]
pub struct SettingsState {
pub id: usize,
pub name: &'static str,
pub struct GameSettingsState {
pub username: String,
pub game_mode: GameMode,
pub map_width: u8,
@@ -53,6 +51,13 @@ pub struct SettingsState {
pub supply_limit: u8,
pub xp_modifier: f32,
pub skill_points_limit: u16,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SettingsState {
pub id: usize,
pub name: &'static str,
pub game_settings: GameSettingsState,
pub selected_setting: usize,
pub show_popup: bool,
pub selected_setting_new_value: String,
@@ -86,16 +91,18 @@ impl GameStates {
selected_setting: 0,
show_popup: false,
selected_setting_new_value: String::new(),
username: args.username,
game_mode: args.game_mode,
map_width: args.map_width,
map_height: args.map_height,
perk_deck: args.perk_deck,
starting_wood: args.starting_wood,
starting_iron: args.starting_iron,
supply_limit: args.supply_limit,
xp_modifier: args.xp_modifier,
skill_points_limit: args.skill_points_limit,
game_settings: GameSettingsState {
username: args.username,
game_mode: args.game_mode,
map_width: args.map_width,
map_height: args.map_height,
perk_deck: args.perk_deck,
starting_wood: args.starting_wood,
starting_iron: args.starting_iron,
supply_limit: args.supply_limit,
xp_modifier: args.xp_modifier,
skill_points_limit: args.skill_points_limit,
},
},
}
}
+17 -12
View File
@@ -38,14 +38,7 @@ pub fn settings_view(app: &App, area: Rect, buf: &mut Buffer) {
)
.render(main_area, buf);
let popup_area: Rect = Rect {
x: main_area.width / 4,
y: main_area.height / 3,
width: main_area.width / 2,
height: main_area.height / 3,
};
let popup: Paragraph<'_> =
if app.states.settings.show_popup {
Paragraph::new(app.states.settings.selected_setting_new_value.clone())
.wrap(Wrap { trim: true })
.style(Style::default().yellow())
@@ -54,11 +47,23 @@ pub fn settings_view(app: &App, area: Rect, buf: &mut Buffer) {
.title("Insert value")
.title_style(Style::default().green())
.borders(Borders::ALL)
.border_style(Style::default().blue()),
.border_style(Style::default().blue())
.padding(Padding {
left: 1,
right: 1,
top: 1,
bottom: 1,
}),
)
.render(
Rect {
x: main_area.width / 3,
y: main_area.height / 2,
width: main_area.width / 3,
height: main_area.height / 7,
},
buf,
);
if app.states.settings.show_popup {
popup.render(popup_area, buf);
}
}