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: multitouch & fullscreen for windows #478

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ async fn the_main() -> Result<()> {
info!("FPS {}", (1. / (t - frame_start)) as u32);
}

#[cfg(target_os = "windows")]
macroquad::window::set_fullscreen(get_data().config.fullscreen_mode);

next_frame().await;
}
Ok(())
Expand Down
22 changes: 22 additions & 0 deletions phira/src/page/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ struct GeneralList {
icon_lang: SafeTexture,

lang_btn: ChooseButton,

#[cfg(target_os = "windows")]
fullscreen_btn: DRectButton,

cache_btn: DRectButton,
offline_btn: DRectButton,
server_status_btn: DRectButton,
Expand Down Expand Up @@ -300,6 +304,10 @@ impl GeneralList {
.and_then(|ident| LANG_IDENTS.iter().position(|it| *it == ident))
.unwrap_or_default(),
),

#[cfg(target_os = "windows")]
fullscreen_btn: DRectButton::new(),

cache_btn: DRectButton::new(),
offline_btn: DRectButton::new(),
server_status_btn: DRectButton::new(),
Expand Down Expand Up @@ -353,6 +361,13 @@ impl GeneralList {
if self.lang_btn.touch(touch, t) {
return Ok(Some(false));
}

#[cfg(target_os = "windows")]
if self.fullscreen_btn.touch(touch, t) {
config.fullscreen_mode ^= true;
return Ok(Some(true));
}

if self.cache_btn.touch(touch, t) {
fs::remove_dir_all(dir::cache()?)?;
self.update_cache_size()?;
Expand Down Expand Up @@ -453,6 +468,13 @@ impl GeneralList {
ui.fill_rect(r, (*self.icon_lang, r));
self.lang_btn.render(ui, rr, t);
}

#[cfg(target_os = "windows")]
item! {
render_title(ui, tl!("item-fullscreen"), Some(tl!("item-fullscreen-sub")));
render_switch(ui, rr, t, &mut self.fullscreen_btn, config.fullscreen_mode);
}

item! {
render_title(ui, tl!("item-offline"), Some(tl!("item-offline-sub")));
render_switch(ui, rr, t, &mut self.offline_btn, config.offline_mode);
Expand Down
2 changes: 2 additions & 0 deletions prpr/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct Config {
pub mp_enabled: bool,
pub mp_address: String,
pub offline_mode: bool,
pub fullscreen_mode: bool,
pub offset: f32,
pub particle: bool,
pub player_name: String,
Expand Down Expand Up @@ -74,6 +75,7 @@ impl Default for Config {
mp_enabled: false,
note_scale: 1.0,
offline_mode: false,
fullscreen_mode: false,
offset: 0.,
particle: true,
player_name: "Mivik".to_string(),
Expand Down
19 changes: 10 additions & 9 deletions prpr/src/judge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ fn get_uptime() -> f64 {
}
}

#[cfg(target_os = "windows")]
fn get_uptime() -> f64 {
use std::time::SystemTime;
let start = SystemTime::UNIX_EPOCH;
let now = SystemTime::now();
let duration = now.duration_since(start).expect("Time went backwards");
duration.as_secs() as f64 + duration.subsec_nanos() as f64 * 1e-9
}

pub struct FlickTracker {
threshold: f32,
last_point: Point,
Expand Down Expand Up @@ -366,7 +375,6 @@ impl Judge {
const X_DIFF_MAX: f32 = 0.21 / (16. / 9.) * 2.;
let spd = res.config.speed;

#[cfg(not(target_os = "windows"))]
let uptime = get_uptime();

let t = res.time;
Expand Down Expand Up @@ -460,14 +468,7 @@ impl Judge {
it.time = if it.time.is_infinite() {
f64::NEG_INFINITY
} else {
#[cfg(target_os = "windows")]
{
it.time
}
#[cfg(not(target_os = "windows"))]
{
t as f64 - (uptime - it.time) * spd as f64
}
t as f64 - (uptime - it.time) * spd as f64
};
it
})
Expand Down