mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-25 14:34:52 +00:00
Better Filename Handling for Abilities, Dash Directional Improvements, Fixed Duplicate Ability Name Handling
This commit is contained in:
1 parent
71dbf77def
commit
3de8cd49b6
23 files changed
+752
-178
No files matched your search
@@ -84,8 +84,12 @@ public class SubGuiAbilitySaveConfirm extends SubGuiInterface implements ISubGui
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
if (subgui instanceof SubGuiDuplicateNameConfirm) {
|
||||
if (((SubGuiDuplicateNameConfirm) subgui).isConfirmed()) {
|
||||
SubGuiDuplicateNameConfirm confirm = (SubGuiDuplicateNameConfirm) subgui;
|
||||
if (confirm.isConfirmed()) {
|
||||
doSave();
|
||||
} else if (confirm.isBack()) {
|
||||
// Keep this save-confirm dialog open.
|
||||
return;
|
||||
} else {
|
||||
close();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,13 @@ import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
*/
|
||||
public class SubGuiDuplicateNameConfirm extends SubGuiInterface {
|
||||
|
||||
private boolean confirmed = false;
|
||||
public enum Result {
|
||||
CONTINUE,
|
||||
BACK,
|
||||
CANCEL
|
||||
}
|
||||
|
||||
private Result result = Result.CANCEL;
|
||||
|
||||
public SubGuiDuplicateNameConfirm() {
|
||||
setBackground("menubg.png");
|
||||
@@ -26,22 +32,38 @@ public class SubGuiDuplicateNameConfirm extends SubGuiInterface {
|
||||
addLabel(new GuiNpcLabel(0, "ability.duplicate.name", guiLeft + 10, y));
|
||||
|
||||
y += 30;
|
||||
addButton(new GuiNpcButton(0, guiLeft + 20, y, 80, 20, "gui.continue"));
|
||||
addButton(new GuiNpcButton(1, guiLeft + 120, y, 80, 20, "gui.cancel"));
|
||||
addButton(new GuiNpcButton(0, guiLeft + 10, y, 65, 20, "gui.continue"));
|
||||
addButton(new GuiNpcButton(1, guiLeft + 78, y, 65, 20, "gui.back"));
|
||||
addButton(new GuiNpcButton(2, guiLeft + 146, y, 65, 20, "gui.cancel"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
if (guibutton.id == 0) {
|
||||
confirmed = true;
|
||||
result = Result.CONTINUE;
|
||||
close();
|
||||
} else if (guibutton.id == 1) {
|
||||
confirmed = false;
|
||||
result = Result.BACK;
|
||||
close();
|
||||
} else if (guibutton.id == 2) {
|
||||
result = Result.CANCEL;
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isConfirmed() {
|
||||
return confirmed;
|
||||
return result == Result.CONTINUE;
|
||||
}
|
||||
|
||||
public boolean isBack() {
|
||||
return result == Result.BACK;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return result == Result.CANCEL;
|
||||
}
|
||||
}
|
||||
@@ -245,6 +245,9 @@ public class GuiFieldBuilder {
|
||||
case STRING: {
|
||||
String sVal = def.getValue() != null ? def.getValue().toString() : "";
|
||||
GuiNpcTextField tf = new GuiNpcTextField(widgetId, parent, fontRenderer, fieldX, y, fieldW, 20, sVal);
|
||||
if ("gui.name".equals(def.getLabel())) {
|
||||
tf.setFileNameSafe();
|
||||
}
|
||||
if (!def.isEnabled()) tf.setEnabled(false);
|
||||
if (hover != null) tf.setHoverText(hover);
|
||||
sw.addTextField(tf);
|
||||
|
||||
@@ -104,7 +104,6 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
// ==================== PENDING SAVE ====================
|
||||
private Ability pendingSaveAbility = null;
|
||||
private boolean pendingNewCreation = false;
|
||||
|
||||
// ==================== PENDING VARIANT ====================
|
||||
private String pendingTypeId = null;
|
||||
@@ -511,13 +510,6 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
Ability newAbility = AbilityController.Instance.create(pendingTypeId);
|
||||
if (newAbility != null) {
|
||||
gui.getVariants().get(idx).apply(newAbility);
|
||||
if (hasDuplicateName(newAbility)) {
|
||||
pendingSaveAbility = newAbility;
|
||||
pendingNewCreation = true;
|
||||
pendingTypeId = null;
|
||||
setSubGui(new SubGuiDuplicateNameConfirm());
|
||||
return true;
|
||||
}
|
||||
pendingTypeId = null;
|
||||
openConfig(newAbility);
|
||||
return true;
|
||||
@@ -544,12 +536,6 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
if (variants.size() == 1) {
|
||||
variants.get(0).apply(newAbility);
|
||||
}
|
||||
if (hasDuplicateName(newAbility)) {
|
||||
pendingSaveAbility = newAbility;
|
||||
pendingNewCreation = true;
|
||||
setSubGui(new SubGuiDuplicateNameConfirm());
|
||||
return true;
|
||||
}
|
||||
openConfig(newAbility);
|
||||
return true;
|
||||
}
|
||||
@@ -561,27 +547,22 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
* @return true if a SubGui was opened (caller should return early, skipping initGui)
|
||||
*/
|
||||
private boolean handleDuplicateNameClosed(SubGuiDuplicateNameConfirm gui) {
|
||||
if (gui.isConfirmed() && pendingSaveAbility != null) {
|
||||
if (pendingNewCreation) {
|
||||
openConfig(pendingSaveAbility);
|
||||
pendingSaveAbility = null;
|
||||
pendingNewCreation = false;
|
||||
return true;
|
||||
} else {
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT()));
|
||||
pendingSaveAbility = null;
|
||||
}
|
||||
} else if (pendingSaveAbility != null) {
|
||||
if (pendingNewCreation) {
|
||||
pendingSaveAbility = null;
|
||||
pendingNewCreation = false;
|
||||
} else {
|
||||
Ability ability = pendingSaveAbility;
|
||||
pendingSaveAbility = null;
|
||||
setSubGui(ability.createConfigGui(this));
|
||||
return true;
|
||||
}
|
||||
if (pendingSaveAbility == null) return false;
|
||||
|
||||
if (gui.isConfirmed()) {
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT()));
|
||||
pendingSaveAbility = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (gui.isBack()) {
|
||||
Ability ability = pendingSaveAbility;
|
||||
pendingSaveAbility = null;
|
||||
setSubGui(ability.createConfigGui(this));
|
||||
return true;
|
||||
}
|
||||
|
||||
pendingSaveAbility = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -590,7 +571,6 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
*/
|
||||
private boolean handlePendingSave() {
|
||||
if (hasDuplicateName(pendingSaveAbility)) {
|
||||
pendingNewCreation = false;
|
||||
setSubGui(new SubGuiDuplicateNameConfirm());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.packets.player.ability.AbilityHotbarSelectPacket;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import noppes.npcs.client.ClientProxy;
|
||||
import noppes.npcs.client.ClientAbilityState;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
@@ -189,6 +190,7 @@ public class AbilityHotbarComponent extends HudComponent {
|
||||
|
||||
int centerX = overlayWidth / 2;
|
||||
int centerY = overlayHeight / 2;
|
||||
boolean activePhase = ClientAbilityState.activePhase;
|
||||
|
||||
// Compute text visibility: 0=Shown, 1=Hidden, 2=Held
|
||||
boolean showText;
|
||||
@@ -246,16 +248,16 @@ public class AbilityHotbarComponent extends HudComponent {
|
||||
|
||||
if (rawSlotIndex == -1) {
|
||||
// Deselect slot — draw empty marker
|
||||
drawDeselectSlot(cx, cy, scaledSize, isCenter, slotAlpha);
|
||||
drawDeselectSlot(cx, cy, scaledSize, isCenter, slotAlpha, activePhase);
|
||||
} else {
|
||||
slots[rawSlotIndex].drawCarousel(mc, sr, slotCooldown, cx, cy, scaledSize, isCenter, slotAlpha, showText);
|
||||
slots[rawSlotIndex].drawCarousel(mc, sr, slotCooldown, cx, cy, scaledSize, isCenter, slotAlpha, showText, activePhase);
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
private void drawDeselectSlot(int cx, int cy, int size, boolean isCenter, float alpha) {
|
||||
private void drawDeselectSlot(int cx, int cy, int size, boolean isCenter, float alpha, boolean activePhase) {
|
||||
float radius = size / 2f;
|
||||
float baseAlpha = isCenter ? 0.9f : 0.6f;
|
||||
float a = baseAlpha * alpha;
|
||||
@@ -268,7 +270,13 @@ public class AbilityHotbarComponent extends HudComponent {
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
if (isCenter) {
|
||||
if (activePhase) {
|
||||
if (isCenter) {
|
||||
GL11.glColor4f(0.65f, 0.14f, 0.14f, a);
|
||||
} else {
|
||||
GL11.glColor4f(0.38f, 0.10f, 0.10f, a);
|
||||
}
|
||||
} else if (isCenter) {
|
||||
GL11.glColor4f(0.5f, 0.2f, 0.2f, a);
|
||||
} else {
|
||||
GL11.glColor4f(0.3f, 0.3f, 0.3f, a);
|
||||
@@ -292,7 +300,13 @@ public class AbilityHotbarComponent extends HudComponent {
|
||||
}
|
||||
|
||||
// Draw X mark
|
||||
if (isCenter) {
|
||||
if (activePhase) {
|
||||
if (isCenter) {
|
||||
GL11.glColor4f(1.0f, 0.45f, 0.35f, alpha);
|
||||
} else {
|
||||
GL11.glColor4f(0.75f, 0.30f, 0.30f, alpha * 0.8f);
|
||||
}
|
||||
} else if (isCenter) {
|
||||
GL11.glColor4f(0.8f, 0.4f, 0.4f, alpha);
|
||||
} else {
|
||||
GL11.glColor4f(0.5f, 0.5f, 0.5f, alpha * 0.8f);
|
||||
|
||||
@@ -48,7 +48,7 @@ public class AbilityHotbarSlotRenderer extends Gui {
|
||||
|
||||
public void drawCarousel(Minecraft mc, ScaledResolution sr, float cooldownProgress,
|
||||
int cx, int cy, int size, boolean isCenter, float slotAlpha,
|
||||
boolean showText) {
|
||||
boolean showText, boolean activePhase) {
|
||||
float nameAlpha = this.nameAlpha;
|
||||
boolean isHorizontal = ConfigClient.AbilityHotbarHorizontal;
|
||||
if (size <= 0 || slotAlpha <= 0) return;
|
||||
@@ -61,21 +61,54 @@ public class AbilityHotbarSlotRenderer extends Gui {
|
||||
|
||||
boolean altTexture = ConfigClient.AbilityHotbarAltTexture;
|
||||
|
||||
if (altTexture) {
|
||||
drawRoundedRect(-radius, -radius, radius, radius, 0.6f, 0.6f, 0.6f, 0.75f * alpha, false);
|
||||
float fillR;
|
||||
float fillG;
|
||||
float fillB;
|
||||
float outlineR;
|
||||
float outlineG;
|
||||
float outlineB;
|
||||
|
||||
if (activePhase) {
|
||||
if (isCenter) {
|
||||
drawRoundedRect(-radius, -radius, radius, radius, 0.8f, 0.8f, 0.2f, alpha, true);
|
||||
fillR = 0.95f;
|
||||
fillG = 0.26f;
|
||||
fillB = 0.22f;
|
||||
outlineR = 1.0f;
|
||||
outlineG = 0.52f;
|
||||
outlineB = 0.28f;
|
||||
} else {
|
||||
drawRoundedRect(-radius, -radius, radius, radius, 0.4f, 0.4f, 0.4f, alpha * 0.8f, true);
|
||||
fillR = 0.36f;
|
||||
fillG = 0.14f;
|
||||
fillB = 0.14f;
|
||||
outlineR = 0.65f;
|
||||
outlineG = 0.22f;
|
||||
outlineB = 0.20f;
|
||||
}
|
||||
} else if (isCenter) {
|
||||
fillR = 0.8f;
|
||||
fillG = 0.8f;
|
||||
fillB = 0.2f;
|
||||
outlineR = 0.8f;
|
||||
outlineG = 0.8f;
|
||||
outlineB = 0.2f;
|
||||
} else {
|
||||
if (isCenter) {
|
||||
drawCircle(radius, 0.8f, 0.8f, 0.2f, 0.66f * alpha, false);
|
||||
drawCircle(radius, 0.8f, 0.8f, 0.2f, alpha, true);
|
||||
} else {
|
||||
drawCircle(radius, 1f, 1f, 1f, 0.66f * alpha, false);
|
||||
drawCircle(radius, 0.4f, 0.4f, 0.4f, alpha * 0.8f, true);
|
||||
}
|
||||
fillR = 0.4f;
|
||||
fillG = 0.4f;
|
||||
fillB = 0.4f;
|
||||
outlineR = 1f;
|
||||
outlineG = 1f;
|
||||
outlineB = 1f;
|
||||
}
|
||||
|
||||
if (altTexture) {
|
||||
float baseR = activePhase ? 0.30f : 0.6f;
|
||||
float baseG = activePhase ? 0.12f : 0.6f;
|
||||
float baseB = activePhase ? 0.12f : 0.6f;
|
||||
drawRoundedRect(-radius, -radius, radius, radius, baseR, baseG, baseB, 0.75f * alpha, false);
|
||||
drawRoundedRect(-radius, -radius, radius, radius, fillR, fillG, fillB, alpha * 0.8f, true);
|
||||
} else {
|
||||
drawCircle(radius, outlineR, outlineG, outlineB, 0.66f * alpha, false);
|
||||
drawCircle(radius, fillR, fillG, fillB, alpha * 0.8f, true);
|
||||
}
|
||||
|
||||
// Ability icon
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
import kamkeel.npcs.util.TextSplitter;
|
||||
import kamkeel.npcs.util.FileNameHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
@@ -26,6 +27,7 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
public float minFloat = 0, maxFloat = Float.MAX_VALUE, defFloat = 0;
|
||||
protected static GuiNpcTextField activeTextfield = null;
|
||||
public boolean canEdit = true;
|
||||
private boolean fileNameSafe = false;
|
||||
public String hoverableText = "";
|
||||
private boolean wasHovered = false;
|
||||
private int hoverCount = 0;
|
||||
@@ -71,6 +73,11 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
public boolean textboxKeyTyped(char c, int i) {
|
||||
if (!canEdit || !isFocused())
|
||||
return false;
|
||||
|
||||
if (fileNameSafe && !GuiScreen.isCtrlKeyDown() && !isFileNameCharAllowed(c, i)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Allow Ctrl shortcuts (select all, copy, paste, cut) to bypass char filter
|
||||
if (GuiScreen.isCtrlKeyDown()) {
|
||||
// For Ctrl+V (paste) on numeric fields, filter clipboard to valid chars
|
||||
@@ -87,7 +94,17 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return super.textboxKeyTyped(c, i);
|
||||
if (i == 47 && fileNameSafe) {
|
||||
String clipboard = GuiScreen.getClipboardString();
|
||||
if (clipboard != null) {
|
||||
String filtered = filterFileNameClipboard(clipboard);
|
||||
if (!filtered.isEmpty())
|
||||
writeText(filtered);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
boolean handled = super.textboxKeyTyped(c, i);
|
||||
return handled;
|
||||
}
|
||||
if (!charAllowed(c, i))
|
||||
return false;
|
||||
@@ -179,6 +196,9 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
else if (getFloat() > maxFloat)
|
||||
setText(maxFloat + "");
|
||||
}
|
||||
if (fileNameSafe) {
|
||||
normalizeFileNameText();
|
||||
}
|
||||
setCursorPositionZero();
|
||||
if (listener != null)
|
||||
listener.unFocused(this);
|
||||
@@ -238,6 +258,51 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
return this;
|
||||
}
|
||||
|
||||
public GuiNpcTextField setFileNameSafe() {
|
||||
fileNameSafe = true;
|
||||
normalizeFileNameText();
|
||||
return this;
|
||||
}
|
||||
|
||||
private boolean isSpecialNavigationKey(int keyCode) {
|
||||
for (int allowed : allowedSpecialChars) {
|
||||
if (allowed == keyCode) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isFileNameCharAllowed(char c, int keyCode) {
|
||||
if (isSpecialNavigationKey(keyCode) || c < 32) {
|
||||
return true;
|
||||
}
|
||||
return Character.isLetterOrDigit(c) || c == '_' || c == '-' || c == ' ';
|
||||
}
|
||||
|
||||
private String filterFileNameClipboard(String clipboard) {
|
||||
StringBuilder filtered = new StringBuilder(clipboard.length());
|
||||
for (int idx = 0; idx < clipboard.length(); idx++) {
|
||||
char c = clipboard.charAt(idx);
|
||||
if (Character.isLetterOrDigit(c) || c == '_' || c == '-') {
|
||||
filtered.append(c);
|
||||
} else if (Character.isWhitespace(c)) {
|
||||
filtered.append(' ');
|
||||
}
|
||||
}
|
||||
return filtered.toString();
|
||||
}
|
||||
|
||||
private void normalizeFileNameText() {
|
||||
String current = getText();
|
||||
String sanitized = FileNameHelper.sanitizeTextInput(current);
|
||||
if (sanitized.equals(current)) return;
|
||||
|
||||
int cursor = getCursorPosition();
|
||||
setText(sanitized);
|
||||
setCursorPosition(Math.min(cursor, sanitized.length()));
|
||||
}
|
||||
|
||||
public void setHoverText(String text) {
|
||||
this.hoverableText = StatCollector.translateToLocal(text);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user