Skip to content

Commit

Permalink
Inventory window- add padding configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
tzachshabtay committed Jan 23, 2019
1 parent 7afdf14 commit 84c388d
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,36 @@ public interface IInventoryWindowComponent : IComponent
/// <value>The top item.</value>
int TopItem { get; set; }

/// <summary>
/// Optional padding from the left side of the inventory window containing panel.
/// </summary>
/// <value>The left padding.</value>
float PaddingLeft { get; set; }

/// <summary>
/// Optional padding from the right side of the inventory window containing panel.
/// </summary>
/// <value>The right padding.</value>
float PaddingRight { get; set; }

/// <summary>
/// Optional padding from the bottom side of the inventory window containing panel.
/// </summary>
/// <value>The bottom padding.</value>
float PaddingBottom { get; set; }

/// <summary>
/// Optional padding from the top side of the inventory window containing panel.
/// </summary>
/// <value>The top padding.</value>
float PaddingTop { get; set; }

/// <summary>
/// Optional padding to apply between the inventory items.
/// </summary>
/// <value>The padding between the inventory items.</value>
SizeF PaddingBetweenItems { get; set; }

/// <summary>
/// Scrolls the inventory window up one row if possible (<see cref="TopItem"/> will change accordingly).
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,36 @@ public Int32 RowCount
get { return _inventoryWindowComponent.RowCount; }
}

public float PaddingLeft
{
get { return _inventoryWindowComponent.PaddingLeft; }
set { _inventoryWindowComponent.PaddingLeft = value; }
}

public float PaddingRight
{
get { return _inventoryWindowComponent.PaddingRight; }
set { _inventoryWindowComponent.PaddingRight = value; }
}

public float PaddingTop
{
get { return _inventoryWindowComponent.PaddingTop; }
set { _inventoryWindowComponent.PaddingTop = value; }
}

public float PaddingBottom
{
get { return _inventoryWindowComponent.PaddingBottom; }
set { _inventoryWindowComponent.PaddingBottom = value; }
}

public SizeF PaddingBetweenItems
{
get { return _inventoryWindowComponent.PaddingBetweenItems; }
set { _inventoryWindowComponent.PaddingBetweenItems = value; }
}

public void ScrollUp()
{
_inventoryWindowComponent.ScrollUp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ public class AGSInventoryWindowComponent : AGSComponent, IInventoryWindowCompone
{
private IList<IObject> _inventoryItems;
private volatile bool _refreshNeeded;
private SizeF _itemSize;
private SizeF _itemSize, _paddingBetweenItems;
private IInventory _inventory;
private int _topItem;
private IGameState _state;
private IGameEvents _gameEvents;
private IScale _scale;
private IInObjectTreeComponent _tree;
private float _paddingLeft, _paddingRight, _paddingTop, _paddingBottom;

public AGSInventoryWindowComponent(IGameState state, IGameEvents gameEvents)
{
Expand Down Expand Up @@ -80,9 +81,59 @@ public int TopItem
}
}

public int ItemsPerRow => (int)(_scale.Width / ItemSize.Width);
public int ItemsPerRow => (int)((_scale.Width - _paddingLeft - _paddingRight) / (_itemSize.Width + _paddingBetweenItems.Width));

public int RowCount => (int)(_scale.Height / ItemSize.Height);
public int RowCount => (int)((_scale.Height - _paddingTop - _paddingBottom) / (_itemSize.Height + _paddingBetweenItems.Height));

public float PaddingLeft
{
get => _paddingLeft;
set
{
_paddingLeft = value;
_refreshNeeded = true;
}
}

public float PaddingRight
{
get => _paddingRight;
set
{
_paddingRight = value;
_refreshNeeded = true;
}
}

public float PaddingTop
{
get => _paddingTop;
set
{
_paddingTop = value;
_refreshNeeded = true;
}
}

public float PaddingBottom
{
get => _paddingBottom;
set
{
_paddingBottom = value;
_refreshNeeded = true;
}
}

public SizeF PaddingBetweenItems
{
get => _paddingBetweenItems;
set
{
_paddingBetweenItems = value;
_refreshNeeded = true;
}
}

#endregion

Expand All @@ -108,10 +159,12 @@ private void onRepeatedlyExecute()

int topItem = TopItem;
int count = Math.Min(topItem + RowCount * ItemsPerRow, items.Count);
float stepX = ItemSize.Width;
float stepY = ItemSize.Height;
float x = stepX/2f;
float y = _scale.Height - stepY/2;
float stepX = _itemSize.Width + _paddingBetweenItems.Width;
float stepY = _itemSize.Height + _paddingBetweenItems.Height;
float left = _itemSize.Width/2f + _paddingLeft;
float right = _scale.Width - _paddingRight - _itemSize.Width / 2f;
float x = left;
float y = _scale.Height - _itemSize.Height / 2 - _paddingTop;
for (int item = topItem; item < count; item++)
{
IObject obj = items[item];
Expand All @@ -126,9 +179,9 @@ private void onRepeatedlyExecute()
obj.Visible = true;

x += stepX;
if (x + stepX/2f >= _scale.Width)
if (x >= right)
{
x = stepX/2f;
x = left;
y -= stepY;
}
}
Expand Down

0 comments on commit 84c388d

Please sign in to comment.