Compare commits
No commits in common. "e6b04bbdd15bddb4b68e211211aa33e96cc48faa" and "9c4787f5e2e34c76a8cff8c50ec52605f36c96e5" have entirely different histories.
e6b04bbdd1
...
9c4787f5e2
18 changed files with 110 additions and 441 deletions
14
Cargo.lock
generated
14
Cargo.lock
generated
|
|
@ -1656,7 +1656,6 @@ dependencies = [
|
|||
"building",
|
||||
"combat",
|
||||
"state",
|
||||
"ui_range_indicator",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1678,10 +1677,8 @@ dependencies = [
|
|||
"avian3d",
|
||||
"bevy",
|
||||
"building",
|
||||
"combat",
|
||||
"input",
|
||||
"physics",
|
||||
"ui_range_indicator",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -2019,7 +2016,6 @@ dependencies = [
|
|||
"ui_health_bar",
|
||||
"ui_ingame",
|
||||
"ui_pause",
|
||||
"ui_range_indicator",
|
||||
"ui_state",
|
||||
"upgrade",
|
||||
]
|
||||
|
|
@ -5311,7 +5307,6 @@ dependencies = [
|
|||
"bevy_egui",
|
||||
"building",
|
||||
"building_placement",
|
||||
"combat",
|
||||
"input",
|
||||
"resources",
|
||||
"state",
|
||||
|
|
@ -5330,15 +5325,6 @@ dependencies = [
|
|||
"ui_state",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ui_range_indicator"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bevy",
|
||||
"combat",
|
||||
"input",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ui_state"
|
||||
version = "0.1.0"
|
||||
|
|
|
|||
|
|
@ -57,5 +57,4 @@ building_barrager = { path = "crates/building_barrager" }
|
|||
resource_graveyard = { path = "crates/resource_graveyard" }
|
||||
upgrade = { path = "crates/upgrade" }
|
||||
ui_health_bar = { path = "crates/ui_health_bar" }
|
||||
ui_range_indicator = { path = "crates/ui_range_indicator" }
|
||||
#new internal crates go here
|
||||
|
|
|
|||
|
|
@ -3,20 +3,20 @@
|
|||
MouseButton(Middle): [
|
||||
CameraOrbitEnable,
|
||||
],
|
||||
KeyCode(ShiftLeft): [
|
||||
MultiPlaceTower,
|
||||
],
|
||||
KeyCode(F1): [
|
||||
ToggleDebugUI,
|
||||
],
|
||||
MouseButton(Right): [
|
||||
PlaceTower,
|
||||
],
|
||||
MouseButton(Left): [
|
||||
CameraPanEnable,
|
||||
],
|
||||
KeyCode(ShiftLeft): [
|
||||
MultiPlaceTower,
|
||||
],
|
||||
MouseScroll: [
|
||||
CameraZoom,
|
||||
],
|
||||
MouseButton(Left): [
|
||||
CameraPanEnable,
|
||||
KeyCode(F1): [
|
||||
ToggleDebugUI,
|
||||
],
|
||||
MouseMovementX: [
|
||||
CameraYaw,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use bevy::{
|
|||
platform::collections::HashMap,
|
||||
prelude::*,
|
||||
};
|
||||
use combat::{Health, Range, Team};
|
||||
use combat::{Health, Team};
|
||||
use input::Selectable;
|
||||
use resources::{Cost, Resources};
|
||||
use state::GameSystemSet;
|
||||
|
|
@ -32,10 +32,6 @@ pub struct Building {
|
|||
pub info: Entity,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
#[require(Range)]
|
||||
pub struct Core;
|
||||
|
||||
#[derive(Component, Clone)]
|
||||
#[require(Name, Cost, UpgradeTree)]
|
||||
#[component(on_add = register_building_info)]
|
||||
|
|
@ -118,13 +114,7 @@ pub fn valid_placement(
|
|||
collider_query: &Query<&Building>,
|
||||
size: Vec3,
|
||||
position: Vec3,
|
||||
core_position_range: Option<(Vec3, f32)>,
|
||||
) -> bool {
|
||||
if let Some((core_position, core_range)) = core_position_range
|
||||
&& !Range(core_range).within(position, core_position)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
!spatial_query
|
||||
.shape_intersections(
|
||||
// shrink the collider a bit to allow for buildings right next to each other
|
||||
|
|
@ -143,7 +133,6 @@ fn place_building(
|
|||
mut resources: ResMut<Resources>,
|
||||
info_query: Query<(&BuildingInfo, &Cost, &Name), With<UpgradeTree>>,
|
||||
building_query: Query<&Building>,
|
||||
core_query: Query<(&GlobalTransform, &Range), With<Core>>,
|
||||
spatial_query: SpatialQuery,
|
||||
) {
|
||||
for PlaceBuilding {
|
||||
|
|
@ -161,16 +150,7 @@ fn place_building(
|
|||
}
|
||||
let size_v3 = info.size.as_vec3();
|
||||
let (collider, position) = info.get_placed_collider_and_position(location.as_vec3());
|
||||
if !valid_placement(
|
||||
&spatial_query,
|
||||
&building_query,
|
||||
size_v3,
|
||||
position,
|
||||
core_query
|
||||
.single()
|
||||
.ok()
|
||||
.map(|(gtf, r)| (gtf.translation(), r.0)),
|
||||
) {
|
||||
if !valid_placement(&spatial_query, &building_query, size_v3, position) {
|
||||
error!("tried to place building colliding with other building");
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use avian3d::prelude::{Collider, LinearVelocity, RigidBody};
|
|||
use bevy::prelude::*;
|
||||
use building::{BuildingInfo, BuildingPreview, PREVIEW_ALPHA, PopulatePlacedBuilding};
|
||||
use combat::{
|
||||
Defense, Health, Range,
|
||||
Defense, Health,
|
||||
projectiles::{Fire, Projectile, ProjectileLauncher, get_shotgun_launch_vectors},
|
||||
};
|
||||
use combat_damagers::ContactDamage;
|
||||
|
|
@ -181,9 +181,9 @@ fn populate(
|
|||
Health::new(20.0),
|
||||
Defense::new(7.0),
|
||||
ContactDamage::new(2.0),
|
||||
Range(10.0),
|
||||
ProjectileLauncher::new(
|
||||
Duration::from_secs(1),
|
||||
50.0,
|
||||
5.0,
|
||||
Vec3::Y * (SIZE.y as f32 + 0.5),
|
||||
Duration::from_secs(10),
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ bevy = { workspace = true }
|
|||
combat = { path = "../combat" }
|
||||
building = { path = "../building" }
|
||||
state = { path = "../state" }
|
||||
ui_range_indicator = { path = "../ui_range_indicator" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@
|
|||
#![allow(clippy::too_many_arguments)]
|
||||
|
||||
use bevy::prelude::*;
|
||||
use building::{BuildingInfo, BuildingPreview, Core, PREVIEW_ALPHA, PopulatePlacedBuilding};
|
||||
use combat::{Defense, Health, Range};
|
||||
use ui_range_indicator::CustomRangeIndicator;
|
||||
use building::{BuildingInfo, BuildingPreview, PREVIEW_ALPHA, PopulatePlacedBuilding};
|
||||
use combat::{Defense, Health};
|
||||
|
||||
pub struct BuildingCorePlugin;
|
||||
|
||||
|
|
@ -15,6 +14,9 @@ impl Plugin for BuildingCorePlugin {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Core;
|
||||
|
||||
#[derive(Resource)]
|
||||
struct CoreResources {
|
||||
mesh: Handle<Mesh>,
|
||||
|
|
@ -70,7 +72,6 @@ fn register(
|
|||
fn populate(
|
||||
trigger: Trigger<PopulatePlacedBuilding>,
|
||||
mut commands: Commands,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
res: Res<CoreResources>,
|
||||
) {
|
||||
if trigger.event().info != res.info_entity {
|
||||
|
|
@ -80,15 +81,7 @@ fn populate(
|
|||
Core,
|
||||
Health::new(100.0),
|
||||
Defense::new(5.0),
|
||||
Range(25.0),
|
||||
Mesh3d(res.mesh.clone()),
|
||||
MeshMaterial3d(res.material.clone()),
|
||||
CustomRangeIndicator::new(materials.add(StandardMaterial {
|
||||
alpha_mode: AlphaMode::Blend,
|
||||
base_color: Color::srgba(0.6, 0.2, 0.2, 0.4),
|
||||
unlit: true,
|
||||
double_sided: true,
|
||||
..default()
|
||||
})),
|
||||
));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ avian3d = { workspace = true }
|
|||
building = { path = "../building" }
|
||||
physics = { path = "../physics" }
|
||||
input = { path = "../input" }
|
||||
combat = { path = "../combat" }
|
||||
ui_range_indicator = { path = "../ui_range_indicator" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
|
|||
|
|
@ -4,11 +4,9 @@
|
|||
|
||||
use avian3d::prelude::SpatialQuery;
|
||||
use bevy::prelude::*;
|
||||
use building::{Building, BuildingInfo, BuildingPreview, Core, PlaceBuilding, valid_placement};
|
||||
use combat::Range;
|
||||
use building::{Building, BuildingInfo, BuildingPreview, PlaceBuilding, valid_placement};
|
||||
use input::{Cancellable, Inputs, Selected, actions::InputAction};
|
||||
use physics::Ground;
|
||||
use ui_range_indicator::DisplayCustomRangeIndicator;
|
||||
|
||||
pub struct BuildingPlacementPlugin;
|
||||
|
||||
|
|
@ -48,59 +46,11 @@ fn cancel_preview(
|
|||
}
|
||||
}
|
||||
|
||||
fn select_preview(
|
||||
mut reader: EventReader<SelectBuildingPreview>,
|
||||
mut old_query: Query<(Entity, &mut Visibility), With<ActiveBuildingPreview>>,
|
||||
core_query: Query<Entity, With<Core>>,
|
||||
new_query: Query<(), With<BuildingPreview>>,
|
||||
mut commands: Commands,
|
||||
) {
|
||||
let Some(SelectBuildingPreview(opt_entity)) = reader.read().last() else {
|
||||
return;
|
||||
};
|
||||
for (entity, mut vis) in old_query.iter_mut() {
|
||||
if *opt_entity != Some(entity) {
|
||||
commands
|
||||
.entity(entity)
|
||||
.remove::<(ActiveBuildingPreview, Cancellable)>();
|
||||
*vis = Visibility::Hidden;
|
||||
}
|
||||
}
|
||||
let Some(new_entity) = opt_entity else {
|
||||
if let Ok(core_entity) = core_query.single() {
|
||||
commands
|
||||
.entity(core_entity)
|
||||
.remove::<DisplayCustomRangeIndicator>();
|
||||
}
|
||||
return;
|
||||
};
|
||||
if !new_query.contains(*new_entity) {
|
||||
error!("tried to select a building without a preview!");
|
||||
if let Ok(core_entity) = core_query.single() {
|
||||
commands
|
||||
.entity(core_entity)
|
||||
.remove::<DisplayCustomRangeIndicator>();
|
||||
}
|
||||
return;
|
||||
}
|
||||
commands.entity(*new_entity).insert((
|
||||
Visibility::Visible,
|
||||
ActiveBuildingPreview::default(),
|
||||
Cancellable,
|
||||
));
|
||||
if let Ok(core_entity) = core_query.single() {
|
||||
commands
|
||||
.entity(core_entity)
|
||||
.insert(DisplayCustomRangeIndicator);
|
||||
}
|
||||
}
|
||||
|
||||
fn move_preview(
|
||||
trigger: Trigger<Pointer<Move>>,
|
||||
preview: Single<(&mut Transform, &mut ActiveBuildingPreview, &BuildingPreview)>,
|
||||
info_query: Query<&BuildingInfo>,
|
||||
building_query: Query<&Building>,
|
||||
core_query: Query<(&GlobalTransform, &Range), With<Core>>,
|
||||
spatial_query: SpatialQuery,
|
||||
) {
|
||||
let Some(dest) = trigger.event().hit.position else {
|
||||
|
|
@ -119,10 +69,6 @@ fn move_preview(
|
|||
&building_query,
|
||||
info.size.as_vec3(),
|
||||
position,
|
||||
core_query
|
||||
.single()
|
||||
.ok()
|
||||
.map(|(gtf, r)| (gtf.translation(), r.0)),
|
||||
) {
|
||||
info!("invalid placement!!!!!");
|
||||
return;
|
||||
|
|
@ -150,3 +96,34 @@ fn place_preview(
|
|||
location: active.0,
|
||||
});
|
||||
}
|
||||
|
||||
fn select_preview(
|
||||
mut reader: EventReader<SelectBuildingPreview>,
|
||||
mut old_query: Query<(Entity, &mut Visibility), With<ActiveBuildingPreview>>,
|
||||
new_query: Query<(), With<BuildingPreview>>,
|
||||
mut commands: Commands,
|
||||
) {
|
||||
let Some(SelectBuildingPreview(opt_entity)) = reader.read().last() else {
|
||||
return;
|
||||
};
|
||||
for (entity, mut vis) in old_query.iter_mut() {
|
||||
if *opt_entity != Some(entity) {
|
||||
commands
|
||||
.entity(entity)
|
||||
.remove::<(ActiveBuildingPreview, Cancellable)>();
|
||||
*vis = Visibility::Hidden;
|
||||
}
|
||||
}
|
||||
let Some(new_entity) = opt_entity else {
|
||||
return;
|
||||
};
|
||||
if !new_query.contains(*new_entity) {
|
||||
error!("tried to select a building without a preview!");
|
||||
return;
|
||||
}
|
||||
commands.entity(*new_entity).insert((
|
||||
Visibility::Visible,
|
||||
ActiveBuildingPreview::default(),
|
||||
Cancellable,
|
||||
));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -253,18 +253,3 @@ fn tick_invulnerability(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Deref, DerefMut)]
|
||||
pub struct Range(pub f32);
|
||||
|
||||
impl Range {
|
||||
pub fn within(&self, a: Vec3, b: Vec3) -> bool {
|
||||
a.distance_squared(b) < self.0 * self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Range {
|
||||
fn default() -> Self {
|
||||
Self(5.)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use physics::PhysicsLayers;
|
|||
use rand::{Rng, thread_rng};
|
||||
use state::GameSystemSet;
|
||||
|
||||
use crate::{Range, Team};
|
||||
use crate::Team;
|
||||
|
||||
pub(crate) struct ProjectilePlugin;
|
||||
|
||||
|
|
@ -46,18 +46,20 @@ impl From<&ProjectileLauncher> for Projectile {
|
|||
}
|
||||
|
||||
#[derive(Component, Clone)]
|
||||
#[require(Team, Range)]
|
||||
#[require(Team)]
|
||||
pub struct ProjectileLauncher {
|
||||
pub fire_timer: Timer,
|
||||
pub fire_offset: Vec3,
|
||||
pub spread: f32,
|
||||
pub lifetime: Duration,
|
||||
pub range: f32,
|
||||
pub damage: f32,
|
||||
}
|
||||
|
||||
impl ProjectileLauncher {
|
||||
pub fn new(
|
||||
fire_interval: Duration,
|
||||
range: f32,
|
||||
damage: f32,
|
||||
fire_offset: Vec3,
|
||||
lifetime: Duration,
|
||||
|
|
@ -65,6 +67,7 @@ impl ProjectileLauncher {
|
|||
) -> Self {
|
||||
Self {
|
||||
fire_timer: Timer::new(fire_interval, TimerMode::Once),
|
||||
range,
|
||||
spread,
|
||||
damage,
|
||||
fire_offset,
|
||||
|
|
@ -88,19 +91,13 @@ pub struct Fire {
|
|||
|
||||
fn fire_launcher(
|
||||
mut commands: Commands,
|
||||
mut launcher_query: Query<(
|
||||
Entity,
|
||||
&mut ProjectileLauncher,
|
||||
&Range,
|
||||
&Team,
|
||||
&GlobalTransform,
|
||||
)>,
|
||||
mut launcher_query: Query<(Entity, &mut ProjectileLauncher, &Team, &GlobalTransform)>,
|
||||
spatial_query: SpatialQuery,
|
||||
enemy_query: Query<(&Team, &GlobalTransform)>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
let delta = time.delta();
|
||||
for (launcher_entity, mut launcher, range, team, gtf) in launcher_query.iter_mut() {
|
||||
for (launcher_entity, mut launcher, team, gtf) in launcher_query.iter_mut() {
|
||||
// see if enough time has passed to shoot
|
||||
launcher.fire_timer.tick(delta);
|
||||
if !launcher.fire_timer.finished() {
|
||||
|
|
@ -109,7 +106,7 @@ fn fire_launcher(
|
|||
|
||||
// see if enemy in range
|
||||
let enemies = spatial_query.shape_intersections(
|
||||
&Collider::sphere(range.0),
|
||||
&Collider::sphere(launcher.range),
|
||||
gtf.translation(),
|
||||
Quat::default(),
|
||||
&SpatialQueryFilter::from_mask(team.enemy_layers()),
|
||||
|
|
|
|||
|
|
@ -19,23 +19,34 @@ impl Plugin for ResourcesPlugin {
|
|||
}
|
||||
|
||||
fn setup(mut commands: Commands) {
|
||||
commands.insert_resource(Resources(Quantity {
|
||||
commands.insert_resource(Resources {
|
||||
souls: 10,
|
||||
bones: 10,
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
#[derive(Resource, Default, Deref, DerefMut)]
|
||||
pub struct Resources(pub Quantity);
|
||||
#[derive(Resource, Default)]
|
||||
pub struct Resources {
|
||||
pub souls: u32,
|
||||
pub bones: u32,
|
||||
}
|
||||
|
||||
impl Resources {
|
||||
pub fn can_buy(&self, cost: &Cost) -> bool {
|
||||
self.souls >= cost.souls && self.bones >= cost.bones
|
||||
}
|
||||
pub fn buy(&mut self, cost: &Cost) -> bool {
|
||||
if !self.can_buy(cost.0) {
|
||||
if !self.can_buy(cost) {
|
||||
return false;
|
||||
}
|
||||
self.0 = self.0 - cost.0;
|
||||
self.souls = self.souls.saturating_sub(cost.souls);
|
||||
self.bones = self.bones.saturating_sub(cost.bones);
|
||||
true
|
||||
}
|
||||
pub fn add(&mut self, quantity: Quantity) {
|
||||
self.souls = self.souls.saturating_add(quantity.souls);
|
||||
self.bones = self.bones.saturating_add(quantity.bones);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Default, Deref, DerefMut)]
|
||||
|
|
@ -48,7 +59,7 @@ pub struct Quantity {
|
|||
}
|
||||
|
||||
impl Quantity {
|
||||
pub fn to_string(self) -> String {
|
||||
pub fn to_string(&self) -> String {
|
||||
let souls_text = if self.souls > 0 {
|
||||
format!("{} souls", self.souls)
|
||||
} else {
|
||||
|
|
@ -68,10 +79,6 @@ impl Quantity {
|
|||
};
|
||||
format!("{}{}{}", souls_text, divider_text, bones_text)
|
||||
}
|
||||
|
||||
pub fn can_buy(self, product: Quantity) -> bool {
|
||||
self.bones >= product.bones && self.souls >= product.souls
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Mul<u32> for Quantity {
|
||||
|
|
@ -85,28 +92,6 @@ impl std::ops::Mul<u32> for Quantity {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::ops::Add<Quantity> for Quantity {
|
||||
type Output = Quantity;
|
||||
|
||||
fn add(self, rhs: Quantity) -> Self::Output {
|
||||
Quantity {
|
||||
souls: self.souls.saturating_add(rhs.souls),
|
||||
bones: self.bones.saturating_add(rhs.bones),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Sub<Quantity> for Quantity {
|
||||
type Output = Quantity;
|
||||
|
||||
fn sub(self, rhs: Quantity) -> Self::Output {
|
||||
Quantity {
|
||||
souls: self.souls.saturating_sub(rhs.souls),
|
||||
bones: self.bones.saturating_sub(rhs.bones),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Drops {
|
||||
pub souls: u32,
|
||||
|
|
@ -161,7 +146,7 @@ fn on_harvest(
|
|||
error!("harvested something that was not a resource deposit or not worked OwO");
|
||||
return;
|
||||
};
|
||||
resources.0 = resources.0 + deposit.bounty * worked.workers;
|
||||
resources.add(deposit.bounty * worked.workers);
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ pub enum BasePhaseState {
|
|||
|
||||
impl Default for BasePhaseState {
|
||||
fn default() -> Self {
|
||||
Self::Plan { phase: 1 }
|
||||
Self::Plan { phase: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ building = { path = "../building" }
|
|||
input = { path = "../input" }
|
||||
building_placement = { path = "../building_placement" }
|
||||
upgrade = { path = "../upgrade" }
|
||||
combat = { path = "../combat" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
|
|||
|
|
@ -9,9 +9,8 @@ use bevy_egui::{
|
|||
EguiContexts, EguiPrimaryContextPass,
|
||||
egui::{self, Align2, RichText},
|
||||
};
|
||||
use building::{BuildingInfo, Core};
|
||||
use building::BuildingInfo;
|
||||
use building_placement::SelectBuildingPreview;
|
||||
use combat::Range;
|
||||
use input::{SelectEntity, Selected};
|
||||
use resources::{AvailableWorkers, Cost, ResourceDeposit, Resources, WorkedResourceDeposit};
|
||||
use state::{BasePhaseState, Phase};
|
||||
|
|
@ -156,14 +155,14 @@ fn transition_ui(
|
|||
return;
|
||||
}
|
||||
egui::Window::new("TRANSITION")
|
||||
.resizable(false)
|
||||
.collapsible(false)
|
||||
.title_bar(false)
|
||||
.anchor(Align2::CENTER_CENTER, [0., 0.])
|
||||
.fixed_size([600., 200.])
|
||||
.show(ctx, |ui| {
|
||||
ui.label(
|
||||
RichText::new(format!(
|
||||
"{} PHASE {}",
|
||||
"{} {}",
|
||||
match curr_transition.get() {
|
||||
PhaseTransitionState::None => "WHAT",
|
||||
PhaseTransitionState::ToExecute => "EXECUTE",
|
||||
|
|
@ -185,12 +184,7 @@ fn side_panel(
|
|||
selected: Query<(Entity, &Name), With<Selected>>,
|
||||
upgradable: Query<&Upgradable>,
|
||||
upgrades: Query<(&Upgrade, &Name)>,
|
||||
core_query: Query<(&GlobalTransform, &Range), With<Core>>,
|
||||
mut selected_resource_deposit: Query<(
|
||||
&ResourceDeposit,
|
||||
&GlobalTransform,
|
||||
Option<&mut WorkedResourceDeposit>,
|
||||
)>,
|
||||
mut selected_resource_deposit: Query<(&ResourceDeposit, Option<&mut WorkedResourceDeposit>)>,
|
||||
mut selected_preview_writer: EventWriter<SelectBuildingPreview>,
|
||||
mut select_writer: EventWriter<SelectEntity>,
|
||||
) {
|
||||
|
|
@ -209,9 +203,7 @@ fn side_panel(
|
|||
|
||||
ui.heading(selected_name.as_str());
|
||||
// resource deposit management
|
||||
if let Ok((deposit, deposit_gtf, mut opt_worked)) =
|
||||
selected_resource_deposit.get_mut(selected)
|
||||
{
|
||||
if let Ok((deposit, mut opt_worked)) = selected_resource_deposit.get_mut(selected) {
|
||||
ui.label(
|
||||
RichText::new(format!("Level {} deposit", deposit.level)).size(FONT_SIZE),
|
||||
);
|
||||
|
|
@ -226,28 +218,21 @@ fn side_panel(
|
|||
);
|
||||
// worker management buttons
|
||||
// add
|
||||
if let Ok((core_gtf, range)) = core_query.single() {
|
||||
if !range.within(core_gtf.translation(), deposit_gtf.translation()) {
|
||||
ui.add_enabled(false, egui::Button::new("Out of Core's range"));
|
||||
} else if available_workers.0 == 0 {
|
||||
ui.add_enabled(false, egui::Button::new("No workers available"));
|
||||
} else {
|
||||
if ui.button("Add worker").clicked() {
|
||||
available_workers.0 = available_workers.0.saturating_sub(1);
|
||||
if let Some(ref mut worked) = opt_worked {
|
||||
worked.workers = worked.workers.saturating_add(1);
|
||||
} else {
|
||||
commands.entity(selected).insert(WorkedResourceDeposit {
|
||||
workers: 1,
|
||||
..default()
|
||||
});
|
||||
}
|
||||
if available_workers.0 == 0 {
|
||||
ui.add_enabled(false, egui::Button::new("No workers available"));
|
||||
} else {
|
||||
if ui.button("Add worker").clicked() {
|
||||
available_workers.0 = available_workers.0.saturating_sub(1);
|
||||
if let Some(ref mut worked) = opt_worked {
|
||||
worked.workers = worked.workers.saturating_add(1);
|
||||
} else {
|
||||
commands.entity(selected).insert(WorkedResourceDeposit {
|
||||
workers: 1,
|
||||
..default()
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ui.add_enabled(false, egui::Button::new("Core required"));
|
||||
}
|
||||
|
||||
// remove
|
||||
if let Some(ref mut worked) = opt_worked {
|
||||
if ui.button("Remove worker").clicked() {
|
||||
|
|
@ -281,17 +266,14 @@ fn side_panel(
|
|||
.iter()
|
||||
.filter_map(|u| upgrades.get(*u).map(|(up, n)| (*u, up, n)).ok())
|
||||
{
|
||||
let button_text =
|
||||
RichText::new(upgrade_name.as_str()).size(LARGE_FONT_SIZE);
|
||||
if resources.0.can_buy(upgrade.cost) {
|
||||
if ui.button(button_text).clicked() {
|
||||
commands.trigger_targets(
|
||||
UnlockUpgrade { building: selected },
|
||||
upgrade_entity,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
ui.add_enabled(false, egui::Button::new(button_text));
|
||||
if ui
|
||||
.button(RichText::new(upgrade_name.as_str()).size(LARGE_FONT_SIZE))
|
||||
.clicked()
|
||||
{
|
||||
commands.trigger_targets(
|
||||
UnlockUpgrade { building: selected },
|
||||
upgrade_entity,
|
||||
);
|
||||
}
|
||||
ui.label(RichText::new(upgrade.description.as_str()).size(FONT_SIZE));
|
||||
ui.label(RichText::new(upgrade.cost.to_string()).size(FONT_SIZE));
|
||||
|
|
@ -322,14 +304,14 @@ fn side_panel(
|
|||
if !info.unlocked {
|
||||
continue;
|
||||
}
|
||||
let button_text =
|
||||
RichText::new(format!("{} - {}", name, cost.0.to_string())).size(FONT_SIZE);
|
||||
if resources.can_buy(cost.0) {
|
||||
if ui.button(button_text).clicked() {
|
||||
selected_preview_writer.write(SelectBuildingPreview(Some(info.preview)));
|
||||
}
|
||||
} else {
|
||||
ui.add_enabled(false, egui::Button::new(button_text));
|
||||
|
||||
if ui
|
||||
.button(
|
||||
RichText::new(format!("{} - {}", name, cost.0.to_string())).size(FONT_SIZE),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
selected_preview_writer.write(SelectBuildingPreview(Some(info.preview)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
[package]
|
||||
name = "ui_range_indicator"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bevy = { workspace = true }
|
||||
|
||||
combat = { path = "../combat" }
|
||||
input = { path = "../input" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
@ -1,197 +0,0 @@
|
|||
//bevy system signatures often violate these rules
|
||||
#![allow(clippy::type_complexity)]
|
||||
#![allow(clippy::too_many_arguments)]
|
||||
|
||||
use std::f32::consts::PI;
|
||||
|
||||
use bevy::{
|
||||
ecs::{component::HookContext, world::DeferredWorld},
|
||||
pbr::{NotShadowCaster, NotShadowReceiver},
|
||||
prelude::*,
|
||||
};
|
||||
use combat::Range;
|
||||
use input::Selected;
|
||||
|
||||
pub struct UiRangeIndicatorPlugin;
|
||||
|
||||
impl Plugin for UiRangeIndicatorPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, init).add_systems(Update, display);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
struct Indicator(Entity, f32);
|
||||
|
||||
#[derive(Component)]
|
||||
struct SelectedIndicator;
|
||||
|
||||
#[derive(Component, Default)]
|
||||
#[component(on_add=create_custom_indicator)]
|
||||
#[component(on_remove=remove_custom_indicator)]
|
||||
pub struct CustomRangeIndicator {
|
||||
material: Handle<StandardMaterial>,
|
||||
indicator: Option<Entity>,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct DisplayCustomRangeIndicator;
|
||||
|
||||
#[derive(Resource)]
|
||||
struct RangeResources {
|
||||
base_mesh: Handle<Mesh>,
|
||||
}
|
||||
|
||||
impl CustomRangeIndicator {
|
||||
pub fn new(material: Handle<StandardMaterial>) -> Self {
|
||||
Self {
|
||||
material,
|
||||
indicator: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn create_custom_indicator(mut world: DeferredWorld, ctx: HookContext) {
|
||||
let attaching_to = ctx.entity;
|
||||
let material = world
|
||||
.entity(attaching_to)
|
||||
.get::<CustomRangeIndicator>()
|
||||
.unwrap()
|
||||
.material
|
||||
.clone();
|
||||
let base_mesh = world.resource::<RangeResources>().base_mesh.clone();
|
||||
let mut commands = world.commands();
|
||||
let indicator = create_indicator(&mut commands, material, base_mesh);
|
||||
world
|
||||
.entity_mut(attaching_to)
|
||||
.get_mut::<CustomRangeIndicator>()
|
||||
.unwrap()
|
||||
.indicator = Some(indicator);
|
||||
}
|
||||
|
||||
fn remove_custom_indicator(mut world: DeferredWorld, ctx: HookContext) {
|
||||
let Some(indicator) = world
|
||||
.entity(ctx.entity)
|
||||
.get::<CustomRangeIndicator>()
|
||||
.unwrap()
|
||||
.indicator
|
||||
else {
|
||||
return;
|
||||
};
|
||||
world.commands().entity(indicator).despawn();
|
||||
}
|
||||
|
||||
fn create_indicator(
|
||||
commands: &mut Commands,
|
||||
material: Handle<StandardMaterial>,
|
||||
base_mesh: Handle<Mesh>,
|
||||
) -> Entity {
|
||||
commands
|
||||
.spawn((
|
||||
Mesh3d(base_mesh),
|
||||
Transform::from_rotation(Quat::from_rotation_x(-PI / 2.)),
|
||||
MeshMaterial3d(material),
|
||||
Indicator(Entity::PLACEHOLDER, 1.0),
|
||||
Visibility::Hidden,
|
||||
NotShadowCaster,
|
||||
NotShadowReceiver,
|
||||
))
|
||||
.id()
|
||||
}
|
||||
|
||||
fn init(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
let material = materials.add(StandardMaterial {
|
||||
alpha_mode: AlphaMode::Blend,
|
||||
base_color: Color::srgba(0.7, 0.7, 0.7, 0.5),
|
||||
unlit: true,
|
||||
double_sided: true,
|
||||
..default()
|
||||
});
|
||||
let mesh = meshes.add(Extrusion::new(Annulus::new(1000. - 0.1, 1000.), 1.0));
|
||||
commands.insert_resource(RangeResources {
|
||||
base_mesh: mesh.clone(),
|
||||
});
|
||||
let selected_indicator = create_indicator(&mut commands, material, mesh);
|
||||
commands
|
||||
.entity(selected_indicator)
|
||||
.insert(SelectedIndicator);
|
||||
}
|
||||
|
||||
// todo - perf and visuals kind of suck here. honeslty this whole thing should be split up and sucks.
|
||||
fn display(
|
||||
selected_query: Query<
|
||||
(Entity, &Range, &GlobalTransform),
|
||||
(With<Selected>, Without<CustomRangeIndicator>),
|
||||
>,
|
||||
selected_indicator_query: Single<
|
||||
(&mut Transform, &mut Visibility, &mut Indicator, &mut Mesh3d),
|
||||
With<SelectedIndicator>,
|
||||
>,
|
||||
custom_entity_query: Query<(
|
||||
Entity,
|
||||
&Range,
|
||||
&GlobalTransform,
|
||||
&CustomRangeIndicator,
|
||||
Option<&Selected>,
|
||||
Option<&DisplayCustomRangeIndicator>,
|
||||
)>,
|
||||
mut indicator_query: Query<
|
||||
(&mut Transform, &mut Visibility, &mut Indicator, &mut Mesh3d),
|
||||
Without<SelectedIndicator>,
|
||||
>,
|
||||
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
) {
|
||||
for (
|
||||
target_entity,
|
||||
range,
|
||||
gtf,
|
||||
CustomRangeIndicator { indicator, .. },
|
||||
opt_selected,
|
||||
opt_display,
|
||||
) in custom_entity_query.iter()
|
||||
{
|
||||
let Some(indicator_entity) = indicator else {
|
||||
continue;
|
||||
};
|
||||
let Ok((mut tf, mut vis, mut indicator, mut mesh)) =
|
||||
indicator_query.get_mut(*indicator_entity)
|
||||
else {
|
||||
error!("invalid setup for custom range indicator");
|
||||
continue;
|
||||
};
|
||||
if target_entity != indicator.0 || indicator.1 != range.0 {
|
||||
indicator.0 = target_entity; //shouldn't ever be different after init, but just to be sure...
|
||||
indicator.1 = range.0;
|
||||
// range or entity changed, generate new mesh
|
||||
mesh.0 = meshes.add(Extrusion::new(Annulus::new(range.0 - 0.1, range.0), 1.0));
|
||||
}
|
||||
*vis = if opt_selected.is_some() || opt_display.is_some() {
|
||||
Visibility::Inherited
|
||||
} else {
|
||||
Visibility::Hidden
|
||||
};
|
||||
tf.translation = gtf.translation().with_y(1.0);
|
||||
}
|
||||
|
||||
//update selected entity
|
||||
{
|
||||
let (mut tf, mut vis, mut indicator, mut mesh) = selected_indicator_query.into_inner();
|
||||
let Ok((entity, range, gtf)) = selected_query.single() else {
|
||||
*vis = Visibility::Hidden;
|
||||
return;
|
||||
};
|
||||
if entity != indicator.0 || indicator.1 != range.0 {
|
||||
indicator.0 = entity;
|
||||
indicator.1 = range.0;
|
||||
// range or entity changed, generate new mesh
|
||||
mesh.0 = meshes.add(Extrusion::new(Annulus::new(range.0 - 0.1, range.0), 1.0));
|
||||
}
|
||||
*vis = Visibility::Inherited;
|
||||
tf.translation = gtf.translation().with_y(1.0);
|
||||
}
|
||||
}
|
||||
|
|
@ -38,7 +38,6 @@ fn main() {
|
|||
resource_graveyard::ResourceGraveyardPlugin,
|
||||
upgrade::UpgradePlugin,
|
||||
ui_health_bar::UiHealthBarPlugin,
|
||||
ui_range_indicator::UiRangeIndicatorPlugin,
|
||||
// new internal crates go here
|
||||
));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue