mirror of
https://github.com/szymon-jozef/checkers.git
synced 2026-10-27 19:20:44 +01:00
feat: add server connection screen
This commit is contained in:
@@ -1,21 +1,17 @@
|
|||||||
use checkers::{
|
use checkers::ui::{
|
||||||
super_advanced_ai::BotDificulty,
|
macroquad::{
|
||||||
ui::{
|
difficulty_selection::draw_dificulty_selection, main_menu::draw_main_menu,
|
||||||
macroquad::{
|
mode_selection::draw_mode_selection, server_selection::draw_server_selection,
|
||||||
difficulty_selection::draw_dificulty_selection,
|
|
||||||
main_menu::{draw_main_menu, get_main_menu_style},
|
|
||||||
mode_selection::draw_mode_selection,
|
|
||||||
},
|
|
||||||
state::{GameContext, GuiState},
|
|
||||||
},
|
},
|
||||||
|
state::{GameContext, GuiState},
|
||||||
};
|
};
|
||||||
use macroquad::{
|
use macroquad::{
|
||||||
color::{BLACK, BLUE, RED, WHITE},
|
color::{BLACK, WHITE},
|
||||||
math::vec2,
|
math::vec2,
|
||||||
miniquad::{self, conf::LinuxBackend::WaylandWithX11Fallback},
|
miniquad::{self, conf::LinuxBackend::WaylandWithX11Fallback},
|
||||||
texture::{DrawTextureParams, draw_texture_ex, load_texture},
|
texture::{DrawTextureParams, draw_texture_ex, load_texture},
|
||||||
ui::{Skin, root_ui},
|
ui::{Skin, root_ui},
|
||||||
window::{Conf, clear_background, next_frame, screen_height, screen_width},
|
window::{Conf, screen_height, screen_width},
|
||||||
};
|
};
|
||||||
|
|
||||||
fn window_conf() -> Conf {
|
fn window_conf() -> Conf {
|
||||||
@@ -88,7 +84,7 @@ pub async fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GuiState::ServerSelection => {
|
GuiState::ServerSelection => {
|
||||||
todo!();
|
draw_server_selection(&mut state, &mut context).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiState::Settings => {
|
GuiState::Settings => {
|
||||||
|
|||||||
@@ -8,25 +8,6 @@ use macroquad::{
|
|||||||
|
|
||||||
use crate::ui::{macroquad::menu_builder::MenuBuilder, state::GuiState};
|
use crate::ui::{macroquad::menu_builder::MenuBuilder, state::GuiState};
|
||||||
|
|
||||||
pub async fn get_main_menu_style() -> Skin {
|
|
||||||
let label_style = root_ui()
|
|
||||||
.style_builder()
|
|
||||||
.text_color(WHITE)
|
|
||||||
.font_size(64)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
let button_style = root_ui()
|
|
||||||
.style_builder()
|
|
||||||
.text_color(BLACK)
|
|
||||||
.font_size(32)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Skin {
|
|
||||||
label_style,
|
|
||||||
button_style,
|
|
||||||
..root_ui().default_skin()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn draw_main_menu(state: &mut GuiState) {
|
pub async fn draw_main_menu(state: &mut GuiState) {
|
||||||
let menu_size = vec2(screen_width() * 0.5, screen_height() * 0.5);
|
let menu_size = vec2(screen_width() * 0.5, screen_height() * 0.5);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use macroquad::{
|
use macroquad::{
|
||||||
math::{Vec2, vec2},
|
math::{Vec2, vec2},
|
||||||
ui::{
|
ui::{
|
||||||
Ui, root_ui,
|
Ui, hash,
|
||||||
widgets::{Button, Label},
|
widgets::{Button, InputText, Label},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -24,13 +24,22 @@ impl MenuBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn text_input(&mut self, ui: &mut Ui, buffer: &mut String) {
|
||||||
|
InputText::new(hash!())
|
||||||
|
.position(vec2(self.center_x, self.current_y))
|
||||||
|
.size(self.button_size)
|
||||||
|
.ui(ui, buffer);
|
||||||
|
|
||||||
|
self.update_height();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn label(&mut self, ui: &mut Ui, label: &str) {
|
pub fn label(&mut self, ui: &mut Ui, label: &str) {
|
||||||
Label::new(label)
|
Label::new(label)
|
||||||
.position(vec2(self.center_x, self.current_y))
|
.position(vec2(self.center_x, self.current_y))
|
||||||
.size(self.button_size)
|
.size(self.button_size)
|
||||||
.ui(ui);
|
.ui(ui);
|
||||||
|
|
||||||
self.current_y += self.button_size.y + self.spacing;
|
self.update_height();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn button(&mut self, ui: &mut Ui, label: &str) -> bool {
|
pub fn button(&mut self, ui: &mut Ui, label: &str) -> bool {
|
||||||
@@ -39,8 +48,11 @@ impl MenuBuilder {
|
|||||||
.size(self.button_size)
|
.size(self.button_size)
|
||||||
.ui(ui);
|
.ui(ui);
|
||||||
|
|
||||||
self.current_y += self.button_size.y + self.spacing;
|
self.update_height();
|
||||||
|
|
||||||
clicked
|
clicked
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn update_height(&mut self) {
|
||||||
|
self.current_y += self.button_size.y + self.spacing;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,3 +2,4 @@ pub mod difficulty_selection;
|
|||||||
pub mod main_menu;
|
pub mod main_menu;
|
||||||
mod menu_builder;
|
mod menu_builder;
|
||||||
pub mod mode_selection;
|
pub mod mode_selection;
|
||||||
|
pub mod server_selection;
|
||||||
|
|||||||
47
src/ui/macroquad/server_selection.rs
Normal file
47
src/ui/macroquad/server_selection.rs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
use macroquad::{
|
||||||
|
color::GRAY,
|
||||||
|
math::vec2,
|
||||||
|
shapes::draw_rectangle,
|
||||||
|
ui::{hash, root_ui, widgets::Group},
|
||||||
|
window::{next_frame, screen_height, screen_width},
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::ui::{
|
||||||
|
macroquad::menu_builder::MenuBuilder,
|
||||||
|
state::{
|
||||||
|
GameContext,
|
||||||
|
GuiState::{self},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub async fn draw_server_selection(state: &mut GuiState, context: &mut GameContext) {
|
||||||
|
let menu_size = vec2(screen_width() * 0.5, screen_height() * 0.5);
|
||||||
|
let menu_pos = vec2(
|
||||||
|
screen_width() / 2.0 - menu_size.x / 2.0,
|
||||||
|
screen_height() / 2.0 - menu_size.y / 2.0,
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut menu_builder = MenuBuilder::new(menu_size.x, menu_size.y * 0.1);
|
||||||
|
|
||||||
|
draw_rectangle(menu_pos.x, menu_pos.y, menu_size.x, menu_size.y, GRAY);
|
||||||
|
|
||||||
|
Group::new(hash!(), menu_size)
|
||||||
|
.position(menu_pos)
|
||||||
|
.ui(&mut root_ui(), |ui| {
|
||||||
|
menu_builder.label(ui, "Server selection");
|
||||||
|
|
||||||
|
menu_builder.text_input(ui, &mut context.server_url_buffer);
|
||||||
|
//context.normalise_url();
|
||||||
|
|
||||||
|
if menu_builder.button(ui, "Connect") {
|
||||||
|
context.is_single = false;
|
||||||
|
*state = GuiState::Game;
|
||||||
|
}
|
||||||
|
|
||||||
|
if menu_builder.button(ui, "Go back") {
|
||||||
|
*state = GuiState::ModeSelection;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
next_frame().await;
|
||||||
|
}
|
||||||
@@ -18,4 +18,5 @@ pub enum GuiState {
|
|||||||
pub struct GameContext {
|
pub struct GameContext {
|
||||||
pub difficulty: BotDificulty,
|
pub difficulty: BotDificulty,
|
||||||
pub is_single: bool,
|
pub is_single: bool,
|
||||||
|
pub server_url_buffer: String,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user