Skip to content

Commit

Permalink
ух.
Browse files Browse the repository at this point in the history
  • Loading branch information
FaDeOkno committed Dec 14, 2024
1 parent 18b8f50 commit eedbaa2
Show file tree
Hide file tree
Showing 22 changed files with 498 additions and 194 deletions.
70 changes: 34 additions & 36 deletions Content.Client/ADT/Research/UI/DraggableResearchPanel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Content.Client.UserInterface.Fragments;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
Expand All @@ -10,6 +11,7 @@
using Robust.Shared.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace Content.Client.ADT.Research.UI;
Expand All @@ -27,51 +29,47 @@ public DraggablePanel()
{
_isDragging = false;
_children = new List<Control>();

this.OnKeyBindDown += args => OnKeybindDown(args);
this.OnKeyBindUp += args => OnKeybindUp(args);
}

public void AddChildElement(Control child)
protected override void Draw(DrawingHandleScreen handle)
{
// Добавляем дочерний элемент в панель
_children.Add(child);
this.AddChild(child); // Также добавляем его в UI панель
}

private void OnKeybindDown(GUIBoundKeyEventArgs args)
{
if (args.Function == EngineKeyFunctions.Use)
foreach (var child in Children)
{
// Начинаем перетаскивание
_isDragging = true;
_dragStartPosition = args.PointerLocation.Position;
_originalPosition = this.Position; // Сохраняем исходную позицию панели
}
}
if (child is not ResearchConsoleItem item)
continue;

protected override void MouseMove(GUIMouseMoveEventArgs args)
{
base.MouseMove(args);
if (item.Prototype.RequiredTech.Count <= 0)
continue;

if (_isDragging)
{
// Перемещаем все дочерние элементы, вычисляя разницу между начальной и текущей позицией мыши
var delta = args.RelativePosition - _dragStartPosition;
var list = Children.Where(x => x is ResearchConsoleItem second && item.Prototype.RequiredTech.Contains(second.Prototype.ID));

foreach (var child in _children)
foreach (var second in list)
{
SetPosition(child, child.Position + delta); // Перемещаем каждого дочернего элемента
}
}
}
var leftOffset = second.PixelPosition.Y;
var rightOffset = item.PixelPosition.Y;

private void OnKeybindUp(GUIBoundKeyEventArgs args)
{
if (args.Function == EngineKeyFunctions.Use)
{
// Завершаем перетаскивание
_isDragging = false;
var y1 = second.PixelPosition.Y + second.PixelHeight / 2 + leftOffset;
var y2 = item.PixelPosition.Y + item.PixelHeight / 2 + rightOffset;

if (second == item)
{
handle.DrawLine(new Vector2(0, y1), new Vector2(PixelWidth, y2), Color.Cyan);
continue;
}
var startCoords = new Vector2(item.PixelPosition.X + 40, item.PixelPosition.Y + 40);
var endCoords = new Vector2(second.PixelPosition.X + 40, second.PixelPosition.Y + 40);

if (second.PixelPosition.Y != item.PixelPosition.Y)
{

handle.DrawLine(startCoords, new(endCoords.X, startCoords.Y), Color.White);
handle.DrawLine(new(endCoords.X, startCoords.Y), endCoords, Color.White);
}
else
{
handle.DrawLine(startCoords, endCoords, Color.White);
}
}
}
}
}
40 changes: 21 additions & 19 deletions Content.Client/ADT/Research/UI/ResearchConsoleItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@
Margin="5"
HorizontalExpand="False">
<BoxContainer Orientation="Vertical">
<PanelContainer Margin="5" SetSize="96 96">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#000000FF" />
</PanelContainer.PanelOverride>
<BoxContainer VerticalExpand="False" Orientation="Vertical" MaxSize="64 64">
<TextureRect
Name="ResearchDisplay"
TextureScale="2 2"
SetSize="96 96"
Stretch="KeepAspectCentered">
</TextureRect>
</BoxContainer>
<Button Name="Buy"
Text="{Loc 'analysis-console-print-button'}"
ToolTip="{Loc 'analysis-console-print-tooltip-info'}"
VerticalExpand="False"
HorizontalExpand="False">
</Button>
</PanelContainer>
<Button Name="Buy"
Text="{Loc 'analysis-console-print-button'}"
ToolTip="{Loc 'analysis-console-print-tooltip-info'}"
VerticalExpand="False"
HorizontalExpand="False"
SetSize="80 80"
StyleClasses="ButtonSquare">
<PanelContainer Name="Main" Margin="5" SetSize="64 64" Access="Public">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#000000FF" />
</PanelContainer.PanelOverride>
<BoxContainer VerticalExpand="False" Orientation="Vertical" MaxSize="64 64">
<TextureRect
Name="ResearchDisplay"
TextureScale="2 2"
SetSize="64 64"
Stretch="KeepAspectCentered">
</TextureRect>
</BoxContainer>
</PanelContainer>
</Button>
</BoxContainer>
</Control>
9 changes: 4 additions & 5 deletions Content.Client/ADT/Research/UI/ResearchConsoleItem.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ public sealed partial class ResearchConsoleItem : Control
[Dependency] private readonly IEntityManager _ent = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;

public ProtoId<TechnologyPrototype> Prototype;
public Action<ProtoId<TechnologyPrototype>>? BuyAction;
public ResearchConsoleItem(ProtoId<TechnologyPrototype> proto, SpriteSystem sprite)
public TechnologyPrototype Prototype;
public Action<TechnologyPrototype>? BuyAction;
public ResearchConsoleItem(TechnologyPrototype proto, SpriteSystem sprite)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
Prototype = proto;
Buy.OnPressed += _ => BuyAction?.Invoke(Prototype);
var tech = _proto.Index(proto);
ResearchDisplay.Texture = sprite.Frame0(tech.Icon);
ResearchDisplay.Texture = sprite.Frame0(proto.Icon);
}

}
69 changes: 20 additions & 49 deletions Content.Client/ADT/Research/UI/ResearchConsoleMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls"
xmlns:adt="clr-namespace:Content.Client.ADT.Research.UI"
Title="{Loc 'research-console-menu-title'}"
MinSize="625 400"
SetSize="760 550"> <!-- Corvax-Localization -->
MinSize="1260 850"
SetSize="1260 850"> <!-- Corvax-Localization -->
<BoxContainer Orientation="Vertical"
HorizontalExpand="True"
VerticalExpand="True">
<controls:StripeBack Name="StationNameContainer" MinSize="52 52">
<BoxContainer Name="DisciplinesContainer"
Orientation="Horizontal"
HorizontalAlignment="Stretch"
MinSize="52 52"
Margin="5"/>
<!--Disciplines populated in .cs-->
</controls:StripeBack>
<BoxContainer Orientation="Horizontal"
HorizontalExpand="True"
VerticalExpand="False"
Expand All @@ -30,59 +39,21 @@
<BoxContainer Orientation="Vertical"
VerticalExpand="True"
HorizontalExpand="True"
SizeFlagsStretchRatio="2"
Margin="10 0 10 10"
MinWidth="175">
<Label Text="{Loc 'research-console-available-text'}" HorizontalAlignment="Center"/>
<customControls:HSeparator StyleClasses="LowDivider" Margin="0 0 0 10"/>
<PanelContainer VerticalExpand="True">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#1B1B1E" />
</PanelContainer.PanelOverride>
<ScrollContainer
HScrollEnabled="False"
HorizontalExpand="True"
VerticalExpand="True">
<BoxContainer
Name="AvailableCardsContainer"
Orientation="Vertical"
VerticalExpand="True">
</BoxContainer>
</ScrollContainer>
</PanelContainer>
<Control MinHeight="10"/>
<Label Text="{Loc 'research-console-unlocked-text'}" HorizontalAlignment="Center"/>
<customControls:HSeparator StyleClasses="LowDivider" Margin="0 0 0 10"/>
<PanelContainer VerticalExpand="True">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#1B1B1E" />
</PanelContainer.PanelOverride>
<LayoutContainer
HorizontalExpand="True"
VerticalExpand="True">
<BoxContainer
Name="UnlockedCardsContainer"
Orientation="Vertical"
VerticalExpand="True">
</BoxContainer>
</LayoutContainer>
</PanelContainer>
</BoxContainer>
<BoxContainer Orientation="Vertical"
VerticalExpand="True"
HorizontalExpand="True"
SizeFlagsStretchRatio="3"
SizeFlagsStretchRatio="4"
Margin="0 0 10 10">
<PanelContainer Name="ResearchesContainer" VerticalExpand="True" MinSize="0 200">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#1B1B1E" />
<gfx:StyleBoxFlat BackgroundColor="#000000FF" />
</PanelContainer.PanelOverride>
<LayoutContainer
<adt:DraggablePanel
HorizontalExpand="True"
SizeFlagsStretchRatio="2"
SizeFlagsStretchRatio="1"
VerticalExpand="True"
Name="DragContainer">
</LayoutContainer>
Name="DragContainer"
MouseFilter="Pass"
RectClipContent="True">
</adt:DraggablePanel>
<Button Name="RecenterButton" Text="{Loc 'research-console-menu-recenter-button'}" MinHeight="40" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="5 5"/>
</PanelContainer>
</BoxContainer>
</BoxContainer>
Expand Down
Loading

0 comments on commit eedbaa2

Please sign in to comment.