Add InstantText, change name of project
This commit is contained in:
parent
de9b1e60fe
commit
dec7627e37
3 changed files with 109 additions and 4 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -994,7 +994,7 @@ version = "1.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ld45_start_with_nothing"
|
name = "ld45_one_and_all"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quicksilver 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quicksilver 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ld45_start_with_nothing"
|
name = "ld45_one_and_all"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Stephen Seo <seo.disparate@gmail.com>"]
|
authors = ["Stephen Seo <seo.disparate@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
109
src/main.rs
109
src/main.rs
|
@ -33,6 +33,12 @@ enum MenuItemType {
|
||||||
text_c: Color,
|
text_c: Color,
|
||||||
timer: f64,
|
timer: f64,
|
||||||
},
|
},
|
||||||
|
InstantText {
|
||||||
|
text: &'static str,
|
||||||
|
text_image: Option<Image>,
|
||||||
|
text_size: f32,
|
||||||
|
text_color: Color,
|
||||||
|
},
|
||||||
Pause {
|
Pause {
|
||||||
timer: f64,
|
timer: f64,
|
||||||
length: f64,
|
length: f64,
|
||||||
|
@ -108,7 +114,57 @@ impl Menu {
|
||||||
is_loaded: false,
|
is_loaded: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
Menu { items: vec![item] }
|
Menu {
|
||||||
|
items: vec![
|
||||||
|
item,
|
||||||
|
Menu::instant_text(
|
||||||
|
150.0,
|
||||||
|
50.0,
|
||||||
|
45.0,
|
||||||
|
true,
|
||||||
|
"One And All",
|
||||||
|
),
|
||||||
|
Menu::instant_text(
|
||||||
|
25.0,
|
||||||
|
HEIGHT_F - 100.0,
|
||||||
|
30.0,
|
||||||
|
true,
|
||||||
|
"Made with quicksilver which is licensed with either",
|
||||||
|
),
|
||||||
|
Menu::instant_text(
|
||||||
|
70.0,
|
||||||
|
HEIGHT_F - 80.0,
|
||||||
|
30.0,
|
||||||
|
true,
|
||||||
|
"MIT License or Apache License Version 2.0",
|
||||||
|
),
|
||||||
|
Menu::instant_text(
|
||||||
|
25.0,
|
||||||
|
HEIGHT_F - 50.0,
|
||||||
|
30.0,
|
||||||
|
true,
|
||||||
|
"Uses Clear-Sans which is licensed with Apache License Version 2.0",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn instant_text(x: f32, y: f32, text_size: f32, first: bool, s: &'static str) -> MenuItem {
|
||||||
|
MenuItem {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
w: 0.0,
|
||||||
|
h: 0.0,
|
||||||
|
item_type: MenuItemType::InstantText {
|
||||||
|
text: s,
|
||||||
|
text_image: None,
|
||||||
|
text_size,
|
||||||
|
text_color: Color::WHITE,
|
||||||
|
},
|
||||||
|
is_hover: false,
|
||||||
|
is_focus: false,
|
||||||
|
is_loaded: !first,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn text(x: f32, y: f32, text_size: f32, first: bool, s: &'static str) -> MenuItem {
|
fn text(x: f32, y: f32, text_size: f32, first: bool, s: &'static str) -> MenuItem {
|
||||||
|
@ -579,6 +635,20 @@ impl State for GameState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MenuItemType::Pause { timer, length } => (),
|
MenuItemType::Pause { timer, length } => (),
|
||||||
|
MenuItemType::InstantText {
|
||||||
|
text,
|
||||||
|
text_image,
|
||||||
|
text_size,
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
@ -733,6 +803,28 @@ impl State for GameState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MenuItemType::InstantText {
|
||||||
|
text,
|
||||||
|
text_image,
|
||||||
|
text_size,
|
||||||
|
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(())
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
if text_image.is_some() {
|
||||||
|
mi.is_loaded = true;
|
||||||
|
if i + 1 < self.menu.items.len() {
|
||||||
|
self.menu.items[i + 1].is_loaded = false;
|
||||||
|
} else {
|
||||||
|
self.current_finished = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -786,6 +878,19 @@ impl State for GameState {
|
||||||
window.draw(&image_rect, Img(i));
|
window.draw(&image_rect, Img(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MenuItemType::InstantText {
|
||||||
|
text,
|
||||||
|
text_image,
|
||||||
|
text_size,
|
||||||
|
text_color,
|
||||||
|
} => {
|
||||||
|
if let Some(i) = text_image {
|
||||||
|
let mut image_rect = i.area();
|
||||||
|
image_rect.pos.x = mi.x;
|
||||||
|
image_rect.pos.y = mi.y;
|
||||||
|
window.draw(&image_rect, Img(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
MenuItemType::Pause { timer, length } => (),
|
MenuItemType::Pause { timer, length } => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -816,7 +921,7 @@ impl State for GameState {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
run::<GameState>(
|
run::<GameState>(
|
||||||
"LudumDare45_StartWithNothing",
|
"One And All - a Ludum Dare 45 compo entry",
|
||||||
Vector::new(800, 600),
|
Vector::new(800, 600),
|
||||||
Settings::default(),
|
Settings::default(),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue