Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr1Furious committed Nov 5, 2024
1 parent 13bc6b5 commit c53e14f
Show file tree
Hide file tree
Showing 30 changed files with 1,109 additions and 685 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

229 changes: 125 additions & 104 deletions launcher/src/app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use eframe::run_native;
use tokio::runtime::Runtime;

use super::auth_state::AuthState;
use super::instance_sync_state::InstanceSyncState;
use super::java_state::JavaState;
use super::launch_state::ForceLaunchResult;
use super::launch_state::LaunchState;
use super::manifest_state::ManifestState;
use super::metadata_state::MetadataState;
use super::modpack_sync_state::ModpackSyncState;
use super::settings::SettingsState;
use crate::config::build_config;
use crate::config::runtime_config;
Expand All @@ -22,15 +22,16 @@ pub struct LauncherApp {
manifest_state: ManifestState,
metadata_state: MetadataState,
java_state: JavaState,
modpack_sync_state: ModpackSyncState,
instance_sync_state: InstanceSyncState,
launch_state: LaunchState,
}

pub fn run_gui(config: runtime_config::Config) {
let native_options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_inner_size((350.0, 300.0))
.with_icon(utils::get_icon_data()),
.with_inner_size((650.0, 500.0))
.with_icon(utils::get_icon_data())
.with_resizable(false),
..Default::default()
};

Expand All @@ -49,18 +50,23 @@ impl eframe::App for LauncherApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
self.ui(ctx);
}

fn clear_color(&self, visuals: &egui::Visuals) -> [f32; 4] {
visuals.window_fill.to_normalized_gamma_f32()
}
}

impl LauncherApp {
fn new(config: runtime_config::Config, ctx: &egui::Context) -> Self {
let runtime = Runtime::new().unwrap();

LauncherApp {
settings_state: SettingsState::new(),
auth_state: AuthState::new(ctx),
manifest_state: ManifestState::new(),
metadata_state: MetadataState::new(),
java_state: JavaState::new(ctx),
modpack_sync_state: runtime.block_on(ModpackSyncState::new(ctx, &config)),
instance_sync_state: runtime.block_on(InstanceSyncState::new(&runtime, ctx, &config)),
launch_state: LaunchState::new(),
runtime,
config,
Expand All @@ -70,134 +76,149 @@ impl LauncherApp {
fn ui(&mut self, ctx: &egui::Context) {
let mut selected_metadata = None;

egui::CentralPanel::default().show(ctx, |ui| {
ui.vertical_centered(|ui| {
let mut need_check = false;

need_check |= self
.manifest_state
.update(&self.runtime, &mut self.config, ctx);

need_check |= self.manifest_state.render_ui(ui, &mut self.config);
ui.separator();

let selected_modpack = self.manifest_state.get_selected_modpack(&self.config);
if let Some(selected_modpack) = selected_modpack {
if need_check {
self.metadata_state.reset();
}

need_check |= self.metadata_state.update(
egui::TopBottomPanel::bottom("bottom_panel")
.resizable(false)
.show(ctx, |ui| {
ui.add_space(5.0);
ui.horizontal(|ui| {
let selected_metadata_ref = selected_metadata.as_deref();
self.settings_state.render_ui(
ui,
&self.runtime,
&mut self.config,
selected_modpack,
ctx,
selected_metadata_ref,
);
});
ui.add_space(5.0);
});

if self.metadata_state.render_ui(ui, &self.config) {
ui.separator();
}
egui::CentralPanel::default()
.frame(
egui::Frame::central_panel(&ctx.style())
.outer_margin(egui::Margin::symmetric(150.0, 100.0))
.stroke(ctx.style().visuals.widgets.noninteractive.bg_stroke)
.rounding(egui::Rounding::same(10.0)),
)
.show(ctx, |ui| {
ui.vertical_centered(|ui| {
let mut need_check = false;

need_check |= self
.manifest_state
.update(&self.runtime, &mut self.config, ctx);

ui.horizontal(|ui| {
need_check |= self.manifest_state.render_ui(ui, &mut self.config);
self.instance_sync_state.render_new_instance_ui(&self.runtime, ui, &mut self.config);
});
ui.separator();

let version_metadata = self.metadata_state.get_version_metadata();
if let Some(version_metadata) = version_metadata {
selected_metadata = Some(version_metadata.clone());
let selected_instance = self.manifest_state.get_selected_instance(&self.config);
if let Some(selected_instance) = selected_instance {
if need_check {
self.auth_state
.reset_auth_if_needed(version_metadata.get_auth_data());
self.metadata_state.reset();
}
need_check |= self
.auth_state
.update(&mut self.config, version_metadata.get_auth_data());

self.auth_state.render_ui(
ui,
&self.config,
need_check |= self.metadata_state.update(
&self.runtime,
&mut self.config,
selected_instance,
ctx,
version_metadata.get_auth_data(),
);

if self
.auth_state
.ready_for_launch(version_metadata.get_auth_data(), &self.config)
{
let manifest_online =
self.manifest_state.online() && self.metadata_state.online();
need_check |= self.modpack_sync_state.update(
&self.runtime,
selected_modpack,
version_metadata.clone(),
&self.config,
need_check,
manifest_online,
);
if self.metadata_state.render_ui(ui, &self.config) {
ui.separator();
}

self.java_state.update(
&self.runtime,
&version_metadata,
&mut self.config,
ctx,
need_check,
);
let version_metadata = self.metadata_state.get_version_metadata();
if let Some(version_metadata) = version_metadata {
selected_metadata = Some(version_metadata.clone());
if need_check {
self.auth_state
.reset_auth_if_needed(version_metadata.get_auth_data());
}
need_check |= self
.auth_state
.update(&mut self.config, version_metadata.get_auth_data());

ui.separator();
self.modpack_sync_state.render_ui(
self.auth_state.render_ui(
ui,
&mut self.config,
manifest_online,
&self.config,
&self.runtime,
ctx,
version_metadata.get_auth_data(),
);

ui.separator();
self.java_state
.render_ui(ui, &mut self.config, &version_metadata);

if self.java_state.ready_for_launch()
&& (self.modpack_sync_state.ready_for_launch() || !manifest_online)
if self
.auth_state
.ready_for_launch(version_metadata.get_auth_data(), &self.config)
{
self.launch_state.update();
let manifest_online =
self.manifest_state.online() && self.metadata_state.online();
need_check |= self.instance_sync_state.update(
&self.runtime,
selected_instance,
version_metadata.clone(),
&self.config,
need_check,
manifest_online,
);

self.launch_state.render_ui(
self.java_state.update(
&self.runtime,
&version_metadata,
&mut self.config,
ctx,
need_check,
);

ui.separator();
self.instance_sync_state.render_ui(
ui,
&mut self.config,
&version_metadata,
self.auth_state.online(),
manifest_online,
);
} else {
let force_launch_result =
self.launch_state.render_download_ui(ui, &mut self.config);
match force_launch_result {
ForceLaunchResult::ForceLaunchSelected => {
self.modpack_sync_state.schedule_sync_if_needed();
self.java_state.schedule_download_if_needed(
&self.runtime,
&version_metadata,
&mut self.config,
);
}
ForceLaunchResult::CancelSelected => {
self.java_state.cancel_download();
self.modpack_sync_state.cancel_sync();

ui.separator();
self.java_state
.render_ui(ui, &mut self.config, &version_metadata);

if self.java_state.ready_for_launch()
&& (self.instance_sync_state.ready_for_launch()
|| !manifest_online)
{
self.launch_state.update();

self.launch_state.render_ui(
&self.runtime,
ui,
&mut self.config,
&version_metadata,
self.auth_state.online(),
);
} else {
let force_launch_result =
self.launch_state.render_download_ui(ui, &mut self.config);
match force_launch_result {
ForceLaunchResult::ForceLaunchSelected => {
self.instance_sync_state.schedule_sync_if_needed();
self.java_state.schedule_download_if_needed(
&self.runtime,
&version_metadata,
&mut self.config,
);
}
ForceLaunchResult::CancelSelected => {
self.java_state.cancel_download();
self.instance_sync_state.cancel_sync();
}
ForceLaunchResult::NotSelected => {}
}
ForceLaunchResult::NotSelected => {}
}
}
}
}
}
});
});

egui::TopBottomPanel::bottom("bottom_panel")
.resizable(false)
.show(ctx, |ui| {
ui.add_space(5.0);
ui.horizontal(|ui| {
let selected_metadata_ref = selected_metadata.as_deref();
self.settings_state
.render_ui(ui, &self.runtime, &mut self.config, selected_metadata_ref);
});
ui.add_space(5.0);
});
}
}
4 changes: 2 additions & 2 deletions launcher/src/app/auth_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl AuthState {
false
}

fn render_auth_window(auth_message: LangMessage, lang: &Lang, ui: &mut egui::Ui) {
fn render_auth_window(auth_message: LangMessage, lang: Lang, ui: &mut egui::Ui) {
egui::Window::new(LangMessage::Authorization.to_string(lang)).show(ui.ctx(), |ui| {
ui.label(auth_message.to_string(lang));
let url = match auth_message {
Expand Down Expand Up @@ -175,7 +175,7 @@ impl AuthState {
ctx: &egui::Context,
auth_data: &AuthData,
) {
let lang = &config.lang;
let lang = config.lang;
let version_auth_data = config.get_version_auth_data(auth_data);
let selected_username = version_auth_data.map(|x| x.user_info.username.clone());
let selected_token = version_auth_data.map(|x| x.token.clone());
Expand Down
Loading

0 comments on commit c53e14f

Please sign in to comment.