Fix popups (#176)

* fix: fix popups

* fix: fix naming for backstab
This commit is contained in:
ThereDrD0
2024-03-04 09:56:23 +03:00
committed by GitHub
parent 6a230aec72
commit 9251e909ab
7 changed files with 51 additions and 45 deletions

View File

@@ -49,29 +49,29 @@ public sealed class ExecutionSystem : EntitySystem
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<SharpComponent, GetVerbsEvent<UtilityVerb>>(OnGetInteractionVerbsMelee); SubscribeLocalEvent<SharpComponent, GetVerbsEvent<UtilityVerb>>(OnGetInteractionVerbsMelee);
SubscribeLocalEvent<GunComponent, GetVerbsEvent<UtilityVerb>>(OnGetInteractionVerbsGun); SubscribeLocalEvent<GunComponent, GetVerbsEvent<UtilityVerb>>(OnGetInteractionVerbsGun);
SubscribeLocalEvent<SharpComponent, ExecutionDoAfterEvent>(OnDoafterMelee); SubscribeLocalEvent<SharpComponent, ExecutionDoAfterEvent>(OnDoafterMelee);
SubscribeLocalEvent<GunComponent, ExecutionDoAfterEvent>(OnDoafterGun); SubscribeLocalEvent<GunComponent, ExecutionDoAfterEvent>(OnDoafterGun);
} }
private void OnGetInteractionVerbsMelee( private void OnGetInteractionVerbsMelee(
EntityUid uid, EntityUid uid,
SharpComponent component, SharpComponent component,
GetVerbsEvent<UtilityVerb> args) GetVerbsEvent<UtilityVerb> args)
{ {
if (args.Hands == null || args.Using == null || !args.CanAccess || !args.CanInteract) if (args.Hands == null || args.Using == null || !args.CanAccess || !args.CanInteract)
return; return;
var attacker = args.User; var attacker = args.User;
var weapon = args.Using!.Value; var weapon = args.Using!.Value;
var victim = args.Target; var victim = args.Target;
if (!CanExecuteWithMelee(weapon, victim, attacker)) if (!CanExecuteWithMelee(weapon, victim, attacker))
return; return;
UtilityVerb verb = new() UtilityVerb verb = new()
{ {
Act = () => Act = () =>
@@ -87,7 +87,7 @@ public sealed class ExecutionSystem : EntitySystem
} }
private void OnGetInteractionVerbsGun( private void OnGetInteractionVerbsGun(
EntityUid uid, EntityUid uid,
GunComponent component, GunComponent component,
GetVerbsEvent<UtilityVerb> args) GetVerbsEvent<UtilityVerb> args)
{ {
@@ -100,7 +100,7 @@ public sealed class ExecutionSystem : EntitySystem
if (!CanExecuteWithGun(weapon, victim, attacker)) if (!CanExecuteWithGun(weapon, victim, attacker))
return; return;
UtilityVerb verb = new() UtilityVerb verb = new()
{ {
Act = () => Act = () =>
@@ -120,15 +120,15 @@ public sealed class ExecutionSystem : EntitySystem
// No point executing someone if they can't take damage // No point executing someone if they can't take damage
if (!TryComp<DamageableComponent>(victim, out var damage)) if (!TryComp<DamageableComponent>(victim, out var damage))
return false; return false;
// You can't execute something that cannot die // You can't execute something that cannot die
if (!TryComp<MobStateComponent>(victim, out var mobState)) if (!TryComp<MobStateComponent>(victim, out var mobState))
return false; return false;
// You're not allowed to execute dead people (no fun allowed) // You're not allowed to execute dead people (no fun allowed)
if (_mobStateSystem.IsDead(victim, mobState)) if (_mobStateSystem.IsDead(victim, mobState))
return false; return false;
// You must be able to attack people to execute // You must be able to attack people to execute
if (!_actionBlockerSystem.CanAttack(attacker, victim)) if (!_actionBlockerSystem.CanAttack(attacker, victim))
return false; return false;
@@ -144,25 +144,25 @@ public sealed class ExecutionSystem : EntitySystem
private bool CanExecuteWithMelee(EntityUid weapon, EntityUid victim, EntityUid user) private bool CanExecuteWithMelee(EntityUid weapon, EntityUid victim, EntityUid user)
{ {
if (!CanExecuteWithAny(weapon, victim, user)) return false; if (!CanExecuteWithAny(weapon, victim, user)) return false;
// We must be able to actually hurt people with the weapon // We must be able to actually hurt people with the weapon
if (!TryComp<MeleeWeaponComponent>(weapon, out var melee) && melee!.Damage.GetTotal() > 0.0f) if (!TryComp<MeleeWeaponComponent>(weapon, out var melee) && melee!.Damage.GetTotal() > 0.0f)
return false; return false;
return true; return true;
} }
private bool CanExecuteWithGun(EntityUid weapon, EntityUid victim, EntityUid user) private bool CanExecuteWithGun(EntityUid weapon, EntityUid victim, EntityUid user)
{ {
if (!CanExecuteWithAny(weapon, victim, user)) return false; if (!CanExecuteWithAny(weapon, victim, user)) return false;
// We must be able to actually fire the gun // We must be able to actually fire the gun
if (!TryComp<GunComponent>(weapon, out var gun) && _gunSystem.CanShoot(gun!)) if (!TryComp<GunComponent>(weapon, out var gun) && _gunSystem.CanShoot(gun!))
return false; return false;
return true; return true;
} }
private void TryStartMeleeExecutionDoafter(EntityUid weapon, EntityUid victim, EntityUid attacker) private void TryStartMeleeExecutionDoafter(EntityUid weapon, EntityUid victim, EntityUid attacker)
{ {
if (!CanExecuteWithMelee(weapon, victim, attacker)) if (!CanExecuteWithMelee(weapon, victim, attacker))
@@ -180,7 +180,7 @@ public sealed class ExecutionSystem : EntitySystem
ShowExecutionPopup("execution-popup-melee-initial-internal", Filter.Entities(attacker), PopupType.Medium, attacker, victim, weapon); ShowExecutionPopup("execution-popup-melee-initial-internal", Filter.Entities(attacker), PopupType.Medium, attacker, victim, weapon);
ShowExecutionPopup("execution-popup-melee-initial-external", Filter.PvsExcept(attacker), PopupType.MediumCaution, attacker, victim, weapon); ShowExecutionPopup("execution-popup-melee-initial-external", Filter.PvsExcept(attacker), PopupType.MediumCaution, attacker, victim, weapon);
} }
var doAfter = var doAfter =
new DoAfterArgs(EntityManager, attacker, executionTime, new ExecutionDoAfterEvent(), weapon, target: victim, used: weapon) new DoAfterArgs(EntityManager, attacker, executionTime, new ExecutionDoAfterEvent(), weapon, target: victim, used: weapon)
{ {
@@ -192,12 +192,12 @@ public sealed class ExecutionSystem : EntitySystem
_doAfterSystem.TryStartDoAfter(doAfter); _doAfterSystem.TryStartDoAfter(doAfter);
} }
private void TryStartGunExecutionDoafter(EntityUid weapon, EntityUid victim, EntityUid attacker) private void TryStartGunExecutionDoafter(EntityUid weapon, EntityUid victim, EntityUid attacker)
{ {
if (!CanExecuteWithGun(weapon, victim, attacker)) if (!CanExecuteWithGun(weapon, victim, attacker))
return; return;
if (attacker == victim) if (attacker == victim)
{ {
ShowExecutionPopup("suicide-popup-gun-initial-internal", Filter.Entities(attacker), PopupType.Medium, attacker, victim, weapon); ShowExecutionPopup("suicide-popup-gun-initial-internal", Filter.Entities(attacker), PopupType.Medium, attacker, victim, weapon);
@@ -225,10 +225,10 @@ public sealed class ExecutionSystem : EntitySystem
{ {
if (args.Handled || args.Cancelled || args.Used == null || args.Target == null) if (args.Handled || args.Cancelled || args.Used == null || args.Target == null)
return false; return false;
if (!CanExecuteWithAny(args.Used.Value, args.Target.Value, uid)) if (!CanExecuteWithAny(args.Used.Value, args.Target.Value, uid))
return false; return false;
// All checks passed // All checks passed
return true; return true;
} }
@@ -237,7 +237,7 @@ public sealed class ExecutionSystem : EntitySystem
{ {
if (args.Handled || args.Cancelled || args.Used == null || args.Target == null) if (args.Handled || args.Cancelled || args.Used == null || args.Target == null)
return; return;
var attacker = args.User; var attacker = args.User;
var victim = args.Target!.Value; var victim = args.Target!.Value;
var weapon = args.Used!.Value; var weapon = args.Used!.Value;
@@ -246,7 +246,7 @@ public sealed class ExecutionSystem : EntitySystem
if (!TryComp<MeleeWeaponComponent>(weapon, out var melee) && melee!.Damage.GetTotal() > 0.0f) if (!TryComp<MeleeWeaponComponent>(weapon, out var melee) && melee!.Damage.GetTotal() > 0.0f)
return; return;
_damageableSystem.TryChangeDamage(victim, melee.Damage * DamageModifier, true); _damageableSystem.TryChangeDamage(victim, melee.Damage * DamageModifier, true);
_audioSystem.PlayEntity(melee.HitSound, Filter.Pvs(weapon), weapon, true, AudioParams.Default); _audioSystem.PlayEntity(melee.HitSound, Filter.Pvs(weapon), weapon, true, AudioParams.Default);
@@ -261,26 +261,26 @@ public sealed class ExecutionSystem : EntitySystem
ShowExecutionPopup("execution-popup-melee-complete-external", Filter.PvsExcept(attacker), PopupType.MediumCaution, attacker, victim, weapon); ShowExecutionPopup("execution-popup-melee-complete-external", Filter.PvsExcept(attacker), PopupType.MediumCaution, attacker, victim, weapon);
} }
} }
// TODO: This repeats a lot of the code of the serverside GunSystem, make it not do that // TODO: This repeats a lot of the code of the serverside GunSystem, make it not do that
private void OnDoafterGun(EntityUid uid, GunComponent component, DoAfterEvent args) private void OnDoafterGun(EntityUid uid, GunComponent component, DoAfterEvent args)
{ {
if (args.Handled || args.Cancelled || args.Used == null || args.Target == null) if (args.Handled || args.Cancelled || args.Used == null || args.Target == null)
return; return;
var attacker = args.User; var attacker = args.User;
var weapon = args.Used!.Value; var weapon = args.Used!.Value;
var victim = args.Target!.Value; var victim = args.Target!.Value;
if (!CanExecuteWithGun(weapon, victim, attacker)) return; if (!CanExecuteWithGun(weapon, victim, attacker)) return;
// Check if any systems want to block our shot // Check if any systems want to block our shot
var prevention = new ShotAttemptedEvent var prevention = new ShotAttemptedEvent
{ {
User = attacker, User = attacker,
Used = weapon Used = weapon
}; };
RaiseLocalEvent(weapon, ref prevention); RaiseLocalEvent(weapon, ref prevention);
if (prevention.Cancelled) if (prevention.Cancelled)
return; return;
@@ -288,7 +288,7 @@ public sealed class ExecutionSystem : EntitySystem
RaiseLocalEvent(attacker, ref prevention); RaiseLocalEvent(attacker, ref prevention);
if (prevention.Cancelled) if (prevention.Cancelled)
return; return;
// Not sure what this is for but gunsystem uses it so ehhh // Not sure what this is for but gunsystem uses it so ehhh
var attemptEv = new AttemptShootEvent(attacker, null); var attemptEv = new AttemptShootEvent(attacker, null);
RaiseLocalEvent(weapon, ref attemptEv); RaiseLocalEvent(weapon, ref attemptEv);
@@ -297,11 +297,11 @@ public sealed class ExecutionSystem : EntitySystem
{ {
if (attemptEv.Message != null) if (attemptEv.Message != null)
{ {
_popupSystem.PopupClient(attemptEv.Message, weapon, attacker); _popupSystem.PopupEntity(attemptEv.Message, weapon, attacker);
return; return;
} }
} }
// Take some ammunition for the shot (one bullet) // Take some ammunition for the shot (one bullet)
var fromCoordinates = Transform(attacker).Coordinates; var fromCoordinates = Transform(attacker).Coordinates;
var ev = new TakeAmmoEvent(1, new List<(EntityUid? Entity, IShootable Shootable)>(), fromCoordinates, attacker); var ev = new TakeAmmoEvent(1, new List<(EntityUid? Entity, IShootable Shootable)>(), fromCoordinates, attacker);
@@ -314,7 +314,7 @@ public sealed class ExecutionSystem : EntitySystem
ShowExecutionPopup("execution-popup-gun-empty", Filter.Pvs(weapon), PopupType.Medium, attacker, victim, weapon); ShowExecutionPopup("execution-popup-gun-empty", Filter.Pvs(weapon), PopupType.Medium, attacker, victim, weapon);
return; return;
} }
// Information about the ammo like damage // Information about the ammo like damage
DamageSpecifier damage = new DamageSpecifier(); DamageSpecifier damage = new DamageSpecifier();
@@ -335,9 +335,9 @@ public sealed class ExecutionSystem : EntitySystem
cartridge.Spent = true; cartridge.Spent = true;
_appearanceSystem.SetData(ammoUid!.Value, AmmoVisuals.Spent, true); _appearanceSystem.SetData(ammoUid!.Value, AmmoVisuals.Spent, true);
Dirty(ammoUid.Value, cartridge); Dirty(ammoUid.Value, cartridge);
break; break;
case AmmoComponent newAmmo: case AmmoComponent newAmmo:
TryComp<ProjectileComponent>(ammoUid, out var projectileB); TryComp<ProjectileComponent>(ammoUid, out var projectileB);
if (projectileB != null) if (projectileB != null)
@@ -346,11 +346,11 @@ public sealed class ExecutionSystem : EntitySystem
} }
Del(ammoUid); Del(ammoUid);
break; break;
case HitscanPrototype hitscan: case HitscanPrototype hitscan:
damage = hitscan.Damage!; damage = hitscan.Damage!;
break; break;
default: default:
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
} }
@@ -369,11 +369,11 @@ public sealed class ExecutionSystem : EntitySystem
return; return;
} }
} }
// Gun successfully fired, deal damage // Gun successfully fired, deal damage
_damageableSystem.TryChangeDamage(victim, damage * DamageModifier, true); _damageableSystem.TryChangeDamage(victim, damage * DamageModifier, true);
_audioSystem.PlayEntity(component.SoundGunshot, Filter.Pvs(weapon), weapon, false, AudioParams.Default); _audioSystem.PlayEntity(component.SoundGunshot, Filter.Pvs(weapon), weapon, false, AudioParams.Default);
// Popups // Popups
if (attacker != victim) if (attacker != victim)
{ {
@@ -394,4 +394,4 @@ public sealed class ExecutionSystem : EntitySystem
locString, ("attacker", attacker), ("victim", victim), ("weapon", weapon)), locString, ("attacker", attacker), ("victim", victim), ("weapon", weapon)),
attacker, filter, true, type); attacker, filter, true, type);
} }
} }

View File

@@ -120,7 +120,7 @@ public sealed class InteractionPopupSystem : EntitySystem
_popupSystem.PopupEntity(msg, uid, user); _popupSystem.PopupEntity(msg, uid, user);
_popupSystem.PopupEntity(msgOthers, uid, Filter.PvsExcept(user, entityManager: EntityManager), true); _popupSystem.PopupEntity(msgOthers, uid, Filter.PvsExcept(user, entityManager: EntityManager), true);
} }
else else if (msg != "") // WD edit
_popupSystem.PopupEntity(msg, uid, user); //play only for the initiating entity. _popupSystem.PopupEntity(msg, uid, user); //play only for the initiating entity.
if (sfx is not null) //not all cases will have sound. if (sfx is not null) //not all cases will have sound.

View File

@@ -323,7 +323,7 @@ namespace Content.Server.VendingMachines
if (_accessReader.IsAllowed(sender, uid, accessReader) || HasComp<EmaggedComponent>(uid)) if (_accessReader.IsAllowed(sender, uid, accessReader) || HasComp<EmaggedComponent>(uid))
return true; return true;
Popup.PopupClient(Loc.GetString("vending-machine-component-try-eject-access-denied"), uid, sender); Popup.PopupEntity(Loc.GetString("vending-machine-component-try-eject-access-denied"), uid, sender);
Deny(uid, vendComponent); Deny(uid, vendComponent);
return false; return false;
} }
@@ -352,7 +352,7 @@ namespace Content.Server.VendingMachines
if (entry == null) if (entry == null)
{ {
if (sender.HasValue) if (sender.HasValue)
Popup.PopupClient(Loc.GetString("vending-machine-component-try-eject-invalid-item"), uid, sender.Value); Popup.PopupEntity(Loc.GetString("vending-machine-component-try-eject-invalid-item"), uid, sender.Value);
Deny(uid, vendComponent); Deny(uid, vendComponent);
@@ -362,7 +362,7 @@ namespace Content.Server.VendingMachines
if (entry.Amount <= 0) if (entry.Amount <= 0)
{ {
if (sender.HasValue) if (sender.HasValue)
Popup.PopupClient(Loc.GetString("vending-machine-component-try-eject-out-of-stock"), uid, sender.Value); Popup.PopupEntity(Loc.GetString("vending-machine-component-try-eject-out-of-stock"), uid, sender.Value);
Deny(uid, vendComponent); Deny(uid, vendComponent);
return; return;

View File

@@ -1,7 +1,7 @@
using Content.Server.Popups;
using Content.Server.Xenoarchaeology.Equipment.Components; using Content.Server.Xenoarchaeology.Equipment.Components;
using Content.Server.Xenoarchaeology.XenoArtifacts; using Content.Server.Xenoarchaeology.XenoArtifacts;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Timing; using Content.Shared.Timing;
namespace Content.Server.Xenoarchaeology.Equipment.Systems; namespace Content.Server.Xenoarchaeology.Equipment.Systems;
@@ -9,7 +9,7 @@ namespace Content.Server.Xenoarchaeology.Equipment.Systems;
public sealed class NodeScannerSystem : EntitySystem public sealed class NodeScannerSystem : EntitySystem
{ {
[Dependency] private readonly UseDelaySystem _useDelay = default!; [Dependency] private readonly UseDelaySystem _useDelay = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly SharedPopupSystem _popupSystem = default!;
/// <inheritdoc/> /// <inheritdoc/>
public override void Initialize() public override void Initialize()
@@ -36,7 +36,7 @@ public sealed class NodeScannerSystem : EntitySystem
return; return;
// WD edit // WD edit
_popupSystem.PopupClient(Loc.GetString("node-scan-popup", _popupSystem.PopupEntity(Loc.GetString("node-scan-popup",
("id", $"{artifact.CurrentNodeId}")), target, args.User); ("id", $"{artifact.CurrentNodeId}")), target, args.User);
} }
} }

View File

@@ -147,12 +147,12 @@ public sealed class CultistFactorySystem : EntitySystem
if (args.IsAnchored) if (args.IsAnchored)
{ {
_transform.Unanchor(target, xform); _transform.Unanchor(target, xform);
_popup.PopupClient(Loc.GetString("anchorable-unanchored"), uid, args.User); _popup.PopupEntity(Loc.GetString("anchorable-unanchored"), uid, args.User);
} }
else else
{ {
_transform.AnchorEntity(target, xform); _transform.AnchorEntity(target, xform);
_popup.PopupClient(Loc.GetString("anchorable-anchored"), uid, args.User); _popup.PopupEntity(Loc.GetString("anchorable-anchored"), uid, args.User);
} }
_audio.PlayPvs("/Audio/Items/ratchet.ogg", uid); _audio.PlayPvs("/Audio/Items/ratchet.ogg", uid);

View File

@@ -48,5 +48,10 @@ public sealed class BackstabSystem : EntitySystem
args.PenetrateArmor = ent.Comp.PenetrateArmor; args.PenetrateArmor = ent.Comp.PenetrateArmor;
if (!_net.IsServer)
return;
var message = Loc.GetString("backstab-damage-betrayal-dagger", ("damage", damage));
_popup.PopupClient(message, args.User, args.User, PopupType.MediumCaution);
} }
} }

View File

@@ -0,0 +1 @@
backstab-damage-betrayal-dagger = Удар в спину: {$damage}!