Skip to content

Commit

Permalink
Add context menu base for group editing
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatGravyBoat committed Nov 9, 2023
1 parent b8751cc commit 7bfc308
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package earth.terrarium.heracles.client.screens;

import com.mojang.blaze3d.systems.RenderSystem;
import com.teamresourceful.resourcefullib.client.screens.BaseCursorScreen;
import com.teamresourceful.resourcefullib.client.screens.PriorityScreen;
import earth.terrarium.heracles.Heracles;
import earth.terrarium.heracles.client.utils.ClientUtils;
import earth.terrarium.heracles.client.widgets.base.TemporyWidget;
Expand All @@ -22,7 +22,7 @@
import java.util.ArrayList;
import java.util.List;

public abstract class AbstractQuestScreen<T> extends BaseCursorScreen {
public abstract class AbstractQuestScreen<T> extends PriorityScreen {

public static final ResourceLocation HEADING = new ResourceLocation(Heracles.MOD_ID, "textures/gui/heading.png");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package earth.terrarium.heracles.client.screens.quests;

import com.mojang.blaze3d.platform.InputConstants;
import com.teamresourceful.resourcefullib.client.components.context.ContextualMenuScreen;
import com.teamresourceful.resourcefullib.client.components.selection.ListEntry;
import com.teamresourceful.resourcefullib.client.components.selection.SelectionList;
import com.teamresourceful.resourcefullib.client.scissor.ScissorBoxStack;
import com.teamresourceful.resourcefullib.client.screens.CursorScreen;
import com.teamresourceful.resourcefullib.client.utils.CursorUtils;
import com.teamresourceful.resourcefullib.client.utils.ScreenUtils;
import earth.terrarium.heracles.client.handlers.ClientQuests;
import earth.terrarium.heracles.client.utils.ClientUtils;
import earth.terrarium.heracles.client.utils.MouseClick;
import earth.terrarium.heracles.common.constants.ConstantComponents;
import earth.terrarium.heracles.common.network.NetworkHandler;
import earth.terrarium.heracles.common.network.packets.groups.DeleteGroupPacket;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -22,9 +27,13 @@
public class GroupsList extends SelectionList<GroupsList.Entry> {

private final int width;
private final Consumer<@Nullable Entry> onSelection;
private final int x;

public GroupsList(int x, int y, int width, int height, Consumer<@Nullable Entry> onSelection) {
super(x, y, width, height, 20, onSelection, true);
super(x, y, width, height, 20, entry -> {}, true);
this.x = x;
this.onSelection = onSelection;
this.width = width;
}

Expand Down Expand Up @@ -100,7 +109,7 @@ protected void render(@NotNull GuiGraphics graphics, @NotNull ScissorBoxStack sc
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
boolean cant = !ClientQuests.byGroup(name).isEmpty() || this.list.children().size() == 1;
if (Minecraft.getInstance().screen instanceof QuestsEditScreen screen && button == 0 && !cant) {
if (Minecraft.getInstance().screen instanceof QuestsEditScreen screen && button == InputConstants.MOUSE_BUTTON_LEFT && !cant) {
boolean closingButton = mouseX >= this.list.width - 11 && mouseX <= this.list.width - 2 && mouseY >= 2 && mouseY <= 12;
if (closingButton) {
screen.confirmModal().setVisible(true);
Expand All @@ -121,6 +130,24 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
return true;
}
}
if (button == InputConstants.MOUSE_BUTTON_RIGHT) {
MouseClick mouse = ClientUtils.getMousePos();
ContextualMenuScreen.getMenu()
.ifPresent(menu -> menu.start(this.list.x + this.list.width + 6, mouse.y())
.addOption(Component.literal("\uD83D\uDDBC Edit Icon"), () ->
System.out.println("Edit Icon") //TODO
)
.addDivider()
.addOption(Component.literal("⬆ Move Up"), () ->
System.out.println("Move UP") //TODO
)
.addOption(Component.literal("⬇ Move Down"), () ->
System.out.println("Move Down") //TODO
)
.open());
return true;
}
this.list.onSelection.accept(this);
return super.mouseClicked(mouseX, mouseY, button);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package earth.terrarium.heracles.client.screens.quests;

import com.mojang.blaze3d.platform.InputConstants;
import com.teamresourceful.resourcefullib.client.components.context.ContextualMenuScreen;
import com.teamresourceful.resourcefullib.client.components.context.ContextMenu;
import earth.terrarium.heracles.api.quests.GroupDisplay;
import earth.terrarium.heracles.api.quests.Quest;
import earth.terrarium.heracles.api.quests.QuestDisplay;
Expand Down Expand Up @@ -33,7 +35,7 @@
import java.util.HashSet;
import java.util.Locale;

public class QuestsEditScreen extends QuestsScreen {
public class QuestsEditScreen extends QuestsScreen implements ContextualMenuScreen {

private SelectableImageButton moveTool;
private SelectableImageButton dragTool;
Expand All @@ -47,6 +49,8 @@ public class QuestsEditScreen extends QuestsScreen {
private AddDependencyModal dependencyModal;
private TextInputModal<MouseClick> questModal;

private ContextMenu contextMenu;

public QuestsEditScreen(QuestsContent content) {
super(content);
}
Expand Down Expand Up @@ -121,6 +125,8 @@ protected void init() {
);
this.questsWidget.addQuest(ClientQuestNetworking.add(text, quest));
}, text -> text.toLowerCase(Locale.ROOT).replaceAll("[^a-zA-Z_-]", "").length() >= 2 && ClientQuests.get(text.trim()).isEmpty()));

this.contextMenu = addRenderableWidget(-1, new ContextMenu());
}

@Override
Expand Down Expand Up @@ -214,4 +220,9 @@ public AddDependencyModal dependencyModal() {
public TextInputModal<MouseClick> questModal() {
return this.questModal;
}

@Override
public ContextMenu getContextMenu() {
return this.contextMenu;
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ group=earth.terrarium.heracles
minecraftVersion=1.20.1
parchmentVersion=2023.07.02

resourcefulLibVersion=2.1.13
resourcefulLibVersion=2.1.16
hermesLibVersion=1.2.1
reiVersion=12.0.630

0 comments on commit 7bfc308

Please sign in to comment.