mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'master' into 'master'
Login Error Window, Alpha Version Display directly pulled from Cargo, Help Window Corrections, Small Fixes See merge request veloren/veloren!46 Former-commit-id: 95e83944512ff30dbfbae59f247cf939d7eeb0cd
This commit is contained in:
commit
871d143855
@ -1,11 +1,10 @@
|
||||
use crate::ui::Ui;
|
||||
use conrod_core::{
|
||||
color,
|
||||
input::Key,
|
||||
position::Dimension,
|
||||
text::font::Id as FontId,
|
||||
widget::{Button, Id, List, Rectangle, Text, TextEdit},
|
||||
widget_ids, Colorable, Positionable, Sizeable, UiCell, Widget,
|
||||
widget_ids, Color, Colorable, Positionable, Sizeable, UiCell, Widget,
|
||||
};
|
||||
use std::collections::VecDeque;
|
||||
|
||||
@ -85,59 +84,48 @@ impl Chat {
|
||||
|
||||
// Chat input with rectangle as background
|
||||
let text_edit = TextEdit::new(&self.input)
|
||||
.w(460.0)
|
||||
.restrict_to_height(false)
|
||||
.line_spacing(2.0)
|
||||
.font_size(15)
|
||||
.font_id(font);
|
||||
let y = match text_edit.get_y_dimension(ui_widgets) {
|
||||
Dimension::Absolute(y) => y + 6.0,
|
||||
_ => 0.0,
|
||||
};
|
||||
Rectangle::fill([470.0, y])
|
||||
.rgba(0.0, 0.0, 0.0, 0.8)
|
||||
.bottom_left_with_margins_on(ui_widgets.window, 10.0, 10.0)
|
||||
.w(470.0)
|
||||
.restrict_to_height(false)
|
||||
.font_size(15)
|
||||
.font_id(font)
|
||||
.bottom_left_with_margins_on(ui_widgets.window, 10.0, 10.0);
|
||||
let dims = match (
|
||||
text_edit.get_x_dimension(ui_widgets),
|
||||
text_edit.get_y_dimension(ui_widgets),
|
||||
) {
|
||||
(Dimension::Absolute(x), Dimension::Absolute(y)) => [x, y],
|
||||
_ => [0.0, 0.0],
|
||||
};
|
||||
Rectangle::fill(dims)
|
||||
.rgba(0.0, 0.0, 0.0, 0.8)
|
||||
.x_position(text_edit.get_x_position(ui_widgets))
|
||||
.y_position(text_edit.get_y_position(ui_widgets))
|
||||
.set(self.ids.input_bg, ui_widgets);
|
||||
if let Some(str) = text_edit
|
||||
.top_left_with_margins_on(self.ids.input_bg, 1.0, 1.0)
|
||||
.set(self.ids.input, ui_widgets)
|
||||
{
|
||||
if let Some(str) = text_edit.set(self.ids.input, ui_widgets) {
|
||||
self.input = str.to_string();
|
||||
self.input.retain(|c| c != '\n');
|
||||
}
|
||||
|
||||
// Message box
|
||||
Rectangle::fill([470.0, 174.0])
|
||||
Rectangle::fill([470.0, 167.0])
|
||||
.rgba(0.0, 0.0, 0.0, 0.4)
|
||||
.up_from(self.ids.input_bg, 0.0)
|
||||
.up_from(self.ids.input, 0.0)
|
||||
.set(self.ids.message_box_bg, ui_widgets);
|
||||
let (mut items, _) = List::flow_down(self.messages.len() + 1)
|
||||
.top_left_of(self.ids.message_box_bg)
|
||||
.w_h(470.0, 174.0)
|
||||
.scroll_kids_vertically()
|
||||
let (mut items, scrollbar) = List::flow_down(self.messages.len())
|
||||
.top_left_with_margins_on(self.ids.message_box_bg, 0.0, 5.0)
|
||||
.w_h(460.0, 160.0)
|
||||
.scrollbar_next_to()
|
||||
.scrollbar_thickness(18.0)
|
||||
.scrollbar_color(Color::Rgba(0.0, 0.0, 0.0, 1.0))
|
||||
.set(self.ids.message_box, ui_widgets);
|
||||
while let Some(item) = items.next(ui_widgets) {
|
||||
// This would be easier if conrod used the v-metrics from rusttype
|
||||
let widget = if item.i < self.messages.len() {
|
||||
let text = Text::new(&self.messages[item.i])
|
||||
item.set(
|
||||
Text::new(&self.messages[item.i])
|
||||
.font_size(15)
|
||||
.font_id(font)
|
||||
.w(470.0)
|
||||
.rgba(1.0, 1.0, 1.0, 1.0)
|
||||
.line_spacing(2.0);
|
||||
// Add space between messages
|
||||
let y = match text.get_y_dimension(ui_widgets) {
|
||||
Dimension::Absolute(y) => y + 2.0,
|
||||
_ => 0.0,
|
||||
};
|
||||
text.h(y)
|
||||
} else {
|
||||
// Spacer at bottom of the last message so that it is not cut off
|
||||
// Needs to be larger than the space above
|
||||
Text::new("").font_size(6).font_id(font).w(470.0)
|
||||
};
|
||||
item.set(widget, ui_widgets);
|
||||
.rgba(1.0, 1.0, 1.0, 1.0),
|
||||
ui_widgets,
|
||||
)
|
||||
}
|
||||
|
||||
// Chat Arrow
|
||||
|
@ -20,6 +20,8 @@ widget_ids! {
|
||||
bag_space_add,
|
||||
inventorytest_button,
|
||||
inventorytest_button_label,
|
||||
// Logo
|
||||
v_logo,
|
||||
|
||||
// Bag and Inventory
|
||||
bag,
|
||||
@ -141,6 +143,8 @@ widget_ids! {
|
||||
// TODO: make macro to mimic widget_ids! for images ids or find another solution to simplify addition of new images.
|
||||
pub(self) struct Imgs {
|
||||
//Missing: ActionBar, Health/Mana/Energy Bar & Char Window BG/Frame
|
||||
//Logo
|
||||
v_logo: ImgId,
|
||||
// Bag
|
||||
bag: ImgId,
|
||||
bag_hover: ImgId,
|
||||
@ -326,6 +330,7 @@ impl Imgs {
|
||||
|
||||
// Window BG
|
||||
window_bg: load("element/misc_backgrounds/window_bg.png"),
|
||||
v_logo: load("element/v_logo.png"),
|
||||
|
||||
//Social Window
|
||||
social_bg: load("element/misc_backgrounds/small_bg.png"),
|
||||
@ -476,6 +481,7 @@ impl Hud {
|
||||
fn update_layout(&mut self) -> Vec<Event> {
|
||||
let mut events = Vec::new();
|
||||
let ref mut ui_widgets = self.ui.set_widgets();
|
||||
let version = env!("Cargo_PKG_VERSION");
|
||||
|
||||
const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0);
|
||||
const HP_COLOR: Color = Color::Rgba(0.33, 0.63, 0.0, 1.0);
|
||||
@ -505,17 +511,22 @@ impl Hud {
|
||||
{
|
||||
events.push(Event::SendMessage(msg));
|
||||
}
|
||||
// Alpha Version
|
||||
Text::new(version)
|
||||
.top_left_with_margins_on(ui_widgets.window, 5.0, 5.0)
|
||||
.font_size(14)
|
||||
.color(TEXT_COLOR)
|
||||
.set(self.ids.v_logo, ui_widgets);
|
||||
// Help Text
|
||||
if self.show_help {
|
||||
Image::new(self.imgs.window_frame_2)
|
||||
.top_left_with_margins_on(ui_widgets.window, 5.0, 5.0)
|
||||
.w_h(300.0, 370.0)
|
||||
.top_left_with_margins_on(ui_widgets.window, 3.0, 3.0)
|
||||
.w_h(300.0, 350.0)
|
||||
.set(self.ids.help_bg, ui_widgets);
|
||||
|
||||
Text::new(
|
||||
"Tab = Free Cursor \n\
|
||||
Esc = Open/Close Menus \n\
|
||||
Q = Back to Login \n\
|
||||
\n\
|
||||
F1 = Toggle this Window \n\
|
||||
F2 = Toggle Interface \n\
|
||||
@ -536,14 +547,12 @@ impl Hud {
|
||||
.font_id(self.font_opensans)
|
||||
.font_size(18)
|
||||
.set(self.ids.help, ui_widgets);
|
||||
if Button::image(self.imgs.button_dark)
|
||||
.w_h(50.0, 30.0)
|
||||
.bottom_right_with_margins_on(self.ids.help_bg, 10.0, 10.0)
|
||||
.hover_image(self.imgs.button_dark_hover)
|
||||
.press_image(self.imgs.button_dark_press)
|
||||
.label("Close")
|
||||
.label_font_size(10)
|
||||
.label_color(TEXT_COLOR)
|
||||
// X-button
|
||||
if Button::image(self.imgs.close_button)
|
||||
.w_h(244.0 * 0.22 / 3.0, 244.0 * 0.22 / 3.0)
|
||||
.hover_image(self.imgs.close_button_hover)
|
||||
.press_image(self.imgs.close_button_press)
|
||||
.top_right_with_margins_on(self.ids.help_bg, 8.0, 3.0)
|
||||
.set(self.ids.button_help2, ui_widgets)
|
||||
.was_clicked()
|
||||
{
|
||||
|
@ -45,10 +45,7 @@ impl PlayState for CharSelectionState {
|
||||
// Handle window events
|
||||
for event in global_state.window.fetch_events() {
|
||||
match event {
|
||||
Event::Close => {
|
||||
global_state.singleplayer = None;
|
||||
return PlayStateResult::Shutdown;
|
||||
},
|
||||
Event::Close => return PlayStateResult::Shutdown,
|
||||
// Pass events to ui
|
||||
Event::Ui(event) => {
|
||||
self.char_selection_ui.handle_event(event);
|
||||
@ -63,10 +60,7 @@ 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 => {
|
||||
global_state.singleplayer = None;
|
||||
return PlayStateResult::Pop;
|
||||
},
|
||||
ui::Event::Logout => return PlayStateResult::Pop,
|
||||
ui::Event::Play => return PlayStateResult::Push(
|
||||
Box::new(SessionState::new(&mut global_state.window, self.client.clone()))
|
||||
),
|
||||
|
@ -411,6 +411,7 @@ impl CharSelectionUi {
|
||||
fn update_layout(&mut self) -> Vec<Event> {
|
||||
let mut events = Vec::new();
|
||||
let ref mut ui_widgets = self.ui.set_widgets();
|
||||
let version = env!("Cargo_PKG_VERSION");
|
||||
|
||||
// Character Selection /////////////////
|
||||
// Supposed functionality:
|
||||
@ -475,7 +476,7 @@ impl CharSelectionUi {
|
||||
Button::image(self.imgs.v_logo)
|
||||
.w_h(346.0, 111.0)
|
||||
.top_left_with_margins_on(self.ids.bg_selection, 30.0, 40.0)
|
||||
.label("Alpha 0.1")
|
||||
.label(version)
|
||||
.label_rgba(1.0, 1.0, 1.0, 1.0)
|
||||
.label_font_size(10)
|
||||
.label_y(conrod_core::position::Relative::Scalar(-40.0))
|
||||
|
@ -22,10 +22,10 @@ pub struct ClientInit {
|
||||
impl ClientInit {
|
||||
pub fn new(
|
||||
connection_args: (String, u16, bool),
|
||||
client_args: (comp::Player, Option<comp::Character>, Option<comp::Animation>, u64),
|
||||
client_args: (comp::Player, Option<comp::Character>, u64),
|
||||
) -> Self {
|
||||
let (server_address, default_port, prefer_ipv6) = connection_args;
|
||||
let (player, character, animation, view_distance) = client_args;
|
||||
let (player, character, view_distance) = client_args;
|
||||
|
||||
let (tx, rx) = channel();
|
||||
|
||||
|
@ -5,12 +5,10 @@ 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};
|
||||
use std::time::Duration;
|
||||
use std::thread;
|
||||
use ui::{Event as MainMenuEvent, MainMenuUi};
|
||||
use vek::*;
|
||||
|
||||
@ -62,7 +60,7 @@ impl PlayState for MainMenuState {
|
||||
global_state.window.renderer_mut().clear(BG_COLOR);
|
||||
|
||||
// Poll client creation
|
||||
match client_init.as_ref().and_then(|init| init.poll()) {
|
||||
match client_init.as_ref().and_then(|init| init.poll()) {
|
||||
Some(Ok(client)) => {
|
||||
self.main_menu_ui.connected();
|
||||
return PlayStateResult::Push(Box::new(CharSelectionState::new(
|
||||
@ -72,11 +70,14 @@ impl PlayState for MainMenuState {
|
||||
}
|
||||
Some(Err(err)) => {
|
||||
client_init = None;
|
||||
self.main_menu_ui.login_error(match err {
|
||||
InitError::BadAddress(_) | InitError::NoAddress => "No such host is known",
|
||||
InitError::ConnectionFailed(_) => "Could not connect to address",
|
||||
}.to_string());
|
||||
},
|
||||
self.main_menu_ui.login_error(
|
||||
match err {
|
||||
InitError::BadAddress(_) | InitError::NoAddress => "Server not found",
|
||||
InitError::ConnectionFailed(_) => "Connection failed",
|
||||
}
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
@ -97,14 +98,10 @@ impl PlayState for MainMenuState {
|
||||
(
|
||||
comp::Player::new(username.clone()),
|
||||
Some(comp::Character::test()),
|
||||
Some(comp::Animation::Idle),
|
||||
300,
|
||||
),
|
||||
)));
|
||||
}
|
||||
MainMenuEvent::StartSingleplayer => {
|
||||
global_state.singleplayer = Some(Singleplayer::new());
|
||||
}
|
||||
MainMenuEvent::Quit => return PlayStateResult::Shutdown,
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
use crate::{
|
||||
DEFAULT_PUBLIC_SERVER,
|
||||
render::Renderer,
|
||||
ui::{self, ScaleMode, Ui},
|
||||
window::Window,
|
||||
};
|
||||
use common::assets;
|
||||
use conrod_core::{
|
||||
color,
|
||||
color::TRANSPARENT,
|
||||
image::Id as ImgId,
|
||||
position::{Dimension, Relative},
|
||||
@ -37,6 +37,9 @@ widget_ids! {
|
||||
servers_button,
|
||||
settings_button,
|
||||
quit_button,
|
||||
// Error
|
||||
error_frame,
|
||||
button_ok,
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,6 +56,11 @@ struct Imgs {
|
||||
button: ImgId,
|
||||
button_hover: ImgId,
|
||||
button_press: ImgId,
|
||||
|
||||
error_frame: ImgId,
|
||||
button_dark: ImgId,
|
||||
button_dark_hover: ImgId,
|
||||
button_dark_press: ImgId,
|
||||
}
|
||||
impl Imgs {
|
||||
fn new(ui: &mut Ui, renderer: &mut Renderer) -> Imgs {
|
||||
@ -83,6 +91,12 @@ impl Imgs {
|
||||
button: load("element/buttons/button.png"),
|
||||
button_hover: load("element/buttons/button_hover.png"),
|
||||
button_press: load("element/buttons/button_press.png"),
|
||||
|
||||
//Error
|
||||
error_frame: load("element/frames/window_2.png"),
|
||||
button_dark: load("element/buttons/button_dark.png"),
|
||||
button_dark_hover: load("element/buttons/button_dark_hover.png"),
|
||||
button_dark_press: load("element/buttons/button_dark_press.png"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -92,7 +106,6 @@ pub enum Event {
|
||||
username: String,
|
||||
server_address: String,
|
||||
},
|
||||
StartSingleplayer,
|
||||
Quit,
|
||||
}
|
||||
|
||||
@ -139,7 +152,7 @@ impl MainMenuUi {
|
||||
font_metamorph,
|
||||
font_opensans,
|
||||
username: "Username".to_string(),
|
||||
server_address: DEFAULT_PUBLIC_SERVER.to_string(),
|
||||
server_address: "veloren.mac94.de".to_string(),
|
||||
login_error: None,
|
||||
connecting: None,
|
||||
}
|
||||
@ -148,6 +161,7 @@ impl MainMenuUi {
|
||||
fn update_layout(&mut self) -> Vec<Event> {
|
||||
let mut events = Vec::new();
|
||||
let ref mut ui_widgets = self.ui.set_widgets();
|
||||
let version = env!("Cargo_PKG_VERSION");
|
||||
// Background image, Veloren logo, Alpha-Version Label
|
||||
Image::new(self.imgs.bg)
|
||||
.middle_of(ui_widgets.window)
|
||||
@ -155,7 +169,7 @@ impl MainMenuUi {
|
||||
Button::image(self.imgs.v_logo)
|
||||
.w_h(346.0, 111.0)
|
||||
.top_left_with_margins(30.0, 40.0)
|
||||
.label("Alpha 0.1")
|
||||
.label(version)
|
||||
.label_rgba(1.0, 1.0, 1.0, 1.0)
|
||||
.label_font_size(10)
|
||||
.label_y(Relative::Scalar(-40.0))
|
||||
@ -174,18 +188,6 @@ impl MainMenuUi {
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
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
|
||||
@ -217,20 +219,34 @@ impl MainMenuUi {
|
||||
// Login error
|
||||
if let Some(msg) = &self.login_error {
|
||||
let text = Text::new(&msg)
|
||||
.rgba(0.5, 0.0, 0.0, 1.0)
|
||||
.rgba(1.0, 1.0, 1.0, 1.0)
|
||||
.font_size(30)
|
||||
.font_id(self.font_opensans);
|
||||
let x = match text.get_x_dimension(ui_widgets) {
|
||||
Dimension::Absolute(x) => x + 10.0,
|
||||
_ => 0.0,
|
||||
};
|
||||
Rectangle::fill([x, 40.0])
|
||||
.rgba(0.2, 0.3, 0.3, 0.7)
|
||||
Rectangle::fill_with([400.0, 100.0], color::TRANSPARENT)
|
||||
.rgba(0.1, 0.1, 0.1, 1.0)
|
||||
.parent(ui_widgets.window)
|
||||
.up_from(self.ids.username_bg, 35.0)
|
||||
.mid_top_with_margin_on(self.ids.username_bg, -35.0)
|
||||
.set(self.ids.login_error_bg, ui_widgets);
|
||||
text.middle_of(self.ids.login_error_bg)
|
||||
Image::new(self.imgs.error_frame)
|
||||
.w_h(400.0, 100.0)
|
||||
.middle_of(self.ids.login_error_bg)
|
||||
.set(self.ids.error_frame, ui_widgets);
|
||||
text.mid_top_with_margin_on(self.ids.error_frame, 10.0)
|
||||
.set(self.ids.login_error, ui_widgets);
|
||||
if Button::image(self.imgs.button_dark)
|
||||
.w_h(100.0, 30.0)
|
||||
.mid_bottom_with_margin_on(self.ids.login_error_bg, 5.0)
|
||||
.hover_image(self.imgs.button_dark_hover)
|
||||
.press_image(self.imgs.button_dark_press)
|
||||
.label_y(Relative::Scalar(2.0))
|
||||
.label("Okay")
|
||||
.label_font_size(10)
|
||||
.label_color(TEXT_COLOR)
|
||||
.set(self.ids.button_ok, ui_widgets)
|
||||
.was_clicked()
|
||||
{
|
||||
self.login_error = None
|
||||
};
|
||||
}
|
||||
// Server address
|
||||
Image::new(self.imgs.input_bg)
|
||||
@ -304,13 +320,13 @@ impl MainMenuUi {
|
||||
.align_middle_x_of(self.ids.address_bg)
|
||||
.label("Singleplayer")
|
||||
.label_color(TEXT_COLOR)
|
||||
.label_font_size(26)
|
||||
.label_font_size(24)
|
||||
.label_y(Relative::Scalar(5.0))
|
||||
.label_x(Relative::Scalar(2.0))
|
||||
.set(self.ids.singleplayer_button, ui_widgets)
|
||||
.was_clicked()
|
||||
{
|
||||
singleplayer!();
|
||||
login!();
|
||||
}
|
||||
// Quit
|
||||
if Button::image(self.imgs.button)
|
||||
|
Loading…
Reference in New Issue
Block a user