From 40c2625a4cfbef124d4f337a0e7c0416b328f987 Mon Sep 17 00:00:00 2001 From: yeet Date: Thu, 18 Apr 2019 15:53:03 +0200 Subject: [PATCH] Fix Singleplayer After a certains person's MR has been merged, for some reason all traces of working Singleplayer have disappeared Former-commit-id: 4119e4609cd39bb1896c7f28d45f5c1a7ec9c129 --- voxygen/src/menu/char_selection/mod.rs | 10 ++++++++-- voxygen/src/menu/main/mod.rs | 6 +++++- voxygen/src/menu/main/ui.rs | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/voxygen/src/menu/char_selection/mod.rs b/voxygen/src/menu/char_selection/mod.rs index 3ba0130622..04504bb6c6 100644 --- a/voxygen/src/menu/char_selection/mod.rs +++ b/voxygen/src/menu/char_selection/mod.rs @@ -45,7 +45,10 @@ impl PlayState for CharSelectionState { // Handle window events for event in global_state.window.fetch_events() { match event { - Event::Close => return PlayStateResult::Shutdown, + Event::Close => { + global_state.singleplayer = None; + return PlayStateResult::Shutdown; + }, // Pass events to ui Event::Ui(event) => { self.char_selection_ui.handle_event(event); @@ -60,7 +63,10 @@ impl PlayState for CharSelectionState { // Maintain the UI for event in self.char_selection_ui.maintain(global_state.window.renderer_mut()) { match event { - ui::Event::Logout => return PlayStateResult::Pop, + ui::Event::Logout => { + global_state.singleplayer = None; + return PlayStateResult::Pop; + }, ui::Event::Play => return PlayStateResult::Push( Box::new(SessionState::new(&mut global_state.window, self.client.clone())) ), diff --git a/voxygen/src/menu/main/mod.rs b/voxygen/src/menu/main/mod.rs index 983a2d41b5..9b0247a775 100644 --- a/voxygen/src/menu/main/mod.rs +++ b/voxygen/src/menu/main/mod.rs @@ -5,6 +5,7 @@ use super::char_selection::CharSelectionState; use crate::{ window::{Event, Window}, GlobalState, PlayState, PlayStateResult, + singleplayer::Singleplayer, }; use client_init::{ClientInit, Error as InitError}; use common::{clock::Clock, comp}; @@ -101,7 +102,10 @@ impl PlayState for MainMenuState { 300, ), ))); - } + }, + MainMenuEvent::StartSingleplayer => { + global_state.singleplayer = Some(Singleplayer::new()); + }, MainMenuEvent::Quit => return PlayStateResult::Shutdown, } } diff --git a/voxygen/src/menu/main/ui.rs b/voxygen/src/menu/main/ui.rs index 798c386182..1a10e3ad14 100644 --- a/voxygen/src/menu/main/ui.rs +++ b/voxygen/src/menu/main/ui.rs @@ -107,6 +107,7 @@ pub enum Event { username: String, server_address: String, }, + StartSingleplayer, Quit, } @@ -189,6 +190,20 @@ impl MainMenuUi { }); }; } + + //Singleplayer + //Used when the singleplayer button is pressed + macro_rules! singleplayer { + () => { + self.login_error = None; + events.push(Event::StartSingleplayer); + events.push(Event::LoginAttempt { + username: "singleplayer".to_string(), + server_address: "localhost".to_string(), + }); + }; + } + const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0); // Username // TODO: get a lower resolution and cleaner input_bg.png @@ -327,6 +342,7 @@ impl MainMenuUi { .set(self.ids.singleplayer_button, ui_widgets) .was_clicked() { + singleplayer!(); login!(); } // Quit