mirror of
https://github.com/gopher64/gopher64.git
synced 2026-07-11 01:25:20 +02:00
@@ -129,6 +129,9 @@ pub fn sdl_close() {
|
||||
}
|
||||
|
||||
pub fn get_dirs() -> Dirs {
|
||||
#[cfg(target_os = "android")]
|
||||
return android::get_dirs();
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
{
|
||||
let exe_path = std::env::current_exe().unwrap();
|
||||
@@ -148,10 +151,6 @@ pub fn get_dirs() -> Dirs {
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
android::get_dirs()
|
||||
}
|
||||
}
|
||||
|
||||
impl Ui {
|
||||
|
||||
@@ -312,6 +312,21 @@ pub fn get_dirs() -> ui::Dirs {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_controller_names() -> Vec<String> {
|
||||
let mut controllers: Vec<String> = list_controllers().into_iter().map(|c| c.name).collect();
|
||||
controllers.insert(0, "None".into());
|
||||
controllers
|
||||
}
|
||||
|
||||
pub fn get_controller_paths() -> Vec<String> {
|
||||
let mut controller_paths: Vec<String> = list_controllers()
|
||||
.into_iter()
|
||||
.map(|c| c.descriptor)
|
||||
.collect();
|
||||
controller_paths.insert(0, String::new());
|
||||
controller_paths
|
||||
}
|
||||
|
||||
pub fn rom_exists(path: &str) -> bool {
|
||||
let path = path.to_string();
|
||||
|
||||
|
||||
+13
-18
@@ -48,18 +48,16 @@ fn check_latest_version(weak: slint::Weak<AppWindow>) {
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
pub fn open_uri(path: impl AsRef<std::ffi::OsStr>) {
|
||||
#[cfg(target_os = "android")]
|
||||
return ui::android::open_uri(path.as_ref().to_str().unwrap());
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
if let Err(e) = open::that_detached(path) {
|
||||
eprintln!("Error opening path: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
pub fn open_uri(path: impl AsRef<std::ffi::OsStr>) {
|
||||
ui::android::open_uri(path.as_ref().to_str().unwrap())
|
||||
}
|
||||
|
||||
fn run_with_path(weak: slint::Weak<AppWindow>, path: std::path::PathBuf) {
|
||||
let weak2 = weak.clone();
|
||||
weak.upgrade_in_event_loop(move |handle| {
|
||||
@@ -608,6 +606,9 @@ pub fn run_rom(
|
||||
}
|
||||
|
||||
pub async fn select_rom(rom_dir: slint::SharedString) -> Option<std::path::PathBuf> {
|
||||
#[cfg(target_os = "android")]
|
||||
return ui::android::select_rom(rom_dir).await;
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
{
|
||||
if !rom_dir.is_empty() && std::fs::exists(&rom_dir).unwrap_or(false) {
|
||||
@@ -621,13 +622,12 @@ pub async fn select_rom(rom_dir: slint::SharedString) -> Option<std::path::PathB
|
||||
.await
|
||||
.map(|file| file.path().to_path_buf())
|
||||
}
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
ui::android::select_rom(rom_dir).await
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn select_gb_rom(player: i32) -> Option<std::path::PathBuf> {
|
||||
#[cfg(target_os = "android")]
|
||||
return ui::android::select_gb_rom(player).await;
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
{
|
||||
rfd::AsyncFileDialog::new()
|
||||
@@ -637,13 +637,12 @@ pub async fn select_gb_rom(player: i32) -> Option<std::path::PathBuf> {
|
||||
.await
|
||||
.map(|file| file.path().to_path_buf())
|
||||
}
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
ui::android::select_gb_rom(player).await
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn select_gb_ram(player: i32) -> Option<std::path::PathBuf> {
|
||||
#[cfg(target_os = "android")]
|
||||
return ui::android::select_gb_ram(player).await;
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
{
|
||||
rfd::AsyncFileDialog::new()
|
||||
@@ -653,10 +652,6 @@ pub async fn select_gb_ram(player: i32) -> Option<std::path::PathBuf> {
|
||||
.await
|
||||
.map(|file| file.path().to_path_buf())
|
||||
}
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
ui::android::select_gb_ram(player).await
|
||||
}
|
||||
}
|
||||
|
||||
fn open_rom(app: &AppWindow) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { StandardButton } from "std-widgets.slint";
|
||||
import { StandardButton, VerticalBox, HorizontalBox } from "std-widgets.slint";
|
||||
import { LocalGame, ControllerConfig, Netplay, Cheats, RetroAchievements, Settings, About } from "pages.slint";
|
||||
import { SideBar } from "side_bar.slint";
|
||||
import { SettingsData } from "settings_page.slint";
|
||||
@@ -250,14 +250,29 @@ export component AppWindow inherits Window {
|
||||
}
|
||||
}
|
||||
|
||||
export component ErrorDialog inherits Dialog {
|
||||
export component ErrorDialog inherits Window {
|
||||
in-out property <string> text;
|
||||
title: @tr("Error");
|
||||
Text {
|
||||
text: text;
|
||||
}
|
||||
callback close_clicked;
|
||||
VerticalBox {
|
||||
alignment: start;
|
||||
vertical-stretch: 1;
|
||||
padding-left: root.safe-area-insets.left;
|
||||
padding-top: root.safe-area-insets.top;
|
||||
padding-right: root.safe-area-insets.right;
|
||||
padding-bottom: root.safe-area-insets.bottom;
|
||||
Text {
|
||||
text: text;
|
||||
}
|
||||
|
||||
StandardButton {
|
||||
kind: close;
|
||||
HorizontalBox {
|
||||
alignment: end;
|
||||
StandardButton {
|
||||
kind: close;
|
||||
clicked => {
|
||||
close_clicked();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { StandardButton, HorizontalBox, VerticalBox, Button, LineEdit, Switch, Slider } from "std-widgets.slint";
|
||||
import { HorizontalBox, VerticalBox, Button, LineEdit, Switch, Slider } from "std-widgets.slint";
|
||||
|
||||
export global InputProfileData {
|
||||
in-out property <bool> dinput;
|
||||
|
||||
@@ -77,7 +77,7 @@ export component Netplay inherits Page {
|
||||
}
|
||||
}
|
||||
|
||||
export component CustomNetplayServer inherits Dialog {
|
||||
export component CustomNetplayServer inherits Window {
|
||||
in-out property custom_server_url <=> NetplayData.custom_server_url;
|
||||
title: @tr("Custom Netplay Server");
|
||||
preferred-width: 400px;
|
||||
@@ -94,14 +94,16 @@ export component CustomNetplayServer inherits Dialog {
|
||||
text: NetplayData.custom_server_url;
|
||||
placeholder-text: "example.com:45000";
|
||||
}
|
||||
}
|
||||
|
||||
StandardButton {
|
||||
vertical-stretch: 0;
|
||||
kind: ok;
|
||||
clicked => {
|
||||
NetplayData.custom_server_url = server_url.text;
|
||||
ok_clicked(NetplayData.custom_server_url);
|
||||
HorizontalBox {
|
||||
alignment: end;
|
||||
StandardButton {
|
||||
kind: ok;
|
||||
clicked => {
|
||||
NetplayData.custom_server_url = server_url.text;
|
||||
ok_clicked(NetplayData.custom_server_url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+34
-45
@@ -343,60 +343,49 @@ fn hotkey_pressed(
|
||||
pressed
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
pub fn get_controller_names() -> Vec<String> {
|
||||
let mut controllers: Vec<String> = vec![];
|
||||
#[cfg(target_os = "android")]
|
||||
return ui::android::get_controller_names();
|
||||
|
||||
for joystick in get_joysticks().iter() {
|
||||
let name = unsafe { sdl3_sys::joystick::SDL_GetJoystickNameForID(*joystick) };
|
||||
controllers.push(if name.is_null() {
|
||||
"Unknown controller".to_string()
|
||||
} else {
|
||||
unsafe { std::ffi::CStr::from_ptr(name).to_str().unwrap() }.to_string()
|
||||
});
|
||||
#[cfg(not(target_os = "android"))]
|
||||
{
|
||||
let mut controllers: Vec<String> = vec![];
|
||||
|
||||
for joystick in get_joysticks().iter() {
|
||||
let name = unsafe { sdl3_sys::joystick::SDL_GetJoystickNameForID(*joystick) };
|
||||
controllers.push(if name.is_null() {
|
||||
"Unknown controller".to_string()
|
||||
} else {
|
||||
unsafe { std::ffi::CStr::from_ptr(name).to_str().unwrap() }.to_string()
|
||||
});
|
||||
}
|
||||
controllers.insert(0, "None".into());
|
||||
|
||||
controllers
|
||||
}
|
||||
controllers.insert(0, "None".into());
|
||||
|
||||
controllers
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
pub fn get_controller_names() -> Vec<String> {
|
||||
let mut controllers: Vec<String> = ui::android::list_controllers()
|
||||
.into_iter()
|
||||
.map(|c| c.name)
|
||||
.collect();
|
||||
controllers.insert(0, "None".into());
|
||||
controllers
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
#[cfg(feature = "gui")]
|
||||
pub fn get_controller_paths() -> Vec<String> {
|
||||
let mut controller_paths: Vec<String> = vec![];
|
||||
#[cfg(target_os = "android")]
|
||||
return ui::android::get_controller_paths();
|
||||
|
||||
for joystick in get_joysticks().iter() {
|
||||
let path = unsafe { sdl3_sys::joystick::SDL_GetJoystickPathForID(*joystick) };
|
||||
controller_paths.push(if path.is_null() {
|
||||
String::new()
|
||||
} else {
|
||||
unsafe { std::ffi::CStr::from_ptr(path).to_str().unwrap() }.to_string()
|
||||
});
|
||||
#[cfg(not(target_os = "android"))]
|
||||
{
|
||||
let mut controller_paths: Vec<String> = vec![];
|
||||
|
||||
for joystick in get_joysticks().iter() {
|
||||
let path = unsafe { sdl3_sys::joystick::SDL_GetJoystickPathForID(*joystick) };
|
||||
controller_paths.push(if path.is_null() {
|
||||
String::new()
|
||||
} else {
|
||||
unsafe { std::ffi::CStr::from_ptr(path).to_str().unwrap() }.to_string()
|
||||
});
|
||||
}
|
||||
controller_paths.insert(0, String::new());
|
||||
|
||||
controller_paths
|
||||
}
|
||||
controller_paths.insert(0, String::new());
|
||||
|
||||
controller_paths
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
#[cfg(feature = "gui")]
|
||||
pub fn get_controller_paths() -> Vec<String> {
|
||||
let mut controller_paths: Vec<String> = ui::android::list_controllers()
|
||||
.into_iter()
|
||||
.map(|c| c.descriptor)
|
||||
.collect();
|
||||
controller_paths.insert(0, String::new());
|
||||
controller_paths
|
||||
}
|
||||
|
||||
fn handle_joystick_events(ui: &mut ui::Ui) {
|
||||
|
||||
Reference in New Issue
Block a user