Skip to content

Commit

Permalink
show item tooltip as named list for small amount of types
Browse files Browse the repository at this point in the history
  • Loading branch information
deirn committed Jun 5, 2024
1 parent bc2fca1 commit 7e6379a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/api/java/mcp/mobius/waila/api/data/ItemData.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ public abstract class ItemData implements IData {
public static final Type<ItemData> TYPE = IData.createType(ID);

public static final ResourceLocation CONFIG_SYNC_NBT = BuiltinDataUtil.rl("item.nbt");
public static final ResourceLocation CONFIG_DISPLAY_MODE = BuiltinDataUtil.rl("item.display_mode");
public static final ResourceLocation CONFIG_MAX_HEIGHT = BuiltinDataUtil.rl("item.max_height");
public static final ResourceLocation CONFIG_SHOW_NAMES = BuiltinDataUtil.rl("item.show_names");
public static final ResourceLocation CONFIG_SORT_BY_COUNT = BuiltinDataUtil.rl("item.sort_by_count");

public enum ItemDisplayMode {
GRID, LIST, DYNAMIC
}

/**
* Creates an item data based from plugin config.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ protected ItemProvider() {
@Override
protected void registerAdditions(IRegistrar registrar, int priority) {
registrar.addSyncedConfig(ItemData.CONFIG_SYNC_NBT, true, false);
registrar.addConfig(ItemData.CONFIG_DISPLAY_MODE, ItemData.ItemDisplayMode.DYNAMIC);
registrar.addConfig(ItemData.CONFIG_MAX_HEIGHT, 3);
registrar.addConfig(ItemData.CONFIG_SHOW_NAMES, false);
registrar.addConfig(ItemData.CONFIG_SORT_BY_COUNT, true);
}

Expand Down Expand Up @@ -94,11 +94,17 @@ protected void appendBody(ITooltip tooltip, ItemDataImpl data, IPluginConfig con
stream = stream.sorted(Comparator.comparingInt(ItemStack::getCount).reversed());
}

if (config.getBoolean(ItemData.CONFIG_SHOW_NAMES)) {
lastItemsComponent = new NamedItemListComponent(stream.toList(), config.getInt(ItemData.CONFIG_MAX_HEIGHT));
} else {
lastItemsComponent = new ItemListComponent(stream.toList(), config.getInt(ItemData.CONFIG_MAX_HEIGHT));
}
var list = stream.toList();
var maxHeight = config.getInt(ItemData.CONFIG_MAX_HEIGHT);

lastItemsComponent = switch (config.<ItemData.ItemDisplayMode>getEnum(ItemData.CONFIG_DISPLAY_MODE)) {
case DYNAMIC -> list.size() <= maxHeight
? new NamedItemListComponent(list, maxHeight)
: new ItemListComponent(list, maxHeight);
case GRID -> new ItemListComponent(list, maxHeight);
case LIST -> new NamedItemListComponent(list, maxHeight);
};

tooltip.setLine(ItemData.ID, lastItemsComponent);
}

Expand Down
6 changes: 5 additions & 1 deletion src/resources/resources/assets/waila/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,12 @@
"config.waila.plugin_wailax.item.enabled_block" : "Show Block Item Contents",
"config.waila.plugin_wailax.item.enabled_entity" : "Show Entity Item Contents",
"config.waila.plugin_wailax.item.nbt" : "Sync NBT Data",
"config.waila.plugin_wailax.item.display_mode" : "Display Mode",
"config.waila.plugin_wailax.item.display_mode_desc" : "Grid: show as a grid, like how the inventory works\nList: show as a vertical list with inline name\nDynamic: switch from list to grid when max height exceeded",
"config.waila.plugin_wailax.item.display_mode_grid" : "Grid",
"config.waila.plugin_wailax.item.display_mode_list" : "List",
"config.waila.plugin_wailax.item.display_mode_dynamic" : "Dynamic",
"config.waila.plugin_wailax.item.max_height" : "Max Height",
"config.waila.plugin_wailax.item.show_names" : "Show Item Names",
"config.waila.plugin_wailax.item.sort_by_count" : "Sort by Count",
"config.waila.plugin_wailax.item.blacklist" : "Item Contents Blacklist",
"config.waila.plugin_wailax.fluid" : "Fluid",
Expand Down

0 comments on commit 7e6379a

Please sign in to comment.