Fix character UI being broken.

Also transition everything away from tscn files.
This commit is contained in:
Pieter-Jan Briers
2019-05-05 23:14:40 +02:00
parent e35d5390db
commit 1fa63179d1
8 changed files with 46 additions and 251 deletions

View File

@@ -9,6 +9,7 @@ using Robust.Shared.Utility;
using System.Collections.Generic;
using System.Linq;
using Robust.Client.Interfaces.Graphics;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.GameObjects.Components.Actor
{
@@ -41,9 +42,7 @@ namespace Content.Client.GameObjects.Components.Actor
var UIcomponents = Owner.GetAllComponents<ICharacterUI>();
_window = new CharacterWindow(UIcomponents);
//Add to screen the window and hide it
_window.AddToScreen();
_window.Close();
//Toggle window visible/invisible on keypress
_openMenuCmdHandler = InputCmdHandler.FromDelegate(session => {
@@ -81,17 +80,24 @@ namespace Content.Client.GameObjects.Components.Actor
/// </summary>
public class CharacterWindow : SS14Window
{
protected override ResourcePath ScenePath => new ResourcePath("/Scenes/Mobs/CharacterWindow.tscn");
private readonly VBoxContainer _contentsVBox;
public CharacterWindow(IEnumerable<ICharacterUI> windowcomponents) : base(IoCManager.Resolve<IDisplayManager>())
public CharacterWindow(IEnumerable<ICharacterUI> windowComponents) : base(IoCManager.Resolve<IDisplayManager>())
{
//TODO: sort window components by priority of window component
foreach(var element in windowcomponents.OrderByDescending(x => x.Priority))
Title = "Character";
HideOnClose = true;
Visible = false;
_contentsVBox = new VBoxContainer();
Contents.AddChild(_contentsVBox);
// TODO: sort window components by priority of window component
foreach (var element in windowComponents.OrderBy(x => x.Priority))
{
Contents.AddChild(element.Scene);
_contentsVBox.AddChild(element.Scene);
}
HideOnClose = true;
Size = CombinedMinimumSize;
}
}
}

View File

@@ -171,16 +171,11 @@ namespace Content.Client.GameObjects
/// <summary>
/// Temporary window to hold the basis for inventory hud
/// </summary>
private class InventoryWindow : PanelContainer
private class InventoryWindow : GridContainer
{
private int elements_x;
private GridContainer GridContainer;
private List<Slots> IndexedSlots;
private Dictionary<Slots, InventoryButton> InventorySlots = new Dictionary<Slots, InventoryButton>(); //ordered dictionary?
private ClientInventoryComponent InventoryComponent;
protected override ResourcePath ScenePath => new ResourcePath("/Scenes/Mobs/HumanInventory.tscn");
private readonly ClientInventoryComponent InventoryComponent;
public InventoryWindow(ClientInventoryComponent inventory)
{
@@ -192,15 +187,13 @@ namespace Content.Client.GameObjects
/// </summary>
public void CreateInventory(Inventory inventory)
{
elements_x = inventory.Columns;
Columns = inventory.Columns;
GridContainer = (GridContainer)GetChild("CenterContainer").GetChild("GridContainer");
GridContainer.Columns = elements_x;
IndexedSlots = new List<Slots>(inventory.SlotMasks);
foreach (Slots slot in IndexedSlots)
foreach (var slot in IndexedSlots)
{
InventoryButton newbutton = new InventoryButton(slot);
var newButton = new InventoryButton(slot);
if (slot == Slots.NONE)
{
@@ -209,18 +202,18 @@ namespace Content.Client.GameObjects
}
else
{
//Store slot button and give it the default onpress behavior for empty elements
newbutton.GetChild<Button>("Button").OnPressed += AddToInventory;
InventorySlots.Add(slot, newbutton);
// Store slot button and give it the default onpress behavior for empty elements
newButton.GetChild<Button>("Button").OnPressed += AddToInventory;
InventorySlots.Add(slot, newButton);
}
if (SlotNames.ContainsKey(slot))
{
var button = newbutton.GetChild<Button>("Button");
var button = newButton.GetChild<Button>("Button");
button.Text = button.ToolTip = SlotNames[slot];
}
GridContainer.AddChild(newbutton);
AddChild(newButton);
}
}
@@ -240,22 +233,8 @@ namespace Content.Client.GameObjects
//Gets entity sprite and assigns it to button texture
if (entity.TryGetComponent(out ISpriteComponent sprite))
{
//var tex = sprite.Icon.Default;
var view = button.GetChild<SpriteView>("SpriteView");
view.Sprite = sprite;
/*
if (tex != null)
{
rect.Texture = tex;
rect.Scale = new Vector2(Math.Min(CalculateMinimumSize().X, 32) / tex.Height, Math.Min(CalculateMinimumSize().Y, 32) / tex.Height);
}
else
{
throw new NotImplementedException();
}
*/
}
}
@@ -290,16 +269,25 @@ namespace Content.Client.GameObjects
}
}
private class InventoryButton : PanelContainer
private sealed class InventoryButton : MarginContainer
{
public Slots Slot;
public EntityUid EntityUid;
protected override ResourcePath ScenePath => new ResourcePath("/Scenes/Mobs/StorageSlot.tscn");
public Slots Slot { get; }
public EntityUid EntityUid { get; set; }
public InventoryButton(Slots slot)
{
Slot = slot;
CustomMinimumSize = (50, 50);
AddChild(new Button("Button")
{
ClipText = true
});
AddChild(new SpriteView("SpriteView")
{
MouseFilter = MouseFilterMode.Ignore
});
}
}
}

View File

@@ -137,28 +137,23 @@ namespace Content.Client.GameObjects
}
}
private class SpeciesWindow : Control
private class SpeciesWindow : TextureRect
{
private TextureRect _textureRect;
protected override ResourcePath ScenePath => new ResourcePath("/Scenes/Mobs/Species.tscn");
protected override void Initialize()
public SpeciesWindow()
{
base.Initialize();
_textureRect = (TextureRect)GetChild("TextureRect");
SizeFlagsHorizontal = SizeFlags.ShrinkCenter;
SizeFlagsVertical = SizeFlags.None;
}
public void SetIcon(HudStateChange changemessage)
public void SetIcon(HudStateChange changeMessage)
{
if (!IoCManager.Resolve<IResourceCache>().TryGetResource<TextureResource>(new ResourcePath("/Textures") / changemessage.StateSprite, out var newtexture))
if (!IoCManager.Resolve<IResourceCache>().TryGetResource<TextureResource>(new ResourcePath("/Textures") / changeMessage.StateSprite, out var newtexture))
{
Logger.Info("The Species Health Sprite {0} Does Not Exist", new ResourcePath("/Textures") / changemessage.StateSprite);
Logger.Info("The Species Health Sprite {0} Does Not Exist", new ResourcePath("/Textures") / changeMessage.StateSprite);
return;
}
_textureRect.Texture = newtexture;
Texture = newtexture;
}
}
}

View File

@@ -1,13 +0,0 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Engine/Scenes/SS14Window/SS14Window.tscn" type="PackedScene" id=1]
[node name="SS14Window" index="0" instance=ExtResource( 1 )]
margin_left = 0.0
margin_top = 0.0
margin_right = 240.0
margin_bottom = 522.0
[node name="Header Text" parent="Header" index="0"]
text = "Character Info"

View File

@@ -1,56 +0,0 @@
[gd_scene format=2]
[node name="PanelContainer" type="PanelContainer"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 0.0
margin_bottom = 400.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 3
_sections_unfolded = [ "Anchor", "Grow Direction", "Margin", "Mouse", "Rect", "Size Flags", "Theme" ]
[node name="CenterContainer" type="CenterContainer" parent="." index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 7.0
margin_top = 7.0
margin_right = 1017.0
margin_bottom = 393.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
use_top_left = false
_sections_unfolded = [ "Anchor", "Focus", "Grow Direction", "Hint", "Margin", "Mouse", "Rect", "Size Flags", "Theme" ]
[node name="GridContainer" type="GridContainer" parent="CenterContainer" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 505.0
margin_top = 193.0
margin_right = 505.0
margin_bottom = 193.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
columns = 3
_sections_unfolded = [ "Anchor", "Focus", "Grow Direction", "Hint", "Margin", "Material", "Mouse", "Rect", "Size Flags", "Theme", "custom_constants" ]

View File

@@ -1,34 +0,0 @@
[gd_scene format=2]
[node name="Control" type="Control" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 0.0
margin_bottom = 64.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
_sections_unfolded = [ "Anchor", "Grow Direction", "Margin", "Rect" ]
[node name="TextureRect" type="TextureRect" parent="." 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 = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
expand = true
stretch_mode = 6
_sections_unfolded = [ "Anchor", "Grow Direction", "Margin" ]

View File

@@ -1,31 +0,0 @@
[gd_resource type="StyleBoxFlat" format=2]
[resource]
content_margin_left = -1.0
content_margin_right = -1.0
content_margin_top = -1.0
content_margin_bottom = -1.0
bg_color = Color( 0.746094, 0.0320587, 0.0320587, 0.519333 )
draw_center = true
border_width_left = 1
border_width_top = 1
border_width_right = 1
border_width_bottom = 1
border_color = Color( 0.8, 0.8, 0.8, 1 )
border_blend = false
corner_radius_top_left = 2
corner_radius_top_right = 2
corner_radius_bottom_right = 2
corner_radius_bottom_left = 2
corner_detail = 8
expand_margin_left = 0.0
expand_margin_right = 0.0
expand_margin_top = 0.0
expand_margin_bottom = 0.0
shadow_color = Color( 0, 0, 0, 0.6 )
shadow_size = 0
anti_aliasing = false
anti_aliasing_size = 1
_sections_unfolded = [ "Anti Aliasing", "Border", "Border Width", "Corner Radius", "Expand Margin", "Shadow" ]

View File

@@ -1,60 +0,0 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://Content/Scenes/Mobs/StorageSlot.tres" type="StyleBox" id=1]
[ext_resource path="res://Engine/Scenes/SpriteMirror/SpriteView.tscn" type="PackedScene" id=2]
[node name="PanelContainer" type="PanelContainer"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = -974.0
margin_bottom = -550.0
rect_min_size = Vector2( 50, 50 )
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = true
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
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="."]
anchor_left = 0.0
anchor_top = 0.0
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
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
toggle_mode = false
action_mode = 0
enabled_focus_mode = 2
shortcut = null
group = null
text = "Slot"
flat = true
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="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
mouse_filter = 2
_sections_unfolded = [ "Mouse" ]