Skip to content

Commit

Permalink
Add arrow key support for moving selected quests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatGravyBoat committed Nov 11, 2023
1 parent 89f29c8 commit 78353ac
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public class ItemRewardSettings implements SettingInitializer<ItemReward>, Custo
public CreationData create(@Nullable ItemReward object) {
CreationData settings = CustomizableQuestElementSettings.super.create(object);
settings.put("item", ItemSetting.NO_TAGS, getDefaultItem(object));
settings.put("count", IntSetting.ONE, getDefaultCount(object));
settings.put("amount", IntSetting.ONE, getDefaultCount(object));
return settings;
}

@Override
public ItemReward create(String id, @Nullable ItemReward object, Data data) {
ItemStack stack = data.get("item", ItemSetting.NO_TAGS).orElse(getDefaultItem(object))
.map(Function.identity(), key -> new ItemStack(Items.AIR));
stack.setCount(data.get("count", IntSetting.ONE).orElse(getDefaultCount(object)));
stack.setCount(data.get("amount", IntSetting.ONE).orElse(getDefaultCount(object)));
if (object != null) {
stack.setTag(object.stack().getTag());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,15 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double dra
return true;
}

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
MouseMode mode = this.mouseMode.get();
if (mode.canSelect() && this.selectHandler.onKeyPress(keyCode)) {
return true;
}
return super.keyPressed(keyCode, scanCode, modifiers);
}

@Override
public boolean isMouseOver(double mouseX, double mouseY) {
return mouseX >= this.x && mouseX <= this.x + this.width && mouseY >= this.y && mouseY <= this.y + this.height;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package earth.terrarium.heracles.client.screens.quests;

import com.mojang.blaze3d.platform.InputConstants;
import earth.terrarium.heracles.client.handlers.ClientQuests;
import earth.terrarium.heracles.client.screens.mousemode.MouseMode;
import earth.terrarium.heracles.common.network.NetworkHandler;
Expand Down Expand Up @@ -85,6 +86,41 @@ public void onDrag(int mouseX, int mouseY) {
}
}

public boolean onKeyPress(int key) {
int x = 0;
int y = 0;
switch (key) {
case InputConstants.KEY_UP -> y = -1;
case InputConstants.KEY_DOWN -> y = 1;
case InputConstants.KEY_LEFT -> x = -1;
case InputConstants.KEY_RIGHT -> x = 1;
}

if (Screen.hasShiftDown()) {
x *= 10;
y *= 10;
} else if (Screen.hasControlDown()) {
x *= 5;
y *= 5;
}

if (x == 0 && y == 0) return false;
if (selectedQuest == null) return false;

int newX = selectedQuest.x() + x;
int newY = selectedQuest.y() + y;

ClientQuests.updateQuest(selectedQuest.entry(), quest ->
NetworkQuestData.builder().group(quest, selectedQuest.group(), pos -> {
pos.x = newX;
pos.y = newY;
return pos;
}),
false
);
return true;
}

public QuestWidget selectedQuest() {
return selectedQuest;
}
Expand Down

0 comments on commit 78353ac

Please sign in to comment.