generated from GarandPLG/rust-flake-template
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:
+20
-13
@@ -40,9 +40,7 @@ pub struct SkillsConfigState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct SettingsState {
|
pub struct GameSettingsState {
|
||||||
pub id: usize,
|
|
||||||
pub name: &'static str,
|
|
||||||
pub username: String,
|
pub username: String,
|
||||||
pub game_mode: GameMode,
|
pub game_mode: GameMode,
|
||||||
pub map_width: u8,
|
pub map_width: u8,
|
||||||
@@ -53,6 +51,13 @@ pub struct SettingsState {
|
|||||||
pub supply_limit: u8,
|
pub supply_limit: u8,
|
||||||
pub xp_modifier: f32,
|
pub xp_modifier: f32,
|
||||||
pub skill_points_limit: u16,
|
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 selected_setting: usize,
|
||||||
pub show_popup: bool,
|
pub show_popup: bool,
|
||||||
pub selected_setting_new_value: String,
|
pub selected_setting_new_value: String,
|
||||||
@@ -86,16 +91,18 @@ impl GameStates {
|
|||||||
selected_setting: 0,
|
selected_setting: 0,
|
||||||
show_popup: false,
|
show_popup: false,
|
||||||
selected_setting_new_value: String::new(),
|
selected_setting_new_value: String::new(),
|
||||||
username: args.username,
|
game_settings: GameSettingsState {
|
||||||
game_mode: args.game_mode,
|
username: args.username,
|
||||||
map_width: args.map_width,
|
game_mode: args.game_mode,
|
||||||
map_height: args.map_height,
|
map_width: args.map_width,
|
||||||
perk_deck: args.perk_deck,
|
map_height: args.map_height,
|
||||||
starting_wood: args.starting_wood,
|
perk_deck: args.perk_deck,
|
||||||
starting_iron: args.starting_iron,
|
starting_wood: args.starting_wood,
|
||||||
supply_limit: args.supply_limit,
|
starting_iron: args.starting_iron,
|
||||||
xp_modifier: args.xp_modifier,
|
supply_limit: args.supply_limit,
|
||||||
skill_points_limit: args.skill_points_limit,
|
xp_modifier: args.xp_modifier,
|
||||||
|
skill_points_limit: args.skill_points_limit,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-12
@@ -38,14 +38,7 @@ pub fn settings_view(app: &App, area: Rect, buf: &mut Buffer) {
|
|||||||
)
|
)
|
||||||
.render(main_area, buf);
|
.render(main_area, buf);
|
||||||
|
|
||||||
let popup_area: Rect = Rect {
|
if app.states.settings.show_popup {
|
||||||
x: main_area.width / 4,
|
|
||||||
y: main_area.height / 3,
|
|
||||||
width: main_area.width / 2,
|
|
||||||
height: main_area.height / 3,
|
|
||||||
};
|
|
||||||
|
|
||||||
let popup: Paragraph<'_> =
|
|
||||||
Paragraph::new(app.states.settings.selected_setting_new_value.clone())
|
Paragraph::new(app.states.settings.selected_setting_new_value.clone())
|
||||||
.wrap(Wrap { trim: true })
|
.wrap(Wrap { trim: true })
|
||||||
.style(Style::default().yellow())
|
.style(Style::default().yellow())
|
||||||
@@ -54,11 +47,23 @@ pub fn settings_view(app: &App, area: Rect, buf: &mut Buffer) {
|
|||||||
.title("Insert value")
|
.title("Insert value")
|
||||||
.title_style(Style::default().green())
|
.title_style(Style::default().green())
|
||||||
.borders(Borders::ALL)
|
.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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user