mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Rebase and Login Error
Former-commit-id: 1865dd58d43ae0a7d78b61ca3a9684ca76fce02d
This commit is contained in:
parent
69c01a92a5
commit
93fedf3b86
@ -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
|
||||
|
@ -515,7 +515,6 @@ impl Hud {
|
||||
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\
|
||||
|
@ -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()))
|
||||
),
|
||||
|
@ -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::*;
|
||||
|
||||
@ -100,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,12 @@
|
||||
use crate::{
|
||||
DEFAULT_PUBLIC_SERVER,
|
||||
render::Renderer,
|
||||
ui::{self, ScaleMode, Ui},
|
||||
window::Window,
|
||||
};
|
||||
use common::assets;
|
||||
use conrod_core::{
|
||||
color,
|
||||
color::BLACK,
|
||||
color::TRANSPARENT,
|
||||
image::Id as ImgId,
|
||||
position::{Dimension, Relative},
|
||||
@ -23,8 +24,6 @@ widget_ids! {
|
||||
// Login, Singleplayer
|
||||
login_button,
|
||||
login_text,
|
||||
login_error,
|
||||
login_error_bg,
|
||||
address_text,
|
||||
address_bg,
|
||||
address_field,
|
||||
@ -39,6 +38,9 @@ widget_ids! {
|
||||
quit_button,
|
||||
// Error
|
||||
error_frame,
|
||||
button_ok,
|
||||
login_error,
|
||||
login_error_bg,
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,6 +59,9 @@ struct Imgs {
|
||||
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 {
|
||||
@ -90,6 +95,9 @@ impl Imgs {
|
||||
|
||||
//Error
|
||||
error_frame: load("element/frames/skin_eyes.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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -99,7 +107,6 @@ pub enum Event {
|
||||
username: String,
|
||||
server_address: String,
|
||||
},
|
||||
StartSingleplayer,
|
||||
Quit,
|
||||
}
|
||||
|
||||
@ -146,7 +153,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,
|
||||
}
|
||||
@ -181,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
|
||||
@ -227,22 +222,30 @@ impl MainMenuUi {
|
||||
.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, 60.0])
|
||||
|
||||
Rectangle::fill_with([200.0, 100.0], color::BLACK)
|
||||
.rgba(0.1, 0.1, 0.1, 1.0)
|
||||
.parent(ui_widgets.window)
|
||||
.mid_bottom_with_margin_on(self.ids.username_bg, 0.0)
|
||||
.up_from(self.ids.username_bg, 35.0)
|
||||
.set(self.ids.login_error_bg, ui_widgets);
|
||||
text.middle_of(self.ids.login_error_bg)
|
||||
text.mid_top_with_margin_on(self.ids.login_error_bg, 10.0)
|
||||
.set(self.ids.login_error, ui_widgets);
|
||||
Image::new(self.imgs.error_frame)
|
||||
.h(60.0)
|
||||
.middle_of(self.ids.login_error)
|
||||
.set(self.ids.error_frame, ui_widgets);
|
||||
}
|
||||
if Button::image(self.imgs.button_dark)
|
||||
.w_h(50.0, 30.0)
|
||||
.mid_top_with_margin_on(self.ids.login_error_bg, 20.0)
|
||||
.hover_image(self.imgs.button_dark_hover)
|
||||
.press_image(self.imgs.button_dark_press)
|
||||
.label("Ok")
|
||||
.label_font_size(10)
|
||||
.label_color(TEXT_COLOR)
|
||||
.set(self.ids.button_ok, ui_widgets)
|
||||
.was_clicked()
|
||||
{}
|
||||
};
|
||||
|
||||
// Server address
|
||||
Image::new(self.imgs.input_bg)
|
||||
.w_h(337.0, 67.0)
|
||||
@ -321,7 +324,7 @@ impl MainMenuUi {
|
||||
.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