Compare commits
19 Commits
0.2.0
...
bb902cda9e
| Author | SHA1 | Date | |
|---|---|---|---|
| bb902cda9e | |||
| 77d5b18f79 | |||
| 40bff4f8e4 | |||
| c746313c04 | |||
| 86d45ad992 | |||
| 5ba2e78fd0 | |||
| 1265d7f099 | |||
| b713117a70 | |||
| a001017821 | |||
| 5acbe069c2 | |||
| 6defd8edd2 | |||
| ef598dbff4 | |||
| 2abe1c95d0 | |||
| f7bb0ddda2 | |||
| d1114f0295 | |||
| f94a51027b | |||
| f5f2efcfde | |||
| eb9999b85b | |||
| df1d678ab9 |
964
rust/Cargo.lock
generated
964
rust/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -12,11 +12,11 @@ categories = [ "games" ]
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.0.16", features = ["derive"] }
|
clap = { version = "4.2.4", features = ["derive"] }
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
env_logger = "0.9.0"
|
env_logger = "0.10.0"
|
||||||
serde = { version = "1.0.145", features = ["derive"] }
|
serde = { version = "1.0.159", features = ["derive"] }
|
||||||
serde_json = "1.0.85"
|
serde_json = "1.0.96"
|
||||||
actix-web = "4.1.0"
|
actix-web = "4.1.0"
|
||||||
actix-cors = "0.6.2"
|
actix-cors = "0.6.2"
|
||||||
actix = "0.13.0"
|
actix = "0.13.0"
|
||||||
@@ -30,6 +30,6 @@ semver = "1.0.14"
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
#reqwest = { version = "0.11.11", default-features = false, features = ["json", "rustls-tls"] }
|
#reqwest = { version = "0.11.11", default-features = false, features = ["json", "rustls-tls"] }
|
||||||
tokio-tungstenite = "0.17.2"
|
tokio-tungstenite = "0.18.0"
|
||||||
serde_urlencoded = "0.7.1"
|
serde_urlencoded = "0.7.1"
|
||||||
futures = "0.3.23"
|
futures = "0.3.23"
|
||||||
|
|||||||
@@ -13,21 +13,21 @@ categories = [ "games" ]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
sea_battle_backend = { path = "../sea_battle_backend", version = "0.2.0" }
|
sea_battle_backend = { path = "../sea_battle_backend", version = "0.2.0" }
|
||||||
clap = { version = "4.0.16", features = ["derive"] }
|
clap = { version = "4.2.4", features = ["derive"] }
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
env_logger = "0.9.0"
|
env_logger = "0.10.0"
|
||||||
tui = "0.19.0"
|
tui = "0.19.0"
|
||||||
crossterm = "0.25.0"
|
crossterm = "0.26.1"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
tokio = "1.21.2"
|
tokio = "1.28.0"
|
||||||
num = "0.4.0"
|
num = "0.4.0"
|
||||||
num-traits = "0.2.15"
|
num-traits = "0.2.15"
|
||||||
num-derive = "0.3.3"
|
num-derive = "0.3.3"
|
||||||
textwrap = "0.15.1"
|
textwrap = "0.16.0"
|
||||||
tokio-tungstenite = { version = "0.17.2", features = ["__rustls-tls", "rustls-tls-native-roots"] }
|
tokio-tungstenite = { version = "0.18.0", features = ["__rustls-tls", "rustls-tls-native-roots"] }
|
||||||
serde_urlencoded = "0.7.1"
|
serde_urlencoded = "0.7.1"
|
||||||
futures = "0.3.23"
|
futures = "0.3.23"
|
||||||
serde_json = "1.0.85"
|
serde_json = "1.0.96"
|
||||||
hostname = "0.3.1"
|
hostname = "0.3.1"
|
||||||
rustls = "0.20.6"
|
rustls = "0.20.6"
|
||||||
hyper-rustls = { version = "0.23.0", features = ["rustls-native-certs"] }
|
hyper-rustls = { version = "0.23.0", features = ["rustls-native-certs"] }
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ impl Client {
|
|||||||
&cli_args().local_server_address(),
|
&cli_args().local_server_address(),
|
||||||
&format!(
|
&format!(
|
||||||
"/play/bot?{}",
|
"/play/bot?{}",
|
||||||
serde_urlencoded::to_string(&BotPlayQuery {
|
serde_urlencoded::to_string(BotPlayQuery {
|
||||||
rules: rules.clone(),
|
rules: rules.clone(),
|
||||||
player_name: "Human".to_string()
|
player_name: "Human".to_string()
|
||||||
})
|
})
|
||||||
@@ -78,7 +78,7 @@ impl Client {
|
|||||||
&cli_args().remote_server,
|
&cli_args().remote_server,
|
||||||
&format!(
|
&format!(
|
||||||
"/play/random?{}",
|
"/play/random?{}",
|
||||||
serde_urlencoded::to_string(&PlayRandomQuery {
|
serde_urlencoded::to_string(PlayRandomQuery {
|
||||||
player_name: player_name.to_string()
|
player_name: player_name.to_string()
|
||||||
})
|
})
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -93,7 +93,7 @@ impl Client {
|
|||||||
&cli_args().remote_server,
|
&cli_args().remote_server,
|
||||||
&format!(
|
&format!(
|
||||||
"/play/create_invite?{}",
|
"/play/create_invite?{}",
|
||||||
serde_urlencoded::to_string(&CreateInviteQuery {
|
serde_urlencoded::to_string(CreateInviteQuery {
|
||||||
rules: rules.clone(),
|
rules: rules.clone(),
|
||||||
player_name: player_name.to_string()
|
player_name: player_name.to_string()
|
||||||
})
|
})
|
||||||
@@ -109,7 +109,7 @@ impl Client {
|
|||||||
&cli_args().remote_server,
|
&cli_args().remote_server,
|
||||||
&format!(
|
&format!(
|
||||||
"/play/accept_invite?{}",
|
"/play/accept_invite?{}",
|
||||||
serde_urlencoded::to_string(&AcceptInviteQuery {
|
serde_urlencoded::to_string(AcceptInviteQuery {
|
||||||
code,
|
code,
|
||||||
player_name: player_name.to_string()
|
player_name: player_name.to_string()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ use crate::ui_widgets::button_widget::ButtonWidget;
|
|||||||
use crate::ui_widgets::checkbox_widget::CheckboxWidget;
|
use crate::ui_widgets::checkbox_widget::CheckboxWidget;
|
||||||
use crate::ui_widgets::text_editor_widget::TextEditorWidget;
|
use crate::ui_widgets::text_editor_widget::TextEditorWidget;
|
||||||
|
|
||||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Eq, PartialEq)]
|
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Eq, PartialEq, Copy, Clone)]
|
||||||
enum EditingField {
|
enum EditingField {
|
||||||
MapWidth = 0,
|
MapWidth = 0,
|
||||||
MapHeight,
|
MapHeight,
|
||||||
@@ -128,7 +128,7 @@ impl GameRulesConfigurationScreen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyCode::Char(c) if ('0'..='9').contains(&c) => {
|
KeyCode::Char(c) if c.is_ascii_digit() => {
|
||||||
let val = c.to_string().parse::<usize>().unwrap_or_default();
|
let val = c.to_string().parse::<usize>().unwrap_or_default();
|
||||||
|
|
||||||
if self.curr_field == EditingField::MapWidth
|
if self.curr_field == EditingField::MapWidth
|
||||||
@@ -283,10 +283,10 @@ impl GameRulesConfigurationScreen {
|
|||||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
|
||||||
.split(chunks[EditingField::OK as usize]);
|
.split(chunks[EditingField::OK as usize]);
|
||||||
|
|
||||||
let button = ButtonWidget::new("Cancel", self.curr_field == EditingField::Cancel);
|
let button = ButtonWidget::cancel(self.curr_field == EditingField::Cancel);
|
||||||
f.render_widget(button, buttons_chunk[0]);
|
f.render_widget(button, buttons_chunk[0]);
|
||||||
|
|
||||||
let button = ButtonWidget::new("OK", self.curr_field == EditingField::OK)
|
let button = ButtonWidget::ok(self.curr_field == EditingField::OK)
|
||||||
.set_disabled(!self.rules.is_valid());
|
.set_disabled(!self.rules.is_valid());
|
||||||
f.render_widget(button, buttons_chunk[1]);
|
f.render_widget(button, buttons_chunk[1]);
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ pub struct ConfirmDialogScreen<'a> {
|
|||||||
impl<'a> ConfirmDialogScreen<'a> {
|
impl<'a> ConfirmDialogScreen<'a> {
|
||||||
pub fn new(msg: &'a str) -> Self {
|
pub fn new(msg: &'a str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
title: "Confirmation Request",
|
title: "❔ Confirmation Request",
|
||||||
msg,
|
msg,
|
||||||
is_confirm: true,
|
is_confirm: true,
|
||||||
can_escape: false,
|
can_escape: false,
|
||||||
@@ -123,10 +123,10 @@ impl<'a> ConfirmDialogScreen<'a> {
|
|||||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
||||||
.split(chunks[1]);
|
.split(chunks[1]);
|
||||||
|
|
||||||
let cancel_button = ButtonWidget::new("Cancel", true).set_disabled(self.is_confirm);
|
let cancel_button = ButtonWidget::cancel(true).set_disabled(self.is_confirm);
|
||||||
f.render_widget(cancel_button, buttons_area[0]);
|
f.render_widget(cancel_button, buttons_area[0]);
|
||||||
|
|
||||||
let ok_button = ButtonWidget::new("Confirm", true).set_disabled(!self.is_confirm);
|
let ok_button = ButtonWidget::new("✅ Confirm", true).set_disabled(!self.is_confirm);
|
||||||
f.render_widget(ok_button, buttons_area[1]);
|
f.render_widget(ok_button, buttons_area[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,12 +163,12 @@ impl<'a> InputScreen<'a> {
|
|||||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
||||||
.split(*chunks.last().unwrap());
|
.split(*chunks.last().unwrap());
|
||||||
|
|
||||||
let cancel_button = ButtonWidget::new("Cancel", self.is_cancel_hovered)
|
let cancel_button = ButtonWidget::cancel(self.is_cancel_hovered)
|
||||||
.set_disabled(!self.can_cancel)
|
.set_disabled(!self.can_cancel)
|
||||||
.set_min_width(8);
|
.set_min_width(8);
|
||||||
f.render_widget(cancel_button, buttons_area[0]);
|
f.render_widget(cancel_button, buttons_area[0]);
|
||||||
|
|
||||||
let ok_button = ButtonWidget::new("OK", !self.is_cancel_hovered)
|
let ok_button = ButtonWidget::ok(!self.is_cancel_hovered)
|
||||||
.set_min_width(8)
|
.set_min_width(8)
|
||||||
.set_disabled(error.is_some());
|
.set_disabled(error.is_some());
|
||||||
f.render_widget(ok_button, buttons_area[1]);
|
f.render_widget(ok_button, buttons_area[1]);
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ impl<'a> SetBoatsLayoutScreen<'a> {
|
|||||||
.add_colored_cells(current_boat)
|
.add_colored_cells(current_boat)
|
||||||
.add_colored_cells(invalid_boats)
|
.add_colored_cells(invalid_boats)
|
||||||
.add_colored_cells(other_boats)
|
.add_colored_cells(other_boats)
|
||||||
.set_title("Choose your boat layout")
|
.set_title("🛥 Set your boats layout")
|
||||||
.set_yield_func(|c, r| {
|
.set_yield_func(|c, r| {
|
||||||
for i in 0..r.width {
|
for i in 0..r.width {
|
||||||
for j in 0..r.height {
|
for j in 0..r.height {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ pub struct ButtonWidget {
|
|||||||
label: String,
|
label: String,
|
||||||
disabled: bool,
|
disabled: bool,
|
||||||
min_width: usize,
|
min_width: usize,
|
||||||
|
hover_bg_color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ButtonWidget {
|
impl ButtonWidget {
|
||||||
@@ -22,9 +23,18 @@ impl ButtonWidget {
|
|||||||
is_hovered,
|
is_hovered,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
min_width: 0,
|
min_width: 0,
|
||||||
|
hover_bg_color: HIGHLIGHT_COLOR,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn cancel(is_hovered: bool) -> Self {
|
||||||
|
Self::new("❌ Cancel", is_hovered).set_hover_bg_color(Color::Red)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ok(is_hovered: bool) -> Self {
|
||||||
|
Self::new("✅ OK", is_hovered)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_disabled(mut self, disabled: bool) -> Self {
|
pub fn set_disabled(mut self, disabled: bool) -> Self {
|
||||||
self.disabled = disabled;
|
self.disabled = disabled;
|
||||||
self
|
self
|
||||||
@@ -35,6 +45,11 @@ impl ButtonWidget {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_hover_bg_color(mut self, v: Color) -> Self {
|
||||||
|
self.hover_bg_color = v;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn estimated_size(&self) -> (u16, u16) {
|
pub fn estimated_size(&self) -> (u16, u16) {
|
||||||
((self.label.len() + 2).max(self.min_width) as u16, 1)
|
((self.label.len() + 2).max(self.min_width) as u16, 1)
|
||||||
}
|
}
|
||||||
@@ -55,7 +70,7 @@ impl Widget for ButtonWidget {
|
|||||||
let input = Paragraph::new(label.as_ref()).style(match (self.disabled, self.is_hovered) {
|
let input = Paragraph::new(label.as_ref()).style(match (self.disabled, self.is_hovered) {
|
||||||
(true, _) => Style::default(),
|
(true, _) => Style::default(),
|
||||||
(_, false) => Style::default().bg(Color::DarkGray),
|
(_, false) => Style::default().bg(Color::DarkGray),
|
||||||
(_, true) => Style::default().fg(Color::White).bg(HIGHLIGHT_COLOR),
|
(_, true) => Style::default().fg(Color::White).bg(self.hover_bg_color),
|
||||||
});
|
});
|
||||||
|
|
||||||
input.render(area, buf);
|
input.render(area, buf);
|
||||||
|
|||||||
Reference in New Issue
Block a user