Skip to content

Commit

Permalink
fix slot overlay, ability to click hidden cpas
Browse files Browse the repository at this point in the history
configurable trinket slot group
remove debug
  • Loading branch information
deirn committed Jan 2, 2021
1 parent 5e27a4c commit 4d85ceb
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 40 deletions.
16 changes: 8 additions & 8 deletions src/main/java/badasintended/cpas/api/SlotType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@

public enum SlotType {

HEAD(5, 39, new Identifier("textures/item/empty_armor_slot_helmet.png"), "head"),
CHEST(6, 38, new Identifier("textures/item/empty_armor_slot_chestplate.png"), "chest"),
LEGS(7, 37, new Identifier("textures/item/empty_armor_slot_leggings.png"), "legs"),
FEET(8, 36, new Identifier("textures/item/empty_armor_slot_boots.png"), "feet"),
OFFHAND(45, 40, new Identifier("textures/item/empty_armor_slot_shield.png"), "hand", "offhand");
HEAD("head", 5, 39, new Identifier("textures/item/empty_armor_slot_helmet.png")),
CHEST("chest", 6, 38, new Identifier("textures/item/empty_armor_slot_chestplate.png")),
LEGS("legs", 7, 37, new Identifier("textures/item/empty_armor_slot_leggings.png")),
FEET("feet", 8, 36, new Identifier("textures/item/empty_armor_slot_boots.png")),
OFFHAND("offhand", 45, 40, new Identifier("textures/item/empty_armor_slot_shield.png"));

public static final SlotType[] VALUES = values();

public final String id;
public final int handlerId;
public final int inventoryId;
public final Identifier textureId;
public final String[] trinketIds;

SlotType(int handlerId, int inventoryId, Identifier textureId, String... trinketIds) {
SlotType(String id, int handlerId, int inventoryId, Identifier textureId) {
this.id = id;
this.handlerId = handlerId;
this.inventoryId = inventoryId;
this.textureId = textureId;
this.trinketIds = trinketIds;
}

public static SlotType of(int id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) {

@Override
public boolean isMouseOver(double mouseX, double mouseY) {
return super.isMouseOver(mouseX, mouseY) || hoveredElement(mouseX, mouseY).isPresent();
return visible && (super.isMouseOver(mouseX, mouseY) || hoveredElement(mouseX, mouseY).isPresent());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class ArmorPanelWidget extends AbstractPanelWidget {

public ArmorPanelWidget(int x, int y, PlayerInventory playerInventory) {
super(x, y, 32, 5 * 18 + 18);
super(x, y, 32, 108);

for (int i = 0; i < 4; i++) {
children().add(createArmorSlot(x + 7, i * 18 + y + 7, playerInventory, SlotType.of(i)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package badasintended.cpas.client.widget;

import java.util.Arrays;

import badasintended.cpas.Cpas;
import badasintended.cpas.api.SlotType;
import badasintended.cpas.config.CpasConfig;
import dev.emi.trinkets.api.TrinketSlots;
import dev.emi.trinkets.api.TrinketsApi;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
Expand Down Expand Up @@ -45,7 +44,7 @@ public TrinketSlotWidget(int x, int y, PlayerInventory inventory, SlotType slot)
int j = 0;
for (TrinketSlots.SlotGroup slotGroup : TrinketSlots.slotGroups) {
for (TrinketSlots.Slot trinketSlot : slotGroup.slots) {
if (Arrays.stream(slot.trinketIds).anyMatch(it -> it.equals(slotGroup.getName()))) {
if (CpasConfig.getTrinketGroups(slot.id).stream().anyMatch(it -> it.equals(slotGroup.getName()))) {
trinketSlots.put(j, trinketSlot);
trinketSlotNumbers.put(trinketSlot, i);
j++;
Expand Down Expand Up @@ -115,7 +114,7 @@ public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float del
public void renderToolTip(MatrixStack matrices, int mouseX, int mouseY) {
if (wasHovered) {
matrices.push();
matrices.translate(0, 0, 200);
matrices.translate(0, 0, 300);
itemRenderer().zOffset += 200;

fill(matrices, hoveredX + 1, y + 1, hoveredX + 17, y + 17, 0x80ffffff);
Expand Down
52 changes: 31 additions & 21 deletions src/main/java/badasintended/cpas/config/CpasConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import badasintended.cpas.Cpas;
import com.google.gson.Gson;
Expand Down Expand Up @@ -50,6 +52,7 @@ public static CpasConfig get(boolean reload) {
e.printStackTrace();
throw new JsonParseException(new IllegalArgumentException());
}
save();
}
return config;
}
Expand All @@ -72,18 +75,39 @@ public static Entry getEntry(HandledScreen<?> screen) {
return config.entries.get(name);
}

public static Set<String> getTrinketGroups(String slot) {
Map<String, Set<String>> groups = get().trinketSlotGroups;
if (!groups.containsKey(slot)) {
groups.put(slot, new HashSet<>());
save();
}
return groups.get(slot);
}


// ----------------------------------------------------------------------------------


private boolean showHelp = true;

public final Debug debug = new Debug();
public final Map<String, Set<String>> trinketSlotGroups = new HashMap<>();

private Map<String, Entry> entries = new HashMap<>();
public Map<String, Entry> entries = new HashMap<>();

public void setEntries(Map<String, Entry> entries) {
this.entries = entries;
}
public CpasConfig() {
Set<String> head = trinketSlotGroups.computeIfAbsent("head", s -> new HashSet<>());
Set<String> chest = trinketSlotGroups.computeIfAbsent("chest", s -> new HashSet<>());
Set<String> legs = trinketSlotGroups.computeIfAbsent("legs", s -> new HashSet<>());
Set<String> feet = trinketSlotGroups.computeIfAbsent("feet", s -> new HashSet<>());
Set<String> offhand = trinketSlotGroups.computeIfAbsent("offhand", s -> new HashSet<>());

public Map<String, Entry> getEntries() {
return entries;
head.add("head");
chest.add("chest");
chest.add("heartcanisters");
legs.add("legs");
feet.add("feet");
offhand.add("hand");
offhand.add("offhand");
}

public boolean isShowHelp() {
Expand All @@ -94,20 +118,6 @@ public void setShowHelp(boolean showHelp) {
this.showHelp = showHelp;
}

public static class Debug {

private boolean backgroundOverlay = false;

public boolean isBackgroundOverlay() {
return backgroundOverlay;
}

public void setBackgroundOverlay(boolean backgroundOverlay) {
this.backgroundOverlay = backgroundOverlay;
}

}

public static class Entry {

private boolean enabled = true;
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/badasintended/cpas/mixin/MixinGameRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import badasintended.cpas.client.api.CpasTarget;
import badasintended.cpas.client.widget.ArmorPanelWidget;
import badasintended.cpas.client.widget.EditorScreenWidget;
import badasintended.cpas.config.CpasConfig;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
Expand All @@ -18,8 +17,6 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import static net.minecraft.client.gui.DrawableHelper.fill;

@Mixin(GameRenderer.class)
public abstract class MixinGameRenderer {

Expand Down Expand Up @@ -55,8 +52,6 @@ private void render(float tickDelta, long startTime, boolean tick, CallbackInfo
armorPanel.render(matrixStack, i, j, delta);
}
}
if (CpasConfig.get().debug.isBackgroundOverlay())
fill(matrixStack, a.getX(), a.getY(), a.getX() + a.getBackgroundWidth(), a.getY() + a.getBackgroundHeight(), 0x44FF00FF);
}
}

Expand Down

0 comments on commit 4d85ceb

Please sign in to comment.