Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: server status button #376

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions phira/locales/en-US/settings.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions phira/locales/zh-CN/settings.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 多人游戏服务器
Expand Down
16 changes: 14 additions & 2 deletions phira/src/page/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ 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},
};
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 {
Expand Down Expand Up @@ -258,14 +260,15 @@ 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 {
icon_lang: SafeTexture,

lang_btn: ChooseButton,
offline_btn: DRectButton,
server_status_btn: DRectButton,
mp_btn: DRectButton,
mp_addr_btn: DRectButton,
lowq_btn: DRectButton,
Expand All @@ -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(),
Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand Down