mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-26 06:53:20 +00:00
Quest Tracking Changes
This commit is contained in:
1 parent
294abe4d25
commit
c023071ff0
9 files changed
+429
-707
No files matched your search
@@ -0,0 +1,199 @@
|
||||
package noppes.npcs.client.gui.hud;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import noppes.npcs.config.ConfigClient;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class GuiOverlayQuestEditor extends GuiScreen {
|
||||
private GuiScreen parent;
|
||||
// posX and posY are stored as percentages (0-100) of the scaled resolution.
|
||||
private int posX, posY, scale, textAlign;
|
||||
private final int overlayWidth = 200, overlayHeight = 120;
|
||||
|
||||
private boolean dragging = false;
|
||||
private int dragOffsetX, dragOffsetY;
|
||||
private boolean resizing = false;
|
||||
private int initialScale, initialMouseX, initialMouseY;
|
||||
private final int HANDLE_SIZE = 10;
|
||||
|
||||
private GuiButton saveButton, alignButton, resetButton;
|
||||
|
||||
public GuiOverlayQuestEditor(GuiScreen parent) {
|
||||
this.parent = parent;
|
||||
// Load config values (stored as percentages)
|
||||
posX = ConfigClient.QuestOverlayX;
|
||||
posY = ConfigClient.QuestOverlayY;
|
||||
scale = ConfigClient.QuestOverlayScale;
|
||||
textAlign = ConfigClient.QuestOverlayTextAlign;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
buttonList.clear();
|
||||
saveButton = new GuiButton(0, width / 2 - 60, height - 45, 120, 20, "Save and Close");
|
||||
alignButton = new GuiButton(1, width / 2 - 60, height - 70, 120, 20, getAlignText());
|
||||
resetButton = new GuiButton(3, width / 2 - 60, height - 95, 120, 20, "Reset to Center");
|
||||
buttonList.add(saveButton);
|
||||
buttonList.add(alignButton);
|
||||
buttonList.add(resetButton);
|
||||
}
|
||||
|
||||
private String getAlignText() {
|
||||
switch (textAlign) {
|
||||
case 0: return "Align: Left";
|
||||
case 1: return "Align: Center";
|
||||
case 2: return "Align: Right";
|
||||
default: return "Align: Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
drawDefaultBackground();
|
||||
ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int actualX = (int) ((float) posX / 100F * res.getScaledWidth());
|
||||
int actualY = (int) ((float) posY / 100F * res.getScaledHeight());
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(actualX, actualY, 0);
|
||||
float s = scale / 100.0F;
|
||||
GL11.glScalef(s, s, s);
|
||||
|
||||
// Draw preview background
|
||||
drawRect(0, 0, overlayWidth, overlayHeight, 0x40FFFFFF);
|
||||
|
||||
int currentY = 5;
|
||||
currentY = renderDemoTextBlock(new String[] { "Dummy Quest Title" }, currentY, textAlign, 0xFFFFFF);
|
||||
drawDecorativeLine(currentY - 1);
|
||||
currentY += 8;
|
||||
|
||||
currentY = renderDemoTextBlock(new String[] { "Dummy Category" }, currentY, textAlign, 0xCCCCCC);
|
||||
drawDecorativeLine(currentY - 1);
|
||||
currentY += 8;
|
||||
|
||||
currentY = renderDemoTextBlock(new String[] { "Objective: Kill 10 mobs", "Objective: Collect 5 items" }, currentY, textAlign, 0xAAAAAA);
|
||||
drawDecorativeLine(currentY - 1);
|
||||
currentY += 8;
|
||||
|
||||
renderDemoTextBlock(new String[] { "Turn in with NPC" }, currentY, textAlign, 0xAAAAAA);
|
||||
|
||||
// Draw resize handle at bottom-right
|
||||
drawRect(overlayWidth - HANDLE_SIZE, overlayHeight - HANDLE_SIZE, overlayWidth, overlayHeight, 0xFFCCCCCC);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
private int renderDemoTextBlock(String[] lines, int startY, int align, int color) {
|
||||
int y = startY;
|
||||
FontRenderer font = Minecraft.getMinecraft().fontRenderer;
|
||||
for (String line : lines) {
|
||||
int strWidth = font.getStringWidth(line);
|
||||
int xOffset;
|
||||
if (align == 1)
|
||||
xOffset = (overlayWidth - strWidth) / 2;
|
||||
else if (align == 2)
|
||||
xOffset = overlayWidth - strWidth - 5;
|
||||
else
|
||||
xOffset = 5;
|
||||
font.drawStringWithShadow(line, xOffset, y, color);
|
||||
y += font.FONT_HEIGHT + 4;
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
private void drawDecorativeLine(int y) {
|
||||
drawHorizontalLine(5, overlayWidth - 5, y, 0xFF777777);
|
||||
drawHorizontalLine(5, overlayWidth - 5, y + 1, 0xFFA8A8A8);
|
||||
drawHorizontalLine(5, overlayWidth - 5, y + 2, 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int actualX = (int) ((float) posX / 100F * res.getScaledWidth());
|
||||
int actualY = (int) ((float) posY / 100F * res.getScaledHeight());
|
||||
float s = scale / 100.0F;
|
||||
int absWidth = (int) (overlayWidth * s);
|
||||
int absHeight = (int) (overlayHeight * s);
|
||||
if (mouseX >= actualX && mouseX <= actualX + absWidth &&
|
||||
mouseY >= actualY && mouseY <= actualY + absHeight) {
|
||||
// Check if within resize handle
|
||||
if (mouseX >= actualX + absWidth - HANDLE_SIZE && mouseY >= actualY + absHeight - HANDLE_SIZE) {
|
||||
resizing = true;
|
||||
initialScale = scale;
|
||||
initialMouseX = mouseX;
|
||||
initialMouseY = mouseY;
|
||||
} else {
|
||||
dragging = true;
|
||||
dragOffsetX = mouseX - actualX;
|
||||
dragOffsetY = mouseY - actualY;
|
||||
}
|
||||
}
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
// For Minecraft 1.7.10, use mouseMovedOrUp for button release.
|
||||
@Override
|
||||
protected void mouseMovedOrUp(int mouseX, int mouseY, int state) {
|
||||
dragging = false;
|
||||
resizing = false;
|
||||
super.mouseMovedOrUp(mouseX, mouseY, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int scaledWidth = res.getScaledWidth();
|
||||
int scaledHeight = res.getScaledHeight();
|
||||
// Calculate absolute dimensions for the overlay preview
|
||||
int absWidth = (int) (overlayWidth * (scale / 100.0F));
|
||||
int absHeight = (int) (overlayHeight * (scale / 100.0F));
|
||||
|
||||
if (dragging) {
|
||||
// Compute new absolute position in pixels
|
||||
int newX = Mouse.getX() * width / mc.displayWidth - dragOffsetX;
|
||||
int newY = scaledHeight - (Mouse.getY() * scaledHeight / mc.displayHeight) - dragOffsetY;
|
||||
// Clamp the absolute position so that the overlay stays fully on screen
|
||||
if (newX < 0) newX = 0;
|
||||
if (newY < 0) newY = 0;
|
||||
if (newX + absWidth > scaledWidth) newX = scaledWidth - absWidth;
|
||||
if (newY + absHeight > scaledHeight) newY = scaledHeight - absHeight;
|
||||
// Convert back to percentage values
|
||||
posX = (int) (100F * newX / scaledWidth);
|
||||
posY = (int) (100F * newY / scaledHeight);
|
||||
}
|
||||
if (resizing) {
|
||||
int currentMouseX = Mouse.getX() * width / mc.displayWidth;
|
||||
int deltaX = currentMouseX - initialMouseX;
|
||||
scale = initialScale + deltaX; // 1 pixel = 1% change
|
||||
if (scale < 50) scale = 50;
|
||||
if (scale > 300) scale = 300;
|
||||
}
|
||||
super.updateScreen();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
if (button.id == 0) { // Save and close
|
||||
ConfigClient.QuestOverlayX = posX;
|
||||
ConfigClient.QuestOverlayY = posY;
|
||||
ConfigClient.QuestOverlayScale = scale;
|
||||
ConfigClient.QuestOverlayTextAlign = textAlign;
|
||||
if (ConfigClient.config.hasChanged())
|
||||
ConfigClient.config.save();
|
||||
mc.displayGuiScreen(parent);
|
||||
} else if (button.id == 1) { // Cycle alignment
|
||||
textAlign = (textAlign + 1) % 3;
|
||||
button.displayString = getAlignText();
|
||||
} else if (button.id == 3) { // Reset to center
|
||||
posX = 50;
|
||||
posY = 50;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
package noppes.npcs.client.gui.hud;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.config.ConfigClient;
|
||||
import noppes.npcs.controllers.data.Quest;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class OverlayQuestTracking extends Gui {
|
||||
private Minecraft mc;
|
||||
|
||||
// Dimensions for overlay background
|
||||
private int overlayWidth = 200;
|
||||
private int overlayHeight = 120;
|
||||
|
||||
// Text lists for each section
|
||||
private ArrayList<String> questTitleLines = new ArrayList<>();
|
||||
private ArrayList<String> questCategoryLines = new ArrayList<>();
|
||||
private ArrayList<String> objectiveLines = new ArrayList<>();
|
||||
private ArrayList<String> turnInLines = new ArrayList<>();
|
||||
|
||||
public OverlayQuestTracking(Minecraft mc) {
|
||||
this.mc = mc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates overlay text based on quest data.
|
||||
* Converts "&" codes into Minecraft formatting codes.
|
||||
*/
|
||||
public void setQuestData(Quest quest, String category, List<String> objectives, String turnIn) {
|
||||
questTitleLines = splitLines(convertColorCodes(quest.getName()), overlayWidth - 10);
|
||||
questCategoryLines = splitLines(convertColorCodes(category), overlayWidth - 10);
|
||||
objectiveLines.clear();
|
||||
for (String obj : objectives) {
|
||||
objectiveLines.add(convertColorCodes(obj));
|
||||
}
|
||||
turnInLines.clear();
|
||||
if (turnIn != null && !turnIn.isEmpty()) {
|
||||
turnInLines.add(convertColorCodes(turnIn));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads overlay data from an NBT compound and updates the overlay.
|
||||
*/
|
||||
public void setOverlayData(NBTTagCompound compound) {
|
||||
Quest quest = new Quest();
|
||||
quest.readNBT(compound.getCompoundTag("Quest"));
|
||||
String category = compound.getString("CategoryName");
|
||||
|
||||
ArrayList<String> objectives = new ArrayList<>();
|
||||
NBTTagList objectiveList = compound.getTagList("ObjectiveList", 8);
|
||||
for (int i = 0; i < objectiveList.tagCount(); i++) {
|
||||
String objective = objectiveList.getStringTagAt(i);
|
||||
String[] split = objective.split(":");
|
||||
split = split[split.length - 1].split("/");
|
||||
boolean completed = false;
|
||||
try {
|
||||
if (split.length < 2)
|
||||
throw new NumberFormatException("Insufficient data");
|
||||
int killed = Integer.parseInt(split[0].trim());
|
||||
int total = Integer.parseInt(split[1].trim());
|
||||
if (killed / total == 1)
|
||||
completed = true;
|
||||
} catch (NumberFormatException e) {
|
||||
if (objective.endsWith("(Done)") || objective.endsWith("(read)") ||
|
||||
(objective.endsWith("Found") && !objective.endsWith("Not Found")))
|
||||
completed = true;
|
||||
}
|
||||
if (completed) {
|
||||
objective = "&a&o&m" + objective;
|
||||
} else {
|
||||
objective = "&o" + objective;
|
||||
}
|
||||
objectives.add(objective);
|
||||
}
|
||||
|
||||
String turnIn = "";
|
||||
boolean instantComplete = compound.getBoolean("Instant");
|
||||
if (instantComplete) {
|
||||
turnIn = "Completed automatically";
|
||||
} else {
|
||||
String npcName = compound.getString("TurnInNPC");
|
||||
if (!npcName.isEmpty()) {
|
||||
turnIn = "Complete with " + npcName;
|
||||
}
|
||||
}
|
||||
setQuestData(quest, category, objectives, turnIn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the overlay using the current configuration settings.
|
||||
* Here, posX and posY (from config, treated as percentages) are used relative to the current scaled resolution.
|
||||
*/
|
||||
public void renderOverlay(float partialTicks) {
|
||||
ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int actualX = (int) ((float) ConfigClient.QuestOverlayX / 100F * res.getScaledWidth());
|
||||
int actualY = (int) ((float) ConfigClient.QuestOverlayY / 100F * res.getScaledHeight());
|
||||
float s = ConfigClient.QuestOverlayScale / 100.0F;
|
||||
int textAlign = ConfigClient.QuestOverlayTextAlign; // 0: left, 1: center, 2: right
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(actualX, actualY, 0);
|
||||
GL11.glScalef(s, s, s);
|
||||
|
||||
// Draw a lighter, semi-transparent background
|
||||
drawRect(0, 0, overlayWidth, overlayHeight, 0x40FFFFFF);
|
||||
|
||||
int currentY = 5;
|
||||
currentY = renderTextBlock(questTitleLines, currentY, textAlign, 0xFFFFFF);
|
||||
drawDecorativeLine(currentY - 1);
|
||||
currentY += 8;
|
||||
|
||||
currentY = renderTextBlock(questCategoryLines, currentY, textAlign, 0xCCCCCC);
|
||||
drawDecorativeLine(currentY - 1);
|
||||
currentY += 8;
|
||||
|
||||
currentY = renderTextBlock(objectiveLines, currentY, textAlign, 0xAAAAAA);
|
||||
if (!turnInLines.isEmpty()) {
|
||||
drawDecorativeLine(currentY - 1);
|
||||
currentY += 8;
|
||||
}
|
||||
|
||||
renderTextBlock(turnInLines, currentY, textAlign, 0xAAAAAA);
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
private int renderTextBlock(List<String> lines, int startY, int align, int color) {
|
||||
int y = startY;
|
||||
FontRenderer font = mc.fontRenderer;
|
||||
for (String line : lines) {
|
||||
int strWidth = font.getStringWidth(line);
|
||||
int xOffset;
|
||||
if (align == 1)
|
||||
xOffset = (overlayWidth - strWidth) / 2;
|
||||
else if (align == 2)
|
||||
xOffset = overlayWidth - strWidth - 5;
|
||||
else
|
||||
xOffset = 5;
|
||||
font.drawStringWithShadow(line, xOffset, y, color);
|
||||
y += font.FONT_HEIGHT + 4;
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
private void drawDecorativeLine(int y) {
|
||||
int lineStart = 5;
|
||||
int lineEnd = overlayWidth - 5;
|
||||
drawHorizontalLine(lineStart, lineEnd, y, 0xFF777777);
|
||||
drawHorizontalLine(lineStart, lineEnd, y + 1, 0xFFA8A8A8);
|
||||
drawHorizontalLine(lineStart, lineEnd, y + 2, 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
private ArrayList<String> splitLines(String text, int maxWidth) {
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
String[] words = text.split(" ");
|
||||
StringBuilder current = new StringBuilder();
|
||||
FontRenderer font = mc.fontRenderer;
|
||||
for (String word : words) {
|
||||
String test = current.length() == 0 ? word : current.toString() + " " + word;
|
||||
if (font.getStringWidth(test) > maxWidth) {
|
||||
if (current.length() > 0) {
|
||||
lines.add(current.toString());
|
||||
current = new StringBuilder(word);
|
||||
} else {
|
||||
lines.add(word);
|
||||
}
|
||||
} else {
|
||||
if (current.length() > 0)
|
||||
current.append(" ").append(word);
|
||||
else
|
||||
current.append(word);
|
||||
}
|
||||
}
|
||||
if (current.length() > 0)
|
||||
lines.add(current.toString());
|
||||
return lines;
|
||||
}
|
||||
|
||||
private String convertColorCodes(String text) {
|
||||
return text.replaceAll("&([0-9a-fk-or])", "§$1");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user