Skip to content

Commit

Permalink
Merge branch 'juliancoffee/add-asset-override' into 'master'
Browse files Browse the repository at this point in the history
Put VELOREN_ASSETS_OVERRIDE in main settings menu

See merge request veloren/airshipper!162
  • Loading branch information
crabman committed Oct 12, 2024
2 parents 32e1e21 + 8040e70 commit 094d6f9
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 7 deletions.
100 changes: 93 additions & 7 deletions client/src/gui/components/settings_panel.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::{
assets::FOLDER_ICON,
assets::{BOOK_ICON, FOLDER_ICON},
channels::{Channel, Channels},
gui::{
components::GamePanelMessage,
custom_widgets::heading_with_rule,
style::{button::ButtonStyle, container::ContainerStyle, text::TextStyle},
views::{default::DefaultViewMessage, Action},
views::{
default::{DefaultViewMessage, Interaction},
Action,
},
widget::*,
},
profiles,
Expand All @@ -16,7 +19,7 @@ use iced::{
alignment::Horizontal,
widget::{
button, column, container, image, image::Handle, pick_list, row, text,
text_input, tooltip, tooltip::Position,
text_input, tooltip, tooltip::Position, Image,
},
Alignment, Command, Length, Padding,
};
Expand All @@ -29,6 +32,7 @@ pub enum SettingsPanelMessage {
ChannelChanged(Channel),
WgpuBackendChanged(profiles::WgpuBackend),
EnvVarsChanged(String),
AssetsOverrideChanged(String),
OpenLogsPressed,
ChannelsLoaded(Result<Channels>),
}
Expand Down Expand Up @@ -105,6 +109,14 @@ impl SettingsPanelComponent {
DefaultViewMessage::Action,
))
},
SettingsPanelMessage::AssetsOverrideChanged(assets) => {
let mut profile = active_profile.clone();
profile.assets_override = Some(assets);
Some(Command::perform(
async { Action::UpdateProfile(profile) },
DefaultViewMessage::Action,
))
},
SettingsPanelMessage::ChannelsLoaded(result) => {
if let Ok(channels) = result {
debug!(?channels, "Fetched available channels:");
Expand Down Expand Up @@ -220,13 +232,64 @@ impl SettingsPanelComponent {
.size(FONT_SIZE)
.gap(5);

let help_link =
"https://book.veloren.net/players/env-vars.html#veloren_assets_override"
.to_owned();
let assets_override = tooltip(
column![]
.spacing(5)
.push(
row![]
.spacing(5)
.push(
text("ASSETS OVERRIDE").size(15).style(TextStyle::LightGrey),
)
.push(help_link_button(help_link)),
)
.push(
container(
text_input(
"/path/to/asset/folder/with/overrides",
active_profile
.assets_override
.as_deref()
.unwrap_or_default(),
|path| {
DefaultViewMessage::SettingsPanel(
SettingsPanelMessage::AssetsOverrideChanged(path),
)
},
)
.padding(PICK_LIST_PADDING)
.size(FONT_SIZE),
)
.height(Length::Fixed(50.0))
.width(Length::Fixed(260.0)),
),
"Folder where you can put modified assets for testing or fun!",
Position::Top,
)
.style(
// TODO: this and env_vars should probably scream at you for putting
// invalid data in
ContainerStyle::Tooltip,
)
.size(FONT_SIZE)
.gap(5);

let help_link = "https://book.veloren.net/players/env-vars.html".to_owned();
let env_vars = tooltip(
column![]
.spacing(5)
.push(
text("ENVIRONMENT VARIABLES")
.size(15)
.style(TextStyle::LightGrey),
row![]
.spacing(5)
.push(
text("ENVIRONMENT VARIABLES")
.size(15)
.style(TextStyle::LightGrey),
)
.push(help_link_button(help_link)),
)
.push(
container(
Expand Down Expand Up @@ -292,7 +355,18 @@ impl SettingsPanelComponent {
let second_row =
container(row![].spacing(10).push(env_vars).push(channel_picker));

let col = column![].spacing(10).push(first_row).push(second_row);
let third_row = container(
row![]
.spacing(10)
.align_items(Alignment::End)
.push(assets_override),
);

let col = column![]
.spacing(10)
.push(first_row)
.push(second_row)
.push(third_row);

column![]
.push(heading_with_rule("Settings"))
Expand All @@ -304,3 +378,15 @@ impl SettingsPanelComponent {
.into()
}
}

fn help_link_button(url: String) -> Element<'static, DefaultViewMessage> {
button(
Image::new(Handle::from_memory(BOOK_ICON.to_vec()))
.height(Length::Fixed(10.0))
.width(Length::Fixed(10.0)),
)
.on_press(DefaultViewMessage::Interaction(Interaction::OpenURL(url)))
.padding(Padding::new(0.0))
.style(ButtonStyle::Transparent)
.into()
}
11 changes: 11 additions & 0 deletions client/src/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub struct Profile {
pub wgpu_backend: WgpuBackend,
pub log_level: LogLevel,
pub env_vars: String,
// TODO: make a file-picker UI for this
pub assets_override: Option<String>,
// if set, on every download we do a full zip download
pub disable_partial_download: bool,

Expand Down Expand Up @@ -158,6 +160,7 @@ impl Profile {
wgpu_backend: WgpuBackend::Auto,
log_level: LogLevel::Default,
env_vars: String::new(),
assets_override: None,
supported_wgpu_backends: Vec::new(),
disable_partial_download: false,
}
Expand Down Expand Up @@ -237,6 +240,14 @@ impl Profile {
envs.insert("RUST_LOG", log_level);
}

if let Some(path) = &profile.assets_override {
if Path::new(&path).exists() {
envs.insert("VELOREN_ASSETS_OVERRIDE", path.into());
} else {
tracing::warn!("We can't find this assets override path: {}", path);
}
}

envs.insert("VOXYGEN_SCREENSHOT", screenshot_dir);
envs.insert("VELOREN_USERDATA", userdata_dir);
envs.insert("VELOREN_ASSETS", assets_dir);
Expand Down

0 comments on commit 094d6f9

Please sign in to comment.