Skip to content

Commit

Permalink
Merge pull request #16 from Warthunder-Open-Source-Foundation/nightly
Browse files Browse the repository at this point in the history
1.0.0
  • Loading branch information
FlareFlo authored Jan 22, 2022
2 parents f4a8b09 + 5d42324 commit 87ea397
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "wt_custom_lang"
description = "A tool to create custom language files for the game War Thunder"
version = "0.2.1"
version = "1.0.0"
edition = "2021"
rust-version = "1.58"
license = "Apache-2.0"
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Installation guide

* Download latest release for your fitting operating system from <a href="https://github.com/Warthunder-Open-Source-Foundation/wt_custom_lang/releases" title="release URL">here</a>
* Move binary to appropiate location -- or simply execute in place (such as the download folder)
- For windows ```C:\Program Files (x86)\wt_custom_lang```
- For linux ```$HOME/.local/bin/wt_custom_lang```
- Create the appropaite above mentioned (sub-)folder if it doesnt already exist

Done!

# For using the tool, please refer to <a href="https://github.com/Warthunder-Open-Source-Foundation/wt_custom_lang/blob/nightly/guide/how_to_use.md" title="guide">here</a>
15 changes: 14 additions & 1 deletion guide/how_to_use.md
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
WIP
# Creating a new entry
- Select ``Add new entry``
- Check which file to edit (using the wiki to figure out the proper path)
- Enter the current displayed name (turns green when it is found)
- Enter the replaced name

# Removing an entry
- Click undo on the individual entry should return it to the original

# Using/Creating backups
- Select ``Backups``
- Enter name of backup and click create

- Backups can be loaded or deleted via the ``Load`` or ``Delete`` option
68 changes: 36 additions & 32 deletions src/app/basic_prompts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{CustomLang, REPO_URL};

impl CustomLang {
pub fn prompt_for_status(&mut self, ctx: &CtxRef) {
Window::new("Config status").show(ctx, |ui| {
Window::new("Config status").anchor(Align2::CENTER_CENTER, Vec2::new(0.0,0.0)).show(ctx, |ui| {
if self.config.is_wt_path_valid() {
ui.add(Label::new(RichText::new(format!("WT path is defined and working ✅")).color(Color32::from_rgb(0, 255, 0))));
}
Expand All @@ -31,7 +31,7 @@ impl CustomLang {
});
}
pub(crate) fn prompt_for_wt_path(&mut self, ctx: &CtxRef) {
Window::new("First time setup").show(ctx, |ui| {
Window::new("First time setup").anchor(Align2::CENTER_CENTER, Vec2::new(0.0,0.0)).show(ctx, |ui| {
ui.add(Label::new("Select WarThunder installation folder"));
let select_button = ui.add(Button::new(RichText::new("Choose path").text_style(TextStyle::Body)));
ui.add(Hyperlink::from_label_and_url("Where the game might be installed", format!("{}/guide/install_folder.md", REPO_URL)));
Expand All @@ -54,7 +54,7 @@ impl CustomLang {
});
}
pub fn prompt_for_config_blk(&mut self, ctx: &CtxRef) {
Window::new("Configuring the config.blk file").show(ctx, |ui| {
Window::new("Configuring the config.blk file").anchor(Align2::CENTER_CENTER, Vec2::new(0.0,0.0)).show(ctx, |ui| {
if let Some(wt_path) = self.config.wt_path.as_ref() {
let blk_path = format!("{}/config.blk", wt_path);
match fs::read_to_string(&blk_path) {
Expand Down Expand Up @@ -90,46 +90,50 @@ impl CustomLang {
});
}
pub fn prompt_for_lang_folder(&mut self, ctx: &CtxRef) {
Window::new("Steps for generating the lang folder").show(ctx, |ui| {
if ui.add(Button::new(RichText::new("Launch game").text_style(TextStyle::Heading))).clicked() {
// Cloning as the thread consumes the String entirely
if let Some(path) = self.config.wt_path.as_ref() {
#[cfg(target_os = "windows")] let format_path = format!("{}/launcher.exe", path);
Window::new("Launching the game").anchor(Align2::CENTER_CENTER, Vec2::new(0.0,0.0)).show(ctx, |ui| {
ui.horizontal(|ui|{
if ui.add(Button::new(RichText::new("Launch game ⬈").text_style(TextStyle::Heading))).clicked() {
// Cloning as the thread consumes the String entirely
if let Some(path) = self.config.wt_path.as_ref() {
#[cfg(target_os = "windows")] let format_path = format!("{}/launcher.exe", path);

#[cfg(target_os = "linux")] let format_path = format!("{}/launcher", path);
#[cfg(target_os = "linux")] let format_path = format!("{}/launcher", path);

// Spawning loose thread as application completely stalls as long as launcher.exe lives
thread::spawn(move || {
// Not catching as the process will be orphaned
let _ = Command::new(format_path).execute();
});
} else {
self.prompt_error.err_value = Some("No WT path is set, but at this point in time it should be".to_owned());
return;
// Spawning loose thread as application completely stalls as long as launcher.exe lives
thread::spawn(move || {
// Not catching as the process will be orphaned
let _ = Command::new(format_path).execute();
});
} else {
self.prompt_error.err_value = Some("No WT path is set, but at this point in time it should be".to_owned());
return;
}
}
}

ui.add_space(20.0);
ui.add_space(20.0);

if ui.add(Button::new(RichText::new("Check if it was created").text_style(TextStyle::Heading))).clicked() {
if let Some(path) = self.config.wt_path.as_ref() {
if fs::read_dir(format!("{}/lang", path)).is_ok() {
self.config.lang_folder_created = true;
if ui.add(Button::new(RichText::new("Verify folder").text_style(TextStyle::Heading))).clicked() {
if let Some(path) = self.config.wt_path.as_ref() {
if fs::read_dir(format!("{}/lang", path)).is_ok() {
self.config.lang_folder_created = true;
}
} else {
self.prompt_error.err_value = Some("No WT path is set, but at this point in time it should be".to_owned());
return;
}
} else {
self.prompt_error.err_value = Some("No WT path is set, but at this point in time it should be".to_owned());
return;
}
}
});
});
}
#[cfg(windows)]
pub fn prompt_lang_file_warn(&mut self, ctx: &CtxRef) {
Window::new("Setting lang folder permissions").show(ctx, |ui| {
if ui.add(Button::new(RichText::new("Done!").text_style(TextStyle::Heading))).clicked() {
self.config.prompted_about_lang_perm = true;
}
ui.add(Hyperlink::from_label_and_url("I dont know how to do that", "https://github.com/Warthunder-Open-Source-Foundation/wt_custom_lang/blob/master/guide/windows_lang_permission.md"));
Window::new("Setting up permissions").anchor(Align2::CENTER_CENTER, Vec2::new(0.0,0.0)).show(ctx, |ui| {
ui.horizontal(|ui|{
ui.add(Hyperlink::from_label_and_url(RichText::new("How to set up proper permissions").text_style(TextStyle::Heading), "https://github.com/Warthunder-Open-Source-Foundation/wt_custom_lang/blob/master/guide/windows_lang_permission.md"));
if ui.add(Button::new(RichText::new("Done!").text_style(TextStyle::Heading))).clicked() {
self.config.prompted_about_lang_perm = true;
}
});
});
}
}
15 changes: 8 additions & 7 deletions src/app/prompts/prompt_for_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl CustomLang {
Window::new("Adding a new entry").show(ctx, |ui| {
let mut original = self.prompt_for_entry.before_after_entry.clone();

let mut color= Color32::from_rgb(255,255,255);;
let mut color= Color32::from_rgb(255,255,255);

let mut contains = |file_path: &str|{
if fs::read_to_string(format!("{}/lang/{}.csv", wt_raw, file_path)).unwrap_or("".to_owned()).contains(&format!(r#""{}""#, &original.0)) {
Expand All @@ -66,11 +66,6 @@ impl CustomLang {
}
};

contains(self.prompt_for_entry.toggle_dropdown.to_file_name());

ui.add(TextEdit::singleline (&mut original.0).hint_text("Old name").text_color(color));
ui.add(TextEdit::singleline(&mut original.1).hint_text("New name"));

ui.horizontal(|ui| {
ComboBox::from_label("").selected_text(format!("{:?}", self.prompt_for_entry.toggle_dropdown)).show_ui(ui, |ui| {
ui.selectable_value(&mut self.prompt_for_entry.toggle_dropdown, LangType::Units, "Unit");
Expand All @@ -81,10 +76,16 @@ impl CustomLang {
ui.add(Hyperlink::from_label_and_url("What these options mean", "https://github.com/Warthunder-Open-Source-Foundation/wt_custom_lang/wiki/Types-of-supported-language-files"));
});


contains(self.prompt_for_entry.toggle_dropdown.to_file_name());

ui.add(TextEdit::singleline (&mut original.0).hint_text("Old name").text_color(color));
ui.add(TextEdit::singleline(&mut original.1).hint_text("New name"));

self.prompt_for_entry.before_after_entry = original;

ui.horizontal(|ui| {
if ui.add(Button::new(RichText::new("Create!").text_style(TextStyle::Heading))).clicked() {
if ui.add(Button::new(RichText::new("Create").text_style(TextStyle::Heading))).clicked() {
let lang_type = self.prompt_for_entry.toggle_dropdown.to_file_name();
let path: String = format!("{}/lang/{}.csv", wt_raw, lang_type);

Expand Down
10 changes: 5 additions & 5 deletions src/lang_manipulation/primitive_lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ impl PrimitiveEntry {
}
_ => {
panic!("Custom files are currently not implemented");
let mut file = file_to_string(custom_lang, wt_path, &entry.file);
file = file.replace(&format(&entry.original_english), &format(&entry.new_english));
if let Err(error) = fs::write(string_to_path(&entry.file), file) {
custom_lang.prompt_error.err_value = Some(format!("{:?} {}:{} {}", error, line!(), column!(), file!()));
}
// let mut file = file_to_string(custom_lang, wt_path, &entry.file);
// file = file.replace(&format(&entry.original_english), &format(&entry.new_english));
// if let Err(error) = fs::write(string_to_path(&entry.file), file) {
// custom_lang.prompt_error.err_value = Some(format!("{:?} {}:{} {}", error, line!(), column!(), file!()));
// }
}
}
}
Expand Down

0 comments on commit 87ea397

Please sign in to comment.