Skip to content

Commit

Permalink
add support for collapsible fields in Lookup Anything
Browse files Browse the repository at this point in the history
  • Loading branch information
Pathoschild committed Apr 20, 2024
1 parent 8bb0588 commit c229021
Show file tree
Hide file tree
Showing 21 changed files with 66 additions and 23 deletions.
27 changes: 19 additions & 8 deletions LookupAnything/Components/LookupMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ public void HandleLeftClick(int x, int y)
// custom link fields
else
{
foreach (var area in this.LinkFieldAreas)
foreach ((ILinkField link, Rectangle area) in this.LinkFieldAreas)
{
if (area.Value.Contains(x, y))
if (area.Contains(x, y))
{
ISubject? subject = area.Key.GetLinkSubject();
ISubject? subject = link.GetLinkSubject();
if (subject != null)
this.ShowNewPage(subject);
break;
Expand Down Expand Up @@ -380,15 +380,26 @@ public override void draw(SpriteBatch spriteBatch)
if (!field.HasValue)
continue;
// draw label & value
// draw label
Vector2 labelSize = contentBatch.DrawTextBlock(font, field.Label, new Vector2(x + leftOffset + cellPadding, y + topOffset + cellPadding), wrapWidth);
// draw value
Vector2 valuePosition = new Vector2(x + leftOffset + labelWidth + cellPadding * 3, y + topOffset + cellPadding);
Vector2 valueSize =
field.DrawValue(contentBatch, font, valuePosition, valueWidth)
?? contentBatch.DrawTextBlock(font, field.Value, valuePosition, valueWidth);
Vector2 rowSize = new Vector2(labelWidth + valueWidth + cellPadding * 4, Math.Max(labelSize.Y, valueSize.Y));
Vector2 valueSize;
if (field.ExpandLink is not null)
{
valueSize = contentBatch.DrawTextBlock(font, field.ExpandLink.Value, valuePosition, valueWidth);
this.LinkFieldAreas[field.ExpandLink] = new Rectangle((int)valuePosition.X, (int)valuePosition.Y, (int)valueSize.X, (int)valueSize.Y);
}
else
{
valueSize =
field.DrawValue(contentBatch, font, valuePosition, valueWidth)
?? contentBatch.DrawTextBlock(font, field.Value, valuePosition, valueWidth);
}
// draw table row
Vector2 rowSize = new Vector2(labelWidth + valueWidth + cellPadding * 4, Math.Max(labelSize.Y, valueSize.Y));
Color lineColor = Color.Gray;
contentBatch.DrawLine(x + leftOffset, y + topOffset, new Vector2(rowSize.X, tableBorderWidth), lineColor); // top
contentBatch.DrawLine(x + leftOffset, y + topOffset + rowSize.Y, new Vector2(rowSize.X, tableBorderWidth), lineColor); // bottom
Expand Down
20 changes: 17 additions & 3 deletions LookupAnything/Framework/Fields/GenericField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ internal class GenericField : ICustomField
/*********
** Accessors
*********/
/// <summary>A short field label.</summary>
/// <inheritdoc />
public string Label { get; protected set; }

/// <summary>The field value.</summary>
/// <inheritdoc />
public LinkField? ExpandLink { get; protected set; }

/// <inheritdoc />
public IFormattedText[]? Value { get; protected set; }

/// <summary>Whether the field should be displayed.</summary>
/// <inheritdoc />
public bool HasValue { get; protected set; }


Expand Down Expand Up @@ -66,6 +69,17 @@ public GenericField(string label, IEnumerable<IFormattedText> value, bool? hasVa
return null;
}

/// <summary>Collapse the field by default, so the user needs to click a link to expand it.</summary>
/// <param name="linkText">The link text to show.</param>
public void CollapseByDefault(string linkText)
{
this.ExpandLink = new LinkField(this.Label, linkText, () =>
{
this.ExpandLink = null;
return null;
});
}


/*********
** Protected methods
Expand Down
3 changes: 3 additions & 0 deletions LookupAnything/Framework/Fields/ICustomField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ internal interface ICustomField
/// <summary>Whether the field should be displayed.</summary>
bool HasValue { get; }

/// <summary>If the field is currently collapsed, the link to click to expand it.</summary>
LinkField? ExpandLink { get; }


/*********
** Public methods
Expand Down
2 changes: 1 addition & 1 deletion LookupAnything/Framework/Fields/ILinkField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal interface ILinkField : ICustomField
/*********
** Public methods
*********/
/// <summary>Get the subject the link points to.</summary>
/// <summary>Get the subject the link points to, or <c>null</c> to stay on the current subject.</summary>
ISubject? GetLinkSubject();
}
}
12 changes: 6 additions & 6 deletions LookupAnything/Framework/Fields/LinkField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ internal class LinkField : GenericField, ILinkField
/*********
** Fields
*********/
/// <summary>Gets the subject the link points to.</summary>
private readonly Func<ISubject> Subject;
/// <summary>Gets the subject the link points to, or <c>null</c> to stay on the current subject.</summary>
private readonly Func<ISubject?> Subject;


/*********
Expand All @@ -20,15 +20,15 @@ internal class LinkField : GenericField, ILinkField
/// <summary>Construct an instance.</summary>
/// <param name="label">A short field label.</param>
/// <param name="text">The link text.</param>
/// <param name="subject">Gets the subject the link points to.</param>
public LinkField(string label, string text, Func<ISubject> subject)
/// <param name="subject">Gets the subject the link points to, or <c>null</c> to stay on the current subject.</param>
public LinkField(string label, string text, Func<ISubject?> subject)
: base(label, new FormattedText(text, Color.Blue))
{
this.Subject = subject;
}

/// <summary>Get the subject the link points to.</summary>
public ISubject GetLinkSubject()
/// <inheritdoc />
public ISubject? GetLinkSubject()
{
return this.Subject();
}
Expand Down
1 change: 1 addition & 0 deletions LookupAnything/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"generic.price": "{{price}}g",
"generic.price-for-quality": "{{price}}g ({{quality}})",
"generic.price-for-stack": "{{price}}g für einen Stapel von {{count}}",
"generic.show-x-results": "show {{count}} results", // TODO

// types
"type.building": "Gebäude",
Expand Down
1 change: 1 addition & 0 deletions LookupAnything/i18n/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"generic.price": "{{price}}g",
"generic.price-for-quality": "{{price}}g ({{quality}})",
"generic.price-for-stack": "{{price}}g for stack of {{count}}",
"generic.show-x-results": "show {{count}} results",

// types
"type.building": "Building",
Expand Down
1 change: 1 addition & 0 deletions LookupAnything/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"generic.price": "{{price}}g",
"generic.price-for-quality": "{{price}}g ({{quality}})",
"generic.price-for-stack": "{{price}}g por montón de {{count}}",
"generic.show-x-results": "show {{count}} results", // TODO

// types
"type.building": "Edificio",
Expand Down
1 change: 1 addition & 0 deletions LookupAnything/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"generic.price": "{{price}}po",
"generic.price-for-quality": "{{price}}po ({{quality}})",
"generic.price-for-stack": "{{price}}po le lot de {{count}}",
"generic.show-x-results": "show {{count}} results", // TODO

// types
"type.building": "Bâtiment",
Expand Down
1 change: 1 addition & 0 deletions LookupAnything/i18n/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"generic.price": "{{price}}g",
"generic.price-for-quality": "{{price}}g ({{quality}})",
"generic.price-for-stack": "{{price}}g {{count}} rakásért",
"generic.show-x-results": "show {{count}} results", // TODO

// types
"type.building": "Építmény",
Expand Down
1 change: 1 addition & 0 deletions LookupAnything/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"generic.price": "{{price}}g",
"generic.price-for-quality": "{{price}}g ({{quality}})",
"generic.price-for-stack": "{{price}}g ogni {{count}}",
"generic.show-x-results": "show {{count}} results", // TODO

// types
"type.building": "Edificio",
Expand Down
1 change: 1 addition & 0 deletions LookupAnything/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"generic.price": "{{price}}G",
"generic.price-for-quality": "{{price}}G ({{quality}})",
"generic.price-for-stack": "{{price}}g (スタック:{{count}})",
"generic.show-x-results": "show {{count}} results", // TODO

// types
"type.building": "建物",
Expand Down
1 change: 1 addition & 0 deletions LookupAnything/i18n/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"generic.price": "{{price}}g",
"generic.price-for-quality": "{{price}}g ({{quality}})",
"generic.price-for-stack": "{{count}}개를 묶음 판매 시 {{price}}G",
"generic.show-x-results": "show {{count}} results", // TODO

// types 유형
"type.building": "건물",
Expand Down
1 change: 1 addition & 0 deletions LookupAnything/i18n/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"generic.price": "{{price}}zł",
"generic.price-for-quality": "{{price}}zł ({{quality}})",
"generic.price-for-stack": "{{price}}zł za {{count}}",
"generic.show-x-results": "show {{count}} results", // TODO

// types
"type.building": "Budowla",
Expand Down
1 change: 1 addition & 0 deletions LookupAnything/i18n/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"generic.price": "{{price}} ouros",
"generic.price-for-quality": "{{price}} ouros ({{quality}})",
"generic.price-for-stack": "{{price}} ouros por uma pilha de {{count}}",
"generic.show-x-results": "show {{count}} results", // TODO

// types
"type.building": "Construção",
Expand Down
1 change: 1 addition & 0 deletions LookupAnything/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"generic.price": "{{price}}з.",
"generic.price-for-quality": "{{price}}з. ({{quality}})",
"generic.price-for-stack": "{{price}}з. за набор из {{count}} шт.",
"generic.show-x-results": "show {{count}} results", // TODO

// types
"type.building": "Постройка",
Expand Down
1 change: 1 addition & 0 deletions LookupAnything/i18n/th.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"generic.price": "{{price}}g",
"generic.price-for-quality": "{{price}}g ({{quality}})",
"generic.price-for-stack": "{{price}}g สำหรับปริมาณ {{count}} ชิ้น",
"generic.show-x-results": "show {{count}} results", // TODO

// types
"type.building": "สิ่งก่อสร้าง",
Expand Down
1 change: 1 addition & 0 deletions LookupAnything/i18n/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"generic.price": "{{price}}g",
"generic.price-for-quality": "{{price}}g ({{quality}})",
"generic.price-for-stack": "{{count}} adet için {{price}}g",
"generic.show-x-results": "show {{count}} results", // TODO

// types
"type.building": "Bina",
Expand Down
1 change: 1 addition & 0 deletions LookupAnything/i18n/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"generic.price": "{{price}} з.",
"generic.price-for-quality": "{{price}} з. ({{quality}})",
"generic.price-for-stack": "{{price}} з. за набір з {{count}} од.",
"generic.show-x-results": "show {{count}} results", // TODO

// types
"type.building": "Будівля",
Expand Down
1 change: 1 addition & 0 deletions LookupAnything/i18n/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"generic.price": "{{price}}金",
"generic.price-for-quality": "{{price}}金({{quality}})",
"generic.price-for-stack": "{{count}}个,总共价值{{price}}金",
"generic.show-x-results": "show {{count}} results", // TODO

// types
"type.building": "建筑",
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ on the wiki for help contributing translations.

&nbsp; | Automate | Chests Anywhere | Data Layers | Debug Mode | Fast Animations | Horse Flute Anywhere | Lookup Anything | Noclip Mode | Skip Intro | Small Beach Farm | Tractor Mod
:---------- | :------------------------- | :------------------------------- | :--------------------------- | :-------------------------- | :------------------------------- | :----------------------------------- | :------------------------------- | :--------------------------- | :-------------------------- | :------------------------------- | :---------------------------
Chinese | [](Automate/i18n/zh.json) | [](ChestsAnywhere/i18n/zh.json) | [](DataLayers/i18n/zh.json) | [](DebugMode/i18n/zh.json) | [](FastAnimations/i18n/zh.json) | [](HorseFluteAnywhere/i18n/zh.json) | [](LookupAnything/i18n/zh.json) | [](NoclipMode/i18n/zh.json) | [](SkipIntro/i18n/zh.json) | [](SmallBeachFarm/i18n/zh.json) | [](TractorMod/i18n/zh.json)
Chinese | [](Automate/i18n/zh.json) | [](ChestsAnywhere/i18n/zh.json) | [](DataLayers/i18n/zh.json) | [](DebugMode/i18n/zh.json) | [](FastAnimations/i18n/zh.json) | [](HorseFluteAnywhere/i18n/zh.json) | [](LookupAnything/i18n/zh.json) | [](NoclipMode/i18n/zh.json) | [](SkipIntro/i18n/zh.json) | [](SmallBeachFarm/i18n/zh.json) | [](TractorMod/i18n/zh.json)
French | [](Automate/i18n/fr.json) | [](ChestsAnywhere/i18n/fr.json) | [](DataLayers/i18n/fr.json) | [](DebugMode/i18n/fr.json) | [](FastAnimations/i18n/fr.json) | [](HorseFluteAnywhere/i18n/fr.json) | [](LookupAnything/i18n/fr.json) | [](NoclipMode/i18n/fr.json) | [](SkipIntro/i18n/fr.json) | [](SmallBeachFarm/i18n/fr.json) | [](TractorMod/i18n/fr.json)
German | [](Automate/i18n/de.json) | [](ChestsAnywhere/i18n/de.json) | [](DataLayers/i18n/de.json) | [](DebugMode/i18n/de.json) | [](FastAnimations/i18n/de.json) | [](HorseFluteAnywhere/i18n/de.json) | [](LookupAnything/i18n/de.json) | [](NoclipMode/i18n/de.json) | [](SkipIntro/i18n/de.json) | [](SmallBeachFarm/i18n/de.json) | [](TractorMod/i18n/de.json)
German | [](Automate/i18n/de.json) | [](ChestsAnywhere/i18n/de.json) | [](DataLayers/i18n/de.json) | [](DebugMode/i18n/de.json) | [](FastAnimations/i18n/de.json) | [](HorseFluteAnywhere/i18n/de.json) | [](LookupAnything/i18n/de.json) | [](NoclipMode/i18n/de.json) | [](SkipIntro/i18n/de.json) | [](SmallBeachFarm/i18n/de.json) | [](TractorMod/i18n/de.json)
Hungarian | [](Automate/i18n/hu.json) | [](ChestsAnywhere/i18n/hu.json) | [](DataLayers/i18n/hu.json) | [](DebugMode/i18n/hu.json) | [](FastAnimations/i18n/hu.json) | [](HorseFluteAnywhere/i18n/hu.json) | [](LookupAnything/i18n/hu.json) | [](NoclipMode/i18n/hu.json) | [](SkipIntro/i18n) | [](SmallBeachFarm/i18n/hu.json) | [](TractorMod/i18n/hu.json)
Italian | [](Automate/i18n/it.json) | [](ChestsAnywhere/i18n/it.json) | [](DataLayers/i18n/it.json) | [](DebugMode/i18n/it.json) | [](FastAnimations/i18n/it.json) | [](HorseFluteAnywhere/i18n/it.json) | [](LookupAnything/i18n/it.json) | [](NoclipMode/i18n/it.json) | [](SkipIntro/i18n/it.json) | [](SmallBeachFarm/i18n/it.json) | [](TractorMod/i18n/it.json)
Italian | [](Automate/i18n/it.json) | [](ChestsAnywhere/i18n/it.json) | [](DataLayers/i18n/it.json) | [](DebugMode/i18n/it.json) | [](FastAnimations/i18n/it.json) | [](HorseFluteAnywhere/i18n/it.json) | [](LookupAnything/i18n/it.json) | [](NoclipMode/i18n/it.json) | [](SkipIntro/i18n/it.json) | [](SmallBeachFarm/i18n/it.json) | [](TractorMod/i18n/it.json)
Japanese | [](Automate/i18n) | [](ChestsAnywhere/i18n/ja.json) | [](DataLayers/i18n/ja.json) | [](DebugMode/i18n/ja.json) | [](FastAnimations/i18n) | [](HorseFluteAnywhere/i18n) | [](LookupAnything/i18n/ja.json) | [](NoclipMode/i18n/ja.json) | [](SkipIntro/i18n) | [](SmallBeachFarm/i18n) | [](TractorMod/i18n/ja.json)
Korean | [](Automate/i18n/ko.json) | [](ChestsAnywhere/i18n/ko.json) | [](DataLayers/i18n/ko.json) | [](DebugMode/i18n/ko.json) | [](FastAnimations/i18n/ko.json) | [](HorseFluteAnywhere/i18n/ko.json) | [](LookupAnything/i18n/ko.json) | [](NoclipMode/i18n/ko.json) | [](SkipIntro/i18n/ko.json) | [](SmallBeachFarm/i18n/ko.json) | [](TractorMod/i18n/ko.json)
Korean | [](Automate/i18n/ko.json) | [](ChestsAnywhere/i18n/ko.json) | [](DataLayers/i18n/ko.json) | [](DebugMode/i18n/ko.json) | [](FastAnimations/i18n/ko.json) | [](HorseFluteAnywhere/i18n/ko.json) | [](LookupAnything/i18n/ko.json) | [](NoclipMode/i18n/ko.json) | [](SkipIntro/i18n/ko.json) | [](SmallBeachFarm/i18n/ko.json) | [](TractorMod/i18n/ko.json)
[Polish] | [](Automate/i18n) | [](ChestsAnywhere/i18n/pl.json) | [](DataLayers/i18n/pl.json) | [](DebugMode/i18n/pl.json) | [](FastAnimations/i18n) | [](HorseFluteAnywhere/i18n) | [](LookupAnything/i18n/pl.json) | [](NoclipMode/i18n/pl.json) | [](SkipIntro/i18n) | [](SmallBeachFarm/i18n) | [](TractorMod/i18n/pl.json)
Portuguese | [](Automate/i18n/pt.json) | [](ChestsAnywhere/i18n/pt.json) | [](DataLayers/i18n/pt.json) | [](DebugMode/i18n/pt.json) | [](FastAnimations/i18n/pt.json) | [](HorseFluteAnywhere/i18n/pt.json) | [](LookupAnything/i18n/pt.json) | [](NoclipMode/i18n/pt.json) | [](SkipIntro/i18n/pt.json) | [](SmallBeachFarm/i18n/pt.json) | [](TractorMod/i18n/pt.json)
Portuguese | [](Automate/i18n/pt.json) | [](ChestsAnywhere/i18n/pt.json) | [](DataLayers/i18n/pt.json) | [](DebugMode/i18n/pt.json) | [](FastAnimations/i18n/pt.json) | [](HorseFluteAnywhere/i18n/pt.json) | [](LookupAnything/i18n/pt.json) | [](NoclipMode/i18n/pt.json) | [](SkipIntro/i18n/pt.json) | [](SmallBeachFarm/i18n/pt.json) | [](TractorMod/i18n/pt.json)
Russian | [](Automate/i18n/ru.json) | [](ChestsAnywhere/i18n/ru.json) | [](DataLayers/i18n/ru.json) | [](DebugMode/i18n/ru.json) | [](FastAnimations/i18n/ru.json) | [](HorseFluteAnywhere/i18n/ru.json) | [](LookupAnything/i18n/ru.json) | [](NoclipMode/i18n/ru.json) | [](SkipIntro/i18n/ru.json) | [](SmallBeachFarm/i18n/ru.json) | [](TractorMod/i18n/ru.json)
Spanish | [](Automate/i18n/es.json) | [](ChestsAnywhere/i18n/es.json) | [](DataLayers/i18n/es.json) | [](DebugMode/i18n/es.json) | [](FastAnimations/i18n/es.json) | [](HorseFluteAnywhere/i18n/es.json) | [](LookupAnything/i18n/es.json) | [](NoclipMode/i18n/es.json) | [](SkipIntro/i18n/es.json) | [](SmallBeachFarm/i18n/es.json) | [](TractorMod/i18n/es.json)
[Thai] | [](Automate/i18n/th.json) | [](ChestsAnywhere/i18n/th.json) | [](DataLayers/i18n/th.json) | [](DebugMode/i18n/th.json) | [](FastAnimations/i18n/th.json) | [](HorseFluteAnywhere/i18n/th.json) | [](LookupAnything/i18n/th.json) | [](NoclipMode/i18n/th.json) | [](SkipIntro/i18n/th.json) | [](SmallBeachFarm/i18n/th.json) | [](TractorMod/i18n/th.json)
Expand Down

0 comments on commit c229021

Please sign in to comment.