Skip to content

Commit 91cb2e6

Browse files
committed
Add button to preview the chat of each demo file
1 parent 3cece9d commit 91cb2e6

5 files changed

Lines changed: 67 additions & 6 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "coldmaps"
3-
version = "0.4.1"
3+
version = "0.4.2"
44
authors = ["Tails8521 <tails8521@gmail.com>"]
55
edition = "2021"
66

fonts/icons.ttf

984 Bytes
Binary file not shown.

src/chat.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use coldmaps::heatmap_analyser::HeatmapAnalysis;
2+
3+
pub fn format_chat_messages(analysis: &HeatmapAnalysis) -> Vec<String> {
4+
let interval_per_tick = analysis.interval_per_tick;
5+
analysis
6+
.chat
7+
.iter()
8+
.filter_map(|message| {
9+
let total_seconds = (message.tick as f32 * interval_per_tick) as u32;
10+
let minutes = total_seconds / 60;
11+
let seconds = total_seconds % 60;
12+
match message.kind {
13+
tf_demo_parser::demo::message::usermessage::ChatMessageKind::ChatAll => Some(format!("[{:02}:{:02}] {}: {}", minutes, seconds, message.from, message.text,)),
14+
tf_demo_parser::demo::message::usermessage::ChatMessageKind::ChatTeam => {
15+
Some(format!("[{:02}:{:02}] (TEAM) {}: {}", minutes, seconds, message.from, message.text,))
16+
}
17+
tf_demo_parser::demo::message::usermessage::ChatMessageKind::ChatAllDead => {
18+
Some(format!("[{:02}:{:02}] *DEAD* {}: {}", minutes, seconds, message.from, message.text,))
19+
}
20+
tf_demo_parser::demo::message::usermessage::ChatMessageKind::ChatTeamDead => {
21+
Some(format!("[{:02}:{:02}] *DEAD*(TEAM) {}: {}", minutes, seconds, message.from, message.text,))
22+
}
23+
tf_demo_parser::demo::message::usermessage::ChatMessageKind::ChatAllSpec => {
24+
Some(format!("[{:02}:{:02}] *SPEC* {}: {}", minutes, seconds, message.from, message.text,))
25+
}
26+
tf_demo_parser::demo::message::usermessage::ChatMessageKind::NameChange => None,
27+
tf_demo_parser::demo::message::usermessage::ChatMessageKind::Empty => None,
28+
}
29+
})
30+
.collect()
31+
}

src/main.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
use chat::format_chat_messages;
12
use coldmaps::*;
23

4+
mod chat;
35
mod demo_player;
46
mod demostf;
57
mod gui_filters;
@@ -25,16 +27,20 @@ const ICONS: Font = Font::External {
2527
bytes: include_bytes!("../fonts/icons.ttf"),
2628
};
2729

28-
fn icon(unicode: char) -> Text {
30+
fn icon(unicode: char, color: [f32; 3]) -> Text {
2931
Text::new(&unicode.to_string())
3032
.font(ICONS)
31-
.color([1.0, 0.0, 0.0])
33+
.color(color)
3234
.horizontal_alignment(alignment::Horizontal::Center)
3335
.size(20)
3436
}
3537

3638
fn delete_icon() -> Text {
37-
icon('\u{F1F8}')
39+
icon('\u{F1F8}', [1.0, 0.0, 0.0])
40+
}
41+
42+
fn chat_preview_icon() -> Text {
43+
icon('\u{E802}', [1.0, 1.0, 1.0])
3844
}
3945

4046
pub fn main() -> Result<(), iced::Error> {
@@ -79,6 +85,7 @@ struct DemoFile {
7985
_path: PathBuf,
8086
file_name: String,
8187
delete_button: button::State,
88+
chat_preview_button: button::State,
8289
heatmap_analysis: HeatmapAnalysis,
8390
}
8491

@@ -87,6 +94,7 @@ enum Message {
8794
WindowEventOccurred(iced_native::Event),
8895
PaneResized(pane_grid::ResizeEvent),
8996
DemoRemoved(usize),
97+
ChatPreview(usize),
9098
ThemeChanged(style::Theme),
9199
CoordsTypeChanged(CoordsType),
92100
HeatmapTypeChanged(HeatmapType),
@@ -172,7 +180,14 @@ impl DemoList {
172180
.enumerate()
173181
.fold(Column::new().spacing(10), |column, (index, demo)| {
174182
let delete_button = Button::new(&mut demo.delete_button, delete_icon()).style(theme).on_press(Message::DemoRemoved(index));
175-
let row = Row::new().push(delete_button).push(Text::new(&demo.file_name).size(20));
183+
let chat_preview_button = Button::new(&mut demo.chat_preview_button, chat_preview_icon())
184+
.style(theme)
185+
.on_press(Message::ChatPreview(index));
186+
let row = Row::new()
187+
.spacing(2)
188+
.push(delete_button)
189+
.push(chat_preview_button)
190+
.push(Text::new(&demo.file_name).size(20));
176191
column.push(row)
177192
})
178193
.into(),
@@ -408,6 +423,7 @@ impl LogPane {
408423
}
409424

410425
fn log(&mut self, message: &str) {
426+
println!("{}", message);
411427
self.log.push_str(message);
412428
self.log.push('\n');
413429
// TODO replace this by a cleaner way to scroll down once possible
@@ -546,6 +562,19 @@ impl Application for App {
546562
self.show_stats();
547563
self.try_generate_heatmap();
548564
}
565+
Message::ChatPreview(index) => {
566+
let demo_list = self.get_demo_list_pane_mut();
567+
let demo = &demo_list.demo_files[index];
568+
let messages = format_chat_messages(&demo.heatmap_analysis);
569+
let header_message = format!("Chat log of {}:", demo.file_name);
570+
self.log("");
571+
self.log(&header_message);
572+
self.log("======================");
573+
for message in messages {
574+
self.log(&message);
575+
}
576+
self.log("======================");
577+
}
549578
Message::ThemeChanged(theme) => {
550579
self.theme = theme;
551580
self.get_demo_list_pane_mut().theme = theme;
@@ -634,6 +663,7 @@ impl Application for App {
634663
file_name,
635664
heatmap_analysis,
636665
delete_button: Default::default(),
666+
chat_preview_button: Default::default(),
637667
};
638668
demo_list.demo_files.push(demo_file);
639669
}

0 commit comments

Comments
 (0)