Make content UI scaling aware.

This commit is contained in:
Pieter-Jan Briers
2019-05-11 16:05:41 +02:00
parent fa8fbc49f5
commit 57bcb2a16d
4 changed files with 19 additions and 13 deletions

View File

@@ -1,6 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using Content.Shared.Chat; using Content.Shared.Chat;
using Robust.Client.Console;
using Robust.Client.Graphics.Drawing; using Robust.Client.Graphics.Drawing;
using Robust.Client.Input; using Robust.Client.Input;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;

View File

@@ -36,8 +36,8 @@ namespace Content.Client.UserInterface
private IEntity LeftHand; private IEntity LeftHand;
private IEntity RightHand; private IEntity RightHand;
private UIBox2i handL; private UIBox2i _handL;
private UIBox2i handR; private UIBox2i _handR;
private SpriteView LeftSpriteView; private SpriteView LeftSpriteView;
private SpriteView RightSpriteView; private SpriteView RightSpriteView;
@@ -60,24 +60,24 @@ namespace Content.Client.UserInterface
SetMarginsPreset(LayoutPreset.CenterBottom); SetMarginsPreset(LayoutPreset.CenterBottom);
SetAnchorPreset(LayoutPreset.CenterBottom); SetAnchorPreset(LayoutPreset.CenterBottom);
handL = new UIBox2i(0, 0, BOX_SIZE, BOX_SIZE); _handL = new UIBox2i(0, 0, BOX_SIZE, BOX_SIZE);
handR = handL.Translated(new Vector2i(BOX_SIZE + BOX_SPACING, 0)); _handR = _handL.Translated(new Vector2i(BOX_SIZE + BOX_SPACING, 0));
MouseFilter = MouseFilterMode.Stop; MouseFilter = MouseFilterMode.Stop;
LeftSpriteView = new SpriteView {MouseFilter = MouseFilterMode.Ignore}; LeftSpriteView = new SpriteView {MouseFilter = MouseFilterMode.Ignore};
AddChild(LeftSpriteView); AddChild(LeftSpriteView);
LeftSpriteView.Size = handL.Size; LeftSpriteView.Size = _handL.Size;
LeftSpriteView.Position = handL.TopLeft; LeftSpriteView.Position = _handL.TopLeft;
RightSpriteView = new SpriteView {MouseFilter = MouseFilterMode.Ignore}; RightSpriteView = new SpriteView {MouseFilter = MouseFilterMode.Ignore};
AddChild(RightSpriteView); AddChild(RightSpriteView);
RightSpriteView.Size = handR.Size; RightSpriteView.Size = _handR.Size;
RightSpriteView.Position = handR.TopLeft; RightSpriteView.Position = _handR.TopLeft;
} }
protected override Vector2 CalculateMinimumSize() protected override Vector2 CalculateMinimumSize()
{ {
return new Vector2(BOX_SIZE * 2 + 1, BOX_SIZE); return new Vector2(BOX_SIZE * 2 + 1, BOX_SIZE) * UIScale;
} }
protected override void Draw(DrawingHandleScreen handle) protected override void Draw(DrawingHandleScreen handle)
@@ -87,6 +87,9 @@ namespace Content.Client.UserInterface
var leftActive = hands.ActiveIndex == "left"; var leftActive = hands.ActiveIndex == "left";
var handL = new UIBox2(_handL.TopLeft * UIScale, _handL.BottomRight * UIScale);
var handR = new UIBox2(_handR.TopLeft * UIScale, _handR.BottomRight * UIScale);
handle.DrawStyleBox(handBox, leftActive ? handL : handR); handle.DrawStyleBox(handBox, leftActive ? handL : handR);
handle.DrawStyleBox(inactiveHandBox, leftActive ? handR : handL); handle.DrawStyleBox(inactiveHandBox, leftActive ? handR : handL);
} }
@@ -187,15 +190,15 @@ namespace Content.Client.UserInterface
protected override bool HasPoint(Vector2 point) protected override bool HasPoint(Vector2 point)
{ {
return handL.Contains((Vector2i) point) || handR.Contains((Vector2i) point); return _handL.Contains((Vector2i) point) || _handR.Contains((Vector2i) point);
} }
protected override void MouseDown(GUIMouseButtonEventArgs args) protected override void MouseDown(GUIMouseButtonEventArgs args)
{ {
base.MouseDown(args); base.MouseDown(args);
var leftHandContains = handL.Contains((Vector2i) args.RelativePosition); var leftHandContains = _handL.Contains((Vector2i) args.RelativePosition);
var rightHandContains = handR.Contains((Vector2i) args.RelativePosition); var rightHandContains = _handR.Contains((Vector2i) args.RelativePosition);
string handIndex; string handIndex;
if (leftHandContains) if (leftHandContains)

View File

@@ -0,0 +1,2 @@
sample:
filter: true

View File

@@ -0,0 +1,2 @@
sample:
filter: true