Button images rough implementation

Tuning font sizing and need to add font changes upon interaction
main
Elijah C. Voigt 2 years ago
parent 8e2d4ab7af
commit a7ffd6e0f9

Binary file not shown.

@ -0,0 +1,93 @@
Copyright 2011 The Montserrat Project Authors (https://github.com/JulietaUla/Montserrat)
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

Binary file not shown.

Binary file not shown.

@ -7,9 +7,9 @@ text = """
An Icehouse game by Andrew Looney
Art by Sam Hall
Art: Sam Hall
Programming by Elijah Voigt
Programming: Elijah Voigt
---
@ -25,13 +25,15 @@ FMOD/FMOD Studio: fmod.com
Image Textures retrieved from textures.com:
Concrete Energy Pole - https://www.textures.com/download/PBR0340/136381
Concrete Energy Pole: https://www.textures.com/download/PBR0340/136381
Space Blanket Folds - https://www.textures.com/download/PBR0152/133187
Space Blanket Folds: https://www.textures.com/download/PBR0152/133187
Background 2D art by NASA: LINK HERE
Silkscreen Font by Jason Kottke - https://www.kottke.org/plus/type/silkscreen/
Silkscreen Font by Jason Kottke: https://www.kottke.org/plus/type/silkscreen/
Neothic Font by Daymarius: https://www.dafont.com/neothic.font
"""
###
@ -115,6 +117,11 @@ end = ["Ok, now move some pieces somewheres!"]
x = 640
y = 480
[buttons]
image_resting = "images/Blank Button (Resting).png"
image_depressed = "images/Blank Button (Depressed).png"
font = "fonts/Neothic/Neothic.ttf"
#########################################################################
# Audio settings
#########################################################################

@ -4,7 +4,7 @@ pub(crate) struct CreditsPlugin;
impl Plugin for CreditsPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, init_credits_ui)
app.add_systems(OnExit(GameState::Loading), init_credits_ui)
.add_systems(OnEnter(GameState::Credits), update_credits);
}
}
@ -12,7 +12,15 @@ impl Plugin for CreditsPlugin {
#[derive(Debug, Component)]
struct Credits;
fn init_credits_ui(mut commands: Commands) {
fn init_credits_ui(
mut commands: Commands,
tweaks_file: Res<tweak::GameTweaks>,
tweaks: Res<Assets<tweak::Tweaks>>,
) {
let tweak = tweaks.get(tweaks_file.handle.clone()).expect("Load tweaks");
let button_handle = tweak.get_handle::<Image>("buttons_image_resting").unwrap();
let font_handle = tweak.get_handle::<Font>("buttons_font").unwrap();
commands
.spawn((
GameState::Credits,
@ -39,7 +47,7 @@ fn init_credits_ui(mut commands: Commands) {
padding: UiRect::all(Val::Px(25.0)),
..default()
},
background_color: Color::BLACK.with_a(0.5).into(),
background_color: Color::BLACK.into(),
..default()
},
))
@ -67,25 +75,36 @@ fn init_credits_ui(mut commands: Commands) {
margin: UiRect::all(Val::Px(5.0)),
..default()
},
background_color: Color::ORANGE.with_a(0.5).into(),
image: UiImage {
texture: button_handle.clone(),
..default()
},
..default()
},
))
.with_children(|parent| {
parent.spawn(TextBundle {
parent.spawn(
TextBundle {
text: Text {
sections: vec![TextSection {
value: "Back".into(),
sections: vec![
TextSection {
value: "B a c k".into(),
style: TextStyle {
color: Color::BLACK,
font_size: 32.0,
color: Color::WHITE,
font_size: 12.0,
font: font_handle.clone(),
},
}
],
..default()
},
}],
style: Style {
margin: UiRect::all(Val::Px(20.0)),
..default()
},
..default()
});
}
);
});
});
}

@ -596,7 +596,16 @@ fn check_endgame(board: Res<Board>, mut next_state: ResMut<NextState<GameState>>
}
}
fn set_endgame(score: Res<Score>, mut commands: Commands) {
fn set_endgame(
score: Res<Score>,
mut commands: Commands,
tweaks_file: Res<tweak::GameTweaks>,
tweaks: Res<Assets<tweak::Tweaks>>,
) {
let tweak = tweaks.get(tweaks_file.handle.clone()).expect("Load tweaks");
let button_handle = tweak.get_handle::<Image>("buttons_image_resting").unwrap();
let font_handle = tweak.get_handle::<Font>("buttons_font").unwrap();
commands
.spawn((
Endgame,
@ -663,19 +672,36 @@ fn set_endgame(score: Res<Score>, mut commands: Commands) {
margin: UiRect::all(Val::Px(5.0)),
..default()
},
background_color: Color::ORANGE.with_a(0.5).into(),
image: UiImage {
texture: button_handle.clone(),
..default()
},
..default()
},
))
.with_children(|parent| {
parent.spawn((TextBundle::from_section(
"New Game",
TextStyle {
color: Color::BLACK,
font_size: 32.0,
parent.spawn(
TextBundle {
text: Text {
sections: vec![
TextSection {
value: "N e w G a m e".into(),
style: TextStyle {
color: Color::WHITE,
font_size: 16.0,
font: font_handle.clone(),
},
}
],
..default()
},
),));
style: Style {
margin: UiRect::all(Val::Px(20.0)),
..default()
},
..default()
}
);
});
// Quit button
@ -689,19 +715,36 @@ fn set_endgame(score: Res<Score>, mut commands: Commands) {
margin: UiRect::all(Val::Px(5.0)),
..default()
},
background_color: Color::ORANGE.with_a(0.5).into(),
image: UiImage {
texture: button_handle.clone(),
..default()
},
..default()
},
))
.with_children(|parent| {
parent.spawn((TextBundle::from_section(
"Quit",
TextStyle {
color: Color::BLACK,
font_size: 32.0,
parent.spawn(
TextBundle {
text: Text {
sections: vec![
TextSection {
value: "Q u i t".into(),
style: TextStyle {
color: Color::WHITE,
font_size: 16.0,
font: font_handle.clone(),
},
}
],
..default()
},
style: Style {
margin: UiRect::all(Val::Px(20.0)),
..default()
},
),));
..default()
}
);
});
});
});

@ -41,9 +41,17 @@ pub(crate) enum MenuState {
#[derive(Debug, Component)]
pub(crate) struct ButtonAction<S: States + Clone + Component>(pub S);
fn init_play_menu(mut commands: Commands) {
fn init_play_menu(
mut commands: Commands,
tweaks_file: Res<tweak::GameTweaks>,
tweaks: Res<Assets<tweak::Tweaks>>,
) {
info!("Initializing Play menu");
let tweak = tweaks.get(tweaks_file.handle.clone()).expect("Load tweaks");
let button_handle = tweak.get_handle::<Image>("buttons_image_resting").unwrap();
let font_handle = tweak.get_handle::<Font>("buttons_font").unwrap();
commands
.spawn((
MenuState::On,
@ -84,19 +92,36 @@ fn init_play_menu(mut commands: Commands) {
margin: UiRect::all(Val::Px(5.0)),
..default()
},
background_color: Color::ORANGE.with_a(0.5).into(),
image: UiImage {
texture: button_handle.clone(),
..default()
},
..default()
},
))
.with_children(|parent| {
parent.spawn((TextBundle::from_section(
"Continue",
TextStyle {
color: Color::BLACK,
font_size: 32.0,
parent.spawn(
TextBundle {
text: Text {
sections: vec![
TextSection {
value: "C o n t i n u e".into(),
style: TextStyle {
color: Color::WHITE,
font_size: 16.0,
font: font_handle.clone(),
},
}
],
..default()
},
),));
style: Style {
margin: UiRect::all(Val::Px(20.0)),
..default()
},
..default()
}
);
});
// Tutorial button
@ -110,19 +135,36 @@ fn init_play_menu(mut commands: Commands) {
margin: UiRect::all(Val::Px(5.0)),
..default()
},
background_color: Color::ORANGE.with_a(0.5).into(),
image: UiImage {
texture: button_handle.clone(),
..default()
},
..default()
},
))
.with_children(|parent| {
parent.spawn((TextBundle::from_section(
"Tutorial",
TextStyle {
color: Color::BLACK,
font_size: 32.0,
parent.spawn(
TextBundle {
text: Text {
sections: vec![
TextSection {
value: "T u t o r i a l".into(),
style: TextStyle {
color: Color::WHITE,
font_size: 16.0,
font: font_handle.clone(),
},
}
],
..default()
},
),));
style: Style {
margin: UiRect::all(Val::Px(20.0)),
..default()
},
..default()
}
);
});
// Credits button
@ -136,19 +178,36 @@ fn init_play_menu(mut commands: Commands) {
margin: UiRect::all(Val::Px(5.0)),
..default()
},
background_color: Color::ORANGE.with_a(0.5).into(),
image: UiImage {
texture: button_handle.clone(),
..default()
},
..default()
},
))
.with_children(|parent| {
parent.spawn((TextBundle::from_section(
"Credits",
TextStyle {
color: Color::BLACK,
font_size: 32.0,
parent.spawn(
TextBundle {
text: Text {
sections: vec![
TextSection {
value: "C r e d i t s".into(),
style: TextStyle {
color: Color::WHITE,
font_size: 16.0,
font: font_handle.clone(),
},
}
],
..default()
},
),));
style: Style {
margin: UiRect::all(Val::Px(20.0)),
..default()
},
..default()
}
);
});
// Quit button
@ -162,19 +221,36 @@ fn init_play_menu(mut commands: Commands) {
margin: UiRect::all(Val::Px(5.0)),
..default()
},
background_color: Color::ORANGE.with_a(0.5).into(),
image: UiImage {
texture: button_handle.clone(),
..default()
},
..default()
},
))
.with_children(|parent| {
parent.spawn((TextBundle::from_section(
"Quit",
TextStyle {
color: Color::BLACK,
font_size: 32.0,
parent.spawn(
TextBundle {
text: Text {
sections: vec![
TextSection {
value: "Q u i t".into(),
style: TextStyle {
color: Color::WHITE,
font_size: 16.0,
font: font_handle.clone(),
},
}
],
..default()
},
),));
style: Style {
margin: UiRect::all(Val::Px(20.0)),
..default()
},
..default()
}
);
});
});
}

@ -85,6 +85,8 @@ fn initialize_tutorial(
let background_hex = tweak.get::<String>("tutorial_rgba_background").unwrap();
let text_visible_hex = tweak.get::<String>("tutorial_rgba_visible").unwrap();
let button_handle = tweak.get_handle::<Image>("buttons_image_resting").unwrap();
let font_handle = tweak.get_handle::<Font>("buttons_font").unwrap();
// List of (state, lines) for tutorial steps
[
@ -235,19 +237,36 @@ fn initialize_tutorial(
margin: UiRect::all(Val::Px(5.0)),
..default()
},
background_color: Color::ORANGE.with_a(0.5).into(),
image: UiImage {
texture: button_handle.clone(),
..default()
},
..default()
},
))
.with_children(|parent| {
parent.spawn((TextBundle::from_section(
"Start Over",
TextStyle {
color: Color::BLACK,
font_size: 16.0,
parent.spawn(
TextBundle {
text: Text {
sections: vec![
TextSection {
value: "R e s t a r t".into(),
style: TextStyle {
color: Color::WHITE,
font_size: 12.0,
font: font_handle.clone(),
},
}
],
..default()
},
style: Style {
margin: UiRect::all(Val::Px(20.0)),
..default()
},
),));
..default()
}
);
});
parent
@ -261,19 +280,36 @@ fn initialize_tutorial(
margin: UiRect::all(Val::Px(5.0)),
..default()
},
background_color: Color::ORANGE.with_a(0.5).into(),
image: UiImage {
texture: button_handle.clone(),
..default()
},
..default()
},
))
.with_children(|parent| {
parent.spawn((TextBundle::from_section(
"Continue Game",
TextStyle {
color: Color::BLACK,
font_size: 16.0,
parent.spawn(
TextBundle {
text: Text {
sections: vec![
TextSection {
value: "C o n t i n u e".into(),
style: TextStyle {
color: Color::WHITE,
font_size: 12.0,
font: font_handle.clone(),
},
}
],
..default()
},
style: Style {
margin: UiRect::all(Val::Px(20.0)),
..default()
},
),));
..default()
}
);
});
});
}

@ -51,6 +51,8 @@ impl Tweaks {
Some(load_context.load::<Gltf>(s).untyped())
} else if s.ends_with(".png") {
Some(load_context.load::<Image>(s).untyped())
} else if s.ends_with(".ttf") || s.ends_with(".otf") {
Some(load_context.load::<Font>(s).untyped())
} else {
None
}

@ -69,22 +69,36 @@ fn manage_cursor(
}
fn interactive_button(
mut events: Query<(&mut BackgroundColor, &Interaction), (With<Button>, Changed<Interaction>)>,
mut events: Query<(&mut UiImage, &Interaction), (With<Button>, Changed<Interaction>)>,
mut writer: EventWriter<audio::AudioEvent>,
tweaks_file: Res<tweak::GameTweaks>,
tweaks: Res<Assets<tweak::Tweaks>>,
) {
let tweak = tweaks.get(tweaks_file.handle.clone()).expect("Load tweaks");
let resting_handle = tweak.get_handle::<Image>("buttons_image_resting").unwrap();
let depressed_handle = tweak
.get_handle::<Image>("buttons_image_depressed")
.unwrap();
events
.iter_mut()
.for_each(|(mut bg_color, interaction)| match interaction {
.for_each(|(mut ui_image, interaction)| match interaction {
Interaction::None => {
bg_color.0.set_a(0.5);
ui_image.texture = resting_handle.clone();
info!("TODO: Change text color");
info!("TODO: Change position");
}
Interaction::Hovered => {
bg_color.0.set_a(0.75);
ui_image.texture = depressed_handle.clone();
writer.send(audio::AudioEvent::MenuHover);
info!("TODO: Change text color");
info!("TODO: Change position");
}
Interaction::Pressed => {
bg_color.0.set_a(1.0);
ui_image.texture = depressed_handle.clone();
writer.send(audio::AudioEvent::MenuSelect);
info!("TODO: Change text color");
info!("TODO: Change position");
}
});
}

Loading…
Cancel
Save