From 7fbaa506b0d0e4fcdf3e8f4e4fd3027dc789ce9a Mon Sep 17 00:00:00 2001 From: yueyan <1344915157@qq.com> Date: Mon, 28 Jul 2025 18:06:04 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E7=9A=84=E5=AD=97=E4=BD=93=E5=B0=BA=E5=AF=B8=E3=80=82=202.=20?= =?UTF-8?q?=E5=9B=BE=E4=BE=8B=E5=AD=97=E4=BD=93=E6=97=8F=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E7=AD=89=E5=AE=BD=E5=AD=97=E4=BD=93=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A5=BC=E5=9B=BE=E5=9B=BE=E4=BE=8B=E7=9A=84?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=EF=BC=8C=E6=95=B0=E6=8D=AE=E8=83=BD?= =?UTF-8?q?=E6=9B=B4=E5=A5=BD=E7=9A=84=E5=AF=B9=E9=BD=90.=203.=20=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E9=A5=BC=E5=9B=BE=E8=BE=B9=E7=95=8C=EF=BC=8C=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=83=85=E5=86=B5=E4=B8=8B=E5=9B=BE=E4=BE=8B=E4=B8=8D?= =?UTF-8?q?=E4=BC=9A=E9=81=AE=E6=8C=A1=E9=A5=BC=E5=9B=BE=E3=80=82=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E4=BA=86=E5=85=89=E6=A0=87=E5=9C=A8=E5=9B=BE=E8=A1=A8?= =?UTF-8?q?=E4=B8=AD=E6=97=B6=E4=B8=8D=E5=BF=85=E8=A6=81=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E7=9A=84x=3D***=20y=3D***=E3=80=82=204.=20=E5=8F=96=E6=B6=88St?= =?UTF-8?q?eamer=20Mode=E7=9A=84=E9=BB=98=E8=AE=A4=E5=BC=80=E5=90=AF?= =?UTF-8?q?=E3=80=82=205.=20Overlay=E8=8F=9C=E5=8D=95=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=96=87=E6=9C=AC=E6=A1=86=E5=B1=95=E7=A4=BA=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E7=BD=91=E9=A1=B5=E6=9C=8D=E5=8A=A1=E7=9A=84=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E3=80=82=206.=20=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=ADCargo.toml=E7=9A=84edtion=E4=BB=8E2021=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=BA2024=EF=BC=8C=E4=BD=BF=E7=94=A82021=E5=9C=A8?= =?UTF-8?q?=E6=88=91=E7=9A=84=E8=AE=BE=E5=A4=87=E4=B8=8A=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E3=80=82=200.=20=E6=B2=A1=E5=AD=A6=E8=BF=87r?= =?UTF-8?q?ust=EF=BC=8C=E7=BA=AF=E9=97=AEai=E7=8E=B0=E5=AD=A6=E7=8E=B0?= =?UTF-8?q?=E6=94=B9=EF=BC=8C=E6=9C=89bug=E5=88=AB=E6=89=BE=E6=88=91?= =?UTF-8?q?=EF=BC=8C=E6=88=91=E4=B9=9F=E4=B8=8D=E4=BC=9A=20(T=5FT)?= =?UTF-8?q?=E3=80=82=20----=201.=20Modify=20the=20font=20size=20of=20the?= =?UTF-8?q?=20interface.=202.=20The=20font=20family=20type=20of=20the=20le?= =?UTF-8?q?gend=20has=20been=20changed=20to=20a=20monospaced=20font=20to?= =?UTF-8?q?=20optimize=20the=20formatting=20of=20the=20pie=20chart=20legen?= =?UTF-8?q?d,=20ensuring=20better=20alignment=20of=20the=20data.=203.=20Ad?= =?UTF-8?q?just=20the=20boundaries=20of=20the=20pie=20chart.=20By=20defaul?= =?UTF-8?q?t,=20the=20legend=20will=20not=20cover=20the=20pie=20chart.=20T?= =?UTF-8?q?he=20unnecessary=20display=20of=20x=3D***=20y=3D***=20when=20th?= =?UTF-8?q?e=20cursor=20is=20on=20the=20chart=20has=20been=20removed.=204.?= =?UTF-8?q?=20Disable=20the=20default=20on=20of=20Steamer=20Mode.=205.=20A?= =?UTF-8?q?dd=20a=20text=20box=20to=20the=20Overlay=20menu=20to=20display?= =?UTF-8?q?=20the=20address=20of=20the=20local=20web=20service.=206.=20In?= =?UTF-8?q?=20the=20configuration=20file,=20the=20edtion=20of=20Cargo.toml?= =?UTF-8?q?=20was=20changed=20from=202021=20to=202024.=20When=20compiling?= =?UTF-8?q?=20with=202021=20on=20my=20device,=20some=20errors=20occurred.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 2 +- src/ui/app.rs | 39 +++++++++++++++++++++++++++++++++---- src/ui/helpers.rs | 11 ++++++++++- src/ui/widgets.rs | 49 +++++++++++++++++++++++++++++++++++------------ 4 files changed, 83 insertions(+), 18 deletions(-) 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;