Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AeEn123 committed Dec 19, 2024
2 parents 85ea1fb + 2d6e2ab commit b2b1d06
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 30 deletions.
2 changes: 2 additions & 0 deletions CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
- [ ] - Update locales (Deadline: 25/12/2024 (Christmas :D))

## Future releases

- [ ] - Jump to asset on keyboard press
- [ ] - Docs available in different languages
- [ ] - Finish CLI mode documentation
- [ ] - Built-in media player/image decoder to quickly preview assets
Expand Down
6 changes: 3 additions & 3 deletions locales/de-DE.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ confirmation-custom-directory-description = Willst du ein anderen Cacheordner au
confirmation-ban-warning-title = Potenzielle Bannwarnung
confirmation-ban-warning-description = Assets in Spielen zu bearbeiten kann dazuführen ,dass sich dein Spiel anders verhält was zu potenziellen Bännen in Spielen führen kann! Benutze es mit dein eigenen Risiko. Verstehst du es?
button-swap = Swap assets <F4> # TODO: Translate
swap-with = Choose a file to swap with "{ $asset }" # TODO: Translate
swap-choose-file = Choose a file to swap # TODO: Translate
button-swap = Assets austauschen <F4>
swap-choose-file = Doppelklicke eine Datei um sie auszutauschen
swap-with = Doppelklicke eine Datei um sie mit "{ $asset }" auszutauschen
4 changes: 2 additions & 2 deletions locales/en-GB.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ clear-cache-description = If it is taking too long to list files and extracting
extract-all-description = The button below will copy all assets and create folders e.g /sounds, /images to catagorize them. You can choose the root folder when starting.
custom-cache-dir-description = If you want to access the cache in a different Roblox installation, change your cache directory below, you can set it back to default with the other button.
use-alias-description = Instead of exporting the raw file name for the asset, checking this checkbox will export the filename you choose instead. You can do this by renaming within the application itself.
swap-choose-file = Choose a file to swap
swap-with = Choose a file to swap with "{ $asset }"
swap-choose-file = Double click a file to swap
swap-with = Double click a file to swap with "{ $asset }"
# Statuses
Expand Down
4 changes: 2 additions & 2 deletions locales/ja-JP.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ confirmation-custom-directory-title = Choose a different directory # TODO: Trans
confirmation-ban-warning-description = Editing assets in games can cause your client to behave differently leading to potential game bans! Use at your own risk. Do you understand? # TODO: Translate
confirmation-ban-warning-title = Potential ban alert # TODO: Translate
button-swap = Swap assets <F4> # TODO: Translate
swap-with = Choose a file to swap with "{ $asset }" # TODO: Translate
swap-choose-file = Choose a file to swap # TODO: Translate
swap-choose-file = Double click a file to swap # TODO: Translate
swap-with = Double click a file to swap with "{ $asset }" # TODO: Translate
4 changes: 2 additions & 2 deletions locales/pl-PL.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ use-alias = Eksportuj nazwy alternatywne dla plików
# Descriptions
swap-choose-file = Choose a file to swap # TODO: Translate
swap-with = Choose a file to swap with "{ $asset }" # TODO: Translate
swap-with = Double click a file to swap with "{ $asset }" # TODO: Translate
swap-choose-file = Double click a file to swap # TODO: Translate
clear-cache-description = Jeżeli wyświetlanie lub wyodrębnianie plików zajmuje za długo, możesz wyczyścić pamieć podręczną gry Roblox. Usunie to wszystkie pliki z pamięci podręcznej i gra Roblox wygeneruje pliki, kiedy są wymagane.
extract-all-description = Ten przycisk skopiuje wszystkie zasoby i stworzy katalogi np. /sounds, /images aby je kategoryzować. Możesz zmienić folder do wypakowania przed startem.
custom-cache-dir-description = Jeżeli potrzebujesz dostęp do pamięci potrzebnej innej instalacji gry Roblox, możesz zmienić katalog pamięci podręcznej poniżej, a możesz ustawić go spowrotem do domyślnego ustawienia klikając inny przycisk.
Expand Down
10 changes: 9 additions & 1 deletion src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,15 @@ impl MyApp {
None => {
println!("No Japanese fonts detected, Japanese characters will not render.")
}
}
}

// Get theme from config
match logic::get_config_string("theme").unwrap_or("system".to_owned()).as_str() {
"dark" => cc.egui_ctx.set_theme(egui::Theme::Dark),
"light" => cc.egui_ctx.set_theme(egui::Theme::Light),
_ => ()
}

Default::default()
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/gui/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ pub fn behavior(ui: &mut egui::Ui, locale: &FluentBundle<Arc<FluentResource>>) {
ui.separator();
ui.heading(logic::get_message(locale, "behavior", None));

egui::widgets::global_theme_preference_buttons(ui);
match ui.ctx().options(|opt| opt.theme_preference) {
egui::ThemePreference::Dark => logic::set_config_value("theme", "dark".into()),
egui::ThemePreference::Light => logic::set_config_value("theme", "light".into()),
egui::ThemePreference::System => logic::set_config_value("theme", "system".into())
}


ui.label(logic::get_message(locale, "use-alias-description", None));

let mut use_alias = logic::get_config_bool("use_alias").unwrap_or(true);
Expand Down
54 changes: 53 additions & 1 deletion src/gui/welcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,58 @@ pub struct MyApp {
locale: FluentBundle<Arc<FluentResource>>,
}

fn detect_japanese_font() -> Option<String> {
let font_dirs = ["C:\\Windows\\Fonts\\msgothic.ttc", "/usr/share/fonts/noto-cjk/NotoSerifCJK-Regular.ttc", "~/.local/share/fonts/noto-cjk/NotoSerifCJK-Regular.ttc", "~/.fonts/noto-cjk/NotoSerifCJK-Regular.ttc"];

for font in font_dirs {
let resolved_font = logic::resolve_path(&font);
match std::fs::metadata(&resolved_font) {
Ok(metadata) => {
if metadata.is_file() {
println!("{}: valid", resolved_font);
return Some(resolved_font);
}
}
Err(e) => {
println!("{}: invalid - {}", resolved_font, e)
}
}

};
return None;
}

// https://users.rust-lang.org/t/is-posible-egui-change-fonts-to-japanese-how/59662/5
impl MyApp {
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
//Custom font install
// 1. Create a `FontDefinitions` object.
let mut font = egui::FontDefinitions::default();
// Install my own font (maybe supporting non-latin characters):
// 2. register the font content with a name.
match detect_japanese_font() {
Some(font_path) => {
match std::fs::read(font_path) {
Ok(bytes) => {
font.font_data.insert("japanese".to_owned(),egui::FontData::from_owned(bytes));
font.families.get_mut(&egui::FontFamily::Monospace).unwrap().push("japanese".to_owned());
font.families.get_mut(&egui::FontFamily::Proportional).unwrap().push("japanese".to_owned());
// 3. Configure context with modified `FontDefinitions`.
cc.egui_ctx.set_fonts(font);
}
Err(e) => {
println!("Error loading Japanese fonts: {e}")
}
}
}
None => {
println!("No Japanese fonts detected, Japanese characters will not render.")
}
}
Default::default()
}
}

impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
Expand Down Expand Up @@ -60,7 +112,7 @@ pub fn run_gui() -> eframe::Result {
eframe::run_native(
&format!("Roblox Assets Extractor v{VERSION}").to_owned(),
options,
Box::new(|_cc| Ok(Box::<MyApp>::default())),
Box::new(|cc| Ok(Box::new(MyApp::new(cc)))),
)

}
89 changes: 70 additions & 19 deletions src/updater/gui.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use eframe::egui;
use crate::logic;
use crate::logic::get_config_string;
use crate::updater;
use egui_commonmark::*;
use fluent_bundle::{FluentBundle, FluentResource};
Expand All @@ -13,6 +14,73 @@ struct App {
name: String,
}

fn detect_japanese_font() -> Option<String> {
let font_dirs = ["C:\\Windows\\Fonts\\msgothic.ttc", "/usr/share/fonts/noto-cjk/NotoSerifCJK-Regular.ttc", "~/.local/share/fonts/noto-cjk/NotoSerifCJK-Regular.ttc", "~/.fonts/noto-cjk/NotoSerifCJK-Regular.ttc"];

for font in font_dirs {
let resolved_font = logic::resolve_path(&font);
match std::fs::metadata(&resolved_font) {
Ok(metadata) => {
if metadata.is_file() {
println!("{}: valid", resolved_font);
return Some(resolved_font);
}
}
Err(e) => {
println!("{}: invalid - {}", resolved_font, e)
}
}

};
return None;
}

// https://users.rust-lang.org/t/is-posible-egui-change-fonts-to-japanese-how/59662/5
impl App {
pub fn new(cc: &eframe::CreationContext<'_>, text: String, name: String, url: String) -> Self {
//Custom font install
// 1. Create a `FontDefinitions` object.
let mut font = egui::FontDefinitions::default();
// Install my own font (maybe supporting non-latin characters):
// 2. register the font content with a name.
match detect_japanese_font() {
Some(font_path) => {
match std::fs::read(font_path) {
Ok(bytes) => {
font.font_data.insert("japanese".to_owned(),egui::FontData::from_owned(bytes));
font.families.get_mut(&egui::FontFamily::Monospace).unwrap().push("japanese".to_owned());
font.families.get_mut(&egui::FontFamily::Proportional).unwrap().push("japanese".to_owned());
// 3. Configure context with modified `FontDefinitions`.
cc.egui_ctx.set_fonts(font);
}
Err(e) => {
println!("Error loading Japanese fonts: {e}")
}
}
}
None => {
println!("No Japanese fonts detected, Japanese characters will not render.")
}
}

// Set system theme from config
match get_config_string("theme").unwrap_or("system".to_owned()).as_str() {
"dark" => cc.egui_ctx.set_theme(egui::Theme::Dark),
"light" => cc.egui_ctx.set_theme(egui::Theme::Light),
_ => ()
}

// Return self
Self {
cache: CommonMarkCache::default(),
changelog: text,
locale: logic::get_locale(None),
name: name,
url: url
}
}
}

const VERSION: &str = env!("CARGO_PKG_VERSION");

impl eframe::App for App {
Expand All @@ -34,7 +102,7 @@ impl eframe::App for App {
});
egui::TopBottomPanel::bottom("buttons").show(ctx, |ui| {
ui.horizontal(|ui| {
ui.heading("Do you want to install the new update?");
ui.heading(logic::get_message(&self.locale, "download-update-question", None));
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
if ui.button(logic::get_message(&self.locale, "button-no", None)).clicked() {
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
Expand All @@ -51,33 +119,16 @@ impl eframe::App for App {
}

pub fn run_gui(text: String, name: String, url: String) -> eframe::Result {
let mut args = std::env::args();
args.next();

eframe::run_native(
&format!("Roblox Assets Extractor Updater v{}", VERSION),
eframe::NativeOptions::default(),
Box::new(move |cc| {
if let Some(theme) = args.next() {
if theme == "light" {
cc.egui_ctx.set_theme(egui::Theme::Light);
} else if theme == "dark" {
cc.egui_ctx.set_theme(egui::Theme::Dark);
}
}

cc.egui_ctx.style_mut(|style| {
// Show the url of a hyperlink on hover
style.url_in_tooltip = true;
});

Ok(Box::new(App {
cache: CommonMarkCache::default(),
changelog: text,
locale: logic::get_locale(None),
name: name,
url: url
}))
Ok(Box::new(App::new(cc, text, name, url)))
}),
)
}

0 comments on commit b2b1d06

Please sign in to comment.