Skip to content

Commit

Permalink
Fix position updating and description saving
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatGravyBoat committed Nov 12, 2023
1 parent 78353ac commit 790c8b5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
6 changes: 3 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- Make it so that titles of quests are not synced back to the user that updated them (ThatGravyBoat)
- Make it so that position of quests are not synced back to the user that updated them (ThatGravyBoat)
- Make it so that the quest subtitles is not synced back to the user that updated it (ThatGravyBoat)
- Description content will be saved on resize (ThatGravyBoat)
- Added CTRL+S shortcut to save (ThatGravyBoat)
- Fixed position boxes sending packets back to you (ThatGravyBoat)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package earth.terrarium.heracles.client.screens.quest;

import com.mojang.blaze3d.platform.InputConstants;
import earth.terrarium.heracles.api.client.settings.SettingInitializer;
import earth.terrarium.heracles.api.client.settings.Settings;
import earth.terrarium.heracles.api.rewards.QuestReward;
Expand Down Expand Up @@ -29,6 +30,7 @@
import net.minecraft.client.gui.components.ImageButton;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -58,6 +60,18 @@ public void updateProgress(@Nullable QuestProgress newProgress) {
this.rewardList.update(this.content.fromGroup(), this.content.id(), this.quest());
}

@Override
protected void rebuildWidgets() {
var oldBox = this.descriptionBox;
ClientQuests.updateQuest(
entry(),
quest -> NetworkQuestData.builder().description(new ArrayList<>(this.descriptionBox.lines())),
false
);
super.rebuildWidgets();
this.descriptionBox.update(oldBox);
}

@Override
protected void init() {
super.init();
Expand Down Expand Up @@ -150,6 +164,7 @@ protected void init() {
this.descriptionBox = new QuestTextEditor(contentX, contentY, contentWidth, contentHeight);
this.descriptionBox.setContent(String.join("\n", this.quest().display().description()).replace("§", "&&"));


if (Minecraft.getInstance().isLocalServer()) {
addRenderableWidget(new ImageButton(this.width - 36, 1, 11, 11, 33, 59, 11, HEADING, 256, 256, (button) -> {
Path path = QuestHandler.getQuestPath(this.quest(), this.getQuestId());
Expand Down Expand Up @@ -202,6 +217,19 @@ private <T extends QuestReward<T>> void rewardPopup(QuestRewardType<T> type, Str
}
}

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (Screen.hasControlDown() && keyCode == InputConstants.KEY_S) {
ClientQuests.updateQuest(
entry(),
quest -> NetworkQuestData.builder().description(new ArrayList<>(this.descriptionBox.lines())),
false
);
return true;
}
return super.keyPressed(keyCode, scanCode, modifiers);
}

@Override
public void removed() {
super.removed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ public SelectQuestWidget(int x, int y, int width, int height, QuestsWidget widge

this.xBox = this.addChild(new PositionBox(this.font, this.x + 16, this.y + 44, boxWidth, 10, ConstantComponents.X));
this.yBox = this.addChild(new PositionBox(this.font, this.x + 33 + boxWidth, this.y + 44, boxWidth, 10, Component.literal("y")));
this.xBox.setNumberResponder(value -> updateQuest(quest -> NetworkQuestData.builder().group(quest, this.group, pos -> {
this.xBox.setNumberResponder(value -> ClientQuests.updateQuest(this.entry, quest -> NetworkQuestData.builder().group(quest, this.group, pos -> {
pos.x = value;
return pos;
})));
this.yBox.setNumberResponder(value -> updateQuest(quest -> NetworkQuestData.builder().group(quest, this.group, pos -> {
}), false));
this.yBox.setNumberResponder(value -> ClientQuests.updateQuest(this.entry, quest -> NetworkQuestData.builder().group(quest, this.group, pos -> {
pos.y = value;
return pos;
})));
}), false));

this.subtitleBox = this.addChild(new MultiLineEditBox(this.font, this.x + 6, this.y + 76, this.width - 12, 40, CommonComponents.EMPTY, CommonComponents.EMPTY));
this.subtitleBox.setValueListener(s -> ClientQuests.updateQuest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public TextEditor(int x, int y, int width, int height, int cursorColor, int line
this.lineNumColor = lineNumColor;
}

public void update(TextEditor editor) {
this.content.lines().clear();
this.content.lines().addAll(editor.content.lines());
this.content.cursor().set(editor.content.cursor());
this.content.setSelection(editor.content.selection());
}

public void setContent(String content) {
this.content.lines().clear();
this.content.lines().addAll(List.of(content.split("\n")));
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx2G

enabledPlatforms=fabric,forge

version=1.1.2
version=1.1.3
group=earth.terrarium.heracles

minecraftVersion=1.20.1
Expand Down

0 comments on commit 790c8b5

Please sign in to comment.