Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "Astrolabe"
edition = "2021"
edition = "2024"
license-file = "LICENSE"
repository = "https://github.com/hessiser/veritas/"

Expand Down
39 changes: 35 additions & 4 deletions src/ui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/ui/helpers.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
49 changes: 37 additions & 12 deletions src/ui/widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,25 @@ 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)
.clamp_grid(true)
.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<'_>| {
Expand All @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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();

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down