remove title screen

Former-commit-id: 53b269b28ac38290c50bcf38c266534b673dacd2
This commit is contained in:
Imbris 2019-03-29 03:34:33 -04:00
parent 8c94b0fa2c
commit cf9780e1ec
5 changed files with 3 additions and 138 deletions

View File

@ -25,7 +25,7 @@ use pretty_env_logger;
// Crate
use crate::{
menu::title::TitleState,
menu::main::MainMenuState,
window::Window,
};
@ -78,7 +78,7 @@ fn main() {
};
// Set up the initial play state
let mut states: Vec<Box<dyn PlayState>> = vec![Box::new(TitleState::new(
let mut states: Vec<Box<dyn PlayState>> = vec![Box::new(MainMenuState::new(
&mut global_state.window,
))];
states.last().map(|current_state| {

View File

@ -52,6 +52,7 @@ struct Imgs {
}
impl Imgs {
fn new(ui: &mut Ui, renderer: &mut Renderer) -> Imgs {
// TODO: update paths
let mut load = |filename| {
let image = image::open(
&[

View File

@ -1,3 +1,2 @@
pub mod char_selection;
pub mod main;
pub mod title;

View File

@ -1,84 +0,0 @@
mod ui;
use super::main::MainMenuState;
use crate::{
window::{Event, Window},
GlobalState, PlayState, PlayStateResult,
};
use common::clock::Clock;
use std::time::Duration;
use ui::TitleUi;
use vek::*;
const FPS: u64 = 60;
pub struct TitleState {
title_ui: TitleUi,
}
impl TitleState {
/// Create a new `TitleState`
pub fn new(window: &mut Window) -> Self {
Self {
title_ui: TitleUi::new(window),
}
}
}
// The background colour
const BG_COLOR: Rgba<f32> = Rgba {
r: 0.0,
g: 0.3,
b: 1.0,
a: 1.0,
};
impl PlayState for TitleState {
fn play(&mut self, global_state: &mut GlobalState) -> PlayStateResult {
// Set up an fps clock
let mut clock = Clock::new();
loop {
// Handle window events
for event in global_state.window.fetch_events() {
match event {
Event::Close => return PlayStateResult::Shutdown,
// When any key is pressed, go to the main menu
Event::Char(_) => {
return PlayStateResult::Push(Box::new(MainMenuState::new(
&mut global_state.window,
)));
}
// Pass events to ui
Event::Ui(event) => {
self.title_ui.handle_event(event);
}
// Ignore all other events
_ => {}
}
}
global_state.window.renderer_mut().clear(BG_COLOR);
// Maintain the UI
self.title_ui.maintain(global_state.window.renderer_mut());
// Draw the UI to the screen
self.title_ui.render(global_state.window.renderer_mut());
// Finish the frame
global_state.window.renderer_mut().flush();
global_state
.window
.swap_buffers()
.expect("Failed to swap window buffers");
// Wait for the next tick
clock.tick(Duration::from_millis(1000 / FPS));
}
}
fn name(&self) -> &'static str {
"Title"
}
}

View File

@ -1,51 +0,0 @@
use crate::{render::Renderer, ui::{self, Ui}, window::Window};
use conrod_core::{
image::Id as ImgId,
widget::{Id as WidgId, Image as ImageWidget},
Positionable, Widget,
};
pub struct TitleUi {
ui: Ui,
widget_id: WidgId,
title_img_id: ImgId,
}
impl TitleUi {
pub fn new(window: &mut Window) -> Self {
let mut ui = Ui::new(window).unwrap();
let widget_id = ui.id_generator().next();
// TODO: use separate image for logo
let image = image::open(concat!(
env!("CARGO_MANIFEST_DIR"),
"/test_assets/ui/title/splash.png"
))
.unwrap();
let title_img_id = ui.new_image(window.renderer_mut(), &image).unwrap();
Self {
ui,
widget_id,
title_img_id,
}
}
fn ui_layout(&mut self) {
let mut ui_cell = self.ui.set_widgets();
ImageWidget::new(self.title_img_id)
.top_left()
.set(self.widget_id, &mut ui_cell);
}
pub fn handle_event(&mut self, event: ui::Event) {
self.ui.handle_event(event);
}
pub fn maintain(&mut self, renderer: &mut Renderer) {
self.ui_layout();
self.ui.maintain(renderer);
}
pub fn render(&self, renderer: &mut Renderer) {
self.ui.render(renderer);
}
}