This commit is contained in:
radimous 2024-12-04 16:14:45 +00:00
parent 14c0e90b00
commit 096a5e764a
11 changed files with 451 additions and 329 deletions

View file

@ -10,6 +10,10 @@ public class Config {
public static final ForgeConfigSpec.IntValue BUTTON_Y; public static final ForgeConfigSpec.IntValue BUTTON_Y;
public static final ForgeConfigSpec.BooleanValue COMBINE_LVL_TO_ABILITIES; public static final ForgeConfigSpec.BooleanValue COMBINE_LVL_TO_ABILITIES;
public static final ForgeConfigSpec.IntValue MAX_LEVEL_OVERRIDE; public static final ForgeConfigSpec.IntValue MAX_LEVEL_OVERRIDE;
public static final ForgeConfigSpec.BooleanValue SHOW_ABILITY_ENHANCEMENTS;
public static final ForgeConfigSpec.BooleanValue SHOW_WEIGHT;
public static final ForgeConfigSpec.BooleanValue SHOW_CHANCE;
static { static {
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
@ -25,6 +29,8 @@ public class Config {
BUTTON_X = builder BUTTON_X = builder
.comment("x position of the button") .comment("x position of the button")
.defineInRange("buttonPositionX", 5, Integer.MIN_VALUE, Integer.MAX_VALUE); .defineInRange("buttonPositionX", 5, Integer.MIN_VALUE, Integer.MAX_VALUE);
//TODO: auto move the button to 130 if QOL Hunters is loaded (button conflict)
BUTTON_Y = builder BUTTON_Y = builder
.comment("y position of the button") .comment("y position of the button")
.defineInRange("buttonPositionY", 109, Integer.MIN_VALUE, Integer.MAX_VALUE); .defineInRange("buttonPositionY", 109, Integer.MIN_VALUE, Integer.MAX_VALUE);
@ -34,11 +40,23 @@ public class Config {
ALLOW_DUPE = builder ALLOW_DUPE = builder
.comment("allow duplicate modifiers") .comment("allow duplicate modifiers")
.define("allowDupe", false); .define("allowDupe", false);
builder.pop();
MAX_LEVEL_OVERRIDE = builder MAX_LEVEL_OVERRIDE = builder
.comment("override max level") .comment("override max level")
.defineInRange("maxLevelOverride", -1, -1, Integer.MAX_VALUE); .defineInRange("maxLevelOverride", -1, -1, Integer.MAX_VALUE);
builder.pop();
SHOW_ABILITY_ENHANCEMENTS = builder
.comment("show ability enhancements")
.define("showAbilityEnhancements", false);
SHOW_WEIGHT = builder
.comment("show weight")
.define("showWeight", false);
SHOW_CHANCE = builder
.comment("show chance")
.define("showChance", true);
SPEC = builder.build(); SPEC = builder.build();
} }
} }

View file

@ -1,6 +1,8 @@
package com.radimous.vhatcaniroll; package com.radimous.vhatcaniroll;
import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.platform.InputConstants;
import com.radimous.vhatcaniroll.ui.GearModifierScreen;
import net.minecraft.client.KeyMapping; import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;

View file

@ -1,54 +0,0 @@
package com.radimous.vhatcaniroll;
import iskallia.vault.client.gui.framework.ScreenTextures;
import iskallia.vault.client.gui.framework.element.LabelElement;
import iskallia.vault.client.gui.framework.element.VerticalScrollClipContainer;
import iskallia.vault.client.gui.framework.spatial.Padding;
import iskallia.vault.client.gui.framework.spatial.Spatials;
import iskallia.vault.client.gui.framework.spatial.spi.ISpatial;
import iskallia.vault.client.gui.framework.text.LabelTextStyle;
import iskallia.vault.config.gear.VaultGearTierConfig;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.TextComponent;
import java.util.Optional;
public class ModifierListContainer extends VerticalScrollClipContainer<ModifierListContainer> {
public ModifierListContainer(ISpatial spatial, GearModifierScreen parent) {
super(spatial, Padding.ZERO, ScreenTextures.INSET_BLACK_BACKGROUND);
int i = 20;
int k = 9;
boolean legendary = parent.isLegendary();
Optional<VaultGearTierConfig> optCfg = VaultGearTierConfig.getConfig(parent.getCurrGear());
LabelElement<?> itemName = new LabelElement<>(
Spatials.positionXY(k, 5).width(this.innerWidth() - k).height(15), new TextComponent(
parent.getCurrGear().getItem().toString().toUpperCase() + " - LVL " + parent.getCurrLvl())
.withStyle(ChatFormatting.UNDERLINE).withStyle(legendary ? ChatFormatting.GOLD : ChatFormatting.WHITE), LabelTextStyle.defaultStyle()
);
this.addElement(itemName);
if (optCfg.isPresent()) {
VaultGearTierConfig cfg = optCfg.get();
for (var modifier : Helper.getModifierList(parent.getCurrLvl(), cfg, legendary)) {
LabelElement<?> labelelement = new LabelElement<>(
Spatials.positionXY(k, i).width(this.innerWidth() - k).height(15), modifier, LabelTextStyle.defaultStyle()
);
this.addElement(labelelement);
i += 10;
}
} else {
LabelElement<?> labelelement = new LabelElement<>(
Spatials.positionXY(k, i).width(this.innerWidth() - k).height(15), new TextComponent(
parent.getCurrGear().getItem() + " not found"), LabelTextStyle.defaultStyle()
);
this.addElement(labelelement);
}
}
public float getScroll() {
return this.verticalScrollBarElement.getValue();
}
public void setScroll(float scroll) {
this.verticalScrollBarElement.setValue(scroll);
}
}

View file

@ -1,30 +0,0 @@
package com.radimous.vhatcaniroll;
import iskallia.vault.client.gui.framework.element.TextInputElement;
import iskallia.vault.client.gui.framework.spatial.spi.ISpatial;
import net.minecraft.client.gui.Font;
public class ScrollableTextInputElement extends TextInputElement<ScrollableTextInputElement> {
public ScrollableTextInputElement(ISpatial spatial, Font font) {
super(spatial, font);
}
@Override
public boolean onMouseScrolled(double mouseX, double mouseY, double delta) {
if (this.isMouseOver(mouseX, mouseY)) {
int val = parseInt(this.getInput());
val += delta > 0 ? 1 : -1;
this.setInput(String.valueOf(val));
return true;
}
return super.onMouseScrolled(mouseX, mouseY, delta);
}
private int parseInt(String val) {
try {
return Integer.parseInt(val);
} catch (NumberFormatException e) {
return 0;
}
}
}

View file

@ -1,73 +1,16 @@
package com.radimous.vhatcaniroll; package com.radimous.vhatcaniroll;
import iskallia.vault.init.ModItems;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig; import net.minecraftforge.fml.config.ModConfig;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@Mod("vhatcaniroll") @Mod("vhatcaniroll")
public class VHatCanIRoll { public class VHatCanIRoll {
public static final String MODID = "vhatcaniroll"; public static final String MODID = "vhatcaniroll";
private static final List<ItemStack> GEAR_ITEMS = new ArrayList<>();
public VHatCanIRoll() { public VHatCanIRoll() {
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, Config.SPEC); ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, Config.SPEC);
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
} }
public static List<ItemStack> getVaultGearItems() {
if (GEAR_ITEMS.isEmpty()){
GEAR_ITEMS.addAll(List.of(
new ItemStack(ModItems.SWORD),
new ItemStack(ModItems.AXE),
new ItemStack(ModItems.HELMET),
new ItemStack(ModItems.CHESTPLATE),
new ItemStack(ModItems.LEGGINGS),
new ItemStack(ModItems.BOOTS),
new ItemStack(ModItems.FOCUS),
new ItemStack(ModItems.SHIELD),
new ItemStack(ModItems.WAND),
new ItemStack(ModItems.MAGNET),
new ItemStack(ModItems.JEWEL)
)
);
GEAR_ITEMS.addAll(getWoldGearItems());
}
return Collections.unmodifiableList(GEAR_ITEMS);
}
public static List<ItemStack> getWoldGearItems() {
List<ItemStack> woldItems = new ArrayList<>();
List<String> woldItemFields = Arrays.asList(
"BATTLESTAFF",
"TRIDENT",
"PLUSHIE",
"LOOT_SACK"
);
try{
Class<?> wold = Class.forName("xyz.iwolfking.woldsvaults.init.ModItems");
for (String name : woldItemFields) {
try {
Item item = (Item) wold.getField(name).get(null);
woldItems.add(new ItemStack(item));
} catch (IllegalArgumentException | SecurityException | NoSuchFieldException |
IllegalAccessException ignored) {
// no-op
}
}
} catch (ClassNotFoundException ignored) {
// no-op
}
return woldItems;
}
} }

View file

@ -0,0 +1,65 @@
package com.radimous.vhatcaniroll.logic;
import iskallia.vault.init.ModItems;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Items {
private static final List<ItemStack> GEAR_ITEMS = new ArrayList<>();
public static List<ItemStack> getVaultGearItems() {
if (GEAR_ITEMS.isEmpty()){
GEAR_ITEMS.addAll(getVHGearItems());
GEAR_ITEMS.addAll(getWoldGearItems());
}
return Collections.unmodifiableList(GEAR_ITEMS);
}
public static List<ItemStack> getVHGearItems() {
return List.of(
new ItemStack(ModItems.SWORD),
new ItemStack(ModItems.AXE),
new ItemStack(ModItems.HELMET),
new ItemStack(ModItems.CHESTPLATE),
new ItemStack(ModItems.LEGGINGS),
new ItemStack(ModItems.BOOTS),
new ItemStack(ModItems.FOCUS),
new ItemStack(ModItems.SHIELD),
new ItemStack(ModItems.WAND),
new ItemStack(ModItems.MAGNET),
new ItemStack(ModItems.JEWEL)
);
}
public static List<ItemStack> getWoldGearItems() {
List<ItemStack> woldItems = new ArrayList<>();
List<String> woldItemFields = Arrays.asList(
"BATTLESTAFF",
"TRIDENT",
"PLUSHIE",
"LOOT_SACK"
);
try{
Class<?> woldItemClass = Class.forName("xyz.iwolfking.woldsvaults.init.ModItems");
for (String woldFieldName : woldItemFields) {
try {
Item item = (Item) woldItemClass.getField(woldFieldName).get(null);
woldItems.add(new ItemStack(item));
} catch (IllegalArgumentException | SecurityException | NoSuchFieldException |
IllegalAccessException ignored) {
// no-op
}
}
} catch (ClassNotFoundException ignored) {
// no-op
}
return woldItems;
}
}

View file

@ -1,5 +1,6 @@
package com.radimous.vhatcaniroll; package com.radimous.vhatcaniroll.logic;
import com.radimous.vhatcaniroll.Config;
import com.radimous.vhatcaniroll.mixin.EffectConfigAccessor; import com.radimous.vhatcaniroll.mixin.EffectConfigAccessor;
import com.radimous.vhatcaniroll.mixin.VaultGearTierConfigAccessor; import com.radimous.vhatcaniroll.mixin.VaultGearTierConfigAccessor;
import iskallia.vault.config.gear.VaultGearTierConfig; import iskallia.vault.config.gear.VaultGearTierConfig;
@ -10,7 +11,6 @@ import iskallia.vault.gear.attribute.config.BooleanFlagGenerator;
import iskallia.vault.gear.attribute.config.ConfigurableAttributeGenerator; import iskallia.vault.gear.attribute.config.ConfigurableAttributeGenerator;
import iskallia.vault.gear.attribute.custom.effect.EffectGearAttribute; import iskallia.vault.gear.attribute.custom.effect.EffectGearAttribute;
import iskallia.vault.init.ModConfigs; import iskallia.vault.init.ModConfigs;
import iskallia.vault.util.TextComponentUtils;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.MutableComponent;
@ -24,42 +24,59 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class Helper { /**
* This is responsible for all the logic of transforming vh config -> list of components needed for the UI
*/
public class Modifiers {
private static final ChatFormatting[] COLORS = private static final ChatFormatting[] COLORS =
new ChatFormatting[]{ChatFormatting.RED, ChatFormatting.GREEN, ChatFormatting.BLUE, ChatFormatting.YELLOW, new ChatFormatting[]{ChatFormatting.RED, ChatFormatting.GREEN, ChatFormatting.BLUE, ChatFormatting.YELLOW,
ChatFormatting.LIGHT_PURPLE, ChatFormatting.AQUA, ChatFormatting.WHITE}; ChatFormatting.LIGHT_PURPLE, ChatFormatting.AQUA, ChatFormatting.WHITE};
public static List<Component> getModifierList(int lvl, VaultGearTierConfig cfg, boolean legendary) { public static List<Component> getModifierList(int lvl, VaultGearTierConfig cfg, int tierIncrease) {
Map<VaultGearTierConfig.ModifierAffixTagGroup, VaultGearTierConfig.AttributeGroup> modifierGroup = Map<VaultGearTierConfig.ModifierAffixTagGroup, VaultGearTierConfig.AttributeGroup> modifierGroup = ((VaultGearTierConfigAccessor) cfg).getModifierGroup();
((VaultGearTierConfigAccessor) cfg).getModifierGroup();
ArrayList<Component> modList = new ArrayList<>(); ArrayList<Component> modList = new ArrayList<>();
for (VaultGearTierConfig.ModifierAffixTagGroup affixTagGroup : modifierGroup.keySet()) { for (VaultGearTierConfig.ModifierAffixTagGroup affixTagGroup : modifierGroup.keySet()) {
processAffixTagGroup(lvl, affixTagGroup, modifierGroup, modList, legendary); modList.addAll(getAffixGroupComponents(lvl, affixTagGroup, modifierGroup, tierIncrease));
} }
return modList; return modList;
} }
private static void processAffixTagGroup(int lvl, VaultGearTierConfig.ModifierAffixTagGroup affixTagGroup, private static List<Component> getAffixGroupComponents(int lvl, VaultGearTierConfig.ModifierAffixTagGroup affixTagGroup,
Map<VaultGearTierConfig.ModifierAffixTagGroup, VaultGearTierConfig.AttributeGroup> modifierGroup, Map<VaultGearTierConfig.ModifierAffixTagGroup, VaultGearTierConfig.AttributeGroup> modifierGroup,
ArrayList<Component> modList, boolean legendary) { int tierIncrease) {
if (affixTagGroup.equals(VaultGearTierConfig.ModifierAffixTagGroup.ABILITY_ENHANCEMENT)) {
return; ArrayList<Component> componentList = new ArrayList<>();
if (!Config.SHOW_ABILITY_ENHANCEMENTS.get() && affixTagGroup.equals(VaultGearTierConfig.ModifierAffixTagGroup.ABILITY_ENHANCEMENT)) {
return componentList;
} }
if (modifierGroup.get(affixTagGroup).isEmpty()) { if (modifierGroup.get(affixTagGroup).isEmpty()) {
return; return componentList;
} }
modList.add(new TextComponent(affixTagGroup.toString().replace("_", " ")).withStyle(ChatFormatting.BOLD)); componentList.add(new TextComponent(affixTagGroup.toString().replace("_", " ")).withStyle(ChatFormatting.BOLD));
Map<String, Integer> groupCounts = countGroups(lvl, affixTagGroup, modifierGroup, legendary); int totalWeight = modifierGroup.get(affixTagGroup).stream()
.mapToInt(x -> getModifierTiers(lvl, x).stream().mapToInt(VaultGearTierConfig.ModifierTier::getWeight).sum())
.sum();
if (Config.SHOW_WEIGHT.get()) {
componentList.add(new TextComponent("Total Weight: " + totalWeight).withStyle(ChatFormatting.BOLD));
}
Map<String, Integer> groupCounts = countGroups(lvl, affixTagGroup, modifierGroup, tierIncrease);
Map<String, List<Component>> groupedModifiers = new HashMap<>(); Map<String, List<Component>> groupedModifiers = new HashMap<>();
for (VaultGearTierConfig.ModifierTierGroup modifierTierGroup : modifierGroup.get(affixTagGroup)) { for (VaultGearTierConfig.ModifierTierGroup modifierTierGroup : modifierGroup.get(affixTagGroup)) {
ArrayList<VaultGearTierConfig.ModifierTier<?>> mTierList; ArrayList<VaultGearTierConfig.ModifierTier<?>> mTierList;
if (legendary) {
mTierList = getLegendaryModifierTiers(lvl, modifierTierGroup); // TODO: support greater modifiers (greater is +1 tier, legendary is +2 tiers) (look how VH does it)
// maybe ENUM - NORMAL, GREATER, LEGENDARY and the button would cycle through them
if (tierIncrease > 0) {
mTierList = getIncreasedModifierTiers(lvl, modifierTierGroup, tierIncrease);
} else { } else {
mTierList = getModifierTiers(lvl, modifierTierGroup); mTierList = getModifierTiers(lvl, modifierTierGroup);
} }
@ -68,9 +85,9 @@ public class Helper {
continue; continue;
} }
String modGr = modifierTierGroup.getModifierGroup(); String modGr = modifierTierGroup.getModifierGroup();
Component newMod = getVal(
Objects.requireNonNull(VaultGearAttributeRegistry.getAttribute(modifierTierGroup.getAttribute())),
mTierList); Component newMod = getModifierComponent(VaultGearAttributeRegistry.getAttribute(modifierTierGroup.getAttribute()),mTierList);
if (groupCounts.get(modGr) > 1) { if (groupCounts.get(modGr) > 1) {
groupedModifiers.computeIfAbsent(modGr, k -> new ArrayList<>()).add(newMod); groupedModifiers.computeIfAbsent(modGr, k -> new ArrayList<>()).add(newMod);
continue; continue;
@ -79,35 +96,44 @@ public class Helper {
MutableComponent full = new TextComponent(" "); MutableComponent full = new TextComponent(" ");
full.append(newMod); full.append(newMod);
if (Config.ALLOW_DUPE.get() || !(modList.get(modList.size() - 1).getString()).equals(full.getString())) { //dumb way to fix ability lvl+ duplication
modList.add(full); int weight = modTierListWeight(mTierList);
if (Config.SHOW_WEIGHT.get()) {
full.append(" w"+weight);
}
if (Config.SHOW_CHANCE.get()) {
full.append(String.format(" %.2f %%", ((double) weight * 100 / totalWeight)));
}
if (Config.ALLOW_DUPE.get() || !(componentList.get(componentList.size() - 1).getString()).equals(full.getString())) { //dumb way to fix ability lvl+ duplication
componentList.add(full);
} }
} }
boolean useNums = false;
if (groupedModifiers.size() > COLORS.length) {
// more than 7 groups is a bit crazy, but just in case // more than 7 groups is a bit crazy, but just in case
useNums = true; boolean useNums = groupedModifiers.size() > COLORS.length;
}
int i = 0; int i = 0;
for (var modGr: groupedModifiers.values()) { for (var modGr: groupedModifiers.values()) {
for (var mod: modGr) { for (var mod: modGr) {
MutableComponent full = new TextComponent(useNums ? i + " " : "").withStyle(COLORS[i % COLORS.length]); MutableComponent full = new TextComponent(useNums ? i + " " : "").withStyle(COLORS[i % COLORS.length]);
full.append(mod); full.append(mod);
modList.add(full); componentList.add(full);
} }
i++; i++;
} }
modList.add(TextComponent.EMPTY); componentList.add(TextComponent.EMPTY);
return componentList;
} }
private static Map<String, Integer> countGroups(int lvl, VaultGearTierConfig.ModifierAffixTagGroup affixTagGroup, private static Map<String, Integer> countGroups(int lvl, VaultGearTierConfig.ModifierAffixTagGroup affixTagGroup,
Map<VaultGearTierConfig.ModifierAffixTagGroup, VaultGearTierConfig.AttributeGroup> modifierGroup, Map<VaultGearTierConfig.ModifierAffixTagGroup, VaultGearTierConfig.AttributeGroup> modifierGroup,
boolean legendary) { int tierIncrease) {
Map<String, Integer> groupCounts = new HashMap<>(); Map<String, Integer> groupCounts = new HashMap<>();
for (VaultGearTierConfig.ModifierTierGroup modifierTierGroup : modifierGroup.get(affixTagGroup)) { for (VaultGearTierConfig.ModifierTierGroup modifierTierGroup : modifierGroup.get(affixTagGroup)) {
ArrayList<VaultGearTierConfig.ModifierTier<?>> mTierList; ArrayList<VaultGearTierConfig.ModifierTier<?>> mTierList;
if (legendary) { if (tierIncrease > 0) {
mTierList = getLegendaryModifierTiers(lvl, modifierTierGroup); mTierList = getIncreasedModifierTiers(lvl, modifierTierGroup, tierIncrease);
} else { } else {
mTierList = getModifierTiers(lvl, modifierTierGroup); mTierList = getModifierTiers(lvl, modifierTierGroup);
} }
@ -120,15 +146,16 @@ public class Helper {
return groupCounts; return groupCounts;
} }
private static ArrayList<VaultGearTierConfig.ModifierTier<?>> getLegendaryModifierTiers(int lvl, //TODO: check how noLegendary works in VH
VaultGearTierConfig.ModifierTierGroup modifierTierGroup) { private static ArrayList<VaultGearTierConfig.ModifierTier<?>> getIncreasedModifierTiers(int lvl,
VaultGearTierConfig.ModifierTierGroup modifierTierGroup, int tierIncrease) {
var res = new ArrayList<VaultGearTierConfig.ModifierTier<?>>(); var res = new ArrayList<VaultGearTierConfig.ModifierTier<?>>();
var highest = modifierTierGroup.getHighestForLevel(lvl); var highest = modifierTierGroup.getHighestForLevel(lvl);
if (highest == null) { if (highest == null) {
return res; // empty return res; // empty
} }
int index = Math.min(highest.getModifierTier() + 2, modifierTierGroup.size() - 1); int index = Math.min(highest.getModifierTier() + tierIncrease, modifierTierGroup.size() - 1);
var legendTier = modifierTierGroup.get(index); var legendTier = modifierTierGroup.get(index);
if (legendTier == null || legendTier.getWeight() == 0){ if (legendTier == null || legendTier.getWeight() == 0){
return res; // empty return res; // empty
@ -149,39 +176,68 @@ public class Helper {
.collect(Collectors.toCollection(ArrayList::new)); .collect(Collectors.toCollection(ArrayList::new));
} }
// TODO: wtf is this, fix variable names and make it readable @SuppressWarnings("unchecked") // I don't think proper generics are possible, VaultGearTierConfig#getModifiersForLevel returns List<ModifierTier<?>>
// I don't think proper generics are possible, VaultGearTierConfig#getModifiersForLevel returns List<ModifierTier<?>> private static <T, C> Component getModifierComponent(VaultGearAttribute<T> atr,
private static <T, C> Component getVal(VaultGearAttribute<T> atr, ArrayList<VaultGearTierConfig.ModifierTier<?>> modifierTiers) {
ArrayList<VaultGearTierConfig.ModifierTier<?>> val) { if (modifierTiers.isEmpty()) {
if (val.isEmpty()) { return new TextComponent("ERR - EMPTY MODIFIER TIERS");
return new TextComponent("ERR - EMPTY VAL");
} }
if (atr == null) {
return new TextComponent("ERR - NULL ATTRIBUTE");
}
ConfigurableAttributeGenerator<T, C> atrGenerator = (ConfigurableAttributeGenerator<T, C>) atr.getGenerator(); ConfigurableAttributeGenerator<T, C> atrGenerator = (ConfigurableAttributeGenerator<T, C>) atr.getGenerator();
if (atrGenerator == null) { if (atrGenerator == null) {
return new TextComponent("ERR - NULL GENERATOR"); return new TextComponent("ERR - NULL ATTRIBUTE GENERATOR");
} }
C minConfig = (C) val.get(0).getModifierConfiguration(); C minConfig = (C) modifierTiers.get(0).getModifierConfiguration();
C maxConfig = (C) val.get(val.size() - 1).getModifierConfiguration(); C maxConfig = (C) modifierTiers.get(modifierTiers.size() - 1).getModifierConfiguration();
MutableComponent res;
ResourceLocation atrRegName = atr.getRegistryName(); ResourceLocation atrRegName = atr.getRegistryName();
if (atrRegName == null) { if (atrRegName == null) {
return new TextComponent("ERR - NULL REGISTRY NAME"); return new TextComponent("ERR - NULL REGISTRY NAME");
} }
String atrName = atrRegName.toString(); String atrName = atrRegName.toString();
var minConfigDisplay = atrGenerator.getConfigDisplay(atr.getReader(), minConfig);
MutableComponent res = null;
if (modifierTiers.size() > 1) {
res = rangeComponent(atrName, atr, atrGenerator, minConfig, maxConfig);
}
if (res == null && minConfigDisplay != null) {
res = minConfigDisplay.withStyle(atr.getReader().getColoredTextStyle());
if (minConfig instanceof AbilityLevelAttribute.Config minConfigAbility) {
return abilityLvlComponent(res, atr, minConfigAbility);
}
if (minConfig instanceof EffectGearAttribute.Config ) {
return minConfigDisplay;
}
return res;
}
return new TextComponent("ERR - NULL DISPLAY " + atrName);
}
/**
* This method handles combining multiple configs into a single component
* VH doesn't have method for this, so we need to do it manually
* it is using the same logic as VH does when shifting on gear piece to get the range
* and combining it with normal display for single component (that has name and color)
*/
private static <T, C> MutableComponent rangeComponent(String atrName, VaultGearAttribute<T> atr,
ConfigurableAttributeGenerator<T, C> atrGenerator, C minConfig, C maxConfig) {
MutableComponent res = atrGenerator.getConfigRangeDisplay(atr.getReader(), minConfig, maxConfig);
var minConfigDisplay = atrGenerator.getConfigDisplay(atr.getReader(), minConfig); var minConfigDisplay = atrGenerator.getConfigDisplay(atr.getReader(), minConfig);
var maxConfigDisplay = atrGenerator.getConfigDisplay(atr.getReader(), maxConfig); var maxConfigDisplay = atrGenerator.getConfigDisplay(atr.getReader(), maxConfig);
if (val.size() > 1) {
// range
res = atrGenerator.getConfigRangeDisplay(atr.getReader(), minConfig, maxConfig);
if (res != null && minConfig instanceof AbilityLevelAttribute.Config minConfigAbility) { if (res != null && minConfig instanceof AbilityLevelAttribute.Config minConfigAbility) {
return abilityLvlComponent(res, atr, minConfigAbility); return abilityLvlComponent(res, atr, minConfigAbility);
} }
if (res != null && atrName.equals("the_vault:wendarr_affinity")) {
return res.append(" God Affinity").withStyle(atr.getReader().getColoredTextStyle()); //FIXME: poison avoidance was changed to single generic "Effect Avoidance" and it's not working
} //FIXME: clouds with roman numerals are not working
if (atrName.equals("the_vault:effect_avoidance") && minConfigDisplay != null) { if (atrName.equals("the_vault:effect_avoidance") && minConfigDisplay != null) {
// res -> "30% - 50%" // res -> "30% - 50%"
// single -> "30% Poison Avoidance" // single -> "30% Poison Avoidance"
@ -204,30 +260,16 @@ public class Helper {
if (res != null) { if (res != null) {
return atr.getReader().formatConfigDisplay(LogicalSide.CLIENT, res); return atr.getReader().formatConfigDisplay(LogicalSide.CLIENT, res);
} }
}
if (minConfigDisplay != null) {
res = minConfigDisplay.withStyle(atr.getReader().getColoredTextStyle());
if (minConfig instanceof AbilityLevelAttribute.Config minConfigAbility) {
return abilityLvlComponent(res, atr, minConfigAbility);
}
if (atrName.equals("the_vault:wendarr_affinity")) {
return TextComponentUtils.replace(TextComponentUtils.createSourceStack(LogicalSide.CLIENT), res,
"Wendarr Affinity", new TextComponent("God Affinity"))
.withStyle(atr.getReader().getColoredTextStyle());
}
if (minConfig instanceof EffectGearAttribute.Config ) {
return minConfigDisplay;
}
return res; return res;
} }
return new TextComponent("ERR - NULL DISPLAY " + atrName);
} private static MutableComponent abilityLvlComponent(MutableComponent res, VaultGearAttribute<?> atr,
private static Component abilityLvlComponent(MutableComponent res, VaultGearAttribute<?> atr,
AbilityLevelAttribute.Config minConfig) { AbilityLevelAttribute.Config minConfig) {
if (Config.COMBINE_LVL_TO_ABILITIES.get()) { if (Config.COMBINE_LVL_TO_ABILITIES.get()) {
return res.append(" added ability levels").withStyle(atr.getReader().getColoredTextStyle()); return res.append(" added ability levels").withStyle(atr.getReader().getColoredTextStyle());
} else { }
var abComp = new TextComponent("+").withStyle(atr.getReader().getColoredTextStyle()); var abComp = new TextComponent("+").withStyle(atr.getReader().getColoredTextStyle());
var optSkill = ModConfigs.ABILITIES.getAbilityById(minConfig.getAbilityKey()); var optSkill = ModConfigs.ABILITIES.getAbilityById(minConfig.getAbilityKey());
if (optSkill.isEmpty()) { if (optSkill.isEmpty()) {
@ -239,5 +281,11 @@ public class Helper {
abComp.append(new TextComponent(abName).withStyle(Style.EMPTY.withColor(14076214))); abComp.append(new TextComponent(abName).withStyle(Style.EMPTY.withColor(14076214)));
return abComp; return abComp;
} }
private static int modTierListWeight(List<VaultGearTierConfig.ModifierTier<?>> val) {
if (val == null || val.isEmpty()) {
return 0;
}
return val.stream().mapToInt(VaultGearTierConfig.ModifierTier::getWeight).sum();
} }
} }

View file

@ -1,7 +1,7 @@
package com.radimous.vhatcaniroll.mixin; package com.radimous.vhatcaniroll.mixin;
import com.radimous.vhatcaniroll.Config; import com.radimous.vhatcaniroll.Config;
import com.radimous.vhatcaniroll.GearModifierScreen; import com.radimous.vhatcaniroll.ui.GearModifierScreen;
import iskallia.vault.client.gui.framework.ScreenTextures; import iskallia.vault.client.gui.framework.ScreenTextures;
import iskallia.vault.client.gui.framework.element.ButtonElement; import iskallia.vault.client.gui.framework.element.ButtonElement;
import iskallia.vault.client.gui.framework.element.FakeItemSlotElement; import iskallia.vault.client.gui.framework.element.FakeItemSlotElement;

View file

@ -1,6 +1,9 @@
package com.radimous.vhatcaniroll; package com.radimous.vhatcaniroll.ui;
import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.platform.InputConstants;
import com.radimous.vhatcaniroll.Config;
import com.radimous.vhatcaniroll.logic.Items;
import iskallia.vault.client.gui.framework.ScreenRenderers; import iskallia.vault.client.gui.framework.ScreenRenderers;
import iskallia.vault.client.gui.framework.ScreenTextures; import iskallia.vault.client.gui.framework.ScreenTextures;
import iskallia.vault.client.gui.framework.element.FakeItemSlotElement; import iskallia.vault.client.gui.framework.element.FakeItemSlotElement;
@ -8,7 +11,6 @@ import iskallia.vault.client.gui.framework.element.LabelElement;
import iskallia.vault.client.gui.framework.element.NineSliceButtonElement; import iskallia.vault.client.gui.framework.element.NineSliceButtonElement;
import iskallia.vault.client.gui.framework.element.NineSliceElement; import iskallia.vault.client.gui.framework.element.NineSliceElement;
import iskallia.vault.client.gui.framework.element.TabElement; import iskallia.vault.client.gui.framework.element.TabElement;
import iskallia.vault.client.gui.framework.element.TextInputElement;
import iskallia.vault.client.gui.framework.element.TextureAtlasElement; import iskallia.vault.client.gui.framework.element.TextureAtlasElement;
import iskallia.vault.client.gui.framework.element.spi.ILayoutStrategy; import iskallia.vault.client.gui.framework.element.spi.ILayoutStrategy;
import iskallia.vault.client.gui.framework.render.ScreenTooltipRenderer; import iskallia.vault.client.gui.framework.render.ScreenTooltipRenderer;
@ -18,8 +20,6 @@ import iskallia.vault.client.gui.framework.spatial.Spatials;
import iskallia.vault.client.gui.framework.spatial.spi.IPosition; import iskallia.vault.client.gui.framework.spatial.spi.IPosition;
import iskallia.vault.client.gui.framework.spatial.spi.ISpatial; import iskallia.vault.client.gui.framework.spatial.spi.ISpatial;
import iskallia.vault.client.gui.framework.text.LabelTextStyle; import iskallia.vault.client.gui.framework.text.LabelTextStyle;
import iskallia.vault.client.gui.overlay.VaultBarOverlay;
import iskallia.vault.init.ModConfigs;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TextComponent;
@ -30,11 +30,11 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class GearModifierScreen extends AbstractElementScreen { public class GearModifierScreen extends AbstractElementScreen {
//TODO: code cleanup - variable naming, magic numbers, some logic reordering etc //TODO: remove magic numbers
private ModifierListContainer modifierList; private ModifierListContainer modifierList;
private final TextInputElement<?> lvlInput; private final ScrollableLvlInputElement lvlInput;
private boolean legendary; private int tierIncrease = 0;
private LabelElement<?> legendaryLabel; private LabelElement<?> legendaryLabel;
private int currIndex = 0; private int currIndex = 0;
@ -68,62 +68,69 @@ public class GearModifierScreen extends AbstractElementScreen {
createTabs(); createTabs();
this.lvlInput = this.addElement(createLvlInput()); this.lvlInput = this.addElement(createLvlInput());
createLvlButtons();
createLvlButtons(lvlInput);
createLegendaryButton(); createLegendaryButton();
// inner black window // inner black window
this.modifierList = new ModifierListContainer( ISpatial modListSpatial = Spatials.positionXY(7, 50).size(this.getGuiSpatial().width() - 14, this.getGuiSpatial().height() - 57);
Spatials.positionXY(7, 50).size(this.getGuiSpatial().width() - 14, this.getGuiSpatial().height() - 57), this.modifierList = new ModifierListContainer(modListSpatial, lvlInput.getValue(), tierIncrease, getCurrGear()).layout(this.translateWorldSpatial());
this)
.layout(this.translateWorldSpatial());
this.addElement(this.modifierList); this.addElement(this.modifierList);
} }
// helper methods
public ItemStack getCurrGear() { public ItemStack getCurrGear() {
return VHatCanIRoll.getVaultGearItems().get(currIndex); return Items.getVaultGearItems().get(currIndex);
}
public int getCurrLvl() {
try {
return Integer.parseInt(this.lvlInput.getInput());
} catch (NumberFormatException e) {
return 0;
}
}
private void increaseLvl() {
this.lvlInput.setInput(String.valueOf(this.getCurrLvl() + 1));
}
private void decreaseLvl() {
this.lvlInput.setInput(String.valueOf(this.getCurrLvl() - 1));
} }
/**
* Update the modifier list with the current gear item and lvl and legendary flag
* @param keepScroll whether to keep the current scroll position
*/
private void updateModifierList(boolean keepScroll) { private void updateModifierList(boolean keepScroll) {
var oldScroll = this.modifierList.getScroll(); var oldScroll = this.modifierList.getScroll();
this.removeElement(this.modifierList); this.removeElement(this.modifierList);
this.modifierList = new ModifierListContainer( ISpatial modListSpatial = Spatials.positionXY(7, 50).size(this.getGuiSpatial().width() - 14, this.getGuiSpatial().height() - 57);
Spatials.positionXY(7, 50).size(this.getGuiSpatial().width() - 14, this.getGuiSpatial().height() - 57), this.modifierList = new ModifierListContainer(modListSpatial, lvlInput.getValue(), tierIncrease, getCurrGear()).layout(this.translateWorldSpatial());
this)
.layout(this.translateWorldSpatial());
if (keepScroll) { if (keepScroll) {
this.modifierList.setScroll(oldScroll); this.modifierList.setScroll(oldScroll);
} }
this.addElement(this.modifierList); this.addElement(this.modifierList);
ScreenLayout.requestLayout(); ScreenLayout.requestLayout();
} }
// pulled from QuestOverviewElementScreen
private ILayoutStrategy translateWorldSpatial() { private ILayoutStrategy translateWorldSpatial() {
return (screen, gui, parent, world) -> world.translateXY(this.getGuiSpatial()); return (screen, gui, parent, world) -> world.translateXY(this.getGuiSpatial());
} }
private IPosition getPos(int tabIndex, boolean selected) {
if (tabIndex < 11){ // tabs
/**
* Get the position where tab should be drawn
* @param tabIndex
* @param selected
* @return
*/
private IPosition getTabPos(int tabIndex, boolean selected) {
if (tabIndex < 11){ // top tabs
return Spatials.positionXY(5 + tabIndex * 30, 2 + (selected ? 0 : 4)); return Spatials.positionXY(5 + tabIndex * 30, 2 + (selected ? 0 : 4));
} }
return Spatials.positionXY(337 + (selected? 0:3), 35 + (tabIndex-11) * 30); // right tabs (only needed for wold's rn)
return Spatials.positionXY(337 + (selected ? 0:3), 35 + (tabIndex-11) * 30);
} }
/**
* Get the position where item "icon" should be drawn
* @param tabIndex
* @return
*/
private ISpatial getItemPos(int tabIndex) { private ISpatial getItemPos(int tabIndex) {
if (tabIndex < 11){ if (tabIndex < 11){
return Spatials.positionXY(10 + tabIndex * 30, 11); return Spatials.positionXY(10 + tabIndex * 30, 11);
@ -131,16 +138,17 @@ public class GearModifierScreen extends AbstractElementScreen {
return Spatials.positionXY(342, 40 + (tabIndex-11) * 30); return Spatials.positionXY(342, 40 + (tabIndex-11) * 30);
} }
// actual tab
private TabElement<?> getTabElement(int tabIndex, boolean selected) { private TabElement<?> getTabElement(int tabIndex, boolean selected) {
if (tabIndex < 11){ if (tabIndex < 11){ // top tabs
return new TabElement<>(getPos(tabIndex, selected), return new TabElement<>(getTabPos(tabIndex, selected),
new TextureAtlasElement<>( new TextureAtlasElement<>(
selected ? ScreenTextures.TAB_BACKGROUND_TOP_SELECTED : ScreenTextures.TAB_BACKGROUND_TOP), selected ? ScreenTextures.TAB_BACKGROUND_TOP_SELECTED : ScreenTextures.TAB_BACKGROUND_TOP),
new TextureAtlasElement<>(ScreenTextures.EMPTY), () -> switchTab(tabIndex)) new TextureAtlasElement<>(ScreenTextures.EMPTY), () -> switchTab(tabIndex))
.layout(this.translateWorldSpatial()); .layout(this.translateWorldSpatial());
} }
return new TabElement<>(getPos(tabIndex, selected),
return new TabElement<>(getTabPos(tabIndex, selected), // right tabs (only needed for wold's rn)
new TextureAtlasElement<>( new TextureAtlasElement<>(
selected ? ScreenTextures.TAB_BACKGROUND_RIGHT_SELECTED : ScreenTextures.TAB_BACKGROUND_RIGHT), selected ? ScreenTextures.TAB_BACKGROUND_RIGHT_SELECTED : ScreenTextures.TAB_BACKGROUND_RIGHT),
new TextureAtlasElement<>(ScreenTextures.EMPTY), () -> switchTab(tabIndex)) new TextureAtlasElement<>(ScreenTextures.EMPTY), () -> switchTab(tabIndex))
@ -148,7 +156,7 @@ public class GearModifierScreen extends AbstractElementScreen {
} }
private void switchTab(int tabIndex) { private void switchTab(int tabIndex) {
for (int i = 0; i < VHatCanIRoll.getVaultGearItems().size(); i++) { for (int i = 0; i < Items.getVaultGearItems().size(); i++) {
this.removeElement(tabs.get(i)); this.removeElement(tabs.get(i));
TabElement<?> tab = getTabElement(i, i == tabIndex); TabElement<?> tab = getTabElement(i, i == tabIndex);
tabs.set(i, tab); tabs.set(i, tab);
@ -158,44 +166,41 @@ public class GearModifierScreen extends AbstractElementScreen {
updateModifierList(false); updateModifierList(false);
} }
private TextInputElement<?> createLvlInput() { private void createTabs() {
ScrollableTextInputElement inputElement = this.addElement( for (int i = 0; i < Items.getVaultGearItems().size(); i++) {
new ScrollableTextInputElement(Spatials.positionXY(this.getGuiSpatial().width() - 54 - 13, 36).size(26, 12), addTab(i);
addFakeItemSlot(i);
}
}
private void addTab(int index) {
TabElement<?> tab = getTabElement(index, index == currIndex);
tabs.add(this.addElement(tab));
}
private void addFakeItemSlot(int index) {
ItemStack gearItem = Items.getVaultGearItems().get(index);
this.addElement(
new FakeItemSlotElement<>(getItemPos(index), () -> gearItem, () -> false,
ScreenTextures.EMPTY, ScreenTextures.EMPTY).layout(
this.translateWorldSpatial()));
}
// header
private ScrollableLvlInputElement createLvlInput() {
ScrollableLvlInputElement inputElement = this.addElement(
new ScrollableLvlInputElement(Spatials.positionXY(this.getGuiSpatial().width() - 54 - 13, 36).size(26, 12),
Minecraft.getInstance().font) Minecraft.getInstance().font)
.layout((screen, gui, parent, world) -> world.translateXY(gui)) .layout(this.translateWorldSpatial())
); );
inputElement.adjustEditBox(editBox -> {
editBox.setFilter(this::isValidLevel);
editBox.setMaxLength(3);
editBox.setValue(String.valueOf(VaultBarOverlay.vaultLevel));
});
inputElement.onTextChanged(s -> updateModifierList(true)); inputElement.onTextChanged(s -> updateModifierList(true));
return inputElement; return inputElement;
} }
private boolean isValidLevel(String input){ private void createLvlButtons(ScrollableLvlInputElement lvlInput) {
// reminds me of original vault filters
if (input.isEmpty()) {
return true;
}
int lvl;
try {
lvl = Integer.parseInt(input);
} catch (NumberFormatException numberformatexception) {
return false;
}
if (lvl <= ModConfigs.LEVELS_META.getMaxLevel() && lvl >= 0) {
ScreenLayout.requestLayout();
return true;
}
if (lvl <= Config.MAX_LEVEL_OVERRIDE.get() && lvl >= 0) {
ScreenLayout.requestLayout();
return true;
}
return false;
}
private void createLvlButtons() {
LabelElement<?> minusLabel = LabelElement<?> minusLabel =
new LabelElement<>(Spatials.positionXY(this.getGuiSpatial().width() - 68 - 13, 38), new TextComponent("-"), new LabelElement<>(Spatials.positionXY(this.getGuiSpatial().width() - 68 - 13, 38), new TextComponent("-"),
LabelTextStyle.border4(ChatFormatting.BLACK)) LabelTextStyle.border4(ChatFormatting.BLACK))
@ -206,10 +211,10 @@ public class GearModifierScreen extends AbstractElementScreen {
.layout(this.translateWorldSpatial()); .layout(this.translateWorldSpatial());
NineSliceButtonElement<?> btnMinus = NineSliceButtonElement<?> btnMinus =
new NineSliceButtonElement<>(Spatials.positionXY(this.getGuiSpatial().width() - 72 - 13, 35).size(15, 14), new NineSliceButtonElement<>(Spatials.positionXY(this.getGuiSpatial().width() - 72 - 13, 35).size(15, 14),
ScreenTextures.BUTTON_EMPTY_TEXTURES, this::decreaseLvl).layout(this.translateWorldSpatial()); ScreenTextures.BUTTON_EMPTY_TEXTURES, lvlInput::increment).layout(this.translateWorldSpatial());
NineSliceButtonElement<?> btnPlus = NineSliceButtonElement<?> btnPlus =
new NineSliceButtonElement<>(Spatials.positionXY(this.getGuiSpatial().width() - 25 - 13, 35).size(15, 14), new NineSliceButtonElement<>(Spatials.positionXY(this.getGuiSpatial().width() - 25 - 13, 35).size(15, 14),
ScreenTextures.BUTTON_EMPTY_TEXTURES, this::increaseLvl).layout(this.translateWorldSpatial()); ScreenTextures.BUTTON_EMPTY_TEXTURES, lvlInput::decrement).layout(this.translateWorldSpatial());
this.addElement(btnMinus); this.addElement(btnMinus);
this.addElement(minusLabel); this.addElement(minusLabel);
this.addElement(plusLabel); this.addElement(plusLabel);
@ -217,7 +222,7 @@ public class GearModifierScreen extends AbstractElementScreen {
} }
private void toggleLegend() { private void toggleLegend() {
this.legendary = !this.legendary; this.tierIncrease = (tierIncrease + 1) % 3;
updateLegendaryLabel(); updateLegendaryLabel();
updateModifierList(true); updateModifierList(true);
} }
@ -226,7 +231,7 @@ public class GearModifierScreen extends AbstractElementScreen {
if (this.legendaryLabel != null) { if (this.legendaryLabel != null) {
this.removeElement(this.legendaryLabel); this.removeElement(this.legendaryLabel);
} }
var formatting = this.legendary ? ChatFormatting.GOLD : ChatFormatting.WHITE; var formatting = tierIncrease == 2 ? ChatFormatting.GOLD : tierIncrease == 1 ? ChatFormatting.AQUA : ChatFormatting.WHITE;
this.legendaryLabel = new LabelElement<>(Spatials.positionXY(this.getGuiSpatial().width() - 5 - 13, 38), this.legendaryLabel = new LabelElement<>(Spatials.positionXY(this.getGuiSpatial().width() - 5 - 13, 38),
new TextComponent("").withStyle(formatting), LabelTextStyle.defaultStyle()) new TextComponent("").withStyle(formatting), LabelTextStyle.defaultStyle())
.layout(this.translateWorldSpatial()); .layout(this.translateWorldSpatial());
@ -241,38 +246,14 @@ public class GearModifierScreen extends AbstractElementScreen {
this.addElement(btnLegend); this.addElement(btnLegend);
} }
private void createTabs() {
for (int i = 0; i < VHatCanIRoll.getVaultGearItems().size(); i++) {
addTab(i);
addFakeItemSlot(i);
}
}
private void addTab(int index) {
TabElement<?> tab = getTabElement(index, index == currIndex);
tabs.add(this.addElement(tab));
}
private void addFakeItemSlot(int index) {
ItemStack gearItem = VHatCanIRoll.getVaultGearItems().get(index);
this.addElement(
new FakeItemSlotElement<>(getItemPos(index), () -> gearItem, () -> false,
ScreenTextures.EMPTY, ScreenTextures.EMPTY).layout(
this.translateWorldSpatial()));
}
public boolean isLegendary() {
return legendary;
}
@Override @Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) { public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
// left/right to increase/decrease lvl // left/right to increase/decrease lvl
if (keyCode == InputConstants.KEY_L || keyCode == InputConstants.KEY_RIGHT) { if (keyCode == InputConstants.KEY_L || keyCode == InputConstants.KEY_RIGHT) {
increaseLvl(); lvlInput.increment();
} }
if (keyCode == InputConstants.KEY_H || keyCode == InputConstants.KEY_LEFT) { if (keyCode == InputConstants.KEY_H || keyCode == InputConstants.KEY_LEFT) {
decreaseLvl(); lvlInput.decrement();
} }
// up/down to scroll up/down // up/down to scroll up/down
if (keyCode == InputConstants.KEY_K || keyCode == InputConstants.KEY_UP) { if (keyCode == InputConstants.KEY_K || keyCode == InputConstants.KEY_UP) {
@ -283,11 +264,11 @@ public class GearModifierScreen extends AbstractElementScreen {
} }
// tab to next gear item // tab to next gear item
if (keyCode == InputConstants.KEY_TAB && !hasShiftDown()) { if (keyCode == InputConstants.KEY_TAB && !hasShiftDown()) {
switchTab((currIndex + 1) % VHatCanIRoll.getVaultGearItems().size()); switchTab((currIndex + 1) % Items.getVaultGearItems().size());
} }
// shift+tab to previous gear item // shift+tab to previous gear item
if (keyCode == InputConstants.KEY_TAB && hasShiftDown()) { if (keyCode == InputConstants.KEY_TAB && hasShiftDown()) {
switchTab((currIndex - 1 + VHatCanIRoll.getVaultGearItems().size()) % VHatCanIRoll.getVaultGearItems().size()); switchTab((currIndex - 1 + Items.getVaultGearItems().size()) % Items.getVaultGearItems().size());
} }
// alt to toggle legendary // alt to toggle legendary
if (keyCode == InputConstants.KEY_LALT || keyCode == InputConstants.KEY_RALT) { if (keyCode == InputConstants.KEY_LALT || keyCode == InputConstants.KEY_RALT) {

View file

@ -0,0 +1,77 @@
package com.radimous.vhatcaniroll.ui;
import iskallia.vault.client.gui.framework.ScreenTextures;
import iskallia.vault.client.gui.framework.element.LabelElement;
import iskallia.vault.client.gui.framework.element.VerticalScrollClipContainer;
import iskallia.vault.client.gui.framework.spatial.Padding;
import iskallia.vault.client.gui.framework.spatial.Spatials;
import iskallia.vault.client.gui.framework.spatial.spi.ISpatial;
import iskallia.vault.client.gui.framework.text.LabelTextStyle;
import iskallia.vault.config.gear.VaultGearTierConfig;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.world.item.ItemStack;
import java.util.Optional;
import com.radimous.vhatcaniroll.logic.Modifiers;
public class ModifierListContainer extends VerticalScrollClipContainer<ModifierListContainer> {
public ModifierListContainer(ISpatial spatial, int lvl, int tierIncrease, ItemStack gearPiece) {
super(spatial, Padding.ZERO, ScreenTextures.INSET_BLACK_BACKGROUND);
int labelX = 9;
int labelY = 20;
Optional<VaultGearTierConfig> optCfg = VaultGearTierConfig.getConfig(gearPiece);
// Label for the item name and level (GOLD if legendary, AQUA if greater, WHITE if common)
LabelElement<?> itemName = new LabelElement<>(
Spatials.positionXY(labelX, 5).width(this.innerWidth() - labelX).height(15), new TextComponent(
gearPiece.getItem().toString().toUpperCase() + " - LVL " + lvl)
//TODO: make it nicer
.withStyle(ChatFormatting.UNDERLINE).withStyle(tierIncrease == 2 ? ChatFormatting.GOLD : tierIncrease == 1 ? ChatFormatting.AQUA : ChatFormatting.WHITE), LabelTextStyle.defaultStyle()
);
this.addElement(itemName);
if (optCfg.isPresent()) {
VaultGearTierConfig cfg = optCfg.get();
for (var modifier : Modifiers.getModifierList(lvl, cfg, tierIncrease)) {
LabelElement<?> labelelement = new LabelElement<>(
Spatials.positionXY(labelX, labelY).width(this.innerWidth() - labelX).height(15), modifier, LabelTextStyle.defaultStyle()
);
/* TODO: maybe weight/chance should be added here, because there is everything you need for custom position
that would require returning something else from getModifierList (maybe List<Pair<Component, Component>>)
where first component is the modifier and second is the weight/chance or both (depending on the config)
also it should potentionally return a list of modifiers to get all tiers of the modifier
I want to display
<groupPrefix> <value> <name> <chance>
and make it expandable to show all tiers of the modifier
<groupPrefix> <value> <name> <chance>
<groupPrefix> <value> <name> <chance>
<groupPrefix> <value> <name> <chance>
<groupPrefix> <value> <name> <chance>
*/
this.addElement(labelelement);
labelY += 10;
}
} else {
LabelElement<?> labelelement = new LabelElement<>(
Spatials.positionXY(labelX, labelY).width(this.innerWidth() - labelX).height(15), new TextComponent(
"Modifier config for " + gearPiece.getItem() + " not found"), LabelTextStyle.defaultStyle()
);
this.addElement(labelelement);
}
}
public float getScroll() {
return this.verticalScrollBarElement.getValue();
}
public void setScroll(float scroll) {
this.verticalScrollBarElement.setValue(scroll);
}
}

View file

@ -0,0 +1,72 @@
package com.radimous.vhatcaniroll.ui;
import com.radimous.vhatcaniroll.Config;
import iskallia.vault.client.gui.framework.element.TextInputElement;
import iskallia.vault.client.gui.framework.screen.layout.ScreenLayout;
import iskallia.vault.client.gui.framework.spatial.spi.ISpatial;
import iskallia.vault.client.gui.overlay.VaultBarOverlay;
import iskallia.vault.init.ModConfigs;
import net.minecraft.client.gui.Font;
public class ScrollableLvlInputElement extends TextInputElement<ScrollableLvlInputElement> {
public ScrollableLvlInputElement(ISpatial spatial, Font font) {
super(spatial, font);
}
@Override
public boolean onMouseScrolled(double mouseX, double mouseY, double delta) {
if (this.isMouseOver(mouseX, mouseY)) {
int val = parseInt(this.getInput());
val += delta > 0 ? 1 : -1;
this.setInput(String.valueOf(val));
return true;
}
this.adjustEditBox(editBox -> {
editBox.setFilter(s -> isValidLevel(parseInt(s)));
editBox.setMaxLength(3);
editBox.setValue(String.valueOf(VaultBarOverlay.vaultLevel));
});
return super.onMouseScrolled(mouseX, mouseY, delta);
}
public int getValue() {
return parseInt(this.getInput());
}
public void setValue(int value) {
if (isValidLevel(value)) {
this.setInput(String.valueOf(value));
}
}
public void increment() {
this.setValue(getValue() + 1);
}
public void decrement() {
this.setValue(getValue() - 1);
}
private int parseInt(String val) {
try {
return Integer.parseInt(val);
} catch (NumberFormatException e) {
return 0;
}
}
public boolean isValidLevel(int lvl){
if (lvl <= ModConfigs.LEVELS_META.getMaxLevel() && lvl >= 0) {
ScreenLayout.requestLayout();
return true;
}
if (lvl <= Config.MAX_LEVEL_OVERRIDE.get() && lvl >= 0) {
ScreenLayout.requestLayout();
return true;
}
return false;
}
}