From c598633cbec11668ced62d1f2480019a8fe08472 Mon Sep 17 00:00:00 2001 From: liquidhelium Date: Mon, 19 Aug 2024 20:32:14 +0800 Subject: [PATCH] feat: server status button --- phira/locales/en-US/settings.ftl | 3 +++ phira/locales/zh-CN/settings.ftl | 3 +++ phira/src/page/settings.rs | 16 ++++++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/phira/locales/en-US/settings.ftl b/phira/locales/en-US/settings.ftl index 700311e9..6b93c3b8 100644 --- a/phira/locales/en-US/settings.ftl +++ b/phira/locales/en-US/settings.ftl @@ -10,6 +10,9 @@ about = Info item-lang = Language item-offline = Offline mode item-offline-sub = You can't upload playing record in offline mode +item-server-status = Server status +item-server-status-sub = Navigate to the webpage to check the server status +check-status = Check item-mp = Multiplayer item-mp-sub = Enable multiplayer mode item-mp-addr = Multiplayer server diff --git a/phira/locales/zh-CN/settings.ftl b/phira/locales/zh-CN/settings.ftl index 274c564a..1b7c89d5 100644 --- a/phira/locales/zh-CN/settings.ftl +++ b/phira/locales/zh-CN/settings.ftl @@ -10,6 +10,9 @@ about = 关于 item-lang = 语言 item-offline = 离线模式 item-offline-sub = 在离线模式下将不能上传成绩 +item-server-status = 服务器状态 +item-server-status-sub = 转到网页查询服务器状态 +check-status = 查询 item-mp = 多人游戏 item-mp-sub = 启用多人游戏 item-mp-addr = 多人游戏服务器 diff --git a/phira/src/page/settings.rs b/phira/src/page/settings.rs index ba74a1b1..eade5400 100644 --- a/phira/src/page/settings.rs +++ b/phira/src/page/settings.rs @@ -13,7 +13,7 @@ use anyhow::Result; use macroquad::prelude::*; use prpr::{ core::BOLD_FONT, - ext::{poll_future, semi_white, LocalTask, RectExt, SafeTexture}, + ext::{open_url, poll_future, semi_white, LocalTask, RectExt, SafeTexture}, l10n::{LanguageIdentifier, LANG_IDENTS, LANG_NAMES}, scene::{request_input, return_input, show_error, take_input}, ui::{DRectButton, Scroll, Slider, Ui}, @@ -21,6 +21,8 @@ use prpr::{ use std::{borrow::Cow, net::ToSocketAddrs, sync::atomic::Ordering}; const ITEM_HEIGHT: f32 = 0.15; +const INTERACT_WIDTH: f32 = 0.26; +const STATUS_PAGE: &str = "https://status.phira.cn"; #[derive(Clone, Copy, PartialEq, Eq)] enum SettingListType { @@ -258,7 +260,7 @@ fn render_switch(ui: &mut Ui, r: Rect, t: f32, btn: &mut DRectButton, on: bool) #[inline] fn right_rect(w: f32) -> Rect { let rh = ITEM_HEIGHT * 2. / 3.; - Rect::new(w - 0.3, (ITEM_HEIGHT - rh) / 2., 0.26, rh) + Rect::new(w - 0.3, (ITEM_HEIGHT - rh) / 2., INTERACT_WIDTH, rh) } struct GeneralList { @@ -266,6 +268,7 @@ struct GeneralList { lang_btn: ChooseButton, offline_btn: DRectButton, + server_status_btn: DRectButton, mp_btn: DRectButton, mp_addr_btn: DRectButton, lowq_btn: DRectButton, @@ -288,6 +291,7 @@ impl GeneralList { .unwrap_or_default(), ), offline_btn: DRectButton::new(), + server_status_btn: DRectButton::new(), mp_btn: DRectButton::new(), mp_addr_btn: DRectButton::new(), lowq_btn: DRectButton::new(), @@ -312,6 +316,10 @@ impl GeneralList { config.offline_mode ^= true; return Ok(Some(true)); } + if self.server_status_btn.touch(touch, t) { + let _ = open_url(STATUS_PAGE); + return Ok(Some(true)); + } if self.mp_btn.touch(touch, t) { config.mp_enabled ^= true; return Ok(Some(true)); @@ -380,6 +388,10 @@ impl GeneralList { render_title(ui, tl!("item-offline"), Some(tl!("item-offline-sub"))); render_switch(ui, rr, t, &mut self.offline_btn, config.offline_mode); } + item! { + render_title(ui, tl!("item-server-status"), Some(tl!("item-server-status-sub"))); + self.server_status_btn.render_text(ui, rr, t, tl!("check-status"), 0.5, true); + } item! { render_title(ui, tl!("item-mp"), Some(tl!("item-mp-sub"))); render_switch(ui, rr, t, &mut self.mp_btn, config.mp_enabled);