2019-03-15 04:55:52 +00:00
|
|
|
use crate::{
|
|
|
|
render::Renderer,
|
2019-03-22 03:55:42 +00:00
|
|
|
ui::{self, ScaleMode, Ui},
|
2019-03-15 04:55:52 +00:00
|
|
|
window::Window,
|
2019-04-20 16:21:12 +00:00
|
|
|
GlobalState, DEFAULT_PUBLIC_SERVER,
|
2019-04-19 18:14:00 +00:00
|
|
|
};
|
2019-04-20 16:21:12 +00:00
|
|
|
use common::{assets, figure::Segment};
|
2019-03-04 07:28:16 +00:00
|
|
|
use conrod_core::{
|
2019-04-17 17:41:22 +00:00
|
|
|
color,
|
2019-03-15 04:55:52 +00:00
|
|
|
color::TRANSPARENT,
|
2019-03-04 07:28:16 +00:00
|
|
|
image::Id as ImgId,
|
2019-04-14 23:28:29 +00:00
|
|
|
position::{Dimension, Relative},
|
2019-03-04 07:28:16 +00:00
|
|
|
text::font::Id as FontId,
|
2019-04-20 16:21:12 +00:00
|
|
|
widget::{text_box::Event as TextBoxEvent, Button, Image, List, Rectangle, Text, TextBox},
|
2019-04-04 13:49:31 +00:00
|
|
|
widget_ids, Borderable, Color, Colorable, Labelable, Positionable, Sizeable, Widget,
|
2019-03-04 07:28:16 +00:00
|
|
|
};
|
|
|
|
|
2019-03-15 04:55:52 +00:00
|
|
|
widget_ids! {
|
2019-03-04 07:28:16 +00:00
|
|
|
struct Ids {
|
|
|
|
// Background and logo
|
|
|
|
bg,
|
|
|
|
v_logo,
|
2019-03-15 04:55:52 +00:00
|
|
|
alpha_version,
|
|
|
|
// Login, Singleplayer
|
2019-03-04 07:28:16 +00:00
|
|
|
login_button,
|
|
|
|
login_text,
|
2019-04-17 20:38:52 +00:00
|
|
|
login_error,
|
|
|
|
login_error_bg,
|
2019-03-04 07:28:16 +00:00
|
|
|
address_text,
|
|
|
|
address_bg,
|
|
|
|
address_field,
|
|
|
|
username_text,
|
|
|
|
username_bg,
|
|
|
|
username_field,
|
2019-03-15 04:55:52 +00:00
|
|
|
singleplayer_button,
|
|
|
|
singleplayer_text,
|
2019-04-19 11:14:05 +00:00
|
|
|
// Serverlist
|
2019-03-04 07:28:16 +00:00
|
|
|
servers_button,
|
2019-04-19 11:14:05 +00:00
|
|
|
servers_frame,
|
|
|
|
servers_text,
|
|
|
|
servers_close,
|
|
|
|
// Buttons
|
2019-03-04 07:28:16 +00:00
|
|
|
settings_button,
|
|
|
|
quit_button,
|
2019-04-15 20:51:32 +00:00
|
|
|
// Error
|
|
|
|
error_frame,
|
2019-04-17 17:41:22 +00:00
|
|
|
button_ok,
|
2019-04-24 19:55:22 +00:00
|
|
|
version,
|
2019-03-04 07:28:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Imgs {
|
|
|
|
bg: ImgId,
|
|
|
|
v_logo: ImgId,
|
|
|
|
|
|
|
|
input_bg: ImgId,
|
|
|
|
|
2019-04-15 20:51:32 +00:00
|
|
|
error_frame: ImgId,
|
2019-04-17 17:41:22 +00:00
|
|
|
button_dark: ImgId,
|
|
|
|
button_dark_hover: ImgId,
|
|
|
|
button_dark_press: ImgId,
|
2019-04-24 19:55:22 +00:00
|
|
|
button: ImgId,
|
|
|
|
button_hover: ImgId,
|
|
|
|
button_press: ImgId,
|
2019-03-04 07:28:16 +00:00
|
|
|
}
|
|
|
|
impl Imgs {
|
|
|
|
fn new(ui: &mut Ui, renderer: &mut Renderer) -> Imgs {
|
2019-04-20 22:02:48 +00:00
|
|
|
let load_img = |filename, ui: &mut Ui| {
|
2019-04-04 13:49:31 +00:00
|
|
|
let fullpath: String = ["/voxygen/", filename].concat();
|
2019-04-13 01:40:59 +00:00
|
|
|
let image = image::load_from_memory(
|
2019-04-04 13:49:31 +00:00
|
|
|
assets::load(fullpath.as_str())
|
|
|
|
.expect("Error loading file")
|
|
|
|
.as_slice(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2019-04-15 06:07:56 +00:00
|
|
|
ui.new_graphic(ui::Graphic::Image(image))
|
2019-03-04 07:28:16 +00:00
|
|
|
};
|
2019-04-20 22:02:48 +00:00
|
|
|
let load_vox = |filename, ui: &mut Ui| {
|
2019-04-20 01:35:12 +00:00
|
|
|
let fullpath: String = ["/voxygen/", filename].concat();
|
|
|
|
let dot_vox = dot_vox::load_bytes(
|
|
|
|
assets::load(fullpath.as_str())
|
|
|
|
.expect("Error loading file")
|
|
|
|
.as_slice(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
ui.new_graphic(ui::Graphic::Voxel(Segment::from(dot_vox)))
|
|
|
|
};
|
2019-03-04 07:28:16 +00:00
|
|
|
Imgs {
|
2019-04-20 01:35:12 +00:00
|
|
|
bg: load_img("background/bg_main.png", ui),
|
2019-04-24 19:55:22 +00:00
|
|
|
v_logo: load_vox("element/v_logo.vox", ui),
|
2019-03-04 07:28:16 +00:00
|
|
|
|
|
|
|
// Input fields
|
2019-04-24 19:55:22 +00:00
|
|
|
input_bg: load_vox("element/misc_bg/textbox.vox", ui),
|
2019-03-04 07:28:16 +00:00
|
|
|
|
2019-04-20 01:35:12 +00:00
|
|
|
error_frame: load_img("element/frames/window_2.png", ui),
|
2019-04-24 19:55:22 +00:00
|
|
|
button_dark: load_vox("element/buttons/button_dark.vox", ui),
|
|
|
|
button_dark_hover: load_vox("element/buttons/button_dark_hover.vox", ui),
|
|
|
|
button_dark_press: load_vox("element/buttons/button_dark_press.vox", ui),
|
|
|
|
button: load_vox("element/buttons/button.vox", ui),
|
|
|
|
button_hover: load_vox("element/buttons/button_hover.vox", ui),
|
|
|
|
button_press: load_vox("element/buttons/button_press.vox", ui),
|
2019-03-04 07:28:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-17 17:52:54 +00:00
|
|
|
pub enum Event {
|
|
|
|
LoginAttempt {
|
|
|
|
username: String,
|
|
|
|
server_address: String,
|
|
|
|
},
|
2019-04-18 13:53:03 +00:00
|
|
|
StartSingleplayer,
|
2019-03-17 17:52:54 +00:00
|
|
|
Quit,
|
|
|
|
}
|
|
|
|
|
2019-03-04 07:28:16 +00:00
|
|
|
pub struct MainMenuUi {
|
|
|
|
ui: Ui,
|
|
|
|
ids: Ids,
|
|
|
|
imgs: Imgs,
|
2019-03-15 04:55:52 +00:00
|
|
|
font_metamorph: FontId,
|
2019-03-28 02:25:08 +00:00
|
|
|
font_opensans: FontId,
|
2019-03-15 04:55:52 +00:00
|
|
|
username: String,
|
2019-03-04 07:28:16 +00:00
|
|
|
server_address: String,
|
2019-04-04 14:45:57 +00:00
|
|
|
login_error: Option<String>,
|
2019-04-14 23:28:29 +00:00
|
|
|
connecting: Option<std::time::Instant>,
|
2019-04-19 11:14:05 +00:00
|
|
|
show_servers: bool,
|
2019-03-04 07:28:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl MainMenuUi {
|
2019-04-18 17:40:29 +00:00
|
|
|
pub fn new(global_state: &mut GlobalState) -> Self {
|
|
|
|
let mut window = &mut global_state.window;
|
|
|
|
let networking = &global_state.settings.networking;
|
2019-03-04 07:28:16 +00:00
|
|
|
let mut ui = Ui::new(window).unwrap();
|
|
|
|
// TODO: adjust/remove this, right now it is used to demonstrate window scaling functionality
|
|
|
|
ui.scaling_mode(ScaleMode::RelativeToWindow([1920.0, 1080.0].into()));
|
|
|
|
// Generate ids
|
|
|
|
let ids = Ids::new(ui.id_generator());
|
|
|
|
// Load images
|
|
|
|
let imgs = Imgs::new(&mut ui, window.renderer_mut());
|
2019-03-15 04:55:52 +00:00
|
|
|
// Load fonts
|
2019-04-20 22:02:48 +00:00
|
|
|
let load_font = |filename, ui: &mut Ui| {
|
|
|
|
let fullpath: String = ["/voxygen/font", filename].concat();
|
2019-04-25 08:45:01 +00:00
|
|
|
ui.new_font(
|
|
|
|
conrod_core::text::Font::from_bytes(
|
|
|
|
assets::load(fullpath.as_str()).expect("Error loading file"),
|
|
|
|
)
|
|
|
|
.unwrap(),
|
|
|
|
)
|
2019-04-20 22:02:48 +00:00
|
|
|
};
|
|
|
|
let font_opensans = load_font("/OpenSans-Regular.ttf", &mut ui);
|
|
|
|
let font_metamorph = load_font("/Metamorphous-Regular.ttf", &mut ui);
|
|
|
|
|
2019-03-04 07:28:16 +00:00
|
|
|
Self {
|
|
|
|
ui,
|
|
|
|
imgs,
|
|
|
|
ids,
|
2019-03-15 04:55:52 +00:00
|
|
|
font_metamorph,
|
2019-03-28 02:25:08 +00:00
|
|
|
font_opensans,
|
2019-04-18 17:40:29 +00:00
|
|
|
username: networking.username.clone(),
|
2019-04-25 08:45:01 +00:00
|
|
|
server_address: networking.servers[networking.default_server].clone(),
|
2019-04-04 14:45:57 +00:00
|
|
|
login_error: None,
|
2019-04-14 23:28:29 +00:00
|
|
|
connecting: None,
|
2019-04-19 11:14:05 +00:00
|
|
|
show_servers: false,
|
2019-03-04 07:28:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-19 11:14:05 +00:00
|
|
|
fn update_layout(&mut self, global_state: &GlobalState) -> Vec<Event> {
|
2019-03-17 17:52:54 +00:00
|
|
|
let mut events = Vec::new();
|
2019-03-04 07:28:16 +00:00
|
|
|
let ref mut ui_widgets = self.ui.set_widgets();
|
2019-04-18 13:21:25 +00:00
|
|
|
let version = env!("CARGO_PKG_VERSION");
|
2019-03-15 04:55:52 +00:00
|
|
|
// Background image, Veloren logo, Alpha-Version Label
|
|
|
|
Image::new(self.imgs.bg)
|
|
|
|
.middle_of(ui_widgets.window)
|
|
|
|
.set(self.ids.bg, ui_widgets);
|
2019-04-24 19:55:22 +00:00
|
|
|
Image::new(self.imgs.v_logo)
|
|
|
|
.w_h(123.0*3.0, 35.0*3.0)
|
|
|
|
.top_left_with_margins(30.0, 30.0)
|
2019-03-04 07:28:16 +00:00
|
|
|
.set(self.ids.v_logo, ui_widgets);
|
2019-04-24 19:55:22 +00:00
|
|
|
Text::new(version)
|
2019-04-27 20:55:30 +00:00
|
|
|
.top_left_with_margins_on(ui_widgets.window, 5.0, 5.0)
|
|
|
|
.font_size(14)
|
|
|
|
.color(TEXT_COLOR)
|
|
|
|
.set(self.ids.version, ui_widgets);
|
|
|
|
|
2019-03-04 07:28:16 +00:00
|
|
|
// Input fields
|
|
|
|
// Used when the login button is pressed, or enter is pressed within input field
|
|
|
|
macro_rules! login {
|
|
|
|
() => {
|
2019-04-04 14:45:57 +00:00
|
|
|
self.login_error = None;
|
2019-04-14 23:28:29 +00:00
|
|
|
self.connecting = Some(std::time::Instant::now());
|
2019-03-17 17:52:54 +00:00
|
|
|
events.push(Event::LoginAttempt {
|
|
|
|
username: self.username.clone(),
|
|
|
|
server_address: self.server_address.clone(),
|
|
|
|
});
|
2019-03-15 04:55:52 +00:00
|
|
|
};
|
2019-03-04 07:28:16 +00:00
|
|
|
}
|
2019-04-18 13:53:03 +00:00
|
|
|
|
|
|
|
//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(),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-04-10 20:23:49 +00:00
|
|
|
const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0);
|
2019-03-04 07:28:16 +00:00
|
|
|
// Username
|
|
|
|
// TODO: get a lower resolution and cleaner input_bg.png
|
|
|
|
Image::new(self.imgs.input_bg)
|
2019-03-15 04:55:52 +00:00
|
|
|
.w_h(337.0, 67.0)
|
2019-03-04 07:28:16 +00:00
|
|
|
.middle_of(ui_widgets.window)
|
|
|
|
.set(self.ids.username_bg, ui_widgets);
|
|
|
|
for event in TextBox::new(&self.username)
|
2019-03-15 04:55:52 +00:00
|
|
|
.w_h(580.0 / 2.0, 60.0 / 2.0)
|
|
|
|
.mid_bottom_with_margin_on(self.ids.username_bg, 44.0 / 2.0)
|
2019-03-04 07:28:16 +00:00
|
|
|
.font_size(20)
|
2019-03-28 02:25:08 +00:00
|
|
|
.font_id(self.font_opensans)
|
2019-04-09 16:30:13 +00:00
|
|
|
.text_color(TEXT_COLOR)
|
2019-03-04 07:28:16 +00:00
|
|
|
// transparent background
|
|
|
|
.color(TRANSPARENT)
|
|
|
|
.border_color(TRANSPARENT)
|
|
|
|
.set(self.ids.username_field, ui_widgets)
|
2019-03-15 04:55:52 +00:00
|
|
|
{
|
|
|
|
match event {
|
|
|
|
TextBoxEvent::Update(username) => {
|
|
|
|
// Note: TextBox limits the input string length to what fits in it
|
|
|
|
self.username = username.to_string();
|
2019-03-04 07:28:16 +00:00
|
|
|
}
|
2019-04-04 13:49:31 +00:00
|
|
|
TextBoxEvent::Enter => {
|
|
|
|
login!();
|
|
|
|
}
|
2019-03-04 07:28:16 +00:00
|
|
|
}
|
2019-03-15 04:55:52 +00:00
|
|
|
}
|
2019-04-04 14:45:57 +00:00
|
|
|
// Login error
|
|
|
|
if let Some(msg) = &self.login_error {
|
|
|
|
let text = Text::new(&msg)
|
2019-04-15 20:51:32 +00:00
|
|
|
.rgba(1.0, 1.0, 1.0, 1.0)
|
2019-04-04 14:45:57 +00:00
|
|
|
.font_size(30)
|
|
|
|
.font_id(self.font_opensans);
|
2019-04-17 20:38:52 +00:00
|
|
|
Rectangle::fill_with([400.0, 100.0], color::TRANSPARENT)
|
2019-04-15 20:51:32 +00:00
|
|
|
.rgba(0.1, 0.1, 0.1, 1.0)
|
2019-04-04 14:45:57 +00:00
|
|
|
.parent(ui_widgets.window)
|
2019-04-17 20:38:52 +00:00
|
|
|
.mid_top_with_margin_on(self.ids.username_bg, -35.0)
|
2019-04-04 14:45:57 +00:00
|
|
|
.set(self.ids.login_error_bg, ui_widgets);
|
2019-04-15 20:51:32 +00:00
|
|
|
Image::new(self.imgs.error_frame)
|
2019-04-17 20:38:52 +00:00
|
|
|
.w_h(400.0, 100.0)
|
|
|
|
.middle_of(self.ids.login_error_bg)
|
2019-04-15 20:51:32 +00:00
|
|
|
.set(self.ids.error_frame, ui_widgets);
|
2019-04-17 20:38:52 +00:00
|
|
|
text.mid_top_with_margin_on(self.ids.error_frame, 10.0)
|
|
|
|
.set(self.ids.login_error, ui_widgets);
|
2019-04-17 17:41:22 +00:00
|
|
|
if Button::image(self.imgs.button_dark)
|
2019-04-17 20:38:52 +00:00
|
|
|
.w_h(100.0, 30.0)
|
|
|
|
.mid_bottom_with_margin_on(self.ids.login_error_bg, 5.0)
|
2019-04-17 17:41:22 +00:00
|
|
|
.hover_image(self.imgs.button_dark_hover)
|
|
|
|
.press_image(self.imgs.button_dark_press)
|
2019-04-17 20:38:52 +00:00
|
|
|
.label_y(Relative::Scalar(2.0))
|
|
|
|
.label("Okay")
|
2019-04-17 17:41:22 +00:00
|
|
|
.label_font_size(10)
|
|
|
|
.label_color(TEXT_COLOR)
|
|
|
|
.set(self.ids.button_ok, ui_widgets)
|
|
|
|
.was_clicked()
|
2019-04-17 20:38:52 +00:00
|
|
|
{
|
|
|
|
self.login_error = None
|
|
|
|
};
|
|
|
|
}
|
2019-04-19 11:14:05 +00:00
|
|
|
if self.show_servers {
|
|
|
|
Image::new(self.imgs.error_frame)
|
|
|
|
.top_left_with_margins_on(ui_widgets.window, 3.0, 3.0)
|
2019-04-19 17:15:47 +00:00
|
|
|
.w_h(400.0, 400.0)
|
2019-04-19 11:14:05 +00:00
|
|
|
.set(self.ids.servers_frame, ui_widgets);
|
2019-04-19 15:27:37 +00:00
|
|
|
|
|
|
|
let netsettings = &global_state.settings.networking;
|
|
|
|
|
|
|
|
let (mut items, scrollbar) = List::flow_down(netsettings.servers.len())
|
|
|
|
.top_left_with_margins_on(self.ids.servers_frame, 0.0, 5.0)
|
|
|
|
.w_h(400.0, 300.0)
|
|
|
|
.scrollbar_next_to()
|
|
|
|
.scrollbar_thickness(18.0)
|
|
|
|
.scrollbar_color(TEXT_COLOR)
|
2019-04-19 11:14:05 +00:00
|
|
|
.set(self.ids.servers_text, ui_widgets);
|
|
|
|
|
2019-04-19 15:27:37 +00:00
|
|
|
while let Some(item) = items.next(ui_widgets) {
|
|
|
|
let mut text = "".to_string();
|
2019-04-20 16:21:12 +00:00
|
|
|
if &netsettings.servers[item.i] == &self.server_address {
|
|
|
|
text.push_str("* ")
|
|
|
|
} else {
|
|
|
|
text.push_str(" ")
|
|
|
|
}
|
2019-04-19 15:27:37 +00:00
|
|
|
text.push_str(&netsettings.servers[item.i]);
|
|
|
|
|
2019-04-20 16:21:12 +00:00
|
|
|
if item
|
|
|
|
.set(
|
|
|
|
Button::image(self.imgs.button_dark)
|
|
|
|
.w_h(100.0, 53.0)
|
|
|
|
.mid_bottom_with_margin_on(self.ids.servers_frame, 5.0)
|
|
|
|
.hover_image(self.imgs.button_dark_hover)
|
|
|
|
.press_image(self.imgs.button_dark_press)
|
|
|
|
.label_y(Relative::Scalar(2.0))
|
|
|
|
.label(&text)
|
|
|
|
.label_font_size(20)
|
|
|
|
.label_color(TEXT_COLOR),
|
|
|
|
ui_widgets,
|
|
|
|
)
|
|
|
|
.was_clicked()
|
|
|
|
{
|
2019-04-19 15:27:37 +00:00
|
|
|
// TODO: Set as current server address
|
|
|
|
self.server_address = netsettings.servers[item.i].clone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-19 11:14:05 +00:00
|
|
|
if Button::image(self.imgs.button_dark)
|
2019-04-19 17:15:47 +00:00
|
|
|
.w_h(200.0, 53.0)
|
2019-04-19 11:14:05 +00:00
|
|
|
.mid_bottom_with_margin_on(self.ids.servers_frame, 5.0)
|
|
|
|
.hover_image(self.imgs.button_dark_hover)
|
|
|
|
.press_image(self.imgs.button_dark_press)
|
|
|
|
.label_y(Relative::Scalar(2.0))
|
|
|
|
.label("Close")
|
2019-04-19 17:15:47 +00:00
|
|
|
.label_font_size(20)
|
2019-04-19 11:14:05 +00:00
|
|
|
.label_color(TEXT_COLOR)
|
|
|
|
.set(self.ids.servers_close, ui_widgets)
|
|
|
|
.was_clicked()
|
|
|
|
{
|
|
|
|
self.show_servers = false
|
|
|
|
};
|
|
|
|
}
|
2019-03-04 07:28:16 +00:00
|
|
|
// Server address
|
|
|
|
Image::new(self.imgs.input_bg)
|
2019-03-15 04:55:52 +00:00
|
|
|
.w_h(337.0, 67.0)
|
|
|
|
.down_from(self.ids.username_bg, 10.0)
|
2019-03-04 07:28:16 +00:00
|
|
|
.set(self.ids.address_bg, ui_widgets);
|
|
|
|
for event in TextBox::new(&self.server_address)
|
2019-03-15 04:55:52 +00:00
|
|
|
.w_h(580.0 / 2.0, 60.0 / 2.0)
|
|
|
|
.mid_bottom_with_margin_on(self.ids.address_bg, 44.0 / 2.0)
|
2019-03-04 07:28:16 +00:00
|
|
|
.font_size(20)
|
2019-03-28 02:25:08 +00:00
|
|
|
.font_id(self.font_opensans)
|
2019-04-09 16:30:13 +00:00
|
|
|
.text_color(TEXT_COLOR)
|
2019-03-04 07:28:16 +00:00
|
|
|
// transparent background
|
|
|
|
.color(TRANSPARENT)
|
|
|
|
.border_color(TRANSPARENT)
|
|
|
|
.set(self.ids.address_field, ui_widgets)
|
2019-03-15 04:55:52 +00:00
|
|
|
{
|
|
|
|
match event {
|
|
|
|
TextBoxEvent::Update(server_address) => {
|
|
|
|
self.server_address = server_address.to_string();
|
2019-03-04 07:28:16 +00:00
|
|
|
}
|
2019-04-04 13:49:31 +00:00
|
|
|
TextBoxEvent::Enter => {
|
|
|
|
login!();
|
|
|
|
}
|
2019-03-04 07:28:16 +00:00
|
|
|
}
|
2019-03-15 04:55:52 +00:00
|
|
|
}
|
2019-03-04 07:28:16 +00:00
|
|
|
// Login button
|
2019-04-14 23:28:29 +00:00
|
|
|
// Change button text and remove hover/press images if a connection is in progress
|
|
|
|
if let Some(start) = self.connecting {
|
2019-04-24 19:55:22 +00:00
|
|
|
Button::image(self.imgs.button)
|
2019-04-14 23:28:29 +00:00
|
|
|
.w_h(258.0, 68.0)
|
|
|
|
.down_from(self.ids.address_bg, 20.0)
|
|
|
|
.align_middle_x_of(self.ids.address_bg)
|
|
|
|
.label("Connecting...")
|
|
|
|
.label_color({
|
|
|
|
let pulse = ((start.elapsed().as_millis() as f32 * 0.008).sin() + 1.0) / 2.0;
|
|
|
|
Color::Rgba(
|
|
|
|
TEXT_COLOR.red() * (pulse / 2.0 + 0.5),
|
|
|
|
TEXT_COLOR.green() * (pulse / 2.0 + 0.5),
|
|
|
|
TEXT_COLOR.blue() * (pulse / 2.0 + 0.5),
|
|
|
|
pulse / 4.0 + 0.75,
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.label_font_size(24)
|
|
|
|
.label_y(Relative::Scalar(5.0))
|
|
|
|
.set(self.ids.login_button, ui_widgets);
|
|
|
|
} else {
|
2019-04-24 19:55:22 +00:00
|
|
|
if Button::image(self.imgs.button)
|
|
|
|
.hover_image(self.imgs.button_hover)
|
|
|
|
.press_image(self.imgs.button_press)
|
2019-04-14 23:28:29 +00:00
|
|
|
.w_h(258.0, 68.0)
|
|
|
|
.down_from(self.ids.address_bg, 20.0)
|
|
|
|
.align_middle_x_of(self.ids.address_bg)
|
|
|
|
.label("Login")
|
|
|
|
.label_color(TEXT_COLOR)
|
|
|
|
.label_font_size(24)
|
|
|
|
.label_y(Relative::Scalar(5.0))
|
|
|
|
.set(self.ids.login_button, ui_widgets)
|
|
|
|
.was_clicked()
|
|
|
|
{
|
|
|
|
login!();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-04 14:45:57 +00:00
|
|
|
// Singleplayer button
|
2019-04-27 20:55:30 +00:00
|
|
|
if Button::image(self.imgs.button)
|
2019-04-24 19:55:22 +00:00
|
|
|
.hover_image(self.imgs.button_hover)
|
|
|
|
.press_image(self.imgs.button_press)
|
2019-03-15 04:55:52 +00:00
|
|
|
.w_h(258.0, 68.0)
|
|
|
|
.down_from(self.ids.login_button, 20.0)
|
|
|
|
.align_middle_x_of(self.ids.address_bg)
|
|
|
|
.label("Singleplayer")
|
2019-04-09 16:30:13 +00:00
|
|
|
.label_color(TEXT_COLOR)
|
2019-04-17 20:38:52 +00:00
|
|
|
.label_font_size(24)
|
2019-04-14 23:28:29 +00:00
|
|
|
.label_y(Relative::Scalar(5.0))
|
|
|
|
.label_x(Relative::Scalar(2.0))
|
2019-03-15 04:55:52 +00:00
|
|
|
.set(self.ids.singleplayer_button, ui_widgets)
|
|
|
|
.was_clicked()
|
|
|
|
{
|
2019-04-18 13:53:03 +00:00
|
|
|
singleplayer!();
|
2019-03-15 04:55:52 +00:00
|
|
|
}
|
2019-03-04 07:28:16 +00:00
|
|
|
// Quit
|
2019-03-15 04:55:52 +00:00
|
|
|
if Button::image(self.imgs.button)
|
2019-03-04 07:28:16 +00:00
|
|
|
.w_h(203.0, 53.0)
|
|
|
|
.bottom_left_with_margins_on(ui_widgets.window, 60.0, 30.0)
|
|
|
|
.hover_image(self.imgs.button_hover)
|
|
|
|
.press_image(self.imgs.button_press)
|
2019-03-15 04:55:52 +00:00
|
|
|
.label("Quit")
|
2019-04-09 16:30:13 +00:00
|
|
|
.label_color(TEXT_COLOR)
|
2019-03-15 04:55:52 +00:00
|
|
|
.label_font_size(20)
|
2019-04-14 23:28:29 +00:00
|
|
|
.label_y(Relative::Scalar(3.0))
|
2019-03-15 04:55:52 +00:00
|
|
|
.set(self.ids.quit_button, ui_widgets)
|
|
|
|
.was_clicked()
|
|
|
|
{
|
2019-03-17 17:52:54 +00:00
|
|
|
events.push(Event::Quit);
|
2019-03-15 04:55:52 +00:00
|
|
|
};
|
2019-03-04 07:28:16 +00:00
|
|
|
// Settings
|
2019-03-15 04:55:52 +00:00
|
|
|
if Button::image(self.imgs.button)
|
2019-03-04 07:28:16 +00:00
|
|
|
.w_h(203.0, 53.0)
|
|
|
|
.up_from(self.ids.quit_button, 8.0)
|
|
|
|
.hover_image(self.imgs.button_hover)
|
|
|
|
.press_image(self.imgs.button_press)
|
2019-03-15 04:55:52 +00:00
|
|
|
.label("Settings")
|
2019-04-09 16:30:13 +00:00
|
|
|
.label_color(TEXT_COLOR)
|
2019-03-15 04:55:52 +00:00
|
|
|
.label_font_size(20)
|
2019-04-14 23:28:29 +00:00
|
|
|
.label_y(Relative::Scalar(3.0))
|
2019-03-15 04:55:52 +00:00
|
|
|
.set(self.ids.settings_button, ui_widgets)
|
|
|
|
.was_clicked()
|
|
|
|
{};
|
2019-03-04 07:28:16 +00:00
|
|
|
// Servers
|
2019-03-15 04:55:52 +00:00
|
|
|
if Button::image(self.imgs.button)
|
2019-03-04 07:28:16 +00:00
|
|
|
.w_h(203.0, 53.0)
|
|
|
|
.up_from(self.ids.settings_button, 8.0)
|
|
|
|
.hover_image(self.imgs.button_hover)
|
|
|
|
.press_image(self.imgs.button_press)
|
2019-03-15 04:55:52 +00:00
|
|
|
.label("Servers")
|
2019-04-09 16:30:13 +00:00
|
|
|
.label_color(TEXT_COLOR)
|
2019-03-15 04:55:52 +00:00
|
|
|
.label_font_size(20)
|
2019-04-14 23:28:29 +00:00
|
|
|
.label_y(Relative::Scalar(3.0))
|
2019-03-15 04:55:52 +00:00
|
|
|
.set(self.ids.servers_button, ui_widgets)
|
|
|
|
.was_clicked()
|
2019-04-19 11:14:05 +00:00
|
|
|
{
|
|
|
|
self.show_servers = true;
|
|
|
|
};
|
2019-03-17 17:52:54 +00:00
|
|
|
|
|
|
|
events
|
2019-03-04 07:28:16 +00:00
|
|
|
}
|
|
|
|
|
2019-04-04 14:45:57 +00:00
|
|
|
pub fn login_error(&mut self, msg: String) {
|
|
|
|
self.login_error = Some(msg);
|
2019-04-14 23:28:29 +00:00
|
|
|
self.connecting = None;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn connected(&mut self) {
|
|
|
|
self.connecting = None;
|
2019-04-04 14:45:57 +00:00
|
|
|
}
|
|
|
|
|
2019-03-22 03:55:42 +00:00
|
|
|
pub fn handle_event(&mut self, event: ui::Event) {
|
|
|
|
self.ui.handle_event(event);
|
2019-03-04 07:28:16 +00:00
|
|
|
}
|
|
|
|
|
2019-04-19 11:14:05 +00:00
|
|
|
pub fn maintain(&mut self, global_state: &mut GlobalState) -> Vec<Event> {
|
|
|
|
let events = self.update_layout(global_state);
|
|
|
|
self.ui.maintain(global_state.window.renderer_mut());
|
2019-03-17 17:52:54 +00:00
|
|
|
events
|
2019-03-04 07:28:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn render(&self, renderer: &mut Renderer) {
|
|
|
|
self.ui.render(renderer);
|
|
|
|
}
|
|
|
|
}
|