diff --git a/Cargo.toml b/Cargo.toml index 834d30b..f55ecc5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "Astrolabe" -edition = "2021" +edition = "2024" license-file = "LICENSE" repository = "https://github.com/hessiser/veritas/" diff --git a/src/ui/app.rs b/src/ui/app.rs index c7f3746..78a9ad4 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -14,6 +14,10 @@ use windows::Win32::{ UI::{Input::KeyboardAndMouse::VK_MENU, WindowsAndMessaging::WM_KEYDOWN}, }; +use egui::{FontId, FontFamily, TextStyle,}; +use std::collections::BTreeMap; + + #[derive(Default, PartialEq)] pub enum GraphUnit { #[default] @@ -89,14 +93,23 @@ impl Overlay for App { ui.separator(); ui.label(t!("Window Opacity")); - ui.add( - Slider::new(&mut self.widget_opacity, 0.0..=1.0).text(""), + ui.add_sized( + [ui.available_width()*0.8, ui.spacing().interact_size.y], + Slider::new(&mut self.widget_opacity, 0.0..=1.0).text("") ); ui.separator(); ui.label(t!("Streamer Message")); ui.add(TextEdit::singleline(&mut self.streamer_msg)); + ui.separator(); + ui.label(t!("DamageLogger Panel")); + ui.add(TextEdit::multiline(&mut t!("http://localhost:1305/static/"))); + + ui.separator(); + ui.label(t!("Battle Timeline Panel")); + ui.add(TextEdit::multiline(&mut t!("http://localhost:1305/static/battle_timeline.html"))); + ui.separator(); if ui.button(t!("Close Menu")).clicked() { self.show_menu = false; @@ -135,7 +148,8 @@ impl Overlay for App { .corner_radius(10.0); if self.show_damage_distribution { - egui::containers::Window::new("") + // 窗口title未设置,设置为Damage Ratio + egui::containers::Window::new("Damage Ratio") .frame(transparent_frame) .resizable(true) .min_width(200.0) @@ -266,9 +280,26 @@ impl App { style.visuals.widgets.noninteractive.fg_stroke.color = Color32::WHITE; }); + // 更改全局字体样式的大小 + let custom_fontsize_style = egui::Style { + text_styles: BTreeMap::from([ + (TextStyle::Heading, FontId::new(30.0, FontFamily::Proportional)), + (TextStyle::Name("Heading2".into()), FontId::new(26.0, FontFamily::Proportional)), + (TextStyle::Name("Context".into()), FontId::new(24.0, FontFamily::Proportional)), + (TextStyle::Name("Legend".into()), FontId::new(22.0, FontFamily::Monospace)), + (TextStyle::Body, FontId::new(24.0, FontFamily::Proportional)), + (TextStyle::Monospace, FontId::new(24.0, FontFamily::Monospace)), + (TextStyle::Button, FontId::new(22.0, FontFamily::Proportional)), + (TextStyle::Small, FontId::new(18.0, FontFamily::Proportional)), + ]), + ..ctx.style().as_ref().clone() + }; + ctx.set_style(custom_fontsize_style); + Self { widget_opacity: 0.15, - streamer_mode: true, + // 默认不启用Steamer Mode + streamer_mode: false, ..Default::default() } } diff --git a/src/ui/helpers.rs b/src/ui/helpers.rs index 29d86ca..45d220f 100644 --- a/src/ui/helpers.rs +++ b/src/ui/helpers.rs @@ -1,5 +1,14 @@ pub fn format_damage(value: f64) -> String { - if value >= 1_000_000.0 { + if value >= 100_000_000_000.0 { + //100.0G-Inf, 大于999.9G将会导致图例不对齐,这游戏应该不会膨胀到这种程度吧? + let m = value / 1_000_000_000.0; + format!("{m:.1}G") + } else if value >= 1_000_000_000.0 { + //1000M-99999M + let m = value / 1_000_000.0; + format!("{m:.0}M") + } else if value >= 1_000_000.0 { + //1.0M-999.9M let m = value / 1_000_000.0; format!("{m:.1}M") } else if value >= 1_000.0 { diff --git a/src/ui/widgets.rs b/src/ui/widgets.rs index 15b62fc..726746b 100644 --- a/src/ui/widgets.rs +++ b/src/ui/widgets.rs @@ -16,11 +16,17 @@ impl App { let battle_context = BattleContext::get_instance(); let available = ui.available_size(); Plot::new("damage_pie") + //优化饼图显示位置,默认状态下不会被图例遮挡 + .set_margin_fraction(egui::Vec2 { x: (0.), y: (0.05) }) + .default_x_bounds(-13., 13.) + .default_y_bounds(-10.5, 20.) .legend( Legend::default() .position(egui_plot::Corner::RightTop) - .text_style(TextStyle::Small), + .text_style(TextStyle::Name("Legend".into())), ) + .show_x(false) + .show_y(false) .height(available.y) .width(available.x) .data_aspect(1.0) @@ -28,7 +34,7 @@ impl App { .show_grid(false) .show_background(false) .show_axes([false; 2]) - .allow_drag(false) + // .allow_drag(false) .allow_zoom(false) .allow_scroll(false) .show(ui, |plot_ui: &mut egui_plot::PlotUi<'_>| { @@ -43,13 +49,21 @@ impl App { let percentage = segment.value / total_damage * 100.0; let plot_points = PlotPoints::new(segment.points); - let polygon = Polygon::new("Damage Pie", plot_points) - .stroke(Stroke::new(1.5, color)) - .name(format!( - "{}: {:.1}% ({} dmg)", - avatar.name, - percentage, - helpers::format_damage(segment.value) + // 不同的Polygon修改后拥有不同的唯一识别符,避免点击图例后饼图全部消失 + let polygon = Polygon::new( + format!( + "Damage Pie {index} For {avatar_name}", + avatar_name = avatar.name, + index = i + ), + plot_points) + .stroke(Stroke::new(1.8, color)) + .highlight(true) + .name(format!(//优化图例的格式化文本,一般情况下能对齐 + "{name:<}:{damage:>6}#{percentage:>5.1}%", + name = avatar.name, + damage = helpers::format_damage(segment.value), + percentage = percentage )); plot_ui.polygon(polygon); @@ -63,6 +77,8 @@ impl App { let available = ui.available_size(); Plot::new("damage_bars") .legend(Legend::default()) + .show_x(false) + //.show_y(false) .height(available.y) .width(available.x) .allow_drag(false) @@ -91,6 +107,11 @@ impl App { .name(&avatar.name) .fill(helpers::get_character_color(*color_idx)) .width(0.7) + .stroke( + Stroke::new(1.8, + helpers::get_character_color(*color_idx)) + ) + }) .collect(); @@ -105,8 +126,10 @@ impl App { .legend( Legend::default() .position(egui_plot::Corner::RightTop) - .text_style(TextStyle::Small), + .text_style(TextStyle::Name("Legend".into())), ) + .show_x(false) + .show_y(false) .height(available.y) .width(available.x) .include_y(0.0) @@ -143,8 +166,10 @@ impl App { .legend( Legend::default() .position(egui_plot::Corner::RightTop) - .text_style(TextStyle::Small), + .text_style(TextStyle::Name("Legend".into())), ) + .show_x(false) + .show_y(false) .height(available.y) .width(available.x) .include_y(0.0) @@ -289,7 +314,7 @@ fn create_pie_segments( fn create_pie_slice(start_angle: f64, end_angle: f64) -> Vec<[f64; 2]> { let center = [0.0, 0.0]; - let radius = 0.8; + let radius = 10.; let mut points = vec![center]; let steps = 50;