Compare commits

...

4 Commits

Author SHA1 Message Date
f94a51027b Update dependencies to their latest versions
All checks were successful
continuous-integration/drone/push Build is passing
2023-03-19 18:58:34 +01:00
f5f2efcfde cargo update 2023-03-19 18:56:46 +01:00
eb9999b85b Fix build issue 2023-03-19 18:54:44 +01:00
df1d678ab9 Add more emojies
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-18 10:05:43 +02:00
8 changed files with 513 additions and 353 deletions

817
rust/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -14,7 +14,7 @@ categories = [ "games" ]
[dependencies]
clap = { version = "4.0.16", features = ["derive"] }
log = "0.4.17"
env_logger = "0.9.0"
env_logger = "0.10.0"
serde = { version = "1.0.145", features = ["derive"] }
serde_json = "1.0.85"
actix-web = "4.1.0"
@@ -30,6 +30,6 @@ semver = "1.0.14"
[dev-dependencies]
#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"
futures = "0.3.23"

View File

@@ -15,16 +15,16 @@ categories = [ "games" ]
sea_battle_backend = { path = "../sea_battle_backend", version = "0.2.0" }
clap = { version = "4.0.16", features = ["derive"] }
log = "0.4.17"
env_logger = "0.9.0"
env_logger = "0.10.0"
tui = "0.19.0"
crossterm = "0.25.0"
crossterm = "0.26.1"
lazy_static = "1.4.0"
tokio = "1.21.2"
num = "0.4.0"
num-traits = "0.2.15"
num-derive = "0.3.3"
textwrap = "0.15.1"
tokio-tungstenite = { version = "0.17.2", features = ["__rustls-tls", "rustls-tls-native-roots"] }
textwrap = "0.16.0"
tokio-tungstenite = { version = "0.18.0", features = ["__rustls-tls", "rustls-tls-native-roots"] }
serde_urlencoded = "0.7.1"
futures = "0.3.23"
serde_json = "1.0.85"

View File

@@ -25,7 +25,7 @@ use crate::ui_widgets::button_widget::ButtonWidget;
use crate::ui_widgets::checkbox_widget::CheckboxWidget;
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 {
MapWidth = 0,
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();
if self.curr_field == EditingField::MapWidth
@@ -283,10 +283,10 @@ impl GameRulesConfigurationScreen {
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
.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]);
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());
f.render_widget(button, buttons_chunk[1]);

View File

@@ -35,7 +35,7 @@ pub struct ConfirmDialogScreen<'a> {
impl<'a> ConfirmDialogScreen<'a> {
pub fn new(msg: &'a str) -> Self {
Self {
title: "Confirmation Request",
title: "Confirmation Request",
msg,
is_confirm: true,
can_escape: false,
@@ -123,10 +123,10 @@ impl<'a> ConfirmDialogScreen<'a> {
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
.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]);
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]);
}
}

View File

@@ -163,12 +163,12 @@ impl<'a> InputScreen<'a> {
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
.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_min_width(8);
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_disabled(error.is_some());
f.render_widget(ok_button, buttons_area[1]);

View File

@@ -202,7 +202,7 @@ impl<'a> SetBoatsLayoutScreen<'a> {
.add_colored_cells(current_boat)
.add_colored_cells(invalid_boats)
.add_colored_cells(other_boats)
.set_title("Choose your boat layout")
.set_title("🛥 Set your boats layout")
.set_yield_func(|c, r| {
for i in 0..r.width {
for j in 0..r.height {

View File

@@ -13,6 +13,7 @@ pub struct ButtonWidget {
label: String,
disabled: bool,
min_width: usize,
hover_bg_color: Color,
}
impl ButtonWidget {
@@ -22,9 +23,18 @@ impl ButtonWidget {
is_hovered,
disabled: false,
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 {
self.disabled = disabled;
self
@@ -35,6 +45,11 @@ impl ButtonWidget {
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) {
((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) {
(true, _) => Style::default(),
(_, 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);