Skip to content

Commit

Permalink
Fix UI scaling support
Browse files Browse the repository at this point in the history
  • Loading branch information
haroldiedema committed Aug 25, 2024
1 parent 77c7ddb commit b657fcf
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Umbra.Bejeweled/Umbra.Bejeweled.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PropertyGroup>
<Authors>Una</Authors>
<Company>Una XIV</Company>
<Version>1.0.2</Version>
<Version>1.0.3</Version>
<Description>A bejeweled game to kill time while waiting for queues.</Description>
<Copyright>(C)2024</Copyright>
<PackageProjectUrl>https://github.com/una-xiv/Umbra.BejeweledPlugin</PackageProjectUrl>
Expand Down
3 changes: 2 additions & 1 deletion Umbra.Bejeweled/src/Game/Board.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
using System.Numerics;
using FFXIVClientStructs.FFXIV.Client.UI;
using Umbra.Common;
using Una.Drawing;

namespace Umbra.Bejeweled.Game;

internal sealed partial class Board(Viewport viewport, Vec2 size)
{
public const int CellSize = 64;
public int CellSize => (int)Math.Ceiling(64 * Node.ScaleFactor);

public bool Active { get; set; }
public bool EnableSfx { get; set; } = true;
Expand Down
6 changes: 3 additions & 3 deletions Umbra.Bejeweled/src/Game/Entities/Particle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal sealed class Particle(
protected override void OnDraw(float deltaTime)
{
if (_elapsedTime == 0) {
int h = Board.CellSize / 2;
int h = _board.CellSize / 2;
int x = new Random().Next(-h, h);
int y = new Random().Next(-h, h);

Expand All @@ -47,8 +47,8 @@ protected override void OnDraw(float deltaTime)
_uv1 = new(uvOffset, uvOffset);
_uv2 = new(1 - uvOffset, 1 - uvOffset);

_targetPos = _board.Viewport.TopLeft + new Vector2(Board.CellSize, -Board.CellSize);
_position = _board.Viewport.TopLeft + SpritePosition + new Vector2(x + h, y + h);
_targetPos = _board.Viewport.TopLeft + new Vector2(_board.CellSize, -_board.CellSize);
_position = _board.Viewport.TopLeft + SpritePosition + new Vector2(x + h, y + h);

Vector2 accelPos1 = Vector2.Normalize(_targetPos - _position);
Vector2 accelPos2 = new(
Expand Down
6 changes: 3 additions & 3 deletions Umbra.Bejeweled/src/Game/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ internal abstract class Entity(byte entityType, Board board, Vec2 cellPosition)
/// Returns the sprite position of the entity.
/// </summary>
public Vector2 SpritePosition { get; private set; } = new(
Board.CellSize * cellPosition.X,
Board.CellSize * cellPosition.Y
board.CellSize * cellPosition.X,
board.CellSize * cellPosition.Y
);

/// <summary>
Expand Down Expand Up @@ -128,7 +128,7 @@ public void Render(float deltaTime)
protected void DrawIcon(uint iconId, int padding = 4)
{
Rect r = new Rect(Rect.TopLeft, Rect.BottomRight);
r.Shrink(new(padding));
r.Shrink(new((int)(padding * Node.ScaleFactor)));

ImGui
.GetForegroundDrawList()
Expand Down
4 changes: 2 additions & 2 deletions Umbra.Bejeweled/src/Popup/BejeweledPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ protected override unsafe void OnUpdate()
}

float deltaTime = Framework.Instance()->FrameDeltaTime;
Vector2 topLeft = Node.QuerySelector("#Cell-0-0")!.Bounds.MarginRect.TopLeft;
Vector2 bottomRight = Node.QuerySelector("#Cell-9-7")!.Bounds.MarginRect.BottomRight;
Vector2 topLeft = Node.QuerySelector("#Cell-0-0")!.Bounds.ContentRect.TopLeft;
Vector2 bottomRight = Node.QuerySelector("#Cell-9-7")!.Bounds.ContentRect.BottomRight;

for (var y = 0; y < 8; y++) {
for (var x = 0; x < 10; x++) {
Expand Down

0 comments on commit b657fcf

Please sign in to comment.