Add telegrenade cooldown
This commit is contained in:
parent
31b7a053e6
commit
59d1bc415c
BIN
godot/assets/Telegrenade.png
Normal file
BIN
godot/assets/Telegrenade.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 228 KiB |
40
godot/assets/Telegrenade.png.import
Normal file
40
godot/assets/Telegrenade.png.import
Normal file
@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://jlyh7ic6fs3k"
|
||||
path="res://.godot/imported/Telegrenade.png-ce02a7dc5555b6ccd8212790df685ffa.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/Telegrenade.png"
|
||||
dest_files=["res://.godot/imported/Telegrenade.png-ce02a7dc5555b6ccd8212790df685ffa.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=true
|
||||
mipmaps/limit=5
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
Binary file not shown.
Binary file not shown.
@ -10,6 +10,7 @@
|
||||
[ext_resource type="AudioStream" uid="uid://bfg31e3s4jv8c" path="res://raw_assets/sfx/Hit.mp3" id="7_dguuj"]
|
||||
[ext_resource type="AudioStream" uid="uid://cl416orgv11vj" path="res://raw_assets/sfx/ball/little_robot_sound_factory_fantasy_Inventory_Open_00.mp3" id="8_cmcit"]
|
||||
[ext_resource type="AudioStream" uid="uid://uq0o8gkpqhfa" path="res://raw_assets/sfx/ball/zapsplat_foley_stick_swing_air_whoosh_very_fast_hard_003_110413.mp3" id="9_qpw6d"]
|
||||
[ext_resource type="PackedScene" uid="uid://uvwg721hwp71" path="res://scenes/ui/cooldown_icon.tscn" id="10_h6dt6"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_oh8vq"]
|
||||
|
||||
@ -19,7 +20,7 @@ shader_parameter/Color = Color(1, 0, 0, 1)
|
||||
shader_parameter/RimDistance = 0.7
|
||||
shader_parameter/FloatParameter = 3.0
|
||||
|
||||
[node name="player" type="LocalPlayer" unique_id=863055906 node_paths=PackedStringArray("camera", "vignette", "soldier_mesh", "collider", "effects", "dead_cam_target", "respawn_label", "camera_origin", "weapon_node", "hud", "hit_sound", "goal_sound_good", "goal_sound_bad", "pickup_ball_sfx", "throw_ball_sfx")]
|
||||
[node name="player" type="LocalPlayer" unique_id=863055906 node_paths=PackedStringArray("camera", "vignette", "soldier_mesh", "collider", "effects", "dead_cam_target", "respawn_label", "camera_origin", "weapon_node", "hud", "hit_sound", "goal_sound_good", "goal_sound_bad", "pickup_ball_sfx", "throw_ball_sfx", "telegrenade_cooldown")]
|
||||
look_sensitivity = 1.5
|
||||
camera = NodePath("camera_3d")
|
||||
vignette = NodePath("vignette")
|
||||
@ -39,6 +40,7 @@ pickup_ball_sfx = NodePath("ball_pickup_sfx")
|
||||
throw_ball_sfx = NodePath("ball_throw_sfx")
|
||||
health = 100
|
||||
punch_cooldown = 1.0
|
||||
telegrenade_cooldown = NodePath("cooldown_icon")
|
||||
telegrenade_cd = 10.0
|
||||
collision_mask = 4
|
||||
slide_on_ceiling = false
|
||||
@ -123,6 +125,10 @@ bus = &"SFX"
|
||||
stream = ExtResource("9_qpw6d")
|
||||
bus = &"SFX"
|
||||
|
||||
[node name="cooldown_icon" parent="." unique_id=1635472390 instance=ExtResource("10_h6dt6")]
|
||||
max = 10.0
|
||||
value = 0.0
|
||||
|
||||
[node name="hud" parent="." unique_id=2049159590 instance=ExtResource("5_cv68x")]
|
||||
|
||||
[connection signal="on_exit" from="hud" to="." method="exit"]
|
||||
|
||||
63
godot/scenes/ui/cooldown_icon.tscn
Normal file
63
godot/scenes/ui/cooldown_icon.tscn
Normal file
@ -0,0 +1,63 @@
|
||||
[gd_scene format=3 uid="uid://uvwg721hwp71"]
|
||||
|
||||
[ext_resource type="Theme" uid="uid://drydbnrcdv4pk" path="res://default_theme.tres" id="1_3lo81"]
|
||||
[ext_resource type="Texture2D" uid="uid://jlyh7ic6fs3k" path="res://assets/Telegrenade.png" id="2_xkf6q"]
|
||||
|
||||
[node name="cooldown_icon" type="CooldownIcon" unique_id=1635472390 node_paths=PackedStringArray("text_rect", "label", "add_label")]
|
||||
max = 10.0
|
||||
value = 1.5116633333332667
|
||||
text_rect = NodePath("texture_progress_bar")
|
||||
label = NodePath("cd_label")
|
||||
add_label = NodePath("add_label")
|
||||
anchors_preset = 3
|
||||
anchor_left = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -78.0
|
||||
offset_top = -78.0
|
||||
offset_right = -21.0
|
||||
offset_bottom = -21.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
theme = ExtResource("1_3lo81")
|
||||
|
||||
[node name="texture_progress_bar" type="TextureProgressBar" parent="." unique_id=1029250206]
|
||||
propagate_maximum_size = true
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
max_value = 10.0
|
||||
step = 0.05
|
||||
value = 8.5
|
||||
fill_mode = 4
|
||||
nine_patch_stretch = true
|
||||
texture_under = ExtResource("2_xkf6q")
|
||||
texture_progress = ExtResource("2_xkf6q")
|
||||
tint_under = Color(0.30323282, 0.30323282, 0.30323282, 1)
|
||||
metadata/_edit_lock_ = true
|
||||
|
||||
[node name="cd_label" type="Label" parent="." unique_id=694927561]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
text = "1.5"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
metadata/_edit_lock_ = true
|
||||
|
||||
[node name="add_label" type="Label" parent="." unique_id=1246221999]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
@ -33,7 +33,7 @@ use crate::{
|
||||
weapon::{BallWeapon, Raygun, Shotgun, Weapon, WeaponType},
|
||||
},
|
||||
replay::ReplayEvent,
|
||||
ui::{cli::CommandLinePanel, hud::Hud},
|
||||
ui::{cli::CommandLinePanel, cooldown_icon::CooldownIcon, hud::Hud},
|
||||
};
|
||||
|
||||
#[derive(GodotClass)]
|
||||
@ -79,6 +79,8 @@ pub struct LocalPlayer {
|
||||
health: i32,
|
||||
#[export]
|
||||
punch_cooldown: f64,
|
||||
#[export]
|
||||
telegrenade_cooldown: Option<Gd<CooldownIcon>>,
|
||||
|
||||
pub player_id: Option<u16>,
|
||||
|
||||
@ -470,6 +472,17 @@ impl ICharacterBody3D for LocalPlayer {
|
||||
self.punch_cd_remaining -= delta;
|
||||
self.telegrenade_cd_remaining -= delta;
|
||||
|
||||
if let Some(telegrenade_cd) = &mut self.telegrenade_cooldown {
|
||||
telegrenade_cd.bind_mut().value = self.telegrenade_cd_remaining;
|
||||
|
||||
let telegrenade_key = GameSettingsManager::singleton()
|
||||
.bind()
|
||||
.settings
|
||||
.keybinds
|
||||
.telegrenade;
|
||||
telegrenade_cd.bind_mut().add_text = (&telegrenade_key.to_string()).into();
|
||||
}
|
||||
|
||||
if self.is_dead {
|
||||
self.dead_for += delta;
|
||||
|
||||
|
||||
85
rust/src/ui/cooldown_icon.rs
Normal file
85
rust/src/ui/cooldown_icon.rs
Normal file
@ -0,0 +1,85 @@
|
||||
use godot::{
|
||||
classes::{
|
||||
CompressedTexture2D, Control, Engine, IControl, Label, TextureProgressBar,
|
||||
texture_progress_bar::FillMode,
|
||||
},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Copy, GodotConvert, Default, Export, Var)]
|
||||
#[godot(via = u8)]
|
||||
pub enum CooldownType {
|
||||
#[default]
|
||||
Fill,
|
||||
Empty,
|
||||
}
|
||||
|
||||
#[derive(GodotClass)]
|
||||
#[class(base=Control, init, tool)]
|
||||
pub struct CooldownIcon {
|
||||
#[export]
|
||||
pub cd_type: CooldownType,
|
||||
#[export]
|
||||
pub max: f64,
|
||||
#[export]
|
||||
pub min: f64,
|
||||
#[export]
|
||||
pub value: f64,
|
||||
#[export]
|
||||
pub add_text: GString,
|
||||
|
||||
#[export]
|
||||
pub text_rect: Option<Gd<TextureProgressBar>>,
|
||||
#[export]
|
||||
pub label: Option<Gd<Label>>,
|
||||
#[export]
|
||||
pub add_label: Option<Gd<Label>>,
|
||||
|
||||
base: Base<Control>,
|
||||
}
|
||||
|
||||
#[godot_api]
|
||||
impl IControl for CooldownIcon {
|
||||
fn ready(&mut self) {
|
||||
self.update();
|
||||
}
|
||||
|
||||
fn process(&mut self, delta: f64) {
|
||||
let delta = match self.cd_type {
|
||||
CooldownType::Fill => -delta,
|
||||
CooldownType::Empty => delta,
|
||||
};
|
||||
self.value = (self.value + delta).clamp(self.min, self.max);
|
||||
|
||||
self.update();
|
||||
}
|
||||
}
|
||||
|
||||
impl CooldownIcon {
|
||||
pub fn update(&mut self) {
|
||||
if let Some(bar) = &mut self.text_rect {
|
||||
let fill_mode = match self.cd_type {
|
||||
CooldownType::Fill => FillMode::CLOCKWISE,
|
||||
CooldownType::Empty => FillMode::COUNTER_CLOCKWISE,
|
||||
};
|
||||
bar.set_fill_mode(fill_mode);
|
||||
|
||||
bar.set_max(self.max);
|
||||
bar.set_min(self.min);
|
||||
bar.set_value(match self.cd_type {
|
||||
CooldownType::Fill => self.max - self.value,
|
||||
CooldownType::Empty => self.value,
|
||||
});
|
||||
}
|
||||
if let Some(label) = &mut self.label {
|
||||
label.set_text(&format!("{:.1}", self.value));
|
||||
label.set_visible(match self.cd_type {
|
||||
CooldownType::Fill => self.value > 0.05,
|
||||
CooldownType::Empty => self.value < 0.05,
|
||||
});
|
||||
}
|
||||
if let Some(label) = &mut self.add_label {
|
||||
label.set_text(&self.add_text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
pub mod chatbox;
|
||||
pub mod cli;
|
||||
pub mod cooldown_icon;
|
||||
pub mod credits;
|
||||
pub mod game_finished_screen;
|
||||
pub mod hud;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user