Add semi-working hud to replays
This commit is contained in:
parent
2384eb90ba
commit
f5f375db1e
@ -1,6 +1,8 @@
|
||||
[gd_scene format=3 uid="uid://djmb2jqcpkuep"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://d3377ecff6nyn" path="res://scenes/replay_finished.tscn" id="1_q5ujf"]
|
||||
[ext_resource type="PackedScene" uid="uid://c1gs6cqek1qlq" path="res://scenes/ui/hud.tscn" id="2_a451s"]
|
||||
|
||||
[node name="standalone_replay_global" type="StandaloneReplayManager" unique_id=730657724]
|
||||
replay_finished_screen = ExtResource("1_q5ujf")
|
||||
hud_scene = ExtResource("2_a451s")
|
||||
|
||||
@ -19,6 +19,7 @@ use crate::{
|
||||
DamageSource, IPlayer, NetTransform, ball::Ball, remote_player::RemotePlayer,
|
||||
weapon::WeaponType,
|
||||
},
|
||||
ui::hud::Hud,
|
||||
};
|
||||
|
||||
pub const STANDALONE_REPLAY_GLOBAL: &str = "StandaloneReplayGlobal";
|
||||
@ -28,11 +29,14 @@ pub const STANDALONE_REPLAY_GLOBAL: &str = "StandaloneReplayGlobal";
|
||||
pub struct StandaloneReplayManager {
|
||||
#[export]
|
||||
replay_finished_screen: Option<Gd<PackedScene>>,
|
||||
#[export]
|
||||
hud_scene: Option<Gd<PackedScene>>,
|
||||
|
||||
loading_replay: bool,
|
||||
map: Option<Gd<Map>>,
|
||||
pub playback: Option<Gd<ReplayPlayback>>,
|
||||
replay: Option<Replay>,
|
||||
hud: Option<Gd<Hud>>,
|
||||
|
||||
base: Base<Node>,
|
||||
}
|
||||
@ -85,6 +89,12 @@ impl StandaloneReplayManager {
|
||||
playback.bind_mut().spectated_player_id = 0;
|
||||
self.playback = Some(playback.clone());
|
||||
self.base_mut().add_child(&playback);
|
||||
|
||||
if let Some(scene) = &self.hud_scene {
|
||||
let hud = scene.instantiate_as::<Hud>();
|
||||
self.hud = Some(hud.clone());
|
||||
playback.add_child(&hud);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -98,6 +108,9 @@ impl StandaloneReplayManager {
|
||||
pub fn clear(&mut self) {
|
||||
self.replay.take();
|
||||
self.map.take();
|
||||
if let Some(mut hud) = self.hud.take() {
|
||||
hud.queue_free();
|
||||
}
|
||||
if let Some(mut playback) = self.playback.take() {
|
||||
playback.queue_free();
|
||||
}
|
||||
@ -129,6 +142,8 @@ pub struct ReplayPlayback {
|
||||
impl ReplayPlayback {
|
||||
#[signal]
|
||||
pub fn on_finished();
|
||||
#[signal]
|
||||
pub fn on_data_changed();
|
||||
}
|
||||
|
||||
#[godot_api]
|
||||
@ -150,7 +165,7 @@ impl INode for ReplayPlayback {
|
||||
fn physics_process(&mut self, delta: f64) {
|
||||
self.current_time += delta;
|
||||
|
||||
while let Some(frame) = self.replay.frames.get(self.current_frame_idx)
|
||||
while let Some(frame) = self.replay.frames.get(self.current_frame_idx).cloned()
|
||||
&& frame.time <= self.current_time
|
||||
{
|
||||
self.player_data = frame.player_data.clone();
|
||||
@ -264,6 +279,8 @@ impl INode for ReplayPlayback {
|
||||
}
|
||||
}
|
||||
self.current_frame_idx += 1;
|
||||
|
||||
self.signals().on_data_changed().emit();
|
||||
}
|
||||
|
||||
self.fast_forwarding = false;
|
||||
|
||||
@ -48,11 +48,22 @@ impl IHBoxContainer for PlayerListing {
|
||||
.on_player_killed()
|
||||
.connect_other(self, |s, _| s.update());
|
||||
}
|
||||
self.run_deferred(|s| {
|
||||
if let Some(replay_playback) =
|
||||
&mut StandaloneReplayManager::singleton().bind_mut().playback
|
||||
{
|
||||
replay_playback
|
||||
.signals()
|
||||
.on_data_changed()
|
||||
.connect_other(s, |s| s.update());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl PlayerListing {
|
||||
pub fn update(&mut self) {
|
||||
godot_print!("update");
|
||||
if let Some(player_id) = self.player_id {
|
||||
if let Some(game) = Game::singleton() {
|
||||
if let Some(player) = game.bind().find_player(player_id) {
|
||||
@ -79,31 +90,22 @@ impl PlayerListing {
|
||||
}
|
||||
ping_icon.set_modulate(color);
|
||||
}
|
||||
} else {
|
||||
if let Some(name_label) = &mut self.name_label {
|
||||
name_label.set_text("Name");
|
||||
}
|
||||
if let Some(kills_label) = &mut self.kills_label {
|
||||
kills_label.set_text("Kills");
|
||||
}
|
||||
if let Some(deaths_label) = &mut self.deaths_label {
|
||||
deaths_label.set_text("Deaths");
|
||||
}
|
||||
if let Some(ping_label) = &mut self.ping_label {
|
||||
ping_label.set_text("Ping");
|
||||
}
|
||||
}
|
||||
} else if let Some(playback) = &StandaloneReplayManager::singleton().bind().playback {
|
||||
if let Some(player) = playback.bind().replay.players.get(&player_id) {
|
||||
if let Some(name_label) = &mut self.name_label {
|
||||
name_label.set_text(&player.name);
|
||||
}
|
||||
}
|
||||
if let Some(player) = playback.bind().player_data.get(&player_id) {
|
||||
if let Some(kills_label) = &mut self.kills_label {
|
||||
kills_label.set_text(&player.kills.to_string());
|
||||
}
|
||||
if let Some(deaths_label) = &mut self.deaths_label {
|
||||
deaths_label.set_text(&player.deaths.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if let Some(name_label) = &mut self.name_label {
|
||||
name_label.set_text("Name");
|
||||
@ -119,6 +121,4 @@ impl PlayerListing {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user