Work on porting from quicksilver

Can compile at this point, but does not run.
This commit is contained in:
Stephen Seo 2023-02-16 17:53:03 +09:00
parent f14841e27e
commit 751ce637e0
3 changed files with 332 additions and 385 deletions

View file

@ -27,7 +27,7 @@ pub trait ImageInterface {
} }
pub trait FontInterface { pub trait FontInterface {
fn draw(&mut self, s: &str, size: u32) -> Result<(), String>; fn draw(&mut self, s: &str, size: u32, x: f32, y: f32, color: Color) -> Result<(), String>;
} }
pub trait SoundInterface { pub trait SoundInterface {
@ -52,6 +52,9 @@ pub trait GameInterface {
fn get_dimensions(&self) -> Result<(f32, f32), String>; fn get_dimensions(&self) -> Result<(f32, f32), String>;
fn get_key_pressed(&mut self, key: char) -> Result<bool, String>; fn get_key_pressed(&mut self, key: char) -> Result<bool, String>;
fn get_mouse_pressed(&mut self) -> Result<Option<(f32, f32)>, String>; fn get_mouse_pressed(&mut self) -> Result<Option<(f32, f32)>, String>;
fn get_mouse_down(&mut self) -> Result<Option<(f32, f32)>, String>;
fn get_mouse_xy(&self) -> Result<(f32, f32), String>;
fn get_mouse_xy_vec(&self) -> Result<Vector, String>;
fn get_delta_time(&self) -> f32; fn get_delta_time(&self) -> f32;
fn clear_window(&mut self, color: Color) -> Result<(), String>; fn clear_window(&mut self, color: Color) -> Result<(), String>;
fn begin_drawing(&mut self) -> Result<(), String>; fn begin_drawing(&mut self) -> Result<(), String>;

View file

@ -143,19 +143,19 @@ impl Vector {
} }
} }
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Transform { pub struct Transform {
pub mat: [f32; 9], pub mat: [f32; 9],
translate: Vector, //translate: Vector,
rotate: f32, //rotate: f32,
} }
impl Default for Transform { impl Default for Transform {
fn default() -> Self { fn default() -> Self {
Self { Self {
mat: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0], mat: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0],
translate: Vector { x: 0.0, y: 0.0 }, //translate: Vector { x: 0.0, y: 0.0 },
rotate: 0.0, //rotate: 0.0,
} }
} }
} }
@ -187,14 +187,16 @@ impl Mul<Transform> for Transform {
self.mat[6] * rhs.mat[1] + self.mat[7] * rhs.mat[4] + self.mat[8] * rhs.mat[7], self.mat[6] * rhs.mat[1] + self.mat[7] * rhs.mat[4] + self.mat[8] * rhs.mat[7],
self.mat[6] * rhs.mat[2] + self.mat[7] * rhs.mat[5] + self.mat[8] * rhs.mat[8], self.mat[6] * rhs.mat[2] + self.mat[7] * rhs.mat[5] + self.mat[8] * rhs.mat[8],
], ],
translate: self.translate + rhs.translate, //translate: self.translate + rhs.translate,
rotate: self.rotate + rhs.rotate, //rotate: self.rotate + rhs.rotate,
} }
} }
} }
impl Transform { impl Transform {
pub const IDENTITY: Self = Self::default(); pub const IDENTITY: Self = Self {
mat: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0],
};
pub fn rotate(rot: f32) -> Self { pub fn rotate(rot: f32) -> Self {
Self { Self {
@ -209,7 +211,7 @@ impl Transform {
0.0, 0.0,
1.0, 1.0,
], ],
rotate: rot, //rotate: rot,
..Default::default() ..Default::default()
} }
} }
@ -217,18 +219,18 @@ impl Transform {
pub fn translate(x: f32, y: f32) -> Self { pub fn translate(x: f32, y: f32) -> Self {
Self { Self {
mat: [1.0, 0.0, x, 0.0, 1.0, y, 0.0, 0.0, 1.0], mat: [1.0, 0.0, x, 0.0, 1.0, y, 0.0, 0.0, 1.0],
translate: Vector { x, y }, //translate: Vector { x, y },
..Default::default() ..Default::default()
} }
} }
pub fn get_translate(&self) -> Vector { //pub fn get_translate(&self) -> Vector {
self.translate // self.translate
} //}
pub fn get_rotation(&self) -> f32 { //pub fn get_rotation(&self) -> f32 {
self.rotate // self.rotate
} //}
} }
pub struct Window { pub struct Window {
@ -290,7 +292,7 @@ impl Window {
.as_ref()) .as_ref())
} }
pub fn get_image_mut(&self, name: &str) -> Result<&mut dyn ImageInterface, String> { pub fn get_image_mut(&mut self, name: &str) -> Result<&mut dyn ImageInterface, String> {
Ok(self Ok(self
.images .images
.get_mut(name) .get_mut(name)
@ -306,7 +308,7 @@ impl Window {
.as_ref()) .as_ref())
} }
pub fn get_font_mut(&self, name: &str) -> Result<&mut dyn FontInterface, String> { pub fn get_font_mut(&mut self, name: &str) -> Result<&mut dyn FontInterface, String> {
Ok(self Ok(self
.fonts .fonts
.get_mut(name) .get_mut(name)
@ -322,7 +324,7 @@ impl Window {
.as_ref()) .as_ref())
} }
pub fn get_sound_mut(&self, name: &str) -> Result<&mut dyn SoundInterface, String> { pub fn get_sound_mut(&mut self, name: &str) -> Result<&mut dyn SoundInterface, String> {
Ok(self Ok(self
.sounds .sounds
.get_mut(name) .get_mut(name)
@ -338,7 +340,7 @@ impl Window {
.as_ref()) .as_ref())
} }
pub fn get_music_mut(&self, name: &str) -> Result<&mut dyn MusicInterface, String> { pub fn get_music_mut(&mut self, name: &str) -> Result<&mut dyn MusicInterface, String> {
Ok(self Ok(self
.music .music
.get_mut(name) .get_mut(name)
@ -346,7 +348,3 @@ impl Window {
.as_mut()) .as_mut())
} }
} }
pub struct Key {}
pub struct Event {}

View file

@ -18,7 +18,7 @@ use serde::{Deserialize, Serialize};
mod agnostic_interface; mod agnostic_interface;
mod faux_quicksilver; mod faux_quicksilver;
use faux_quicksilver::{Circle, Color, Event, Key, Rectangle, Transform, Vector, Window}; use faux_quicksilver::{Circle, Color, Rectangle, Transform, Vector, Window};
const WIDTH_F: f32 = 800.0; const WIDTH_F: f32 = 800.0;
const HEIGHT_F: f32 = 600.0; const HEIGHT_F: f32 = 600.0;
@ -57,14 +57,12 @@ fn interp_sq(x: f32) -> f32 {
enum MenuItemType { enum MenuItemType {
Button { Button {
text: &'static str, text: &'static str,
text_image: Option<String>,
text_c: Color, text_c: Color,
h_c: Color, h_c: Color,
c: Color, c: Color,
}, },
AppearingText { AppearingText {
text: &'static str, text: &'static str,
text_image: Option<String>,
current_text: String, current_text: String,
text_size: f32, text_size: f32,
text_c: Color, text_c: Color,
@ -72,7 +70,6 @@ enum MenuItemType {
}, },
InstantText { InstantText {
text: &'static str, text: &'static str,
text_image: Option<String>,
text_size: f32, text_size: f32,
text_color: Color, text_color: Color,
}, },
@ -122,7 +119,6 @@ impl Menu {
h, h,
item_type: MenuItemType::Button { item_type: MenuItemType::Button {
text: s, text: s,
text_image: None,
text_c: t_color, text_c: t_color,
h_c: boxh_color, h_c: boxh_color,
c: box_color, c: box_color,
@ -141,7 +137,6 @@ impl Menu {
h: 150.0, h: 150.0,
item_type: MenuItemType::Button { item_type: MenuItemType::Button {
text: "Start the Game", text: "Start the Game",
text_image: None,
text_c: Color::WHITE, text_c: Color::WHITE,
h_c: Color::from_rgba(0x66, 0xFF, 0xFF, 255), h_c: Color::from_rgba(0x66, 0xFF, 0xFF, 255),
c: Color::from_rgba(0x33, 0xDD, 0xDD, 255), c: Color::from_rgba(0x33, 0xDD, 0xDD, 255),
@ -194,7 +189,6 @@ impl Menu {
h: 0.0, h: 0.0,
item_type: MenuItemType::InstantText { item_type: MenuItemType::InstantText {
text: s, text: s,
text_image: None,
text_size, text_size,
text_color: Color::WHITE, text_color: Color::WHITE,
}, },
@ -212,7 +206,6 @@ impl Menu {
h: 0.0, h: 0.0,
item_type: MenuItemType::AppearingText { item_type: MenuItemType::AppearingText {
text: s, text: s,
text_image: None,
text_size, text_size,
current_text: String::new(), current_text: String::new(),
text_c: Color::WHITE, text_c: Color::WHITE,
@ -1011,7 +1004,7 @@ impl Star {
fn draw(&mut self, image: &str, window: &mut Window, transform: Transform) { fn draw(&mut self, image: &str, window: &mut Window, transform: Transform) {
self.particle_system.draw(window, transform); self.particle_system.draw(window, transform);
let image = window.get_image(image).expect("Should be loaded image"); let image = window.get_image_mut(image).expect("Should be loaded image");
let mut image_rect = image.get_wh_rect(); let mut image_rect = image.get_wh_rect();
image_rect.x = self.particle_system.host_circle.x - image_rect.w / 2.0; image_rect.x = self.particle_system.host_circle.x - image_rect.w / 2.0;
image_rect.y = self.particle_system.host_circle.y - image_rect.h / 2.0; image_rect.y = self.particle_system.host_circle.y - image_rect.h / 2.0;
@ -1115,7 +1108,7 @@ impl Fish {
fn draw(&mut self, i_fish: &str, window: &mut Window, transform: Transform) { fn draw(&mut self, i_fish: &str, window: &mut Window, transform: Transform) {
let fish_img = window let fish_img = window
.get_image(i_fish) .get_image_mut(i_fish)
.expect("\"fish\" Image should be loaded"); .expect("\"fish\" Image should be loaded");
let anim_angle = ((self.anim_timer / self.anim_time) * std::f32::consts::PI * 2.0).sin(); let anim_angle = ((self.anim_timer / self.anim_time) * std::f32::consts::PI * 2.0).sin();
let mut body_rect = self.body_rect; let mut body_rect = self.body_rect;
@ -1269,7 +1262,7 @@ impl GameState {
i_fish.clone(), i_fish.clone(),
)?; )?;
let camera = window.get_gi_mut().get_default_camera()?; let mut camera = window.get_gi_mut().get_default_camera()?;
camera.set_view(Rectangle { camera.set_view(Rectangle {
x: 0.0, x: 0.0,
y: 0.0, y: 0.0,
@ -1337,13 +1330,15 @@ impl GameState {
}) })
} }
fn event(&mut self, event: &Event, window: &mut Window) -> Result<(), String> { fn update(&mut self, window: &mut Window) -> Result<(), String> {
match event { let dt = window.get_gi().get_delta_time();
Event::MouseMoved(v) => {
self.mouse_pos = *v; // check mouse pos
{
self.mouse_pos = window.get_gi().get_mouse_xy_vec()?;
let mut hovered = false; let mut hovered = false;
for i in 0..self.menu.items.len() { for i in 0..self.menu.items.len() {
if self.menu.items[i].is_inside(v.x, v.y) { if self.menu.items[i].is_inside(self.mouse_pos.x, self.mouse_pos.y) {
self.menu.items[i].is_hover = true; self.menu.items[i].is_hover = true;
self.current_item = Some(i); self.current_item = Some(i);
hovered = true; hovered = true;
@ -1355,12 +1350,13 @@ impl GameState {
self.current_item = None; self.current_item = None;
} }
} }
Event::MouseButton(button, state) => {
if let ButtonState::Released = state { // check mouse down
if window.get_gi_mut().get_mouse_down()?.is_none() {
if self.dbl_click_timeout.is_none() { if self.dbl_click_timeout.is_none() {
self.click_release_time = 0.0; self.click_release_time = 0.0;
} }
} else if let ButtonState::Pressed = state { } else {
if self.current_finished { if self.current_finished {
if self.is_create_mode { if self.is_create_mode {
if self.click_release_time < DOUBLE_CLICK_TIME { if self.click_release_time < DOUBLE_CLICK_TIME {
@ -1378,10 +1374,7 @@ impl GameState {
self.expl_conv_p_systems.push(expl_conv_system); self.expl_conv_p_systems.push(expl_conv_system);
self.state = 9; self.state = 9;
self.state_dirty = true; self.state_dirty = true;
self.s_boom.execute(|s| { window.get_sound_mut(&self.s_boom)?.play(0.8)?;
s.set_volume(0.8);
s.play()
})?;
} else if self.state == 10 { } else if self.state == 10 {
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();
let rand_out = rng.gen_range(0.0, 1.0); let rand_out = rng.gen_range(0.0, 1.0);
@ -1402,10 +1395,8 @@ impl GameState {
), ),
1.0, 1.0,
); );
expl_conv_system.activate( expl_conv_system
rng.gen_range(13, 40), .activate(rng.gen_range(13, 40), rng.gen_range(150.0, 300.0));
rng.gen_range(150.0, 300.0),
);
self.expl_conv_p_systems.push(expl_conv_system); self.expl_conv_p_systems.push(expl_conv_system);
} else if rand_out < 0.85 { } else if rand_out < 0.85 {
// spawn star // spawn star
@ -1444,10 +1435,7 @@ impl GameState {
)); ));
} }
} }
self.s_boom.execute(|s| { window.get_sound_mut(&self.s_boom)?.play(0.8)?;
s.set_volume(0.8);
s.play()
})?;
} }
} else if self.state == 10 { } else if self.state == 10 {
self.click_time = Some(0.0); self.click_time = Some(0.0);
@ -1486,10 +1474,7 @@ impl GameState {
self.joining_particles.particle_system.color = self.joining_particles.particle_system.color =
Color::from_rgba(0xFF, 0xAA, 0xAA, 255); Color::from_rgba(0xFF, 0xAA, 0xAA, 255);
} }
self.s_get.execute(|s| { window.get_sound_mut(&self.s_get)?.play(0.7)?;
s.set_volume(0.7);
s.play()
})?;
} }
_ => { _ => {
self.state = 0; self.state = 0;
@ -1512,60 +1497,36 @@ impl GameState {
match &mut mi.item_type { match &mut mi.item_type {
MenuItemType::AppearingText { MenuItemType::AppearingText {
text, text,
text_image,
current_text, current_text,
text_size, text_size,
text_c, text_c,
timer, timer,
} => { } => {
self.font.execute(|f| {
*current_text = text.to_string(); *current_text = text.to_string();
let style = FontStyle::new(*text_size, *text_c);
*text_image = Some(f.render(text, &style)?);
Ok(())
})?;
} }
MenuItemType::Button { MenuItemType::Button {
text, text,
text_image,
text_c, text_c,
h_c, h_c,
c, c,
} => { } => {
if text_image.is_none() { //let style = FontStyle::new(42.0, *text_c);
self.font.execute(|font| {
let style = FontStyle::new(42.0, *text_c);
*text_image = Some(font.render(text, &style)?);
Ok(())
})?;
}
} }
MenuItemType::Pause { timer, length } => (), MenuItemType::Pause { timer, length } => (),
MenuItemType::InstantText { MenuItemType::InstantText {
text, text,
text_image,
text_size, text_size,
text_color, text_color,
} => { } => {}
if text_image.is_none() {
self.font.execute(|f| {
let style = FontStyle::new(*text_size, *text_color);
*text_image = Some(f.render(text, &style)?);
Ok(())
})?;
}
}
} }
mi.is_loaded = true; mi.is_loaded = true;
} }
self.current_finished = true; self.current_finished = true;
} }
} }
}
Event::Key(key, state) => { // check pressed keys
if let ButtonState::Pressed = state { if window.get_gi_mut().get_key_pressed('s')? {
match key {
Key::S => {
if self.state == 10 { if self.state == 10 {
let save_data = SaveData { let save_data = SaveData {
planets: self.planets.clone(), planets: self.planets.clone(),
@ -1574,59 +1535,48 @@ impl GameState {
player: self.player.clone(), player: self.player.clone(),
joining_particles: self.joining_particles.clone(), joining_particles: self.joining_particles.clone(),
}; };
save("OneAndAll_LD45", "slot0", &save_data)?; // TODO
//save("OneAndAll_LD45", "slot0", &save_data)?;
self.save_load_notification = Some(SaveLoadNotification::Save { self.save_load_notification = Some(SaveLoadNotification::Save {
text: None, text: None,
timer: SL_NOTIF_TIME, timer: SL_NOTIF_TIME,
}); });
} }
} } else if window.get_gi_mut().get_key_pressed('l')? {
Key::L => { // TODO
let load_result = load::<SaveData>("OneAndAll_LD45", "slot0"); //let load_result = load::<SaveData>("OneAndAll_LD45", "slot0");
if let Ok(save_data) = load_result { //if let Ok(save_data) = load_result {
self.planets = save_data.planets; // self.planets = save_data.planets;
self.stars = save_data.stars; // self.stars = save_data.stars;
self.fishes = save_data.fishes; // self.fishes = save_data.fishes;
self.player = save_data.player; // self.player = save_data.player;
self.joining_particles = save_data.joining_particles; // self.joining_particles = save_data.joining_particles;
self.expl_conv_p_systems.clear(); // self.expl_conv_p_systems.clear();
self.move_to = Vector { // self.move_to = Vector {
x: self.player.x, // x: self.player.x,
y: self.player.y, // y: self.player.y,
}; // };
self.camera.set_view_xy( // self.camera.set_view_xy(
self.player.x - WIDTH_F / 2.0, // self.player.x - WIDTH_F / 2.0,
self.player.y - HEIGHT_F / 2.0, // self.player.y - HEIGHT_F / 2.0,
); // );
self.dbl_click_timeout = None; // self.dbl_click_timeout = None;
self.click_time = None; // self.click_time = None;
self.click_release_time = DOUBLE_CLICK_TIME; // self.click_release_time = DOUBLE_CLICK_TIME;
self.state = 10; // self.state = 10;
self.state_dirty = true; // self.state_dirty = true;
self.save_load_notification = Some(SaveLoadNotification::Load { // self.save_load_notification = Some(SaveLoadNotification::Load {
text: None, // text: None,
timer: SL_NOTIF_TIME, // timer: SL_NOTIF_TIME,
}); // });
} //}
} } else if window.get_gi_mut().get_key_pressed('r')? {
Key::R => {
if self.state == 10 { if self.state == 10 {
self.state = 0; self.state = 0;
self.state_dirty = true; self.state_dirty = true;
} }
} }
_ => (),
}
}
}
_ => (),
}
Ok(())
}
fn update(&mut self, window: &mut Window) -> Result<(), String> {
let dt = window.get_gi().get_delta_time();
self.click_release_time += dt; self.click_release_time += dt;
if let Some(t) = &mut self.click_time { if let Some(t) = &mut self.click_time {
@ -1663,7 +1613,7 @@ impl GameState {
if self.state_dirty { if self.state_dirty {
self.state_dirty = false; self.state_dirty = false;
if self.state > 1 && !self.music_on { if self.state > 1 && !self.music_on {
let music = window.get_music(&self.music2)?; let music = window.get_music_mut(&self.music2)?;
music.set_loop(true)?; music.set_loop(true)?;
music.play(0.5)?; music.play(0.5)?;
self.music_on = true; self.music_on = true;
@ -1763,7 +1713,7 @@ impl GameState {
if self.music_on { if self.music_on {
} else if self.state == 10 { } else if self.state == 10 {
let mut music_on = false; let mut music_on = false;
let music = window.get_music(&self.music2)?; let music = window.get_music_mut(&self.music2)?;
music.set_loop(true)?; music.set_loop(true)?;
music.play(0.5)?; music.play(0.5)?;
self.music_on = true; self.music_on = true;
@ -1775,28 +1725,26 @@ impl GameState {
match &mut mi.item_type { match &mut mi.item_type {
MenuItemType::Button { MenuItemType::Button {
text, text,
text_image,
text_c, text_c,
h_c, h_c,
c, c,
} => { } => {
self.font.execute(|font| { //self.font.execute(|font| {
let style = FontStyle::new(42.0, *text_c); // let style = FontStyle::new(42.0, *text_c);
*text_image = Some(font.render(text, &style)?); // *text_image = Some(font.render(text, &style)?);
Ok(()) // Ok(())
})?; //})?;
if text_image.is_some() { //if text_image.is_some() {
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;
} else { } else {
self.current_finished = true; self.current_finished = true;
} }
} //}
} }
MenuItemType::AppearingText { MenuItemType::AppearingText {
text, text,
text_image,
current_text, current_text,
text_size, text_size,
text_c, text_c,
@ -1808,10 +1756,7 @@ impl GameState {
let next = text.chars().nth(current_text.len()); let next = text.chars().nth(current_text.len());
if let Some(next_t) = next { if let Some(next_t) = next {
current_text.push(next_t); current_text.push(next_t);
self.s_tap.execute(|s| { window.get_sound_mut(&self.s_tap)?.play(0.2)?;
s.set_volume(0.2);
s.play()
})?;
} else { } else {
mi.is_loaded = true; mi.is_loaded = true;
if i + 1 < self.menu.items.len() { if i + 1 < self.menu.items.len() {
@ -1821,11 +1766,11 @@ impl GameState {
} }
continue; continue;
} }
self.font.execute(|font| { //self.font.execute(|font| {
let style = FontStyle::new(*text_size, *text_c); // let style = FontStyle::new(*text_size, *text_c);
*text_image = Some(font.render(current_text, &style)?); // *text_image = Some(font.render(current_text, &style)?);
Ok(()) // Ok(())
})?; //})?;
} }
} }
MenuItemType::Pause { timer, length } => { MenuItemType::Pause { timer, length } => {
@ -1841,25 +1786,24 @@ impl GameState {
} }
MenuItemType::InstantText { MenuItemType::InstantText {
text, text,
text_image,
text_size, text_size,
text_color, text_color,
} => { } => {
if text_image.is_none() { //if text_image.is_none() {
self.font.execute(|f| { // self.font.execute(|f| {
let style = FontStyle::new(*text_size, *text_color); // let style = FontStyle::new(*text_size, *text_color);
*text_image = Some(f.render(text, &style)?); // *text_image = Some(f.render(text, &style)?);
Ok(()) // Ok(())
})?; // })?;
} //}
if text_image.is_some() { //if text_image.is_some() {
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;
} else { } else {
self.current_finished = true; self.current_finished = true;
} }
} //}
} }
} }
} }
@ -1888,12 +1832,12 @@ impl GameState {
if *timer <= 0.0 { if *timer <= 0.0 {
self.save_load_notification = None; self.save_load_notification = None;
} else if text.is_none() { } else if text.is_none() {
self.font.execute(|f| { //self.font.execute(|f| {
*text = Some( // *text = Some(
f.render("Saved the Game", &FontStyle::new(45.0, Color::WHITE))?, // f.render("Saved the Game", &FontStyle::new(45.0, Color::WHITE))?,
); // );
Ok(()) // Ok(())
})?; //})?;
} }
} }
SaveLoadNotification::Load { text, timer } => { SaveLoadNotification::Load { text, timer } => {
@ -1901,12 +1845,12 @@ impl GameState {
if *timer <= 0.0 { if *timer <= 0.0 {
self.save_load_notification = None; self.save_load_notification = None;
} else if text.is_none() { } else if text.is_none() {
self.font.execute(|f| { //self.font.execute(|f| {
*text = Some( // *text = Some(
f.render("Loaded the Game", &FontStyle::new(45.0, Color::WHITE))?, // f.render("Loaded the Game", &FontStyle::new(45.0, Color::WHITE))?,
); // );
Ok(()) // Ok(())
})?; //})?;
} }
} }
} }
@ -1930,7 +1874,6 @@ impl GameState {
match &mut mi.item_type { match &mut mi.item_type {
MenuItemType::Button { MenuItemType::Button {
text, text,
text_image,
text_c, text_c,
h_c, h_c,
c, c,
@ -1940,38 +1883,41 @@ impl GameState {
} else { } else {
window.get_gi_mut().draw_rect(rect, *c)?; window.get_gi_mut().draw_rect(rect, *c)?;
} }
if let Some(i) = text_image { window.get_font_mut(&self.font)?.draw(
let image = window.get_image_mut(&i)?; text,
let mut image_rect = image.get_wh_rect(); rect.h.round() as u32,
image_rect.x = mi.x + (mi.w - image_rect.w) / 2.0; rect.x,
image_rect.y = mi.y + (mi.h - image_rect.h) / 2.0; rect.y,
image.draw(image_rect.x, image_rect.y, Color::WHITE)?; *text_c,
} )?;
} }
MenuItemType::AppearingText { MenuItemType::AppearingText {
text, text,
text_image,
current_text, current_text,
text_size, text_size,
text_c, text_c,
timer, timer,
} => { } => {
if let Some(i) = text_image { window.get_font_mut(&self.font)?.draw(
let image = window.get_image_mut(&i)?; text,
image.draw(mi.x, mi.y, Color::WHITE)?; text_size.round() as u32,
} rect.x,
rect.y,
*text_c,
)?;
} }
MenuItemType::InstantText { MenuItemType::InstantText {
text, text,
text_image,
text_size, text_size,
text_color, text_color,
} => { } => {
if let Some(i) = text_image { window.get_font_mut(&self.font)?.draw(
let image = window.get_image_mut(&i)?; text,
let mut image_rect = image.get_wh_rect(); text_size.round() as u32,
image.draw(mi.x, mi.y, Color::WHITE)?; rect.x,
} rect.y,
*text_color,
)?;
} }
MenuItemType::Pause { timer, length } => (), MenuItemType::Pause { timer, length } => (),
} }