-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cleanup shop window/item #2623
cleanup shop window/item #2623
Conversation
564360a
to
13d8cff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updated shop window should not use the shop.png
background image anymore and should be able to regenerate its own JSON from scratch, and the assets PR should just be uploading a freshly regenerated JSON (and one that doesn't change after being generated and the client reopened).
If you need examples to look at:
- MainMenuWindow
- CreditsWindow
- DebugWindow
- SettingsWindow
- LoginWindow
- RegistrationWindow
- CharacterSelectionWindow
- HotbarWindow (though this isn't a real window)
- EventWindow (also not a real window)
- InputBox / AlertWindow
I believe I have done everything I said, it is like this now 1740543182_Intersect_Client.mp4 |
|
||
public ImagePanel Container; | ||
MinimumSize = new Point(34, 35); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't right, shop items should be square (34, 34)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JSON will need regeneration after fixing this
|
||
private bool mIsEquipped; | ||
// Generate our context menu with basic options. | ||
_contextMenu = new ContextMenu(Interface.CurrentInterface.Root, "ShopContextMenu") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a // TODO: Refactor so shop only has 1 context menu shared between all items
here
|
||
//Drag/Drop References | ||
private ShopWindow mShopWindow; | ||
if (Globals.GameShop == default || Globals.GameShop.SellingItems.Count == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (Globals.GameShop is not { SellingItems.Count: >0 } gameShop)
|
||
public ImagePanel Pnl; | ||
if (!ItemBase.TryGet(Globals.GameShop.SellingItems[_mySlot].CostItemId, out var item)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Globals.GameShop
-> gameShop
mShopWindow = shopWindow; | ||
mMySlot = index; | ||
} | ||
if (Globals.GameShop.SellingItems[_mySlot].Item != default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Globals.GameShop
-> gameShop
var xPosition = column * itemWidthWithPadding + xPadding; | ||
var yPosition = row * itemHeightWithPadding + yPadding; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xPadding
-> slotContainer.Margin.Left
yPadding
-> slotContainer.Margin.Top
item*WithPadding should be replaced with the outerSize stuff already mentioned
// Generate our context menu with basic options. | ||
_contextMenu = new ContextMenu(Interface.CurrentInterface.Root, "ShopContextMenu") | ||
{ | ||
IsHidden = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add ItemFontSize = 10,
and ItemFont = GameContentManager.Current.GetFont(name: "sourcesansproblack"),
var font = GameContentManager.Current.GetFont(name: "sourcesansproblack"); | ||
if (font != default) | ||
{ | ||
_contextMenu.SetItemFont(font, 10); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this entirely
public void SetItemFont(IFont font, int fontSize) | ||
{ | ||
mItemFont = font; | ||
_itemFontSize = fontSize; | ||
mItemFontInfo = $"{font.Name},{fontSize}"; | ||
UpdateItemStyles(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, rename mItemFont
to _itemFont
, delete mItemFontInfo
, add private string? _itemFontName;
Add:
public string? ItemFontName
{
get => _itemFontName;
set => SetItemFont(GameContentManager.Current.GetFont(_itemFontName), _itemFontName);
}
public IFont? ItemFont
{
get => _itemFont;
set => SetItemFont(value, value?.Name);
}
private void SetItemFont(IFont? itemFont, string? itemFontName)
{
var oldValue = _itemFont;
_itemFont = itemFont;
_itemFontName = itemFontName;
if (itemFont != oldValue)
{
OnFontChanged(this, itemFont, oldValue);
}
}
protected virtual void OnFontChanged(Base sender, IFont? newFont, IFont? oldFont)
{
UpdateItemStyles();
}
public int ItemFontSize
{
get => _itemFontSize;
set
{
if (value == _itemFontSize)
{
return;
}
var oldValue = _itemFontSize;
_itemFontSize = value;
OnFontSizeChanged(this, value, oldValue);
}
}
protected virtual void OnFontSizeChanged(Base sender, int newSize, int oldSize)
{
UpdateItemStyles();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For loading JSON
replace the start with
public override void LoadJson(JToken token, bool isRoot = default)
{
base.LoadJson(token, isRoot);
if (token is not JObject obj)
{
return;
}
and replace the "ItemFont"
section with
string? itemFontName = null;
int? itemFontSize = null;
if (obj.TryGetValue(nameof(ItemFont), out var tokenItemFont) &&
tokenItemFont is JValue { Type: JTokenType.String } valueItemFont)
{
var stringItemFont = valueItemFont.Value<string>()?.Trim();
if (!string.IsNullOrWhiteSpace(stringItemFont))
{
var parts = stringItemFont.Split(',');
itemFontName = parts.FirstOrDefault();
if (parts.Length > 1 && int.TryParse(parts[1], out var size))
{
itemFontSize = size;
}
}
}
if (obj.TryGetValue(nameof(ItemFontName), out var tokenItemFontName) &&
tokenItemFontName is JValue { Type: JTokenType.String } valueItemFontName)
{
itemFontName = valueItemFontName.Value<string>();
}
if (obj.TryGetValue(nameof(ItemFontSize), out var tokenItemFontSize) &&
tokenItemFontSize is JValue { Type: JTokenType.Integer } valueItemFontSize)
{
itemFontSize = valueItemFontSize.Value<int>();
}
if (itemFontSize.HasValue)
{
ItemFontSize = itemFontSize.Value;
}
itemFontName = itemFontName?.Trim();
if (!string.IsNullOrWhiteSpace(itemFontName))
{
ItemFontName = itemFontName;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For saving JSON remove the "ItemFont" line and use
serializedProperties.Add(nameof(ItemFontName), ItemFontName);
serializedProperties.Add(nameof(ItemFontSize), ItemFontSize);
public override JObject FixJson(JObject json) | ||
{ | ||
json.Remove("HoverSound"); | ||
json.Remove("MouseUpSound"); | ||
json.Remove("MouseDownSound"); | ||
return base.FixJson(json); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is needed? What would be adding those keys to begin with?
@@ -585,7 +583,7 @@ public bool CloseAllWindows() | |||
closedWindows = true; | |||
} | |||
|
|||
if (mShopWindow != null && mShopWindow.IsVisible()) | |||
if (mShopWindow != null && !mShopWindow.IsHidden) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use IsVisibleInTree
@@ -392,7 +390,7 @@ public void Update(TimeSpan elapsed, TimeSpan total) | |||
GameMenu.OpenInventory(); | |||
} | |||
|
|||
if (mShopWindow != null && (!mShopWindow.IsVisible() || mShouldCloseShop)) | |||
if (mShopWindow != null && (mShopWindow.IsHidden || mShouldCloseShop)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use !IsVisibleInTree
// TODO: Refactor so shop only has 1 context menu shared between all items | ||
_contextMenu = new ContextMenu(Interface.CurrentInterface.Root, "ShopContextMenu") | ||
{ | ||
IsHidden = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IsVisibleInParent = false,
); | ||
} | ||
_contextMenu.UserData = slot; | ||
_contextMenu.SizeToChildren(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't necessary, it's built into the context menu's Open
(via OnOpen()
)
if (Globals.GameShop?.SellingItems[slot] == default) | ||
{ | ||
return; | ||
} | ||
|
||
if (Globals.InputManager.IsMouseButtonDown(MouseButton.Left)) | ||
if (!ItemBase.TryGet(Globals.GameShop.SellingItems[slot].ItemId, out var item)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Globals.GameShop
changes need to be done in this method too, also cache the SellingItems[slot]
array access instead of duplicating it
SetSound(ButtonSoundState.Hover, "octave-tap-resonant.wav"); | ||
SetSound(ButtonSoundState.MouseDown, "octave-tap-warm.wav"); | ||
SetSound(ButtonSoundState.MouseUp, "octave-tap-warm.wav"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I said to add this here I meant specifically the setting of sounds because Dragger
shouldn't have default sounds like Button
, ScrollbarBar
, and SliderBar
do.
I didn't mean to add the infrastructure for sound into this class too, since Dragger
had the infrastructure that stuff should be cleaned up. _stateSoundNames
and _ignoreMouseUpSoundsUntil
(and the methods that use them) should be in Dragger
just like they are in Button
.
Only the SetSound(...);
calls that are right here should stay in this class.
@@ -181,7 +181,7 @@ protected override void Dispose(bool disposing) | |||
|
|||
serializedProperties.Add(nameof(Texture), TextureFilename); | |||
serializedProperties.Add(nameof(TextureNinePatchMargin), TextureNinePatchMargin?.ToString()); | |||
serializedProperties.Add("HoverSound", mHoverSound); | |||
serializedProperties.Add("HoverSound", HoverSound); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nameof(HoverSound)
instead of the string
@@ -19,7 +19,7 @@ public partial class ImagePanel : Base | |||
private readonly float[] _uv; | |||
|
|||
//Sound Effects | |||
protected string mHoverSound; | |||
public string HoverSound; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ get; set; }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also update Left/RightMouseClickSounds to be loaded/saved (and they should be { get; set; }
like HoverSound is
c2ff7a7
to
2b8ac40
Compare
if (obj[nameof(HoverSound)] is JValue { Type: JTokenType.String } hoverSound && | ||
hoverSound.Value<string>()?.Trim() is { Length: > 0 }) | ||
{ | ||
mHoverSound = (string) obj["HoverSound"]; | ||
HoverSound = hoverSound?.Value<string>(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be slightly different to make sure what we compare is what we set, specifically:
if (obj[nameof(HoverSound)] is JValue { Type: JTokenType.String } tokenHoverSound &&
tokenHoverSound.Value<string>()?.Trim() is { Length: > 0 } hoverSound)
{
HoverSound = hoverSound;
}
if (obj[nameof(LeftMouseClickSound)] is JValue { Type: JTokenType.String } leftMouseClickSound && | ||
leftMouseClickSound.Value<string>()?.Trim() is { Length: > 0 }) | ||
{ | ||
mLeftMouseClickSound = (string) obj["LeftMouseClickSound"]; | ||
LeftMouseClickSound = leftMouseClickSound?.Value<string>(); | ||
} | ||
|
||
if (obj["RightMouseClickSound"] != null) | ||
if (obj[nameof(RightMouseClickSound)] is JValue { Type: JTokenType.String } rightMouseClickSound && | ||
rightMouseClickSound.Value<string>()?.Trim() is { Length: > 0 }) | ||
{ | ||
mRightMouseClickSound = (string) obj["RightMouseClickSound"]; | ||
RightMouseClickSound = rightMouseClickSound?.Value<string>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the same thing as I suggested with HoverSound
7d67782
to
6fdb3b1
Compare
resolves #2558
assets in AscensionGameDev/Intersect-Assets#62
Shop Window inherits from Window
ShopItem inheriting from image
code reduction and cleaning in general
Functions delegated correctly now:
I recommend looking at the files directly in the ide, github is showing everything strange
working as it should so far
1740370540_Intersect_Client.mp4