some more UI

This commit is contained in:
Rph :3
2025-04-18 00:15:28 +02:00
parent 165a9fc139
commit 4d6e23980e
8 changed files with 413 additions and 25 deletions

View File

@@ -1,16 +1,18 @@
use std::{f32::consts::E, path::PathBuf, sync::Arc, thread, time::Duration};
use std::{path::PathBuf, sync::Arc};
use crossbeam_channel::Receiver;
use egui::{mutex::Mutex};
use egui::mutex::Mutex;
use log::{debug, info};
use crate::{config::{self, ConfigProvider}, omori_locator};
use crate::{config::{self, ConfigProvider}, mod_builder::ModConfiguration, omori_locator};
#[derive(Clone)]
pub enum UiState {
Loading,
KeyRequired(String),
PickGame(Result<PathBuf, String>, Vec<(PathBuf, u64)>),
PickPlaytest(Vec<(PathBuf, u64)>),
Configure(ModConfiguration),
Error(String)
}
@@ -22,7 +24,8 @@ pub struct UiStateHolder {
pub enum UiEvent {
SetKey(Vec<u8>),
UsePath(PathBuf),
UseSteamPath
UseSteamPath,
UseConfiguration(ModConfiguration)
}
pub struct AppThread {
@@ -36,9 +39,11 @@ impl AppThread {
fn commit(&self, s: UiState) {
let mut state = self.ui_state.state.lock();
*state = s;
drop(state);
self.context.request_repaint();
}
fn get_key(&mut self, reason: String) -> anyhow::Result<Vec<u8>> {
fn get_key(&self, reason: String) -> anyhow::Result<Vec<u8>> {
self.commit(UiState::KeyRequired(reason));
loop {
match self.ui_event_channel.recv()? {
@@ -51,7 +56,7 @@ impl AppThread {
}
}
fn pick_game(&mut self, provider: &mut ConfigProvider) -> anyhow::Result<PathBuf> {
fn pick_game(&self, provider: &mut ConfigProvider) -> anyhow::Result<PathBuf> {
let steam_location = match omori_locator::get_omori_path() {
Ok(l) => Ok(l),
Err(e) => Err(String::from(format!("{:#}", e)))
@@ -77,6 +82,38 @@ impl AppThread {
}
}
fn pick_playtest(&self, provider: &mut ConfigProvider) -> anyhow::Result<PathBuf> {
let playtest_history = provider.get_playtest_paths()?;
self.commit(UiState::PickPlaytest(playtest_history.clone()));
loop {
match self.ui_event_channel.recv()? {
UiEvent::UsePath(path) => {
provider.set_playtest_path_used(&path)?;
self.commit(UiState::Loading);
return Ok(path);
},
_ => {}
}
}
}
fn configure_bundling(&self, provider: &mut ConfigProvider, path: &PathBuf) -> anyhow::Result<ModConfiguration> {
let configuration = provider.get_configuration_for_playtest(path);
self.commit(UiState::Configure(configuration));
loop {
match self.ui_event_channel.recv()? {
UiEvent::UseConfiguration(config) => {
provider.set_configuration_for_playtest(&path, &config)?;
self.commit(UiState::Loading);
return Ok(config);
},
_ => {}
}
}
}
pub fn create(state_holder: &UiStateHolder, context: &egui::Context, ui_event_channel: &Receiver<UiEvent>) -> AppThread {
AppThread {
ui_state: state_holder.clone(),
@@ -105,6 +142,12 @@ impl AppThread {
let game_path = self.pick_game(&mut config_provider)?;
info!("Will use {:?}", game_path);
let playtest_path = self.pick_playtest(&mut config_provider)?;
info!("Playtest {:?}", playtest_path);
let config = self.configure_bundling(&mut config_provider, &playtest_path)?;
info!("Config {:?}", config);
Ok(())
}