Use Sprite proxies for GUIs. (#93)

AKA "welders actually light up in the hands GUI".
This commit is contained in:
Pieter-Jan Briers
2018-08-16 22:43:04 +02:00
committed by GitHub
parent fe1252cca7
commit 189a52c6d7
7 changed files with 56 additions and 107 deletions

View File

@@ -1,6 +1,7 @@
using Content.Shared.GameObjects;
using Content.Shared.Input;
using SS14.Client.GameObjects;
using SS14.Client.Interfaces.GameObjects.Components;
using SS14.Client.Interfaces.Input;
using SS14.Client.UserInterface;
using SS14.Client.UserInterface.Controls;
@@ -162,12 +163,14 @@ namespace Content.Client.GameObjects
button.GetChild<Button>("Button").OnPressed -= AddToInventory;
//Gets entity sprite and assigns it to button texture
if (entity.TryGetComponent(out IconComponent sprite))
if (entity.TryGetComponent(out ISpriteComponent sprite))
{
var tex = sprite.Icon.Default;
//var tex = sprite.Icon.Default;
var rect = button.GetChild("CenterContainer").GetChild<TextureRect>("TextureRect");
var view = button.GetChild<SpriteView>("SpriteView");
view.Sprite = sprite;
/*
if (tex != null)
{
rect.Texture = tex;
@@ -177,6 +180,7 @@ namespace Content.Client.GameObjects
{
throw new NotImplementedException();
}
*/
}
}
@@ -187,7 +191,7 @@ namespace Content.Client.GameObjects
public void RemoveFromSlot(ServerInventoryMessage message)
{
InventoryButton button = InventorySlots[message.Inventoryslot];
button.GetChild("CenterContainer").GetChild<TextureRect>("TextureRect").Texture = null;
button.GetChild<SpriteView>("SpriteView").Sprite = null;
button.EntityUid = EntityUid.Invalid;
button.GetChild<Button>("Button").OnPressed -= RemoveFromInventory;
button.GetChild<Button>("Button").OnPressed += AddToInventory;

View File

@@ -1,6 +1,7 @@
using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Storage;
using SS14.Client.GameObjects;
using SS14.Client.Interfaces.GameObjects.Components;
using SS14.Client.UserInterface;
using SS14.Client.UserInterface.Controls;
using SS14.Client.UserInterface.CustomControls;
@@ -136,22 +137,10 @@ namespace Content.Client.GameObjects.Components.Storage
container.GetChild<Control>("Control").GetChild<Label>("Size").Text = string.Format("{0}", entityuid.Value);
//Gets entity sprite and assigns it to button texture
if (entity.TryGetComponent(out IconComponent icon))
if (entity.TryGetComponent(out ISpriteComponent sprite))
{
var tex = icon.Icon.Default;
var rect = container.GetChild("TextureWrap").GetChild<TextureRect>("TextureRect");
if (tex != null)
{
rect.Texture = tex;
// Copypasted but replaced with 32 dunno if good
var scale = (float)32 / tex.Height;
rect.Scale = new Vector2(scale, scale);
}
else
{
rect.Dispose();
}
var view = container.GetChild<SpriteView>("SpriteView");
view.Sprite = sprite;
}
EntityList.AddChild(button);

View File

@@ -4,6 +4,7 @@ using SS14.Client.GameObjects;
using SS14.Client.Graphics;
using SS14.Client.Graphics.Drawing;
using SS14.Client.Input;
using SS14.Client.Interfaces.GameObjects.Components;
using SS14.Client.Interfaces.Player;
using SS14.Client.Interfaces.ResourceManagement;
using SS14.Client.Interfaces.UserInterface;
@@ -73,6 +74,7 @@ namespace Content.Client.UserInterface
handle.DrawStyleBox(handBox, leftActive ? handL : handR);
handle.DrawStyleBox(inactiveHandBox, leftActive ? handR : handL);
/*
if (LeftHand.Entity != null && LeftHand.HeldSprite != null)
{
var bounds = LeftHand.HeldSprite.Size;
@@ -90,6 +92,7 @@ namespace Content.Client.UserInterface
handR.Top + (int)(handR.Height / 2f - bounds.Y / 2f),
(int)bounds.X, (int)bounds.Y), tile: false);
}
*/
}
/// <summary>
@@ -124,18 +127,26 @@ namespace Content.Client.UserInterface
var left = hands.GetEntity("left");
var right = hands.GetEntity("right");
// I'm naively gonna assume all items are 32x32.
//const float HalfSize = 16;
if (left != null)
{
if (left != LeftHand.Entity)
{
LeftHand.Entity = left;
LeftHand.HeldSprite = GetIconSprite(left);
LeftHand.MirrorHandle?.Dispose();
LeftHand.MirrorHandle = GetSpriteMirror(left);
LeftHand.MirrorHandle.AttachToControl(this);
LeftHand.MirrorHandle.Offset = new Vector2(handL.Left + (int)(handL.Width / 2f),
handL.Top + (int)(handL.Height / 2f));
}
}
else
{
LeftHand.Entity = null;
LeftHand.HeldSprite = null;
LeftHand.MirrorHandle?.Dispose();
LeftHand.MirrorHandle = null;
}
if (right != null)
@@ -143,13 +154,18 @@ namespace Content.Client.UserInterface
if (right != RightHand.Entity)
{
RightHand.Entity = right;
RightHand.HeldSprite = GetIconSprite(right);
RightHand.MirrorHandle?.Dispose();
RightHand.MirrorHandle = GetSpriteMirror(right);
RightHand.MirrorHandle.AttachToControl(this);
RightHand.MirrorHandle.Offset = new Vector2(handR.Left + (int)(handR.Width / 2f),
handR.Top + (int)(handR.Height / 2f));
}
}
else
{
RightHand.Entity = null;
RightHand.HeldSprite = null;
RightHand.MirrorHandle?.Dispose();
RightHand.MirrorHandle = null;
}
}
@@ -204,19 +220,19 @@ namespace Content.Client.UserInterface
}
}
private static Texture GetIconSprite(IEntity entity)
private static ISpriteProxy GetSpriteMirror(IEntity entity)
{
if (entity.TryGetComponent<IconComponent>(out var component) && component.Icon != null)
if (entity.TryGetComponent(out ISpriteComponent component))
{
return component.Icon.Default;
return component.CreateProxy();
}
return IoCManager.Resolve<IResourceCache>().GetFallback<TextureResource>();
return null;
}
private struct UiHandInfo
{
public IEntity Entity { get; set; }
public Texture HeldSprite { get; set; }
public ISpriteProxy MirrorHandle { get; set; }
}
}
}

View File

@@ -12,7 +12,6 @@ namespace Content.Server.GameObjects
{
public override string Name => "Clothing";
public SlotFlags SlotFlags = SlotFlags.PREVENTEQUIP; //Different from None, NONE allows equips if no slot flags are required
private List<string> slotstrings = new List<string>(); //serialization
public override void ExposeData(ObjectSerializer serializer)
{
@@ -21,7 +20,7 @@ namespace Content.Server.GameObjects
// TODO: Writing.
serializer.DataReadFunction("Slots", new List<string>(0), list =>
{
foreach (var slotflagsloaded in slotstrings)
foreach (var slotflagsloaded in list)
{
SlotFlags |= (SlotFlags)Enum.Parse(typeof(SlotFlags), slotflagsloaded.ToUpper());
}

View File

@@ -1,9 +1,9 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=3 format=2]
[ext_resource path="res://Scenes/Inventory/StorageSlot.tres" type="StyleBox" id=1]
[ext_resource path="res://Scenes/SpriteMirror/SpriteView.tscn" type="PackedScene" id=2]
[node name="PanelContainer" type="PanelContainer" index="0"]
[node name="PanelContainer" type="PanelContainer"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
@@ -20,8 +20,7 @@ size_flags_vertical = 1
custom_styles/panel = ExtResource( 1 )
_sections_unfolded = [ "Anchor", "Focus", "Grow Direction", "Hint", "Material", "Mouse", "Rect", "Visibility", "custom_styles" ]
[node name="Button" type="Button" parent="." index="0"]
[node name="Button" type="Button" parent="."]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
@@ -48,42 +47,13 @@ clip_text = true
align = 1
_sections_unfolded = [ "Anchor", "Focus", "Grow Direction", "Hint", "Margin", "Mouse", "Rect", "Size Flags", "Theme", "custom_colors", "custom_constants", "custom_fonts", "custom_styles" ]
[node name="CenterContainer" type="CenterContainer" parent="." index="1"]
anchor_left = 0.0
anchor_top = 0.0
[node name="SpriteView" parent="." instance=ExtResource( 2 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 1.0
margin_top = 1.0
margin_right = 49.0
margin_bottom = 49.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
use_top_left = false
_sections_unfolded = [ "Mouse" ]
[node name="TextureRect" type="TextureRect" parent="CenterContainer" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 24.0
margin_top = 24.0
margin_right = 24.0
margin_bottom = 24.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
stretch_mode = 0
_sections_unfolded = [ "Mouse" ]

View File

@@ -1,4 +1,6 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=3 format=2]
[ext_resource path="res://Scenes/SpriteMirror/SpriteView.tscn" type="PackedScene" id=1]
[sub_resource type="StyleBoxEmpty" id=1]
@@ -7,8 +9,7 @@ content_margin_right = -1.0
content_margin_top = -1.0
content_margin_bottom = -1.0
[node name="StorageEntity" type="PanelContainer" index="0"]
[node name="StorageEntity" type="PanelContainer"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
@@ -20,10 +21,9 @@ mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 3
custom_styles/panel = SubResource( 1 )
_sections_unfolded = [ "Focus", "Hint", "Material", "Mouse", "Size Flags", "Theme", "Visibility", "custom_styles" ]
[node name="Button" type="Button" parent="." index="0"]
_sections_unfolded = [ "Focus", "Hint", "Material", "Mouse", "Rect", "Size Flags", "Theme", "Visibility", "custom_styles" ]
[node name="Button" type="Button" parent="."]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
@@ -45,8 +45,7 @@ flat = false
align = 1
_sections_unfolded = [ "Grow Direction", "Size Flags" ]
[node name="HBoxContainer" type="HBoxContainer" parent="." index="1"]
[node name="HBoxContainer" type="HBoxContainer" parent="."]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
@@ -62,40 +61,15 @@ size_flags_vertical = 1
alignment = 0
_sections_unfolded = [ "Anchor", "Grow Direction", "Hint", "Margin", "Mouse", "Rect", "Size Flags", "Theme", "custom_constants" ]
[node name="TextureWrap" type="Control" parent="HBoxContainer" index="0"]
anchor_left = 0.0
anchor_top = 0.0
[node name="SpriteView" parent="HBoxContainer" instance=ExtResource( 1 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 32.0
margin_bottom = 600.0
rect_min_size = Vector2( 32, 32 )
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
_sections_unfolded = [ "Mouse", "Rect" ]
[node name="TextureRect" type="TextureRect" parent="HBoxContainer/TextureWrap" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 1.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = true
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 4
size_flags_vertical = 4
stretch_mode = 0
_sections_unfolded = [ "Focus", "Grow Direction", "Hint", "Margin", "Mouse", "Rect", "Size Flags", "Theme" ]
[node name="Name" type="Label" parent="HBoxContainer" index="1"]
_sections_unfolded = [ "Rect" ]
[node name="Name" type="Label" parent="HBoxContainer"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
@@ -116,8 +90,7 @@ lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Anchor" ]
[node name="Control" type="Control" parent="HBoxContainer" index="2"]
[node name="Control" type="Control" parent="HBoxContainer"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
@@ -133,8 +106,7 @@ size_flags_horizontal = 3
size_flags_vertical = 1
_sections_unfolded = [ "Mouse", "Size Flags" ]
[node name="Size" type="Label" parent="HBoxContainer/Control" index="0"]
[node name="Size" type="Label" parent="HBoxContainer/Control"]
anchor_left = 1.0
anchor_top = 0.5
anchor_right = 1.0
@@ -157,4 +129,3 @@ lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Margin", "Mouse" ]

2
engine

Submodule engine updated: be10df217e...900e2c94e8