Files

200 lines
6.4 KiB
C#
Raw Permalink Normal View History

using System.Numerics;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Client.Utility;
using Robust.Shared.Input;
using Serilog;
namespace Content.Client._CP14.UserInterface.Systems.NodeTree;
[GenerateTypedNameReferences]
public sealed partial class CP14NodeTreeGraphControl : BoxContainer
{
2025-06-15 22:05:24 +10:00
private const float LocalUIScaleMax = 4f;
private const float LocalUIScaleMin = 1f;
[Dependency] private readonly IEntityManager _entManager = default!;
private CP14NodeTreeUiState? _state;
private CP14NodeTreeElement? _hoveredNode;
private CP14NodeTreeElement? _selectedNode;
private Dictionary<string, CP14NodeTreeElement> _nodeDict = new();
private bool _dragging = false;
private Vector2 _previousMousePosition = Vector2.Zero;
private Vector2 _globalOffset = new (60,60);
2025-06-15 22:05:24 +10:00
private float _localUIScale = LocalUIScaleMin;
private float Scale => UIScale * _localUIScale;
public event Action<CP14NodeTreeElement?>? OnNodeSelected;
public event Action<Vector2>? OnOffsetChanged;
public CP14NodeTreeGraphControl()
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);
OnOffsetChanged?.Invoke(_globalOffset);
}
public void UpdateState(CP14NodeTreeUiState state)
{
_state = state;
_nodeDict.Clear();
foreach (var node in state.Nodes)
{
_nodeDict[node.NodeKey] = node;
}
OnOffsetChanged?.Invoke(_globalOffset);
}
2025-06-15 22:05:24 +10:00
protected override void MouseWheel(GUIMouseWheelEventArgs args)
{
base.MouseWheel(args);
if (args.Handled)
return;
_localUIScale = MathHelper.Clamp(_localUIScale + 0.1f * args.Delta.Y, LocalUIScaleMin, LocalUIScaleMax);
}
protected override void KeyBindDown(GUIBoundKeyEventArgs args)
{
base.KeyBindDown(args);
if (args.Handled)
return;
if (args.Function == EngineKeyFunctions.UIClick)
{
_dragging = true;
if (_hoveredNode == null)
return;
OnNodeSelected?.Invoke(_hoveredNode);
UserInterfaceManager.ClickSound();
_selectedNode = _hoveredNode;
}
if (args.Function == EngineKeyFunctions.UIRightClick)
{
_globalOffset = new Vector2(60, 60); // Reset offset on right click
2025-06-15 22:05:24 +10:00
_localUIScale = LocalUIScaleMin;
OnOffsetChanged?.Invoke(_globalOffset);
}
}
protected override void KeyBindUp(GUIBoundKeyEventArgs args)
{
base.KeyBindUp(args);
if (args.Handled || args.Function != EngineKeyFunctions.UIClick)
return;
_dragging = false;
}
protected override void ExitedTree()
{
base.ExitedTree();
OnNodeSelected?.Invoke(null);
}
protected override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
if (_state is null)
return;
_hoveredNode = null;
var cursor = (UserInterfaceManager.MousePositionScaled.Position * UIScale) - GlobalPixelPosition;
if (_dragging)
{
var delta = cursor - _previousMousePosition;
2025-06-15 22:05:24 +10:00
_globalOffset += delta;
OnOffsetChanged?.Invoke(_globalOffset);
}
_previousMousePosition = cursor;
//Draw connection lines
foreach (var edge in _state.Edges)
{
Vampire clan battle gamemode (#1672) * vampire returns + transformstions redo * carcat fangs fix + greetings music update * vampire skill trees * Blood essence gathering Introduces the vampire blood essence mechanic, including the CP14SpellVampireGatherEssence spell, new skill point consumable component, and related UI/localization updates. Adds clientside effects for spell casting, new vampire skill and action, and refines skill point gain/loss popups. Also restructures vampire components, updates spell logic for client/server prediction, and removes unused parallax files. * perma damage * Add skill point cost to magic system and vampire essence spell Introduced CP14MagicEffectSkillPointCostComponent to allow magic effects to consume skill points. Updated the shared magic system to handle skill point checks and consumption. Added a new vampire spell for creating blood essence, including new icons and localization. Adjusted vampire component to grant and remove skill points, and updated related skill tree and spell prototypes. Minor fixes and refactoring in spell logic and descriptions. * blood step + blood vision skills * vampire clans icons * 50 players limit + vampire objectives * fixes * devourers altar transmutation * Remove StealTarget component from animal, dino, and mole NPCs The StealTarget component and associated stealGroup were removed from boar, dinosaur, and mole NPC definitions. This likely disables these entities from being targeted for stealing, possibly to adjust gameplay balance or fix unintended behavior. * fix * essence creation improve * altars * voice masks * transmutation fix * teleportation glyph * crimson candles * candle crafting * fix pointer predictions * Add Vampire Clan Battle gamemode and update vampire roles Introduces the 'Vampire Clan Battle' gamemode with new localization in English and Russian, updated game preset definitions, and secret weights. Refactors vampire antagonist briefings and objectives for multiple clans, adjusts vampire role preferences and team settings, and reduces the damage of the Vampire Gather Essence spell. Also includes minor improvements to spell and game mode descriptions, and corrects file naming for game preset locales. * powerful kicks in * time gates + vampire tree * vampire proto faction * fix * fixes * tree progression * search enemy * Update CP14SharedVampireSystem.cs * blood essence gathering redo * essence gathering refactor 2 * blood healing * Update secret_weights.yml * tree planting * boodgrass * tree upgrade announcement * construction graph integration * delete transmutation system * workbench crafting returns * cloaks crafting + cloak invisibility * make vampire tree is generic red tree (sad) * clan heart sprite * Refactor vampire tree to clan heart system Replaces the CP14VampireTreeComponent with CP14VampireClanHeartComponent, updating all related logic, appearance, and localization. Adjusts skill requirements, examination, and level progression to use the new clan heart system. Updates entity prototypes, visuals, and adds new orb sprites for clan heart levels. Localization strings and logic are updated to reflect the new terminology and mechanics. * Update SpeciesBlacklist.cs * Refactor vampire clan heart and remove tree spell Refactored the vampire clan heart to support essence regeneration over time and adjusted level thresholds. Removed the vampire tree planting spell and related prototype fields, as well as unused tree system code. Updated localization, entity prototypes, and faction definitions to reflect these changes. * Add clan heart construction for vampire clans Introduces construction graphs, entities, and conditions for building unique clan hearts for each vampire clan (Unnameable, Devourers, NightChildrens). Adds new construction conditions (all clan vampires required, singleton enforcement), updates skill tree to unlock constructions, and removes the now-obsolete CP14MagicEffectAllVampireClanRequiredComponent. Also adds new frame sprites and updates localization and prototype files accordingly. * level up vfx * VFX + lobby track * orb resprite * sprites * Add vampire altar mechanics and improve clan heart behavior Introduces the CP14VampireAltarComponent and altar entity, which doubles blood essence extraction when victims are strapped to the altar. Adds a custom explosion behavior for vampire clan hearts upon destruction, updates construction graphs and recipes for altars, and improves localization. Also refines skill description handling and adjusts vampire bite action text. * essence get when heart destruction * Add clan heart damage and destruction announcements Introduces announcements for when a vampire clan heart is damaged or destroyed, with cooldown to prevent spam. Refactors examination logic and updates localization files for both English and Russian to support new messages and sender formatting. * glyph adaptation * resurrection * Add round end summary for Vampire Clan Battles Implemented detailed round end text for the Vampire Clan Battles game mode, displaying victory, defeat, or draw outcomes based on surviving factions and population percentage. Refactored alive player percentage logic into a shared method and updated localization files with new outcome messages in English and Russian. Also removed an unused field from the defence condition component. * Update vampire_cloak.yml * fix * fix * Update portal_glyph.yml
2025-08-22 18:46:28 +03:00
if (!_nodeDict.ContainsKey(edge.Item1) || !_nodeDict.ContainsKey(edge.Item2))
continue;
var node1 = _nodeDict[edge.Item1];
var node2 = _nodeDict[edge.Item2];
2025-06-15 22:05:24 +10:00
var fromPos = node1.UiPosition * Scale + _globalOffset;
var toPos = node2.UiPosition * Scale + _globalOffset;
var lineColor = node1.Gained || node2.Gained ? _state.ActiveLineColor : _state.LineColor;
handle.DrawLine(fromPos, toPos, lineColor);
}
//Draw Node icons over lines
foreach (var node in _state.Nodes)
{
2025-06-15 22:05:24 +10:00
var pos = node.UiPosition * Scale + _globalOffset;
// Frame
var frameTexture = _state.FrameIcon.Frame0();
2025-06-15 22:05:24 +10:00
var frameSize = new Vector2(frameTexture.Width, frameTexture.Height) * 1.5f * Scale;
var frameQuad = new UIBox2(pos - frameSize / 2, pos + frameSize / 2);
handle.DrawTextureRect(frameTexture, frameQuad);
// Selected Node
if (_selectedNode == node)
{
var selectedTexture = _state.SelectedIcon.Frame0();
2025-06-15 22:05:24 +10:00
var selectedSize = new Vector2(selectedTexture.Width, selectedTexture.Height) * 1.5f * Scale;
var selectedQuad = new UIBox2(pos - selectedSize / 2, pos + selectedSize / 2);
handle.DrawTextureRect(selectedTexture, selectedQuad);
}
// Hovered Node
var hovered = (cursor - pos).LengthSquared() <= (frameSize.X / 2) * (frameSize.X / 2);
if (hovered)
{
_hoveredNode = node;
var hoveredTexture = _state.HoveredIcon.Frame0();
2025-06-15 22:05:24 +10:00
var hoveredSize = new Vector2(hoveredTexture.Width, hoveredTexture.Height) * 1.5f * Scale;
var hoveredQuad = new UIBox2(pos - hoveredSize / 2, pos + hoveredSize / 2);
handle.DrawTextureRect(hoveredTexture, hoveredQuad);
}
// Learned Node
if (node.Gained)
{
var learnedTexture = _state.LearnedIcon.Frame0();
2025-06-15 22:05:24 +10:00
var learnedSize = new Vector2(learnedTexture.Width, learnedTexture.Height) * 1.5f * Scale;
var learnedQuad = new UIBox2(pos - learnedSize / 2, pos + learnedSize / 2);
handle.DrawTextureRect(learnedTexture, learnedQuad);
}
// Base Node icon
if (node.Icon is not null)
{
var baseTexture = node.Icon.Frame0();
2025-06-15 22:05:24 +10:00
var baseSize = new Vector2(baseTexture.Width, baseTexture.Height) * 1.5f * Scale;
var baseQuad = new UIBox2(pos - baseSize / 2, pos + baseSize / 2);
var tint = node.Gained || node.Active ? Color.White : Color.FromSrgb(new Color(0.6f, 0.6f, 0.6f));
handle.DrawTextureRect(baseTexture, baseQuad, tint);
}
}
}
}