Refactor "AppearingText" updating/drawing
This commit is contained in:
parent
f0e3dd5de0
commit
47768972c9
1 changed files with 13 additions and 12 deletions
25
src/main.rs
25
src/main.rs
|
@ -63,7 +63,7 @@ enum MenuItemType {
|
||||||
},
|
},
|
||||||
AppearingText {
|
AppearingText {
|
||||||
text: &'static str,
|
text: &'static str,
|
||||||
current_text: String,
|
text_idx: usize,
|
||||||
text_size: f32,
|
text_size: f32,
|
||||||
text_c: Color,
|
text_c: Color,
|
||||||
timer: f32,
|
timer: f32,
|
||||||
|
@ -207,9 +207,9 @@ impl Menu {
|
||||||
item_type: MenuItemType::AppearingText {
|
item_type: MenuItemType::AppearingText {
|
||||||
text: s,
|
text: s,
|
||||||
text_size,
|
text_size,
|
||||||
current_text: String::new(),
|
|
||||||
text_c: Color::WHITE,
|
text_c: Color::WHITE,
|
||||||
timer: 0.0,
|
timer: 0.0,
|
||||||
|
text_idx: 0,
|
||||||
},
|
},
|
||||||
is_hover: false,
|
is_hover: false,
|
||||||
is_focus: false,
|
is_focus: false,
|
||||||
|
@ -1497,12 +1497,12 @@ impl GameState {
|
||||||
match &mut mi.item_type {
|
match &mut mi.item_type {
|
||||||
MenuItemType::AppearingText {
|
MenuItemType::AppearingText {
|
||||||
text,
|
text,
|
||||||
current_text,
|
text_idx,
|
||||||
text_size,
|
text_size,
|
||||||
text_c,
|
text_c,
|
||||||
timer,
|
timer,
|
||||||
} => {
|
} => {
|
||||||
*current_text = text.to_string();
|
*text_idx = text.len();
|
||||||
}
|
}
|
||||||
MenuItemType::Button {
|
MenuItemType::Button {
|
||||||
text,
|
text,
|
||||||
|
@ -1745,7 +1745,7 @@ impl GameState {
|
||||||
}
|
}
|
||||||
MenuItemType::AppearingText {
|
MenuItemType::AppearingText {
|
||||||
text,
|
text,
|
||||||
current_text,
|
text_idx,
|
||||||
text_size,
|
text_size,
|
||||||
text_c,
|
text_c,
|
||||||
timer,
|
timer,
|
||||||
|
@ -1753,11 +1753,8 @@ impl GameState {
|
||||||
*timer += dt;
|
*timer += dt;
|
||||||
if *timer > TEXT_RATE {
|
if *timer > TEXT_RATE {
|
||||||
*timer -= TEXT_RATE;
|
*timer -= TEXT_RATE;
|
||||||
let next = text.chars().nth(current_text.len());
|
*text_idx += 1;
|
||||||
if let Some(next_t) = next {
|
if *text_idx >= text.len() {
|
||||||
current_text.push(next_t);
|
|
||||||
window.get_sound_mut(&self.s_tap)?.play(0.2)?;
|
|
||||||
} else {
|
|
||||||
mi.is_loaded = true;
|
mi.is_loaded = true;
|
||||||
if i + 1 < self.menu.items.len() {
|
if i + 1 < self.menu.items.len() {
|
||||||
self.menu.items[i + 1].is_loaded = false;
|
self.menu.items[i + 1].is_loaded = false;
|
||||||
|
@ -1893,13 +1890,17 @@ impl GameState {
|
||||||
}
|
}
|
||||||
MenuItemType::AppearingText {
|
MenuItemType::AppearingText {
|
||||||
text,
|
text,
|
||||||
current_text,
|
text_idx,
|
||||||
text_size,
|
text_size,
|
||||||
text_c,
|
text_c,
|
||||||
timer,
|
timer,
|
||||||
} => {
|
} => {
|
||||||
window.get_font_mut(&self.font)?.draw(
|
window.get_font_mut(&self.font)?.draw(
|
||||||
current_text,
|
if *text_idx < text.len() {
|
||||||
|
&text[0..*text_idx]
|
||||||
|
} else {
|
||||||
|
text
|
||||||
|
},
|
||||||
text_size.round() as u32,
|
text_size.round() as u32,
|
||||||
rect.x,
|
rect.x,
|
||||||
rect.y,
|
rect.y,
|
||||||
|
|
Loading…
Reference in a new issue