mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-24 19:54:26 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff33ebfe8d | ||
|
|
5f04b6fa69 | ||
|
|
a4bca99126 | ||
|
|
a7d1b9cd1f | ||
|
|
56c4d3e7f1 | ||
|
|
1f44ea5987 | ||
|
|
cb8a78e82b | ||
|
|
04d37623eb | ||
|
|
1a4f513fb3 | ||
|
|
e187b62348 | ||
|
|
a9e19294f8 | ||
|
|
54a45fbeb8 | ||
|
|
435ff3f5de | ||
|
|
8b92c04c45 | ||
|
|
32e828f2c8 | ||
|
|
689db91622 |
No files matched your search
+1
-1
@@ -5,7 +5,7 @@ plugins {
|
||||
id 'idea'
|
||||
}
|
||||
|
||||
version = "1.10-testingbeta7"
|
||||
version = "1.10-testingbeta1"
|
||||
group= "kamkeel.customnpc-plus"
|
||||
archivesBaseName = "CustomNPC-Plus"
|
||||
|
||||
|
||||
+1
-1
Submodule src/api updated: dfa15687d0...c7a74a3e0e.
@@ -12,7 +12,6 @@ import kamkeel.npcs.controllers.data.attribute.requirement.types.QuestCompletedR
|
||||
*/
|
||||
public class CustomAttributes {
|
||||
public static final String HEALTH_KEY = "health";
|
||||
public static final String HEALTH_BOOST_KEY = "health_boost";
|
||||
public static final String MAIN_ATTACK_KEY = "main_attack";
|
||||
public static final String MAIN_ATTACK_BOOST_KEY = "main_attack_boost";
|
||||
public static final String NEUTRAL_KEY = "neutral";
|
||||
@@ -23,28 +22,24 @@ public class CustomAttributes {
|
||||
public static final String MAGIC_BOOST_KEY = "magic_boost";
|
||||
public static final String MAGIC_DEFENSE_KEY = "magic_defense";
|
||||
public static final String MAGIC_RESISTANCE_KEY = "magic_resistance";
|
||||
public static final String MOVEMENT_SPEED_KEY = "movement_speed";
|
||||
public static final String KNOCKBACK_RES_KEY = "knockback_res";
|
||||
|
||||
public static AttributeDefinition HEALTH;
|
||||
public static AttributeDefinition HEALTH_BOOST;
|
||||
|
||||
public static AttributeDefinition MAIN_ATTACK;
|
||||
public static AttributeDefinition MAIN_BOOST;
|
||||
public static AttributeDefinition NEUTRAL_ATTACK;
|
||||
public static AttributeDefinition NEUTRAL_BOOST;
|
||||
|
||||
public static AttributeDefinition HEALTH;
|
||||
public static AttributeDefinition CRITICAL_CHANCE;
|
||||
public static AttributeDefinition CRITICAL_DAMAGE;
|
||||
|
||||
public static AttributeDefinition MAGIC_DAMAGE;
|
||||
public static AttributeDefinition MAGIC_BOOST;
|
||||
public static AttributeDefinition MAGIC_DEFENSE;
|
||||
public static AttributeDefinition MAGIC_RESISTANCE;
|
||||
public static AttributeDefinition MOVEMENT_SPEED;
|
||||
public static AttributeDefinition KNOCKBACK_RES;
|
||||
|
||||
public CustomAttributes() {
|
||||
HEALTH = AttributeController.registerAttribute(HEALTH_KEY, "Health", 'c', AttributeValueType.FLAT, AttributeDefinition.AttributeSection.BASE);
|
||||
HEALTH_BOOST = AttributeController.registerAttribute(HEALTH_BOOST_KEY, "Health Boost", 'c', AttributeValueType.PERCENT, AttributeDefinition.AttributeSection.MODIFIER);
|
||||
HEALTH_BOOST.setTranslationKey("attribute.name.generic.maxHealth");
|
||||
|
||||
MAIN_ATTACK = AttributeController.registerAttribute(MAIN_ATTACK_KEY, "Main Attack Damage", '4', AttributeValueType.FLAT, AttributeDefinition.AttributeSection.BASE);
|
||||
MAIN_BOOST = AttributeController.registerAttribute(MAIN_ATTACK_BOOST_KEY, "Main Attack Damage", '4', AttributeValueType.PERCENT, AttributeDefinition.AttributeSection.MODIFIER);
|
||||
@@ -61,11 +56,6 @@ public class CustomAttributes {
|
||||
MAGIC_DEFENSE = AttributeController.registerAttribute(MAGIC_DEFENSE_KEY, "Magic Defense", 'b', AttributeValueType.MAGIC, AttributeDefinition.AttributeSection.BASE);
|
||||
MAGIC_RESISTANCE = AttributeController.registerAttribute(MAGIC_RESISTANCE_KEY, "Magic Resistance", 'b', AttributeValueType.MAGIC, AttributeDefinition.AttributeSection.MODIFIER);
|
||||
|
||||
MOVEMENT_SPEED = AttributeController.registerAttribute(MOVEMENT_SPEED_KEY, "Movement Speed", 'a', AttributeValueType.PERCENT, AttributeDefinition.AttributeSection.MODIFIER);
|
||||
MOVEMENT_SPEED.setTranslationKey("attribute.name.generic.movementSpeed");
|
||||
|
||||
KNOCKBACK_RES = AttributeController.registerAttribute(KNOCKBACK_RES_KEY, "Knockback Resistance", 'b', AttributeValueType.PERCENT, AttributeDefinition.AttributeSection.MODIFIER);
|
||||
KNOCKBACK_RES.setTranslationKey("attribute.name.generic.knockbackResistance");
|
||||
|
||||
// TODO: Attributes
|
||||
// Durability Attribute
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
package kamkeel.npcs.addon.client;
|
||||
|
||||
import net.minecraft.client.model.ModelBiped;
|
||||
import net.minecraft.client.model.ModelRenderer;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.client.gui.mainmenu.GuiNpcStats;
|
||||
import noppes.npcs.client.gui.util.GuiNPCInterface2;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
@@ -47,8 +42,4 @@ public class DBCClient {
|
||||
public GuiNPCInterface2 manageCustomAuras(EntityNPCInterface npcInterface) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Animation Render Helper
|
||||
public void applyRenderModel(ModelRenderer renderer){}
|
||||
public boolean firstPersonAnimation(float partialRenderTick, EntityPlayer player, ModelBiped model, RenderBlocks renderBlocksIr, ResourceLocation resItemGlint) { return false; }
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package kamkeel.npcs.command.profile;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -5,10 +5,6 @@ import kamkeel.npcs.controllers.data.attribute.AttributeDefinition;
|
||||
import kamkeel.npcs.controllers.data.attribute.AttributeValueType;
|
||||
import kamkeel.npcs.controllers.data.attribute.tracker.PlayerAttributeTracker;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.handler.IAttributeHandler;
|
||||
import noppes.npcs.api.handler.data.IAttributeDefinition;
|
||||
import noppes.npcs.api.handler.data.IPlayerAttributes;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -19,9 +15,9 @@ import java.util.UUID;
|
||||
* AttributeController is the central registry for attribute definitions.
|
||||
* It ensures that keys are unique.
|
||||
*/
|
||||
public class AttributeController implements IAttributeHandler {
|
||||
public class AttributeController {
|
||||
|
||||
public static AttributeController Instance;
|
||||
public AttributeController Instance;
|
||||
public CustomAttributes attributes;
|
||||
|
||||
// Tracking Player Attributes
|
||||
@@ -29,7 +25,7 @@ public class AttributeController implements IAttributeHandler {
|
||||
private static final Map<String, AttributeDefinition> definitions = new HashMap<>();
|
||||
|
||||
public AttributeController() {
|
||||
Instance = this;
|
||||
this.Instance = this;
|
||||
definitions.clear();
|
||||
trackers.clear();
|
||||
attributes = new CustomAttributes();
|
||||
@@ -79,20 +75,4 @@ public class AttributeController implements IAttributeHandler {
|
||||
tracker.updateIfChanged(player);
|
||||
}
|
||||
}
|
||||
|
||||
public IPlayerAttributes getPlayerAttributes(IPlayer player) {
|
||||
if(player == null || player.getMCEntity() == null)
|
||||
return null;
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer) player.getMCEntity();
|
||||
return trackers.computeIfAbsent(entityPlayer.getUniqueID(), id -> new PlayerAttributeTracker(id));
|
||||
}
|
||||
|
||||
public IAttributeDefinition getAttributeDefinition(String key) {
|
||||
return definitions.get(key);
|
||||
}
|
||||
|
||||
public IAttributeDefinition[] getAllAttributesArray() {
|
||||
return definitions.values().toArray(new AttributeDefinition[definitions.size()]);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package kamkeel.npcs.controllers.data.attribute;
|
||||
|
||||
import noppes.npcs.api.handler.data.IAttributeDefinition;
|
||||
|
||||
public class AttributeDefinition implements IAttributeDefinition {
|
||||
public class AttributeDefinition {
|
||||
private final String key;
|
||||
private String translationKey;// e.g., "main_attack_flat"
|
||||
private final String displayName; // Human‑readable name
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package kamkeel.npcs.controllers.data.attribute;
|
||||
|
||||
/**
|
||||
* IAttributeInstance represents an instance of an attribute (with a base value and applied modifiers).
|
||||
*/
|
||||
public interface ICustomAttribute {
|
||||
AttributeDefinition getAttribute();
|
||||
|
||||
float getValue();
|
||||
|
||||
void setValue(float value);
|
||||
}
|
||||
@@ -1,15 +1,13 @@
|
||||
package kamkeel.npcs.controllers.data.attribute;
|
||||
|
||||
|
||||
import noppes.npcs.api.handler.data.ICustomAttribute;
|
||||
|
||||
public class PlayerAttribute implements ICustomAttribute {
|
||||
private final AttributeDefinition attribute;
|
||||
public float value;
|
||||
private float baseValue;
|
||||
|
||||
public PlayerAttribute(AttributeDefinition attribute, float value) {
|
||||
public PlayerAttribute(AttributeDefinition attribute, float baseValue) {
|
||||
this.attribute = attribute;
|
||||
this.value = value;
|
||||
this.baseValue = baseValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -19,6 +17,11 @@ public class PlayerAttribute implements ICustomAttribute {
|
||||
|
||||
@Override
|
||||
public float getValue() {
|
||||
return value;
|
||||
return baseValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(float value) {
|
||||
this.baseValue = value;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package kamkeel.npcs.controllers.data.attribute;
|
||||
|
||||
import noppes.npcs.api.handler.data.ICustomAttribute;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -10,18 +8,22 @@ import java.util.Map;
|
||||
* CustomAttributeMap holds a set of attribute instances for an entity (or item).
|
||||
*/
|
||||
public class PlayerAttributeMap {
|
||||
public final Map<AttributeDefinition, PlayerAttribute> map = new HashMap<>();
|
||||
private final Map<AttributeDefinition, ICustomAttribute> map = new HashMap<>();
|
||||
|
||||
public PlayerAttribute registerAttribute(AttributeDefinition attribute, float baseValue) {
|
||||
public ICustomAttribute registerAttribute(AttributeDefinition attribute, float baseValue) {
|
||||
if (map.containsKey(attribute)) {
|
||||
throw new IllegalArgumentException("Attribute already registered: " + attribute.getKey());
|
||||
}
|
||||
PlayerAttribute instance = new PlayerAttribute(attribute, baseValue);
|
||||
ICustomAttribute instance = new PlayerAttribute(attribute, baseValue);
|
||||
map.put(attribute, instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
public PlayerAttribute getAttributeInstance(AttributeDefinition attribute) {
|
||||
public ICustomAttribute getAttributeInstance(AttributeDefinition attribute) {
|
||||
return map.get(attribute);
|
||||
}
|
||||
|
||||
public Collection<ICustomAttribute> getAllAttributes() {
|
||||
return map.values();
|
||||
}
|
||||
}
|
||||
-2
@@ -11,8 +11,6 @@ public interface IRequirementChecker {
|
||||
|
||||
String getTooltipValue(NBTTagCompound nbt);
|
||||
|
||||
Object getValue(NBTTagCompound nbt);
|
||||
|
||||
void apply(NBTTagCompound nbt, Object value);
|
||||
|
||||
/**
|
||||
|
||||
-8
@@ -29,14 +29,6 @@ public class QuestActiveRequirement implements IRequirementChecker {
|
||||
return "null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(NBTTagCompound nbt) {
|
||||
if (nbt.hasKey(getKey())) {
|
||||
return nbt.getInteger(getKey());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(NBTTagCompound nbt, Object value) {
|
||||
if (value instanceof Integer) {
|
||||
|
||||
-8
@@ -36,14 +36,6 @@ public class QuestCompletedRequirement implements IRequirementChecker {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(NBTTagCompound nbt) {
|
||||
if (nbt.hasKey(getKey())) {
|
||||
return nbt.getInteger(getKey());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(EntityPlayer player, NBTTagCompound nbt) {
|
||||
if (nbt.hasKey(getKey())) {
|
||||
|
||||
+15
-103
@@ -3,9 +3,7 @@ package kamkeel.npcs.controllers.data.attribute.tracker;
|
||||
import kamkeel.npcs.CustomAttributes;
|
||||
import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.data.attribute.AttributeDefinition;
|
||||
import kamkeel.npcs.controllers.data.attribute.PlayerAttribute;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.handler.data.ICustomAttribute;
|
||||
import kamkeel.npcs.controllers.data.attribute.ICustomAttribute;
|
||||
import kamkeel.npcs.controllers.data.attribute.PlayerAttributeMap;
|
||||
import kamkeel.npcs.controllers.data.attribute.requirement.RequirementCheckerRegistry;
|
||||
import kamkeel.npcs.util.AttributeAttackUtil;
|
||||
@@ -16,28 +14,21 @@ import net.minecraft.entity.ai.attributes.IAttributeInstance;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.api.handler.data.IPlayerAttributes;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerAttributeTracker implements IPlayerAttributes {
|
||||
public class PlayerAttributeTracker {
|
||||
|
||||
public static UUID healthUUID = UUID.fromString("48a0ad75-2cf8-4838-ad2f-9a0aadc57dfe");
|
||||
public static UUID healthBoostUUID = UUID.fromString("93cfba41-294a-4e6b-a98b-bee76a9f813b");
|
||||
public static UUID movementSpeedUUID = UUID.fromString("e7e0dd10-8ed5-42fb-8167-e71f8de4ea0c");
|
||||
public static UUID knockbackResUUID = UUID.fromString("b2f261e8-34f0-4140-9828-b56c1f6e0ff2");
|
||||
|
||||
|
||||
private final UUID playerId;
|
||||
private PlayerAttributeMap playerAttributes = new PlayerAttributeMap();
|
||||
|
||||
public float extraHealth = 0;
|
||||
public float extraHealthBoost = 0;
|
||||
public float movementSpeed = 0;
|
||||
public float knockbackRes = 0;
|
||||
|
||||
public float gearOutput = 0.0f;
|
||||
|
||||
public final Map<Integer, Float> magicDamage = new HashMap<>();
|
||||
@@ -53,6 +44,10 @@ public class PlayerAttributeTracker implements IPlayerAttributes {
|
||||
recalcAttributes(null);
|
||||
}
|
||||
|
||||
public PlayerAttributeMap getPlayerAttributes() {
|
||||
return playerAttributes;
|
||||
}
|
||||
|
||||
public void recalcAttributes(EntityPlayer player) {
|
||||
// Reset aggregated attributes and magic maps.
|
||||
playerAttributes = new PlayerAttributeMap();
|
||||
@@ -82,11 +77,11 @@ public class PlayerAttributeTracker implements IPlayerAttributes {
|
||||
float value = entry.getValue();
|
||||
AttributeDefinition def = AttributeController.getAttribute(key);
|
||||
if (def != null) {
|
||||
PlayerAttribute inst = playerAttributes.getAttributeInstance(def);
|
||||
ICustomAttribute inst = playerAttributes.getAttributeInstance(def);
|
||||
if (inst == null) {
|
||||
inst = playerAttributes.registerAttribute(def, 0.0f);
|
||||
}
|
||||
inst.value = (inst.getValue() + value);
|
||||
inst.setValue(inst.getValue() + value);
|
||||
}
|
||||
}
|
||||
// Process Magic
|
||||
@@ -122,16 +117,9 @@ public class PlayerAttributeTracker implements IPlayerAttributes {
|
||||
}
|
||||
equipmentTracker = currentEquip;
|
||||
gearOutput = AttributeAttackUtil.calculateGearOutput(this);
|
||||
|
||||
extraHealth = getAttributeValue(CustomAttributes.HEALTH);
|
||||
extraHealthBoost = getAttributeValue(CustomAttributes.HEALTH_BOOST);
|
||||
movementSpeed = getAttributeValue(CustomAttributes.MOVEMENT_SPEED);
|
||||
knockbackRes = getAttributeValue(CustomAttributes.KNOCKBACK_RES);
|
||||
|
||||
// Update vanilla attributes with our aggregated values.
|
||||
updatePlayerMaxHealth(player);
|
||||
updatePlayerMovementSpeed(player);
|
||||
updatePlayerKnockbackRes(player);
|
||||
|
||||
// Post Recalculation Event to Listeners
|
||||
AttributeRecalcEvent.post(player, this);
|
||||
@@ -146,61 +134,24 @@ public class PlayerAttributeTracker implements IPlayerAttributes {
|
||||
*/
|
||||
public void updatePlayerMaxHealth(EntityPlayer player) {
|
||||
float bonusHealth = extraHealth;
|
||||
float healthBoostPercent = extraHealthBoost / 100;
|
||||
IAttributeInstance maxHealthAttr = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.maxHealth);
|
||||
try {
|
||||
AttributeModifier oldFlat = maxHealthAttr.getModifier(healthUUID);
|
||||
if (oldFlat != null) {
|
||||
maxHealthAttr.removeModifier(oldFlat);
|
||||
AttributeModifier old = maxHealthAttr.getModifier(healthUUID);
|
||||
if (old != null) {
|
||||
maxHealthAttr.removeModifier(old);
|
||||
}
|
||||
AttributeModifier oldBoost = maxHealthAttr.getModifier(healthBoostUUID);
|
||||
if (oldBoost != null) {
|
||||
maxHealthAttr.removeModifier(oldBoost);
|
||||
}
|
||||
} catch (Exception ignored) { }
|
||||
// Apply the flat bonus (operation 0)
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
if (bonusHealth != 0) {
|
||||
maxHealthAttr.applyModifier(new AttributeModifier(healthUUID, "RPGCoreHealthBonus", bonusHealth, 0));
|
||||
}
|
||||
// Apply the percent boost (operation 1 multiplies the base health, here assumed to be 20)
|
||||
if (healthBoostPercent != 0) {
|
||||
maxHealthAttr.applyModifier(new AttributeModifier(healthBoostUUID, "RPGCoreHealthBoost", healthBoostPercent, 1));
|
||||
}
|
||||
// Ensure current health is within the new maximum.
|
||||
// Ensure the player's current health does not exceed the new maximum.
|
||||
float currentHealth = player.getHealth();
|
||||
if (currentHealth > maxHealthAttr.getAttributeValue()) {
|
||||
player.setHealth((float) maxHealthAttr.getAttributeValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePlayerMovementSpeed(EntityPlayer player) {
|
||||
float extraSpeed = movementSpeed / 100;
|
||||
IAttributeInstance speedAttr = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.movementSpeed);
|
||||
try {
|
||||
AttributeModifier old = speedAttr.getModifier(movementSpeedUUID);
|
||||
if (old != null) {
|
||||
speedAttr.removeModifier(old);
|
||||
}
|
||||
} catch (Exception ignored) { }
|
||||
if (extraSpeed != 0) {
|
||||
speedAttr.applyModifier(new AttributeModifier(movementSpeedUUID, "RPGCoreMovementSpeed", extraSpeed, 1));
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePlayerKnockbackRes(EntityPlayer player) {
|
||||
float extraRes = knockbackRes / 100;
|
||||
IAttributeInstance knockResAttr = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.knockbackResistance);
|
||||
try {
|
||||
AttributeModifier old = knockResAttr.getModifier(knockbackResUUID);
|
||||
if (old != null) {
|
||||
knockResAttr.removeModifier(old);
|
||||
}
|
||||
} catch (Exception ignored) { }
|
||||
if (extraRes != 0) {
|
||||
knockResAttr.applyModifier(new AttributeModifier(knockbackResUUID, "RPGCoreKnockbackRes", extraRes, 1));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player's equipment has changed and recalculates attributes if needed.
|
||||
*/
|
||||
@@ -216,43 +167,4 @@ public class PlayerAttributeTracker implements IPlayerAttributes {
|
||||
ICustomAttribute inst = playerAttributes.getAttributeInstance(def);
|
||||
return inst != null ? inst.getValue() : 0.0f;
|
||||
}
|
||||
|
||||
public void recalculate(IPlayer player) {
|
||||
if(player == null || player.getMCEntity() == null)
|
||||
return;
|
||||
|
||||
recalcAttributes((EntityPlayer) player.getMCEntity());
|
||||
}
|
||||
|
||||
public ICustomAttribute[] getAttributes() {
|
||||
return playerAttributes.map.values().toArray(new ICustomAttribute[playerAttributes.map.size()]);
|
||||
}
|
||||
|
||||
public float getAttributeValue(String key) {
|
||||
for (ICustomAttribute inst : getAttributes()) {
|
||||
if (inst.getAttribute().getKey().equalsIgnoreCase(key)) {
|
||||
return inst.getValue();
|
||||
}
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasAttribute(String key) {
|
||||
for (ICustomAttribute inst : getAttributes()) {
|
||||
if (inst.getAttribute().getKey().equalsIgnoreCase(key)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ICustomAttribute getAttribute(String key) {
|
||||
for (ICustomAttribute inst : getAttributes()) {
|
||||
if (inst.getAttribute().getKey().equalsIgnoreCase(key)) {
|
||||
return inst;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package kamkeel.npcs.editorgui;
|
||||
|
||||
import net.minecraft.client.gui.Gui;
|
||||
|
||||
/**
|
||||
* AbstractEditorComponent provides common fields and methods for all editor components.
|
||||
*/
|
||||
public abstract class AbstractEditorComponent extends Gui implements IEditorComponent {
|
||||
// Store the editor component's ID.
|
||||
protected int id;
|
||||
// Position and size.
|
||||
public int posX, posY, width, height;
|
||||
protected boolean selected = false;
|
||||
|
||||
public AbstractEditorComponent(int posX, int posY, int width, int height) {
|
||||
this.posX = posX;
|
||||
this.posY = posY;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID for this editor component.
|
||||
*/
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(boolean selected) {
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws an outline around the component.
|
||||
* Yellow if selected; grey if not.
|
||||
*/
|
||||
protected void renderSelectionOutline() {
|
||||
int outlineColor = selected ? 0xFFFFFF00 : 0xFF888888;
|
||||
// Top border
|
||||
drawRect(posX - 1, posY - 1, posX + width + 1, posY, outlineColor);
|
||||
// Bottom border
|
||||
drawRect(posX - 1, posY + height, posX + width + 1, posY + height + 1, outlineColor);
|
||||
// Left border
|
||||
drawRect(posX - 1, posY - 1, posX, posY + height + 1, outlineColor);
|
||||
// Right border
|
||||
drawRect(posX + width, posY - 1, posX + width + 1, posY + height + 1, outlineColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() { }
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package kamkeel.npcs.editorgui;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.scripted.gui.ScriptGui;
|
||||
import noppes.npcs.util.NBTJsonUtil;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* CustomGuiEditorController handles saving and loading of ScriptGui objects.
|
||||
*/
|
||||
public class CustomGuiEditorController {
|
||||
private ScriptGui currentGui;
|
||||
|
||||
public CustomGuiEditorController() {
|
||||
currentGui = new ScriptGui();
|
||||
}
|
||||
|
||||
public void saveGui(File file, ScriptGui gui) {
|
||||
NBTTagCompound compound = gui.toNBT();
|
||||
try {
|
||||
NBTJsonUtil.SaveFile(file, compound);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
currentGui = gui;
|
||||
}
|
||||
|
||||
public ScriptGui loadGui(File file) {
|
||||
try {
|
||||
NBTTagCompound compound = NBTJsonUtil.LoadFile(file);
|
||||
currentGui = (ScriptGui) (new ScriptGui()).fromNBT(compound);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return currentGui;
|
||||
}
|
||||
|
||||
public void applyGuiToPlayer(EntityPlayer player) {
|
||||
// player.showCustomGui(currentGui);
|
||||
}
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
package kamkeel.npcs.editorgui;
|
||||
|
||||
import noppes.npcs.scripted.gui.ScriptGuiButton;
|
||||
import noppes.npcs.client.gui.custom.components.CustomGuiButton;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* EditorButtonComponent wraps a ScriptGuiButton for editing.
|
||||
*/
|
||||
public class EditorButtonComponent extends AbstractEditorComponent {
|
||||
private ScriptGuiButton buttonComponent;
|
||||
|
||||
public EditorButtonComponent(ScriptGuiButton button) {
|
||||
super(button.getPosX(), button.getPosY(), button.getWidth(), button.getHeight());
|
||||
this.buttonComponent = button;
|
||||
this.id = button.getID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float partialTicks) {
|
||||
CustomGuiButton renderBtn = CustomGuiButton.fromComponent(buttonComponent);
|
||||
renderBtn.xPosition = this.posX;
|
||||
renderBtn.yPosition = this.posY;
|
||||
renderBtn.scale = buttonComponent.getScale();
|
||||
renderBtn.alpha = buttonComponent.getAlpha();
|
||||
renderBtn.onRender(Minecraft.getMinecraft(), mouseX, mouseY, 0, partialTicks);
|
||||
renderSelectionOutline();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (mouseX >= posX && mouseX <= posX + width &&
|
||||
mouseY >= posY && mouseY <= posY + height) {
|
||||
selected = true;
|
||||
return true;
|
||||
}
|
||||
selected = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(int mouseX, int mouseY, int mouseButton) {
|
||||
if (selected) {
|
||||
buttonComponent.setPos(posX, posY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY, int state) { }
|
||||
|
||||
@Override
|
||||
public Object toScriptComponent() {
|
||||
return buttonComponent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEditorButtons(List<GuiButton> buttonList) {
|
||||
buttonList.add(new GuiButton(101, 0, 0, 30, 20, "W+"));
|
||||
buttonList.add(new GuiButton(102, 0, 0, 30, 20, "W-"));
|
||||
buttonList.add(new GuiButton(103, 0, 0, 30, 20, "H+"));
|
||||
buttonList.add(new GuiButton(104, 0, 0, 30, 20, "H-"));
|
||||
buttonList.add(new GuiButton(105, 0, 0, 30, 20, "Sc"));
|
||||
buttonList.add(new GuiButton(106, 0, 0, 30, 20, "Al"));
|
||||
buttonList.add(new GuiButton(107, 0, 0, 30, 20, "Rt"));
|
||||
buttonList.add(new GuiButton(108, 0, 0, 30, 20, "Lbl"));
|
||||
buttonList.add(new GuiButton(110, 0, 0, 30, 20, "ID"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEditorButtonPressed(GuiButton button) {
|
||||
GuiCustomGuiEditor editor = (GuiCustomGuiEditor) Minecraft.getMinecraft().currentScreen;
|
||||
switch (button.id) {
|
||||
case 101:
|
||||
width += 5;
|
||||
buttonComponent.setSize(width, height);
|
||||
break;
|
||||
case 102:
|
||||
width = Math.max(10, width - 5);
|
||||
buttonComponent.setSize(width, height);
|
||||
break;
|
||||
case 103:
|
||||
height += 5;
|
||||
buttonComponent.setSize(width, height);
|
||||
break;
|
||||
case 104:
|
||||
height = Math.max(10, height - 5);
|
||||
buttonComponent.setSize(width, height);
|
||||
break;
|
||||
case 105:
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Scale", Float.toString(buttonComponent.getScale()),
|
||||
newValue -> {
|
||||
try {
|
||||
float newScale = Float.parseFloat(newValue);
|
||||
buttonComponent.setScale(newScale);
|
||||
} catch (NumberFormatException e) { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 106:
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Alpha", Float.toString(buttonComponent.getAlpha()),
|
||||
newValue -> {
|
||||
try {
|
||||
float newAlpha = Float.parseFloat(newValue);
|
||||
buttonComponent.setAlpha(newAlpha);
|
||||
} catch (NumberFormatException e) { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 107:
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Rotation", Float.toString(buttonComponent.getRotation()),
|
||||
newValue -> {
|
||||
try {
|
||||
float newRot = Float.parseFloat(newValue);
|
||||
buttonComponent.setRotation(newRot);
|
||||
} catch (NumberFormatException e) { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 108:
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Label", buttonComponent.getLabel(),
|
||||
newValue -> buttonComponent.setLabel(newValue), () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 110:
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("ID", Integer.toString(buttonComponent.getID()),
|
||||
newValue -> {
|
||||
try {
|
||||
int newID = Integer.parseInt(newValue);
|
||||
buttonComponent.setID(newID);
|
||||
} catch (NumberFormatException e) { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
package kamkeel.npcs.editorgui;
|
||||
|
||||
import noppes.npcs.scripted.gui.ScriptGuiLabel;
|
||||
import noppes.npcs.client.gui.custom.components.CustomGuiLabel;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import java.util.List;
|
||||
|
||||
public class EditorLabelComponent extends AbstractEditorComponent {
|
||||
private ScriptGuiLabel labelComponent;
|
||||
|
||||
public EditorLabelComponent(ScriptGuiLabel label) {
|
||||
super(label.getPosX(), label.getPosY(), label.getWidth(), label.getHeight());
|
||||
this.labelComponent = label;
|
||||
this.id = label.getID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float partialTicks) {
|
||||
CustomGuiLabel renderLbl = CustomGuiLabel.fromComponent(labelComponent);
|
||||
renderLbl.x = this.posX;
|
||||
renderLbl.y = this.posY;
|
||||
renderLbl.setScale(labelComponent.getScale());
|
||||
renderLbl.alpha = labelComponent.getAlpha();
|
||||
renderLbl.rotation = labelComponent.getRotation();
|
||||
renderLbl.onRender(Minecraft.getMinecraft(), mouseX, mouseY, 0, partialTicks);
|
||||
renderSelectionOutline();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (mouseX >= posX && mouseX <= posX + width &&
|
||||
mouseY >= posY && mouseY <= posY + height) {
|
||||
selected = true;
|
||||
return true;
|
||||
}
|
||||
selected = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(int mouseX, int mouseY, int mouseButton) {
|
||||
if (selected) {
|
||||
labelComponent.setPos(posX, posY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY, int state) { }
|
||||
|
||||
@Override
|
||||
public Object toScriptComponent() {
|
||||
return labelComponent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEditorButtons(List<GuiButton> buttonList) {
|
||||
buttonList.add(new GuiButton(201, 0, 0, 30, 20, "W+"));
|
||||
buttonList.add(new GuiButton(202, 0, 0, 30, 20, "W-"));
|
||||
buttonList.add(new GuiButton(203, 0, 0, 30, 20, "H+"));
|
||||
buttonList.add(new GuiButton(204, 0, 0, 30, 20, "H-"));
|
||||
buttonList.add(new GuiButton(205, 0, 0, 30, 20, "Sc"));
|
||||
buttonList.add(new GuiButton(206, 0, 0, 30, 20, "Al"));
|
||||
buttonList.add(new GuiButton(207, 0, 0, 30, 20, "Rt"));
|
||||
buttonList.add(new GuiButton(208, 0, 0, 30, 20, "Txt"));
|
||||
buttonList.add(new GuiButton(210, 0, 0, 30, 20, "ID"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEditorButtonPressed(GuiButton button) {
|
||||
GuiCustomGuiEditor editor = (GuiCustomGuiEditor) Minecraft.getMinecraft().currentScreen;
|
||||
switch(button.id) {
|
||||
case 201:
|
||||
width += 5;
|
||||
labelComponent.setSize(width, height);
|
||||
break;
|
||||
case 202:
|
||||
width = Math.max(10, width - 5);
|
||||
labelComponent.setSize(width, height);
|
||||
break;
|
||||
case 203:
|
||||
height += 5;
|
||||
labelComponent.setSize(width, height);
|
||||
break;
|
||||
case 204:
|
||||
height = Math.max(10, height - 5);
|
||||
labelComponent.setSize(width, height);
|
||||
break;
|
||||
case 205:
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Scale", Float.toString(labelComponent.getScale()),
|
||||
newValue -> {
|
||||
try {
|
||||
float newScale = Float.parseFloat(newValue);
|
||||
labelComponent.setScale(newScale);
|
||||
} catch (NumberFormatException e) { }
|
||||
}, () -> {
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 206:
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Alpha", Float.toString(labelComponent.getAlpha()),
|
||||
newValue -> {
|
||||
try {
|
||||
float newAlpha = Float.parseFloat(newValue);
|
||||
labelComponent.setAlpha(newAlpha);
|
||||
} catch (NumberFormatException e) { }
|
||||
}, () -> {
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 207:
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Rotation", Float.toString(labelComponent.getRotation()),
|
||||
newValue -> {
|
||||
try {
|
||||
float newRot = Float.parseFloat(newValue);
|
||||
labelComponent.setRotation(newRot);
|
||||
} catch (NumberFormatException e) { }
|
||||
}, () -> {
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 208:
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Text", labelComponent.getText(),
|
||||
newValue -> labelComponent.setText(newValue), () -> {
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 210:
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("ID", Integer.toString(labelComponent.getID()),
|
||||
newValue -> {
|
||||
try {
|
||||
int newID = Integer.parseInt(newValue);
|
||||
labelComponent.setID(newID);
|
||||
} catch (NumberFormatException e) { }
|
||||
}, () -> {
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
package kamkeel.npcs.editorgui;
|
||||
|
||||
import noppes.npcs.scripted.gui.ScriptGuiTextField;
|
||||
import noppes.npcs.client.gui.custom.components.CustomGuiTextField;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* EditorTextFieldComponent wraps a ScriptGuiTextField.
|
||||
* It renders the actual text field and provides editing buttons for width, height, default text, and ID.
|
||||
*/
|
||||
public class EditorTextFieldComponent extends AbstractEditorComponent {
|
||||
private ScriptGuiTextField textFieldComponent;
|
||||
|
||||
public EditorTextFieldComponent(ScriptGuiTextField textField) {
|
||||
// TextField uses its original width, height, and position.
|
||||
super(textField.getPosX(), textField.getPosY(), textField.getWidth(), textField.getHeight());
|
||||
this.textFieldComponent = textField;
|
||||
this.id = textField.getID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float partialTicks) {
|
||||
CustomGuiTextField renderField = CustomGuiTextField.fromComponent(textFieldComponent);
|
||||
renderField.xPosition = this.posX;
|
||||
renderField.yPosition = this.posY;
|
||||
renderField.drawTextBox();
|
||||
renderSelectionOutline();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (mouseX >= posX && mouseX < posX + width &&
|
||||
mouseY >= posY && mouseY < posY + height) {
|
||||
selected = true;
|
||||
return true;
|
||||
}
|
||||
selected = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(int mouseX, int mouseY, int mouseButton) {
|
||||
if (selected) {
|
||||
textFieldComponent.setPos(posX, posY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY, int state) { }
|
||||
|
||||
@Override
|
||||
public Object toScriptComponent() {
|
||||
return textFieldComponent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEditorButtons(List<GuiButton> buttonList) {
|
||||
buttonList.add(new GuiButton(301, 0, 0, 30, 20, "W+"));
|
||||
buttonList.add(new GuiButton(302, 0, 0, 30, 20, "W-"));
|
||||
buttonList.add(new GuiButton(303, 0, 0, 30, 20, "H+"));
|
||||
buttonList.add(new GuiButton(304, 0, 0, 30, 20, "H-"));
|
||||
buttonList.add(new GuiButton(307, 0, 0, 30, 20, "Txt"));
|
||||
buttonList.add(new GuiButton(310, 0, 0, 30, 20, "ID"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEditorButtonPressed(GuiButton button) {
|
||||
GuiCustomGuiEditor editor = (GuiCustomGuiEditor) Minecraft.getMinecraft().currentScreen;
|
||||
switch(button.id) {
|
||||
case 301:
|
||||
width += 5;
|
||||
textFieldComponent.setSize(width, height);
|
||||
break;
|
||||
case 302:
|
||||
width = Math.max(10, width - 5);
|
||||
textFieldComponent.setSize(width, height);
|
||||
break;
|
||||
case 303:
|
||||
height += 5;
|
||||
textFieldComponent.setSize(width, height);
|
||||
break;
|
||||
case 304:
|
||||
height = Math.max(10, height - 5);
|
||||
textFieldComponent.setSize(width, height);
|
||||
break;
|
||||
case 307:
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Default Text", textFieldComponent.getText(),
|
||||
newValue -> textFieldComponent.setText(newValue), () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 310:
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("ID", Integer.toString(textFieldComponent.getID()),
|
||||
newValue -> {
|
||||
try {
|
||||
int newID = Integer.parseInt(newValue);
|
||||
textFieldComponent.setID(newID);
|
||||
} catch (NumberFormatException e) { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
package kamkeel.npcs.editorgui;
|
||||
|
||||
import noppes.npcs.scripted.gui.ScriptGuiTexturedRect;
|
||||
import noppes.npcs.client.gui.custom.components.CustomGuiTexturedRect;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import java.util.List;
|
||||
|
||||
public class EditorTexturedRectComponent extends AbstractEditorComponent {
|
||||
private ScriptGuiTexturedRect texturedRect;
|
||||
|
||||
public EditorTexturedRectComponent(ScriptGuiTexturedRect rect) {
|
||||
super(rect.getPosX(), rect.getPosY(), rect.getWidth(), rect.getHeight());
|
||||
this.texturedRect = rect;
|
||||
this.id = rect.getID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float partialTicks) {
|
||||
CustomGuiTexturedRect renderRect = CustomGuiTexturedRect.fromComponent(texturedRect);
|
||||
renderRect.x = this.posX;
|
||||
renderRect.y = this.posY;
|
||||
renderRect.scale = texturedRect.getScale();
|
||||
renderRect.alpha = texturedRect.getAlpha();
|
||||
renderRect.rotation = texturedRect.getRotation();
|
||||
renderRect.onRender(Minecraft.getMinecraft(), mouseX, mouseY, 0, partialTicks);
|
||||
renderSelectionOutline();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (mouseX >= posX && mouseX < posX + width &&
|
||||
mouseY >= posY && mouseY < posY + height) {
|
||||
selected = true;
|
||||
return true;
|
||||
}
|
||||
selected = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(int mouseX, int mouseY, int mouseButton) {
|
||||
if (selected) {
|
||||
texturedRect.setPos(posX, posY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY, int state) { }
|
||||
|
||||
@Override
|
||||
public Object toScriptComponent() {
|
||||
return texturedRect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEditorButtons(List<GuiButton> buttonList) {
|
||||
buttonList.add(new GuiButton(401, 0, 0, 30, 20, "W+"));
|
||||
buttonList.add(new GuiButton(402, 0, 0, 30, 20, "W-"));
|
||||
buttonList.add(new GuiButton(403, 0, 0, 30, 20, "H+"));
|
||||
buttonList.add(new GuiButton(404, 0, 0, 30, 20, "H-"));
|
||||
buttonList.add(new GuiButton(405, 0, 0, 30, 20, "Sc"));
|
||||
buttonList.add(new GuiButton(406, 0, 0, 30, 20, "Al"));
|
||||
buttonList.add(new GuiButton(407, 0, 0, 30, 20, "Rt"));
|
||||
buttonList.add(new GuiButton(408, 0, 0, 30, 20, "Tex"));
|
||||
buttonList.add(new GuiButton(409, 0, 0, 30, 20, "TxX"));
|
||||
buttonList.add(new GuiButton(410, 0, 0, 30, 20, "TxY"));
|
||||
buttonList.add(new GuiButton(411, 0, 0, 30, 20, "ID"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEditorButtonPressed(GuiButton button) {
|
||||
GuiCustomGuiEditor editor = (GuiCustomGuiEditor) Minecraft.getMinecraft().currentScreen;
|
||||
switch(button.id) {
|
||||
case 401:
|
||||
width += 5;
|
||||
texturedRect.setSize(width, height);
|
||||
break;
|
||||
case 402:
|
||||
width = Math.max(10, width - 5);
|
||||
texturedRect.setSize(width, height);
|
||||
break;
|
||||
case 403:
|
||||
height += 5;
|
||||
texturedRect.setSize(width, height);
|
||||
break;
|
||||
case 404:
|
||||
height = Math.max(10, height - 5);
|
||||
texturedRect.setSize(width, height);
|
||||
break;
|
||||
case 405:
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Scale", Float.toString(texturedRect.getScale()),
|
||||
newValue -> {
|
||||
try {
|
||||
float newScale = Float.parseFloat(newValue);
|
||||
texturedRect.setScale(newScale);
|
||||
} catch (NumberFormatException e) { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 406:
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Alpha", Float.toString(texturedRect.getAlpha()),
|
||||
newValue -> {
|
||||
try {
|
||||
float newAlpha = Float.parseFloat(newValue);
|
||||
texturedRect.setAlpha(newAlpha);
|
||||
} catch (NumberFormatException e) { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 407:
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Rotation", Float.toString(texturedRect.getRotation()),
|
||||
newValue -> {
|
||||
try {
|
||||
float newRot = Float.parseFloat(newValue);
|
||||
texturedRect.setRotation(newRot);
|
||||
} catch (NumberFormatException e) { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 408:
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Texture", texturedRect.getTexture(),
|
||||
newValue -> texturedRect.setTexture(newValue), () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 409:
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("TxX", Integer.toString(texturedRect.getTextureX()),
|
||||
newValue -> {
|
||||
try {
|
||||
int newX = Integer.parseInt(newValue);
|
||||
texturedRect.setTextureOffset(newX, texturedRect.getTextureY());
|
||||
} catch (NumberFormatException e) { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 410:
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("TxY", Integer.toString(texturedRect.getTextureY()),
|
||||
newValue -> {
|
||||
try {
|
||||
int newY = Integer.parseInt(newValue);
|
||||
texturedRect.setTextureOffset(texturedRect.getTextureX(), newY);
|
||||
} catch (NumberFormatException e) { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 411:
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("ID", Integer.toString(texturedRect.getID()),
|
||||
newValue -> {
|
||||
try {
|
||||
int newID = Integer.parseInt(newValue);
|
||||
texturedRect.setID(newID);
|
||||
} catch (NumberFormatException e) { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
package kamkeel.npcs.editorgui;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* EditorToolBar renders a toolbar at the bottom with buttons to add components or save the GUI.
|
||||
*/
|
||||
public class EditorToolBar extends Gui {
|
||||
private List<GuiButton> buttons = new ArrayList<>();
|
||||
private int x, y, width, height;
|
||||
|
||||
public EditorToolBar(int x, int y, int width, int height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
initButtons();
|
||||
}
|
||||
|
||||
private void initButtons() {
|
||||
buttons.clear();
|
||||
// IDs: 1 = Add Button, 2 = Add Label, 3 = Add TextField, 4 = Add Rect, 8 = Save.
|
||||
buttons.add(new GuiButton(1, x + 10, y + 10, 80, 20, "Add Button"));
|
||||
buttons.add(new GuiButton(2, x + 100, y + 10, 80, 20, "Add Label"));
|
||||
buttons.add(new GuiButton(3, x + 190, y + 10, 80, 20, "Add TextField"));
|
||||
buttons.add(new GuiButton(4, x + 280, y + 10, 80, 20, "Add Rect"));
|
||||
buttons.add(new GuiButton(8, x + 370, y + 10, 80, 20, "Save"));
|
||||
}
|
||||
|
||||
public void render(int mouseX, int mouseY, float partialTicks) {
|
||||
// Optionally draw a background (commented out if undesired).
|
||||
// drawRect(x, y, x + width, y + height, 0xAA333333);
|
||||
for (GuiButton btn : buttons) {
|
||||
btn.drawButton(Minecraft.getMinecraft(), mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
public List<GuiButton> getButtons() {
|
||||
return buttons;
|
||||
}
|
||||
|
||||
public void updateDimensions(int newX, int newY, int newWidth, int newHeight) {
|
||||
this.x = newX;
|
||||
this.y = newY;
|
||||
this.width = newWidth;
|
||||
this.height = newHeight;
|
||||
initButtons();
|
||||
}
|
||||
|
||||
private int getDefaultId() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void actionPerformed(GuiButton button, GuiCustomGuiEditor editor) {
|
||||
int centerX = editor.canvasX + editor.canvasWidth / 2;
|
||||
int centerY = editor.canvasY + editor.canvasHeight / 2;
|
||||
switch (button.id) {
|
||||
case 1:
|
||||
noppes.npcs.scripted.gui.ScriptGuiButton newButton =
|
||||
new noppes.npcs.scripted.gui.ScriptGuiButton(getDefaultId(), "New Button", centerX - 40, centerY - 10, 80, 20);
|
||||
EditorButtonComponent eButton = new EditorButtonComponent(newButton);
|
||||
editor.addEditorComponent(eButton);
|
||||
break;
|
||||
case 2:
|
||||
noppes.npcs.scripted.gui.ScriptGuiLabel newLabel =
|
||||
new noppes.npcs.scripted.gui.ScriptGuiLabel(getDefaultId(), "New Label", centerX - 40, centerY - 10, 80, 20);
|
||||
EditorLabelComponent eLabel = new EditorLabelComponent(newLabel);
|
||||
editor.addEditorComponent(eLabel);
|
||||
break;
|
||||
case 3:
|
||||
noppes.npcs.scripted.gui.ScriptGuiTextField newField =
|
||||
new noppes.npcs.scripted.gui.ScriptGuiTextField(getDefaultId(), centerX - 50, centerY - 10, 100, 20);
|
||||
EditorTextFieldComponent eField = new EditorTextFieldComponent(newField);
|
||||
editor.addEditorComponent(eField);
|
||||
break;
|
||||
case 4:
|
||||
noppes.npcs.scripted.gui.ScriptGuiTexturedRect newRect =
|
||||
new noppes.npcs.scripted.gui.ScriptGuiTexturedRect(getDefaultId(), "default:texture", centerX - 40, centerY - 10, 80, 20);
|
||||
EditorTexturedRectComponent eRect = new EditorTexturedRectComponent(newRect);
|
||||
editor.addEditorComponent(eRect);
|
||||
break;
|
||||
case 8:
|
||||
editor.saveAndClose();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,277 +0,0 @@
|
||||
package kamkeel.npcs.editorgui;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import noppes.npcs.scripted.gui.ScriptGui;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* GuiCustomGuiEditor is the main editor screen.
|
||||
* The canvas covers the full scaled resolution.
|
||||
* The toolbar is positioned at the bottom.
|
||||
* Custom editing buttons (IDs 101–500) are arranged in a single row at the top.
|
||||
* Components are sorted by ID so that higher IDs render on top.
|
||||
* A SubGuiEditProperty overlay is used for property editing.
|
||||
*/
|
||||
public class GuiCustomGuiEditor extends GuiScreen {
|
||||
// Full-screen canvas.
|
||||
public int canvasX = 0;
|
||||
public int canvasY = 0;
|
||||
public int canvasWidth;
|
||||
public int canvasHeight;
|
||||
|
||||
private List<IEditorComponent> editorComponents = new ArrayList<>();
|
||||
private EditorToolBar toolBar;
|
||||
private IEditorComponent selectedComponent;
|
||||
private CustomGuiEditorController controller;
|
||||
|
||||
// The sub–GUI overlay for property editing; null if none is open.
|
||||
private SubGuiEditProperty subGuiOverlay = null;
|
||||
|
||||
// For dragging: offset from mouse to component's top–left.
|
||||
private int dragOffsetX, dragOffsetY;
|
||||
private boolean isDragging = false;
|
||||
|
||||
public GuiCustomGuiEditor() {
|
||||
controller = new CustomGuiEditorController();
|
||||
mc = Minecraft.getMinecraft();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
canvasWidth = res.getScaledWidth();
|
||||
canvasHeight = res.getScaledHeight();
|
||||
canvasX = 0;
|
||||
canvasY = 0;
|
||||
toolBar = new EditorToolBar(canvasX, canvasY + canvasHeight - 40, canvasWidth, 40);
|
||||
toolBar.updateDimensions(canvasX, canvasY + canvasHeight - 40, canvasWidth, 40);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawDefaultBackground() {
|
||||
// Fill the full screen with a light background.
|
||||
drawRect(canvasX, canvasY, canvasX + canvasWidth, canvasY + canvasHeight, 0xFFCCCCCC);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
drawDefaultBackground();
|
||||
// Sort components by ID ascending so that higher IDs render on top.
|
||||
toolBar.render(mouseX, mouseY, partialTicks);
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
// If a sub–GUI overlay is open, draw it on top.
|
||||
if (subGuiOverlay != null) {
|
||||
subGuiOverlay.drawScreen(mouseX, mouseY, partialTicks);
|
||||
} else {
|
||||
Collections.sort(editorComponents, new Comparator<IEditorComponent>() {
|
||||
@Override
|
||||
public int compare(IEditorComponent o1, IEditorComponent o2) {
|
||||
int id1 = ((AbstractEditorComponent) o1).getID();
|
||||
int id2 = ((AbstractEditorComponent) o2).getID();
|
||||
return Integer.compare(id1, id2);
|
||||
}
|
||||
});
|
||||
for (IEditorComponent comp : editorComponents) {
|
||||
comp.render(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (subGuiOverlay != null) {
|
||||
subGuiOverlay.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
return;
|
||||
}
|
||||
// Check if any custom editing button (IDs 101–500) is clicked.
|
||||
for (Object obj : this.buttonList) {
|
||||
GuiButton btn = (GuiButton) obj;
|
||||
if (btn.id >= 101 && btn.id < 500 && btn.mousePressed(mc, mouseX, mouseY)) {
|
||||
this.actionPerformed(btn);
|
||||
updateCustomButtons();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Let toolbar buttons handle clicks.
|
||||
for (GuiButton btn : toolBar.getButtons()) {
|
||||
if (btn.mousePressed(mc, mouseX, mouseY)) {
|
||||
toolBar.actionPerformed(btn, this);
|
||||
updateCustomButtons();
|
||||
return;
|
||||
}
|
||||
}
|
||||
boolean anySelected = false;
|
||||
for (IEditorComponent comp : editorComponents) {
|
||||
if (comp.mouseClicked(mouseX, mouseY, mouseButton)) {
|
||||
selectedComponent = comp;
|
||||
anySelected = true;
|
||||
} else {
|
||||
comp.setSelected(false);
|
||||
}
|
||||
}
|
||||
if (!anySelected) {
|
||||
selectedComponent = null;
|
||||
} else if (selectedComponent != null) {
|
||||
dragOffsetX = mouseX - ((AbstractEditorComponent) selectedComponent).posX;
|
||||
dragOffsetY = mouseY - ((AbstractEditorComponent) selectedComponent).posY;
|
||||
isDragging = true;
|
||||
}
|
||||
updateCustomButtons();
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseMovedOrUp(int mouseX, int mouseY, int state) {
|
||||
if (subGuiOverlay != null) {
|
||||
subGuiOverlay.mouseMovedOrUp(mouseX, mouseY, state);
|
||||
return;
|
||||
}
|
||||
if (selectedComponent != null) {
|
||||
selectedComponent.mouseReleased(mouseX, mouseY, state);
|
||||
}
|
||||
isDragging = false;
|
||||
super.mouseMovedOrUp(mouseX, mouseY, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClickMove(int mouseX, int mouseY, int mouseButton, long timeSinceLastClick) {
|
||||
if (subGuiOverlay != null) {
|
||||
subGuiOverlay.mouseClickMove(mouseX, mouseY, mouseButton, timeSinceLastClick);
|
||||
return;
|
||||
}
|
||||
if (isDragging && selectedComponent != null) {
|
||||
int newX = mouseX - dragOffsetX;
|
||||
int newY = mouseY - dragOffsetY;
|
||||
int compW = ((AbstractEditorComponent) selectedComponent).width;
|
||||
int compH = ((AbstractEditorComponent) selectedComponent).height;
|
||||
if (newX < canvasX) newX = canvasX;
|
||||
if (newY < canvasY) newY = canvasY;
|
||||
if (newX + compW > canvasWidth) newX = canvasWidth - compW;
|
||||
if (newY + compH > canvasHeight) newY = canvasHeight - compH;
|
||||
((AbstractEditorComponent) selectedComponent).posX = newX;
|
||||
((AbstractEditorComponent) selectedComponent).posY = newY;
|
||||
selectedComponent.mouseDragged(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
super.mouseClickMove(mouseX, mouseY, mouseButton, timeSinceLastClick);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char typedChar, int keyCode) {
|
||||
if (subGuiOverlay != null) {
|
||||
subGuiOverlay.keyTyped(typedChar, keyCode);
|
||||
return;
|
||||
}
|
||||
if (keyCode == Keyboard.KEY_ESCAPE) {
|
||||
saveAndClose();
|
||||
return;
|
||||
}
|
||||
if (keyCode == Keyboard.KEY_DELETE || keyCode == Keyboard.KEY_BACK) {
|
||||
if (selectedComponent != null) {
|
||||
Iterator<IEditorComponent> iter = editorComponents.iterator();
|
||||
while (iter.hasNext()) {
|
||||
IEditorComponent comp = iter.next();
|
||||
if (comp == selectedComponent) {
|
||||
iter.remove();
|
||||
selectedComponent = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
updateCustomButtons();
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
if (button.id >= 101 && button.id < 500) {
|
||||
if (selectedComponent != null)
|
||||
selectedComponent.onEditorButtonPressed(button);
|
||||
updateCustomButtons();
|
||||
} else {
|
||||
toolBar.actionPerformed(button, this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates custom editing buttons (IDs 101–500) so they appear in a single row at the top.
|
||||
*/
|
||||
private void updateCustomButtons() {
|
||||
for (int i = buttonList.size() - 1; i >= 0; i--) {
|
||||
GuiButton btn = (GuiButton) buttonList.get(i);
|
||||
if (btn.id >= 101 && btn.id < 500) {
|
||||
buttonList.remove(i);
|
||||
}
|
||||
}
|
||||
if (selectedComponent != null) {
|
||||
List<GuiButton> customButtons = new ArrayList<>();
|
||||
selectedComponent.addEditorButtons(customButtons);
|
||||
int startX = 5;
|
||||
int startY = 5;
|
||||
int buttonWidth = 30;
|
||||
int buttonHeight = 20;
|
||||
int spacing = 5;
|
||||
int currentX = startX;
|
||||
for (GuiButton btn : customButtons) {
|
||||
btn.xPosition = currentX;
|
||||
btn.yPosition = startY;
|
||||
btn.width = buttonWidth;
|
||||
btn.height = buttonHeight;
|
||||
currentX += buttonWidth + spacing;
|
||||
}
|
||||
buttonList.addAll(customButtons);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new editor component.
|
||||
*/
|
||||
public void addEditorComponent(IEditorComponent comp) {
|
||||
editorComponents.add(comp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the selected editor component.
|
||||
*/
|
||||
public void setSelectedComponent(IEditorComponent comp) {
|
||||
this.selectedComponent = comp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a ScriptGui from the editor components, saves it, and closes the editor.
|
||||
*/
|
||||
public void saveAndClose() {
|
||||
ScriptGui newGui = new ScriptGui();
|
||||
for (IEditorComponent comp : editorComponents) {
|
||||
newGui.updateComponent((noppes.npcs.api.gui.ICustomGuiComponent) comp.toScriptComponent());
|
||||
}
|
||||
CustomGuiEditorController controller = new CustomGuiEditorController();
|
||||
controller.saveGui(new File("customgui.json"), newGui);
|
||||
Minecraft.getMinecraft().displayGuiScreen(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current sub–GUI overlay (for property editing) and forwards events to it.
|
||||
*/
|
||||
public void setSubGuiOverlay(SubGuiEditProperty overlay) {
|
||||
overlay.initGui();
|
||||
this.subGuiOverlay = overlay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the sub–GUI overlay.
|
||||
*/
|
||||
public void clearSubGuiOverlay() {
|
||||
this.subGuiOverlay = null;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package kamkeel.npcs.editorgui;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* IEditorComponent defines the methods that all editor wrappers must implement.
|
||||
*/
|
||||
public interface IEditorComponent {
|
||||
void render(int mouseX, int mouseY, float partialTicks);
|
||||
boolean mouseClicked(int mouseX, int mouseY, int mouseButton);
|
||||
void mouseDragged(int mouseX, int mouseY, int mouseButton);
|
||||
void mouseReleased(int mouseX, int mouseY, int state);
|
||||
void update();
|
||||
Object toScriptComponent();
|
||||
void setSelected(boolean selected);
|
||||
boolean isSelected();
|
||||
|
||||
/**
|
||||
* Add custom editing buttons (IDs 101–500) to the provided list.
|
||||
*/
|
||||
default void addEditorButtons(List<GuiButton> buttonList) { }
|
||||
|
||||
/**
|
||||
* Called when one of the custom editing buttons is pressed.
|
||||
*/
|
||||
default void onEditorButtonPressed(GuiButton button) { }
|
||||
|
||||
default NBTTagCompound toEditorNBT() {
|
||||
return new NBTTagCompound();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package kamkeel.npcs.editorgui;
|
||||
|
||||
/**
|
||||
* IPropertyEditorCallback is used by the property editor overlay
|
||||
* to return the updated value.
|
||||
*/
|
||||
public interface IPropertyEditorCallback {
|
||||
void propertyUpdated(String newValue);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package kamkeel.npcs.editorgui;
|
||||
|
||||
/**
|
||||
* ISubGuiCallback allows a sub–GUI overlay to notify its parent when it’s done.
|
||||
*/
|
||||
public interface ISubGuiCallback {
|
||||
void onSubGuiClosed();
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
package kamkeel.npcs.editorgui;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
* SubGuiEditProperty is a modal overlay for editing a single property.
|
||||
* It overlays on top of the current editor screen.
|
||||
* When "Done" is pressed, the provided property callback is invoked and the overlay is closed.
|
||||
* All overridden methods are declared public.
|
||||
*/
|
||||
public class SubGuiEditProperty extends GuiScreen {
|
||||
private ISubGuiCallback subGuiCallback;
|
||||
private IPropertyEditorCallback propCallback;
|
||||
private GuiTextField textField;
|
||||
private String propertyName;
|
||||
private String initialValue;
|
||||
|
||||
// Overlay dimensions
|
||||
private int overlayX, overlayY, overlayWidth, overlayHeight;
|
||||
|
||||
/**
|
||||
* Creates a new property editor overlay.
|
||||
* @param propertyName the name of the property being edited
|
||||
* @param initialValue the current value (as String)
|
||||
* @param propCallback callback for when the property is updated
|
||||
* @param subGuiCallback callback for when the overlay is closed
|
||||
*/
|
||||
public SubGuiEditProperty(String propertyName, String initialValue, IPropertyEditorCallback propCallback, ISubGuiCallback subGuiCallback) {
|
||||
this.propertyName = propertyName;
|
||||
this.initialValue = (initialValue == null ? "" : initialValue);
|
||||
this.propCallback = propCallback;
|
||||
this.subGuiCallback = subGuiCallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
this.mc = Minecraft.getMinecraft();
|
||||
ScaledResolution res = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight);
|
||||
if (this.fontRendererObj == null) {
|
||||
this.fontRendererObj = Minecraft.getMinecraft().fontRenderer;
|
||||
}
|
||||
|
||||
// Use the current width/height from this screen.
|
||||
this.width = res.getScaledWidth();
|
||||
this.height = res.getScaledHeight();
|
||||
overlayWidth = 150;
|
||||
overlayHeight = 20;
|
||||
overlayX = (this.width - overlayWidth) / 2;
|
||||
overlayY = (this.height - overlayHeight) / 2;
|
||||
textField = new GuiTextField(this.fontRendererObj, overlayX, overlayY, overlayWidth, overlayHeight);
|
||||
textField.setText(initialValue);
|
||||
textField.setFocused(true);
|
||||
buttonList.clear();
|
||||
// "Done" button positioned below the text field.
|
||||
buttonList.add(new GuiButton(1000000, overlayX, overlayY + overlayHeight + 5, overlayWidth, 20, "Done"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
textField.updateCursorCounter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
if (this.fontRendererObj == null) {
|
||||
this.fontRendererObj = Minecraft.getMinecraft().fontRenderer;
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
// Draw semi-transparent background and overlay elements
|
||||
drawRect(0, 0, this.width, this.height, 0x88000000);
|
||||
drawCenteredString(this.fontRendererObj, "Edit " + propertyName, this.width / 2, overlayY - 30, 0xFFFFFF);
|
||||
textField.drawTextBox();
|
||||
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char typedChar, int keyCode) {
|
||||
textField.textboxKeyTyped(typedChar, keyCode);
|
||||
if (keyCode == Keyboard.KEY_ESCAPE) {
|
||||
closeOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton button) {
|
||||
if (button.id == 1000000) {
|
||||
if (propCallback != null) {
|
||||
propCallback.propertyUpdated(textField.getText());
|
||||
}
|
||||
closeOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseMovedOrUp(int mouseX, int mouseY, int state) {
|
||||
super.mouseMovedOrUp(mouseX, mouseY, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClickMove(int mouseX, int mouseY, int mouseButton, long timeSinceLastClick) {
|
||||
super.mouseClickMove(mouseX, mouseY, mouseButton, timeSinceLastClick);
|
||||
}
|
||||
|
||||
public void closeOverlay() {
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
if(textField != null) {
|
||||
textField.setFocused(false);
|
||||
}
|
||||
if (subGuiCallback != null) {
|
||||
subGuiCallback.onSubGuiClosed();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,6 @@ import kamkeel.npcs.network.packets.player.customgui.CustomGuiButtonPacket;
|
||||
import kamkeel.npcs.network.packets.player.customgui.CustomGuiClosePacket;
|
||||
import kamkeel.npcs.network.packets.player.customgui.CustomGuiUnfocusedPacket;
|
||||
import kamkeel.npcs.network.packets.player.customgui.CustomScrollClickPacket;
|
||||
import kamkeel.npcs.network.packets.player.item.GuiMagicBookPacket;
|
||||
import kamkeel.npcs.network.packets.player.item.GuiPaintbrushPacket;
|
||||
import kamkeel.npcs.network.packets.player.item.MagicCyclesPacket;
|
||||
import kamkeel.npcs.network.packets.player.profile.*;
|
||||
import kamkeel.npcs.network.packets.request.*;
|
||||
import kamkeel.npcs.network.packets.request.animation.AnimationGetPacket;
|
||||
@@ -432,11 +429,6 @@ public class PacketHandler {
|
||||
PLAYER_PACKET.registerPacket(new CustomGuiUnfocusedPacket());
|
||||
PLAYER_PACKET.registerPacket(new CustomScrollClickPacket());
|
||||
|
||||
// Item Gui Packets
|
||||
PLAYER_PACKET.registerPacket(new GuiPaintbrushPacket());
|
||||
PLAYER_PACKET.registerPacket(new GuiMagicBookPacket());
|
||||
PLAYER_PACKET.registerPacket(new MagicCyclesPacket());
|
||||
|
||||
// Profile Packets
|
||||
PLAYER_PACKET.registerPacket(new ProfileCreatePacket());
|
||||
PLAYER_PACKET.registerPacket(new ProfileRemovePacket());
|
||||
|
||||
@@ -95,14 +95,7 @@ public class PacketUtil {
|
||||
break;
|
||||
case HAMMER:
|
||||
if (item.getItem() != CustomItems.tool || item.getItemDamage() != 0) {
|
||||
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Hammer, they could be a hacker",
|
||||
player.getCommandSenderName(), type));
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case MAGIC_BOOK:
|
||||
if (item.getItem() != CustomItems.tool || item.getItemDamage() != 2) {
|
||||
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Magic Book, they could be a hacker",
|
||||
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Pather, they could be a hacker",
|
||||
player.getCommandSenderName(), type));
|
||||
return false;
|
||||
}
|
||||
@@ -165,8 +158,6 @@ public class PacketUtil {
|
||||
return item.getItem() == CustomItems.tool && item.getItemDamage() == 1;
|
||||
case HAMMER:
|
||||
return item.getItem() == CustomItems.tool && item.getItemDamage() == 0;
|
||||
case MAGIC_BOOK:
|
||||
return item.getItem() == CustomItems.tool && item.getItemDamage() == 2;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -206,8 +197,6 @@ public class PacketUtil {
|
||||
return "Paintbrush";
|
||||
case HAMMER:
|
||||
return "Hammer";
|
||||
case MAGIC_BOOK:
|
||||
return "Magic Book";
|
||||
default:
|
||||
return type.toString();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,5 @@ public enum EnumItemPacketType {
|
||||
PATHER,
|
||||
BLOCK,
|
||||
BRUSH,
|
||||
HAMMER,
|
||||
MAGIC_BOOK
|
||||
HAMMER
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
import noppes.npcs.client.gui.custom.components.CustomGuiButton;
|
||||
|
||||
public enum EnumPlayerPacket {
|
||||
FollowerAction,
|
||||
Transport,
|
||||
@@ -16,16 +14,12 @@ public enum EnumPlayerPacket {
|
||||
GetRole,
|
||||
InputDevice,
|
||||
ScreenSize,
|
||||
MagicCycles,
|
||||
|
||||
CustomGuiButton,
|
||||
CustomGuiScrollClick,
|
||||
CustomGuiClose,
|
||||
CustomGuiUnfocused,
|
||||
|
||||
GuiPaintbrush,
|
||||
GuiMagicBook,
|
||||
|
||||
ProfileCreate,
|
||||
ProfileRemove,
|
||||
ProfileRename,
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
package kamkeel.npcs.network.packets.player.item;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.PacketUtil;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumPlayerPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GuiMagicBookPacket extends AbstractPacket {
|
||||
public static String packetName = "Player|GuiMagicBook";
|
||||
|
||||
private int guiIndex, posX, posY, posZ;
|
||||
|
||||
public GuiMagicBookPacket(int guiIndex, int posX, int posY, int posZ) {
|
||||
this.guiIndex = guiIndex;
|
||||
this.posX = posX;
|
||||
this.posY = posY;
|
||||
this.posZ = posZ;
|
||||
}
|
||||
|
||||
public GuiMagicBookPacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumPlayerPacket.GuiMagicBook;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.PLAYER_PACKET;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(guiIndex);
|
||||
out.writeInt(posX);
|
||||
out.writeInt(posY);
|
||||
out.writeInt(posZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
if (!PacketUtil.verifyItemPacket(player, EnumItemPacketType.MAGIC_BOOK))
|
||||
return;
|
||||
|
||||
int index = in.readInt();
|
||||
int x = in.readInt();
|
||||
int y = in.readInt();
|
||||
int z = in.readInt();
|
||||
EnumGuiType gui = EnumGuiType.values()[index];
|
||||
NoppesUtilServer.sendOpenGui(player, gui, null, x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package kamkeel.npcs.network.packets.player.item;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.PacketUtil;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumPlayerPacket;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GuiPaintbrushPacket extends AbstractPacket {
|
||||
public static String packetName = "Player|GuiPaintbrush";
|
||||
|
||||
private int guiIndex, posX, posY, posZ;
|
||||
|
||||
public GuiPaintbrushPacket(int guiIndex, int posX, int posY, int posZ) {
|
||||
this.guiIndex = guiIndex;
|
||||
this.posX = posX;
|
||||
this.posY = posY;
|
||||
this.posZ = posZ;
|
||||
}
|
||||
|
||||
public GuiPaintbrushPacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumPlayerPacket.GuiPaintbrush;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.PLAYER_PACKET;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(guiIndex);
|
||||
out.writeInt(posX);
|
||||
out.writeInt(posY);
|
||||
out.writeInt(posZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
if (!PacketUtil.verifyItemPacket(player, EnumItemPacketType.BRUSH))
|
||||
return;
|
||||
|
||||
int index = in.readInt();
|
||||
int x = in.readInt();
|
||||
int y = in.readInt();
|
||||
int z = in.readInt();
|
||||
EnumGuiType gui = EnumGuiType.values()[index];
|
||||
NoppesUtilServer.sendOpenGui(player, gui, null, x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package kamkeel.npcs.network.packets.player.item;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.*;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumPlayerPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import kamkeel.npcs.network.packets.request.magic.MagicGetPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
import noppes.npcs.constants.EnumScrollData;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
import noppes.npcs.controllers.data.MagicCycle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static kamkeel.npcs.network.packets.data.large.ScrollDataPacket.sendScrollData;
|
||||
|
||||
public class MagicCyclesPacket extends AbstractPacket {
|
||||
public static String packetName = "Player|MagicCycles";
|
||||
|
||||
private int id;
|
||||
|
||||
public MagicCyclesPacket() {}
|
||||
|
||||
public MagicCyclesPacket(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumPlayerPacket.MagicCycles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.PLAYER_PACKET;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(this.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
if (!PacketUtil.verifyItemPacket(player, EnumItemPacketType.MAGIC_BOOK))
|
||||
return;
|
||||
|
||||
int id = in.readInt();
|
||||
if(id == -1){
|
||||
HashMap<String, Integer> map = new HashMap<>();
|
||||
for (MagicCycle magicCycle : MagicController.getInstance().cycles.values()) {
|
||||
map.put(magicCycle.displayName.replace("&", "\u00A7"), magicCycle.id);
|
||||
}
|
||||
sendScrollData((EntityPlayerMP) player, map, EnumScrollData.MAGIC_CYCLES);
|
||||
} else {
|
||||
MagicCycle cycle = MagicController.getInstance().getCycle(id);
|
||||
if(cycle == null)
|
||||
return;
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
NBTTagCompound magicCompound = new NBTTagCompound();
|
||||
cycle.writeNBT(magicCompound);
|
||||
compound.setTag("MagicCycle", magicCompound);
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
|
||||
}
|
||||
}
|
||||
|
||||
public static void GetAll() {
|
||||
PacketClient.sendClient(new MagicCyclesPacket(-1));
|
||||
}
|
||||
|
||||
public static void GetCycle(int id) {
|
||||
PacketClient.sendClient(new MagicCyclesPacket(id));
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public final class GuiRequestPacket extends AbstractPacket {
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
if (!PacketUtil.verifyItemPacket(player, EnumItemPacketType.WAND, EnumItemPacketType.CLONER, EnumItemPacketType.BRUSH, EnumItemPacketType.MAGIC_BOOK))
|
||||
if (!PacketUtil.verifyItemPacket(player, EnumItemPacketType.WAND, EnumItemPacketType.CLONER, EnumItemPacketType.BRUSH))
|
||||
return;
|
||||
int index = in.readInt();
|
||||
int x = in.readInt();
|
||||
|
||||
@@ -44,7 +44,7 @@ public final class TraderMarketSavePacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.NPC_ADVANCED_TRADER;
|
||||
return CustomNpcsPermissions.NPC_ADVANCED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ public final class DialogNpcRemovePacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.NPC_ADVANCED_DIALOG;
|
||||
return CustomNpcsPermissions.NPC_ADVANCED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -45,7 +45,7 @@ public final class DialogNpcSetPacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.NPC_ADVANCED_DIALOG;
|
||||
return CustomNpcsPermissions.NPC_ADVANCED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,7 +39,7 @@ public final class FactionSetPacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.NPC_ADVANCED_FACTION;
|
||||
return CustomNpcsPermissions.NPC_ADVANCED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -37,7 +37,7 @@ public final class JobGetPacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.NPC_ADVANCED_JOB;
|
||||
return CustomNpcsPermissions.NPC_ADVANCED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,7 +40,7 @@ public final class JobSavePacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.NPC_ADVANCED_JOB;
|
||||
return CustomNpcsPermissions.NPC_ADVANCED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -60,7 +60,7 @@ public final class JobSpawnerAddPacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.NPC_ADVANCED_JOB;
|
||||
return CustomNpcsPermissions.NPC_ADVANCED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -42,7 +42,7 @@ public final class JobSpawnerRemovePacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.NPC_ADVANCED_JOB;
|
||||
return CustomNpcsPermissions.NPC_ADVANCED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -41,7 +41,7 @@ public final class LinkedSetPacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.NPC_ADVANCED_LINKED;
|
||||
return CustomNpcsPermissions.NPC_ADVANCED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -52,7 +52,7 @@ public final class MagicGetPacket extends AbstractPacket {
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
if (!PacketUtil.verifyItemPacket(player, EnumItemPacketType.WAND))
|
||||
if (!PacketUtil.verifyItemPacket(EnumItemPacketType.WAND, player))
|
||||
return;
|
||||
|
||||
Action action = Action.values()[in.readInt()];
|
||||
|
||||
@@ -46,7 +46,7 @@ public final class MagicNpcSavePacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.NPC_ADVANCED_MAGIC;
|
||||
return CustomNpcsPermissions.NPC_ADVANCED;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ public final class RoleCompanionUpdatePacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.NPC_ADVANCED_ROLE;
|
||||
return CustomNpcsPermissions.NPC_ADVANCED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -41,7 +41,7 @@ public final class RoleSavePacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.NPC_ADVANCED_ROLE;
|
||||
return CustomNpcsPermissions.NPC_ADVANCED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -44,7 +44,7 @@ public final class TagSetPacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.NPC_ADVANCED_TAGS;
|
||||
return CustomNpcsPermissions.NPC_ADVANCED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public final class TransformGetPacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.NPC_ADVANCED_TRANSFORM;
|
||||
return CustomNpcsPermissions.NPC_ADVANCED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ public final class TransformLoadPacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.NPC_ADVANCED_TRANSFORM;
|
||||
return CustomNpcsPermissions.NPC_ADVANCED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ public final class TransformSavePacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.NPC_ADVANCED_TRANSFORM;
|
||||
return CustomNpcsPermissions.NPC_ADVANCED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ public final class TransportSavePacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.NPC_ADVANCED_TRANSPORT;
|
||||
return CustomNpcsPermissions.NPC_ADVANCED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -281,14 +281,10 @@ public class AttributeItemUtil {
|
||||
baseOrder.put("Health", 1);
|
||||
baseOrder.put("Main Attack Damage", 2);
|
||||
baseOrder.put("Neutral Damage", 3);
|
||||
|
||||
// For Modifier: Main Attack Damage then Neutral Damage.
|
||||
Map<String, Integer> modOrder = new HashMap<>();
|
||||
modOrder.put("Health Boost", 1);
|
||||
modOrder.put("Main Attack Damage", 2);
|
||||
modOrder.put("Neutral Damage", 3);
|
||||
modOrder.put("Movement Speed", 4);
|
||||
modOrder.put("Knockback Resistance", 5);
|
||||
modOrder.put("Main Attack Damage", 1);
|
||||
modOrder.put("Neutral Damage", 2);
|
||||
|
||||
// Build sections using our custom sorting.
|
||||
newTooltips.addAll(buildSection(baseList, baseOrder));
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package noppes.npcs;
|
||||
|
||||
import kamkeel.npcs.addon.DBCAddon;
|
||||
import kamkeel.npcs.addon.client.DBCClient;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
@@ -53,9 +52,7 @@ public class AnimationMixinFunctions {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(DBCAddon.IsAvailable() && ClientEventHandler.renderingPlayer != null){
|
||||
DBCClient.Instance.applyRenderModel(modelRenderer);
|
||||
} else if (!DBCAddon.IsAvailable() && ClientEventHandler.renderingPlayer != null) {
|
||||
if (ClientEventHandler.renderingPlayer != null) {
|
||||
ClientEventHandler.playerModel = (modelRenderer).baseModel;
|
||||
if (ClientCacheHandler.playerAnimations.containsKey(ClientEventHandler.renderingPlayer.getUniqueID())) {
|
||||
AnimationData animData = ClientCacheHandler.playerAnimations.get(ClientEventHandler.renderingPlayer.getUniqueID());
|
||||
@@ -224,10 +221,6 @@ public class AnimationMixinFunctions {
|
||||
}
|
||||
|
||||
public static boolean mixin_renderFirstPersonAnimation(float partialRenderTick, EntityPlayer player, ModelBiped model, RenderBlocks renderBlocksIr, ResourceLocation resItemGlint) {
|
||||
if (DBCAddon.IsAvailable()) {
|
||||
return DBCClient.Instance.firstPersonAnimation(partialRenderTick, player,model, renderBlocksIr, resItemGlint);
|
||||
}
|
||||
|
||||
AnimationData animationData = ClientCacheHandler.playerAnimations.get(player.getUniqueID());
|
||||
if (animationData != null && animationData.isActive()) {
|
||||
Frame frame = (Frame) animationData.animation.currentFrame();
|
||||
@@ -905,9 +898,9 @@ public class AnimationMixinFunctions {
|
||||
tailCol = (int) JRMCoreH.getMethod(
|
||||
"stat", Entity.class, int.class, int.class, int.class, int.class, int.class, int.class, float.class).invoke(null,
|
||||
par1EntityPlayer, 2,
|
||||
JRMCoreH.getField("Pwrtyp").get(null), 2,
|
||||
(byte) JRMCoreH.getField("Pwrtyp").get(null), 2,
|
||||
((int[]) JRMCoreH.getField("PlyrAttrbts").get(null))[2], race,
|
||||
JRMCoreH.getField("Class").get(null), 0.0F);
|
||||
(byte) JRMCoreH.getField("Class").get(null), 0.0F);
|
||||
jx = Integer.parseInt((String) JRMCoreH.getMethod("data", String.class, int.class, String.class).invoke(null, par1EntityPlayer.getCommandSenderName(), 8, "200"));
|
||||
float one = (float) tailCol / 100.0F;
|
||||
int perc = (int) ((float) jx / one);
|
||||
|
||||
@@ -39,20 +39,9 @@ public class CustomNpcsPermissions {
|
||||
public static final Permission NPC_STATS = new Permission("customnpcs.npc.stats");
|
||||
public static final Permission NPC_CLONE = new Permission("customnpcs.npc.clone");
|
||||
|
||||
public static final Permission NPC_ADVANCED_TRADER = new Permission("customnpcs.npc.advanced.trader");
|
||||
public static final Permission NPC_ADVANCED_DIALOG = new Permission("customnpcs.npc.advanced.dialog");
|
||||
public static final Permission NPC_ADVANCED_FACTION = new Permission("customnpcs.npc.advanced.faction");
|
||||
public static final Permission NPC_ADVANCED_JOB = new Permission("customnpcs.npc.advanced.job");
|
||||
public static final Permission NPC_ADVANCED_ROLE = new Permission("customnpcs.npc.advanced.role");
|
||||
public static final Permission NPC_ADVANCED_TRANSPORT = new Permission("customnpcs.npc.advanced.transport");
|
||||
public static final Permission NPC_ADVANCED_TRANSFORM = new Permission("customnpcs.npc.advanced.transform");
|
||||
public static final Permission NPC_ADVANCED_LINKED = new Permission("customnpcs.npc.advanced.linked");
|
||||
public static final Permission NPC_ADVANCED_MAGIC = new Permission("customnpcs.npc.advanced.linked");
|
||||
public static final Permission NPC_ADVANCED_TAGS = new Permission("customnpcs.npc.advanced.tags");
|
||||
|
||||
public static final Permission GLOBAL_REMOTE = new Permission("customnpcs.global.remote");
|
||||
|
||||
// Save Global Preferences
|
||||
// Save Globel Preferences
|
||||
public static final Permission GLOBAL_LINKED = new Permission("customnpcs.global.linked");
|
||||
public static final Permission GLOBAL_PLAYERDATA = new Permission("customnpcs.global.playerdata");
|
||||
public static final Permission GLOBAL_BANK = new Permission("customnpcs.global.bank");
|
||||
|
||||
@@ -21,7 +21,6 @@ import noppes.npcs.api.gui.ICustomGui;
|
||||
import noppes.npcs.api.gui.IItemSlot;
|
||||
import noppes.npcs.api.handler.data.IAnimation;
|
||||
import noppes.npcs.api.handler.data.IFrame;
|
||||
import noppes.npcs.api.handler.data.IPlayerEffect;
|
||||
import noppes.npcs.api.handler.data.IProfile;
|
||||
import noppes.npcs.api.item.IItemCustomizable;
|
||||
import noppes.npcs.api.item.IItemLinked;
|
||||
@@ -407,27 +406,6 @@ public class EventHooks {
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onEffectAdded(IPlayer player, IPlayerEffect effect) {
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
PlayerEvent.EffectEvent.Added event = new PlayerEvent.EffectEvent.Added(player, effect);
|
||||
handler.callScript(EffectScript.ScriptType.OnEffectAdd.function, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onEffectTick(IPlayer player, IPlayerEffect effect) {
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
PlayerEvent.EffectEvent.Ticked event = new PlayerEvent.EffectEvent.Ticked(player, effect);
|
||||
handler.callScript(EffectScript.ScriptType.OnEffectTick.function, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onEffectRemove(IPlayer player, IPlayerEffect effect, EffectEvent.ExpirationType type) {
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
PlayerEvent.EffectEvent.Removed event = new PlayerEvent.EffectEvent.Removed(player, effect, type);
|
||||
handler.callScript(EffectScript.ScriptType.OnEffectRemove.function, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onStartUsingItem(PlayerDataScript handler, IPlayer player, int duration, ItemStack item) {
|
||||
PlayerEvent.StartUsingItem event = new PlayerEvent.StartUsingItem(player, item, duration);
|
||||
handler.callScript(EnumScriptType.START_USING_ITEM, event);
|
||||
|
||||
@@ -706,15 +706,15 @@ public class NoppesUtilServer {
|
||||
public static void sendMagicInfo(EntityPlayerMP player, boolean cycles) {
|
||||
HashMap<String, Integer> map = new HashMap<String, Integer>();
|
||||
if (cycles) {
|
||||
for (MagicCycle magicCycle : MagicController.getInstance().cycles.values()) {
|
||||
map.put(magicCycle.name, magicCycle.id);
|
||||
}
|
||||
sendScrollData(player, map, EnumScrollData.MAGIC_CYCLES);
|
||||
} else {
|
||||
for (Magic magic : MagicController.getInstance().magics.values()) {
|
||||
map.put(magic.name, magic.id);
|
||||
}
|
||||
sendScrollData(player, map, EnumScrollData.MAGIC);
|
||||
} else {
|
||||
for (MagicCycle magicCycle : MagicController.getInstance().cycles.values()) {
|
||||
map.put(magicCycle.name, magicCycle.id);
|
||||
}
|
||||
sendScrollData(player, map, EnumScrollData.MAGIC_CYCLES);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
||||
import kamkeel.npcs.addon.client.DBCClient;
|
||||
import kamkeel.npcs.editorgui.GuiCustomGuiEditor;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.model.ModelBiped;
|
||||
@@ -44,7 +43,6 @@ import noppes.npcs.client.fx.EntityRainbowFX;
|
||||
import noppes.npcs.client.gui.*;
|
||||
import noppes.npcs.client.gui.custom.GuiCustom;
|
||||
import noppes.npcs.client.gui.global.*;
|
||||
import noppes.npcs.client.gui.item.GuiNpcMagicBook;
|
||||
import noppes.npcs.client.gui.item.GuiNpcPaintbrush;
|
||||
import noppes.npcs.client.gui.mainmenu.*;
|
||||
import noppes.npcs.client.gui.player.*;
|
||||
@@ -268,10 +266,8 @@ public class ClientProxy extends CommonProxy {
|
||||
else if (gui == EnumGuiType.MovingPath)
|
||||
return new GuiNpcPather(npc);
|
||||
|
||||
else if (gui == EnumGuiType.ManageFactions)
|
||||
return new GuiCustomGuiEditor();
|
||||
// TODO: CHANGE BACK
|
||||
// return new GuiNPCManageFactions(npc);
|
||||
else if (gui == EnumGuiType.ManageFactions)
|
||||
return new GuiNPCManageFactions(npc);
|
||||
|
||||
else if (gui == EnumGuiType.ManageCustomForms)
|
||||
return DBCClient.Instance.manageCustomForms(npc);
|
||||
@@ -296,6 +292,7 @@ public class ClientProxy extends CommonProxy {
|
||||
animNpc.display.texture = "customnpcs:textures/entity/humanmale/AnimationBody.png";
|
||||
save = false;
|
||||
}
|
||||
animNpc.display.setName("Animation Dude");
|
||||
return new GuiNPCManageAnimations(animNpc, save);
|
||||
} else if (gui == EnumGuiType.ManageLinked)
|
||||
return new GuiNPCManageLinked(npc);
|
||||
@@ -426,9 +423,6 @@ public class ClientProxy extends CommonProxy {
|
||||
else if (gui == EnumGuiType.Paintbrush)
|
||||
return new GuiNpcPaintbrush();
|
||||
|
||||
else if (gui == EnumGuiType.MagicBook)
|
||||
return new GuiNpcMagicBook();
|
||||
|
||||
else if (gui == EnumGuiType.GlobalRemote)
|
||||
return new GuiNPCGlobalMainMenu(null);
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import noppes.npcs.client.gui.hud.CompassHudComponent;
|
||||
import noppes.npcs.client.gui.hud.EnumHudComponent;
|
||||
import noppes.npcs.client.gui.hud.HudComponent;
|
||||
import noppes.npcs.client.gui.player.inventory.GuiCNPCInventory;
|
||||
import noppes.npcs.client.gui.util.animation.Cursors;
|
||||
import noppes.npcs.client.renderer.RenderNPCInterface;
|
||||
import noppes.npcs.constants.MarkType;
|
||||
import noppes.npcs.controllers.data.MarkData;
|
||||
@@ -86,6 +87,8 @@ public class ClientTickHandler {
|
||||
PacketClient.sendClient(new ScreenSizePacket(mc.displayWidth, mc.displayHeight));
|
||||
}
|
||||
|
||||
Cursors.tick();
|
||||
|
||||
if (mc.theWorld == null)
|
||||
return;
|
||||
|
||||
|
||||
@@ -54,12 +54,10 @@ public class GuiMagicCycleMap extends GuiDiagram {
|
||||
|
||||
// Use the cycle's layout if set; otherwise default to CIRCULAR_MANUAL.
|
||||
setLayout(cycle.layout != null ? cycle.layout : EnumDiagramLayout.CIRCULAR_MANUAL);
|
||||
setLayout(EnumDiagramLayout.CIRCULAR_MANUAL);
|
||||
setCurvedArrows(true);
|
||||
setCurveAngle(-20);
|
||||
invalidateCache();
|
||||
|
||||
this.allowTwoWay = true;
|
||||
this.iconSize = 20;
|
||||
this.slotSize = iconSize + slotPadding;
|
||||
}
|
||||
@@ -111,10 +109,7 @@ public class GuiMagicCycleMap extends GuiDiagram {
|
||||
int targetId = entry.getKey();
|
||||
if (!orderMap.containsKey(targetId)) continue;
|
||||
float percent = entry.getValue();
|
||||
String modifier = "";
|
||||
if(percent > 0.0)
|
||||
modifier += "+";
|
||||
String hover = modifier + (int) (percent * 100) + "%";
|
||||
String hover = "+" + (int) (percent * 100) + "%";
|
||||
conns.add(new DiagramConnection(m.id, targetId, percent, hover));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ public class CustomGuiButton extends GuiButton implements IClickListener {
|
||||
String label;
|
||||
String[] hoverText;
|
||||
|
||||
public int color;
|
||||
public float alpha;
|
||||
public float scale = 1.0F;
|
||||
int color;
|
||||
float alpha;
|
||||
float scale = 1.0F;
|
||||
|
||||
public CustomGuiButton(int id, String buttonText, int x, int y) {
|
||||
super(id, x, y, buttonText);
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class CustomGuiLabel extends Gui implements IGuiComponent {
|
||||
public int x, y, width, height;
|
||||
int x, y, width, height;
|
||||
GuiCustom parent;
|
||||
String fullLabel;
|
||||
String[] hoverText;
|
||||
@@ -30,9 +30,9 @@ public class CustomGuiLabel extends Gui implements IGuiComponent {
|
||||
boolean labelBgEnabled = true;
|
||||
boolean labelShadowEnabled = false;
|
||||
|
||||
public int color;
|
||||
public float alpha;
|
||||
public float rotation;
|
||||
int color;
|
||||
float alpha;
|
||||
float rotation;
|
||||
|
||||
protected int field_146167_a;
|
||||
protected int field_146161_f;
|
||||
|
||||
@@ -15,20 +15,20 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
|
||||
GuiCustom parent;
|
||||
|
||||
ImageData imageData = null;
|
||||
public String texture;
|
||||
public int id;
|
||||
public int x;
|
||||
public int y;
|
||||
public int width;
|
||||
public int height;
|
||||
public int textureX;
|
||||
public int textureY;
|
||||
public float scale;
|
||||
String texture;
|
||||
int id;
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
int textureX;
|
||||
int textureY;
|
||||
float scale;
|
||||
String[] hoverText;
|
||||
|
||||
public int color;
|
||||
public float alpha;
|
||||
public float rotation;
|
||||
int color;
|
||||
float alpha;
|
||||
float rotation;
|
||||
|
||||
public CustomGuiTexturedRect(int id, String texture, int x, int y, int width, int height) {
|
||||
this(id, texture, x, y, width, height, 0, 0);
|
||||
|
||||
@@ -8,7 +8,9 @@ import noppes.npcs.client.gui.SubGuiAnimationFrame;
|
||||
import noppes.npcs.client.gui.SubGuiAnimationOptions;
|
||||
import noppes.npcs.client.gui.SubGuiColorSelector;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.client.gui.util.animation.AnimationGraphEditor;
|
||||
import noppes.npcs.constants.EnumAnimationPart;
|
||||
import noppes.npcs.constants.animation.EnumFrameType;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.controllers.data.AnimationData;
|
||||
import noppes.npcs.controllers.data.Frame;
|
||||
@@ -34,6 +36,7 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
||||
private final GuiScreen parent;
|
||||
private long prevTick;
|
||||
|
||||
|
||||
private final GuiNpcSlider[] rotationSliders = new GuiNpcSlider[3];
|
||||
private final GuiNpcSlider[] pivotSliders = new GuiNpcSlider[3];
|
||||
|
||||
@@ -42,12 +45,18 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
||||
private final int visibleFrames = 25;
|
||||
private boolean overrideFrame = false;
|
||||
|
||||
public AnimationGraphEditor graphEditor;
|
||||
public GuiNpcButton toggleGraph;
|
||||
private boolean toggleGraphEditor = true;
|
||||
|
||||
public GuiNPCEditAnimation(GuiScreen parent, Animation animation, EntityNPCInterface npc) {
|
||||
super((EntityCustomNpc) npc);
|
||||
this.parent = parent;
|
||||
this.followMouse = false;
|
||||
xOffset = 0;
|
||||
yOffset = -21;
|
||||
maxZoom = 120;
|
||||
drawRenderButtons = false;
|
||||
|
||||
this.animation = animation;
|
||||
AnimationData data = npc.display.animationData;
|
||||
@@ -61,6 +70,7 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
||||
this.pivotSliders[i] = new GuiNpcSlider(this, 95 + i, guiLeft + bodyPartX, guiTop + bodyPartY + 115 + (20 * i), 0.5F);
|
||||
}
|
||||
|
||||
graphEditor = new AnimationGraphEditor(this);
|
||||
this.frameSlider = new GuiNpcSlider(this, 350, 0, 0, 0.0F);
|
||||
}
|
||||
|
||||
@@ -68,7 +78,17 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
if (animation == null) return;
|
||||
if (animation == null)
|
||||
return;
|
||||
yOffset = -21;
|
||||
|
||||
addButton(toggleGraph = new GuiNpcButton(777, guiLeft - 80, guiTop - 2 + 84, 70, 20, "Toggle Graph"));
|
||||
if (toggleGraphEditor) {
|
||||
yOffset = -80;
|
||||
graphEditor.initGui(guiLeft - 10, guiTop + 120, guiLeft - 10 + xSize, guiTop + 135 + 105);
|
||||
addGraphEditor(0, graphEditor);
|
||||
|
||||
}
|
||||
|
||||
frameIndex = !animation.frames.isEmpty() ? frameIndex % animation.frames.size() : 0;
|
||||
this.updateSliders();
|
||||
@@ -98,20 +118,18 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
||||
data.animation.smooth = animation.smooth;
|
||||
data.animation.loop = 0;
|
||||
if (editingFrame != null) {
|
||||
data.animation.frames.add(editingFrame);
|
||||
data.animation.addFrame(editingFrame);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (Frame frame : animation.frames) {
|
||||
frame.parent = animation;
|
||||
if (!frame.isCustomized()) {
|
||||
frame.speed = animation.speed;
|
||||
frame.smooth = animation.smooth;
|
||||
}
|
||||
for (Map.Entry<EnumAnimationPart, FramePart> entry : frame.frameParts.entrySet()) {
|
||||
FramePart part = entry.getValue();
|
||||
part.parent = animation;
|
||||
if (!part.isCustomized()) {
|
||||
part.speed = frame.speed;
|
||||
part.smooth = frame.smooth;
|
||||
@@ -129,37 +147,6 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
||||
overrideFrame = false;
|
||||
}
|
||||
|
||||
this.addLabel(new GuiNpcLabel(10, "animation.frames", guiLeft + 40, guiTop + 176 - 10, 0xFFFFFF));
|
||||
this.addButton(new GuiNpcButton(11, guiLeft - 10, guiTop + 189 - 10, 45, 20, "gui.add"));
|
||||
if (!animation.frames.isEmpty()) {
|
||||
this.addButton(new GuiNpcButton(12, guiLeft + 35, guiTop + 189 - 10, 45, 20, "gui.remove"));
|
||||
this.addButton(new GuiNpcButton(13, guiLeft + 80, guiTop + 189 - 10, 45, 20, "gui.copy"));
|
||||
this.addButton(new GuiNpcButton(14, guiLeft - 10, guiTop + 210 - 3, 20, 20, "<"));
|
||||
this.addTextField(new GuiNpcTextField(15, this, guiLeft + 15, guiTop + 212 - 3, 20, 17, frameIndex + ""));
|
||||
this.getTextField(15).integersOnly = true;
|
||||
this.getTextField(15).setMinMaxDefault(0, animation.frames.size() - 1, frameIndex);
|
||||
this.addButton(new GuiNpcButton(16, guiLeft + 40, guiTop + 210 - 3, 20, 20, ">"));
|
||||
}
|
||||
|
||||
int playPauseX = 330;
|
||||
int playPauseY = 10;
|
||||
String animTexture = "customnpcs:textures/gui/animation.png";
|
||||
if (data.animation != null && data.animation.frames.size() > 0) {
|
||||
if (!this.playingAnimation || data.animation.paused) {//Play
|
||||
this.addLabel(new GuiNpcLabel(210, data.animation.paused ? "animation.paused" : "animation.stopped", guiLeft + playPauseX - 15, guiTop + playPauseY + 203, 0xFFFFFF));
|
||||
if (data.animation.paused) {
|
||||
this.addLabel(new GuiNpcLabel(211, "", guiLeft + playPauseX + 21, guiTop + playPauseY + 203, 0xFFFFFF));
|
||||
}
|
||||
this.addButton(new GuiTexturedButton(200, "", guiLeft + playPauseX + 35, guiTop + playPauseY + 197, 11, 20, animTexture, 18, 71));
|
||||
} else {//Pause
|
||||
this.addLabel(new GuiNpcLabel(212, "animation.playing", guiLeft + playPauseX - 15, guiTop + playPauseY + 203, 0xFFFFFF));
|
||||
this.addLabel(new GuiNpcLabel(213, "", guiLeft + playPauseX + 20, guiTop + playPauseY + 203, 0xFFFFFF));
|
||||
this.addButton(new GuiTexturedButton(201, "", guiLeft + playPauseX + 35, guiTop + playPauseY + 197, 14, 20, animTexture, 0, 71));
|
||||
}
|
||||
if (this.playingAnimation) {//Stop
|
||||
this.addButton(new GuiTexturedButton(202, "", guiLeft + playPauseX + 55, guiTop + playPauseY + 197, 14, 20, animTexture, 33, 71));
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -194,174 +181,211 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
if (editingFrame != null) {
|
||||
int frameX = animationX;
|
||||
int frameY = playPauseY + 100;
|
||||
if (!toggleGraphEditor) {
|
||||
int guiLeft = this.guiLeft;
|
||||
this.addLabel(new GuiNpcLabel(10, "animation.frames", guiLeft + 40, guiTop + 176 - 10, 0xFFFFFF));
|
||||
this.addButton(new GuiNpcButton(11, guiLeft - 10, guiTop + 189 - 10, 45, 20, "gui.add"));
|
||||
if (!animation.frames.isEmpty()) {
|
||||
this.addButton(new GuiNpcButton(12, guiLeft + 35, guiTop + 189 - 10, 45, 20, "gui.remove"));
|
||||
this.addButton(new GuiNpcButton(13, guiLeft + 80, guiTop + 189 - 10, 45, 20, "gui.copy"));
|
||||
this.addButton(new GuiNpcButton(14, guiLeft - 10, guiTop + 210 - 3, 20, 20, "<"));
|
||||
this.addTextField(new GuiNpcTextField(15, this, guiLeft + 15, guiTop + 212 - 3, 20, 17, frameIndex + ""));
|
||||
this.getTextField(15).integersOnly = true;
|
||||
this.getTextField(15).setMinMaxDefault(0, animation.frames.size() - 1, frameIndex);
|
||||
this.addButton(new GuiNpcButton(16, guiLeft + 40, guiTop + 210 - 3, 20, 20, ">"));
|
||||
}
|
||||
|
||||
this.addLabel(new GuiNpcLabel(50, "animation.frame", guiLeft + frameX + 50, guiTop + frameY - 3, 0xFFFFFF));
|
||||
//
|
||||
//duration - textfield
|
||||
this.addLabel(new GuiNpcLabel(51, "animation.duration", guiLeft + frameX, guiTop + frameY + 15, 0xFFFFFF));
|
||||
this.addTextField(new GuiNpcTextField(51, this, guiLeft + frameX + 88, guiTop + frameY + 11, 30, 15, editingFrame.duration + ""));
|
||||
this.getTextField(51).integersOnly = true;
|
||||
this.getTextField(51).setMinMaxDefaultFloat(0, Integer.MAX_VALUE, 10);
|
||||
int playPauseX = 330;
|
||||
int playPauseY = 10;
|
||||
|
||||
this.addButton(new GuiNpcButton(52, guiLeft + frameX, guiTop + frameY + 31, 80, 20, "animation.frameOptions"));
|
||||
this.addButton(new GuiNpcButton(53, guiLeft + frameX + getButton(52).width + 5, guiTop + frameY + 31, 35, 20, "gui.color"));
|
||||
|
||||
int bodyPartX = 280;
|
||||
int bodyPartY = -5;
|
||||
|
||||
//
|
||||
//6 body part textured buttons
|
||||
//Add/remove part button
|
||||
// 6 custom GUI textured buttons for each body part determine "this.currentPart (enum)".
|
||||
// If the current frame doesn't have that part, the button will say "Add part"
|
||||
// otherwise, the button will say "Remove", and more options for editing the part become available:
|
||||
//
|
||||
|
||||
//Head
|
||||
this.addButton(new GuiTexturedButton(60, "", guiLeft + bodyPartX, guiTop + bodyPartY, 22, 23, animTexture, 0, 0));
|
||||
//Body
|
||||
this.addButton(new GuiTexturedButton(61, "", guiLeft + bodyPartX, guiTop + bodyPartY + 23, 22, 23, animTexture, 24, 0));
|
||||
//Right Arm
|
||||
this.addButton(new GuiTexturedButton(62, "", guiLeft + bodyPartX - 9, guiTop + bodyPartY + 23, 8, 23, animTexture, 48, 0));
|
||||
//Left Arm
|
||||
this.addButton(new GuiTexturedButton(63, "", guiLeft + bodyPartX + 26, guiTop + bodyPartY + 23, 8, 23, animTexture, 48, 0));
|
||||
//Right Leg
|
||||
this.addButton(new GuiTexturedButton(64, "", guiLeft + bodyPartX + 1, guiTop + bodyPartY + 48, 10, 23, animTexture, 58, 0));
|
||||
//Left Leg
|
||||
this.addButton(new GuiTexturedButton(65, "", guiLeft + bodyPartX + 12, guiTop + bodyPartY + 48, 10, 23, animTexture, 58, 0));
|
||||
//Full Body
|
||||
this.addButton(new GuiTexturedButton(66, "", guiLeft + bodyPartX + 40, guiTop + bodyPartY + 2, 17, 23, animTexture, 70, 0));
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
if (this.buttons.containsKey(60 + i)) {
|
||||
((GuiTexturedButton) this.getButton(60 + i)).scale = 1.2F;
|
||||
if (!editingFrame.frameParts.containsKey(EnumAnimationPart.values()[i])) {
|
||||
((GuiTexturedButton) this.getButton(60 + i)).textureX += 96;
|
||||
String animTexture = "customnpcs:textures/gui/animation.png";
|
||||
if (data.animation != null && data.animation.frames.size() > 0) {
|
||||
if (!this.playingAnimation || data.animation.paused) {//Play
|
||||
this.addLabel(new GuiNpcLabel(210, data.animation.paused ? "animation.paused" : "animation.stopped", guiLeft + playPauseX - 15, guiTop + playPauseY + 203, 0xFFFFFF));
|
||||
if (data.animation.paused) {
|
||||
this.addLabel(new GuiNpcLabel(211, "", guiLeft + playPauseX + 21, guiTop + playPauseY + 203, 0xFFFFFF));
|
||||
}
|
||||
this.addButton(new GuiTexturedButton(200, "", guiLeft + playPauseX + 35, guiTop + playPauseY + 197, 11, 20, animTexture, 18, 71));
|
||||
} else {//Pause
|
||||
this.addLabel(new GuiNpcLabel(212, "animation.playing", guiLeft + playPauseX - 15, guiTop + playPauseY + 203, 0xFFFFFF));
|
||||
this.addLabel(new GuiNpcLabel(213, "", guiLeft + playPauseX + 20, guiTop + playPauseY + 203, 0xFFFFFF));
|
||||
this.addButton(new GuiTexturedButton(201, "", guiLeft + playPauseX + 35, guiTop + playPauseY + 197, 14, 20, animTexture, 0, 71));
|
||||
}
|
||||
if (this.playingAnimation) {//Stop
|
||||
this.addButton(new GuiTexturedButton(202, "", guiLeft + playPauseX + 55, guiTop + playPauseY + 197, 14, 20, animTexture, 33, 71));
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
if (editingFrame != null) {
|
||||
int frameX = animationX;
|
||||
int frameY = playPauseY + 100;
|
||||
|
||||
if (editingPart != null) {
|
||||
//remove part button
|
||||
this.addLabel(new GuiNpcLabel(67, editingPart.part.name(), guiLeft + bodyPartX + 65, guiTop + bodyPartY + 20, 0xFFFFFF));
|
||||
this.addButton(new GuiNpcButton(67, guiLeft + bodyPartX + 45, guiTop + bodyPartY + 35, 60, 20, "gui.remove"));
|
||||
this.addLabel(new GuiNpcLabel(50, "animation.frame", guiLeft + frameX + 50, guiTop + frameY - 3, 0xFFFFFF));
|
||||
//
|
||||
//duration - textfield
|
||||
this.addLabel(new GuiNpcLabel(51, "animation.duration", guiLeft + frameX, guiTop + frameY + 15, 0xFFFFFF));
|
||||
this.addTextField(new GuiNpcTextField(51, this, guiLeft + frameX + 88, guiTop + frameY + 11, 30, 15, editingFrame.duration + ""));
|
||||
this.getTextField(51).integersOnly = true;
|
||||
this.getTextField(51).setMinMaxDefaultFloat(0, Integer.MAX_VALUE, 10);
|
||||
|
||||
this.addButton(new GuiNpcButton(68, guiLeft + bodyPartX + 45, guiTop + bodyPartY + 57, 60, 20, new String[]{"model.sliders", "model.manual"}, partEditMode));
|
||||
this.addButton(new GuiNpcButton(52, guiLeft + frameX, guiTop + frameY + 31, 80, 20, "animation.frameOptions"));
|
||||
this.addButton(new GuiNpcButton(53, guiLeft + frameX + getButton(52).width + 5, guiTop + frameY + 31, 35, 20, "gui.color"));
|
||||
|
||||
if (partEditMode == 0) {
|
||||
this.addButton(new GuiNpcButton(69, guiLeft + bodyPartX, guiTop + bodyPartY + 80, 60, 20, "model.rotate"));
|
||||
this.addButton(new GuiNpcButton(70, guiLeft + bodyPartX + 62, guiTop + bodyPartY + 80, 60, 20, "model.pivot"));
|
||||
int bodyPartX = 280;
|
||||
int bodyPartY = -5;
|
||||
|
||||
this.getButton(69).setEnabled(sliderSelection == 1);
|
||||
this.getButton(70).setEnabled(sliderSelection == 0);
|
||||
//
|
||||
//6 body part textured buttons
|
||||
//Add/remove part button
|
||||
// 6 custom GUI textured buttons for each body part determine "this.currentPart (enum)".
|
||||
// If the current frame doesn't have that part, the button will say "Add part"
|
||||
// otherwise, the button will say "Remove", and more options for editing the part become available:
|
||||
//
|
||||
|
||||
if (sliderSelection == 0) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
this.rotationSliders[i].width = 122;
|
||||
this.rotationSliders[i].height = 20;
|
||||
this.rotationSliders[i].xPosition = guiLeft + bodyPartX;
|
||||
//Head
|
||||
this.addButton(new GuiTexturedButton(60, "", guiLeft + bodyPartX, guiTop + bodyPartY, 22, 23, animTexture, 0, 0));
|
||||
//Body
|
||||
this.addButton(new GuiTexturedButton(61, "", guiLeft + bodyPartX, guiTop + bodyPartY + 23, 22, 23, animTexture, 24, 0));
|
||||
//Right Arm
|
||||
this.addButton(new GuiTexturedButton(62, "", guiLeft + bodyPartX - 9, guiTop + bodyPartY + 23, 8, 23, animTexture, 48, 0));
|
||||
//Left Arm
|
||||
this.addButton(new GuiTexturedButton(63, "", guiLeft + bodyPartX + 26, guiTop + bodyPartY + 23, 8, 23, animTexture, 48, 0));
|
||||
//Right Leg
|
||||
this.addButton(new GuiTexturedButton(64, "", guiLeft + bodyPartX + 1, guiTop + bodyPartY + 48, 10, 23, animTexture, 58, 0));
|
||||
//Left Leg
|
||||
this.addButton(new GuiTexturedButton(65, "", guiLeft + bodyPartX + 12, guiTop + bodyPartY + 48, 10, 23, animTexture, 58, 0));
|
||||
//Full Body
|
||||
this.addButton(new GuiTexturedButton(66, "", guiLeft + bodyPartX + 40, guiTop + bodyPartY + 2, 17, 23, animTexture, 70, 0));
|
||||
|
||||
int yOffset = 20;
|
||||
if (i != 0)
|
||||
yOffset += 3;
|
||||
yOffset *= i;
|
||||
this.rotationSliders[i].yPosition = guiTop + bodyPartY + 105 + yOffset;
|
||||
|
||||
this.addSlider(this.rotationSliders[i]);
|
||||
for (int i = 0; i < 7; i++) {
|
||||
if (this.buttons.containsKey(60 + i)) {
|
||||
((GuiTexturedButton) this.getButton(60 + i)).scale = 1.2F;
|
||||
if (!editingFrame.frameParts.containsKey(EnumAnimationPart.values()[i])) {
|
||||
((GuiTexturedButton) this.getButton(60 + i)).textureX += 96;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.addLabel(new GuiNpcLabel(90, "X", guiLeft + bodyPartX - 10, guiTop + bodyPartY + 112, 0xFFFFFF));
|
||||
this.addLabel(new GuiNpcLabel(91, "Y", guiLeft + bodyPartX - 10, guiTop + bodyPartY + 135, 0xFFFFFF));
|
||||
this.addLabel(new GuiNpcLabel(92, "Z", guiLeft + bodyPartX - 10, guiTop + bodyPartY + 157, 0xFFFFFF));
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
if (editingPart != null) {
|
||||
//remove part button
|
||||
this.addLabel(new GuiNpcLabel(67, editingPart.part.name(), guiLeft + bodyPartX + 65, guiTop + bodyPartY + 20, 0xFFFFFF));
|
||||
this.addButton(new GuiNpcButton(67, guiLeft + bodyPartX + 45, guiTop + bodyPartY + 35, 60, 20, "gui.remove"));
|
||||
|
||||
this.addButton(new GuiNpcButton(68, guiLeft + bodyPartX + 45, guiTop + bodyPartY + 57, 60, 20, new String[]{"model.sliders", "model.manual"}, partEditMode));
|
||||
|
||||
if (partEditMode == 0) {
|
||||
this.addButton(new GuiNpcButton(69, guiLeft + bodyPartX, guiTop + bodyPartY + 80, 60, 20, "model.rotate"));
|
||||
this.addButton(new GuiNpcButton(70, guiLeft + bodyPartX + 62, guiTop + bodyPartY + 80, 60, 20, "model.pivot"));
|
||||
|
||||
this.getButton(69).setEnabled(sliderSelection == 1);
|
||||
this.getButton(70).setEnabled(sliderSelection == 0);
|
||||
|
||||
if (sliderSelection == 0) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
this.rotationSliders[i].width = 122;
|
||||
this.rotationSliders[i].height = 20;
|
||||
this.rotationSliders[i].xPosition = guiLeft + bodyPartX;
|
||||
|
||||
int yOffset = 20;
|
||||
if (i != 0)
|
||||
yOffset += 3;
|
||||
yOffset *= i;
|
||||
this.rotationSliders[i].yPosition = guiTop + bodyPartY + 105 + yOffset;
|
||||
|
||||
this.addSlider(this.rotationSliders[i]);
|
||||
}
|
||||
|
||||
this.addLabel(new GuiNpcLabel(90, "X", guiLeft + bodyPartX - 10, guiTop + bodyPartY + 112, 0xFFFFFF));
|
||||
this.addLabel(new GuiNpcLabel(91, "Y", guiLeft + bodyPartX - 10, guiTop + bodyPartY + 135, 0xFFFFFF));
|
||||
this.addLabel(new GuiNpcLabel(92, "Z", guiLeft + bodyPartX - 10, guiTop + bodyPartY + 157, 0xFFFFFF));
|
||||
} else {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
this.pivotSliders[i].width = 122;
|
||||
this.pivotSliders[i].height = 20;
|
||||
this.pivotSliders[i].xPosition = guiLeft + bodyPartX;
|
||||
|
||||
int yOffset = 20;
|
||||
if (i != 0)
|
||||
yOffset += 3;
|
||||
yOffset *= i;
|
||||
this.pivotSliders[i].yPosition = guiTop + bodyPartY + 105 + yOffset;
|
||||
this.addSlider(this.pivotSliders[i]);
|
||||
}
|
||||
|
||||
this.addLabel(new GuiNpcLabel(95, "X", guiLeft + bodyPartX - 10, guiTop + bodyPartY + 112, 0xFFFFFF));
|
||||
this.addLabel(new GuiNpcLabel(96, "Y", guiLeft + bodyPartX - 10, guiTop + bodyPartY + 135, 0xFFFFFF));
|
||||
this.addLabel(new GuiNpcLabel(97, "Z", guiLeft + bodyPartX - 10, guiTop + bodyPartY + 157, 0xFFFFFF));
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
this.pivotSliders[i].width = 122;
|
||||
this.pivotSliders[i].height = 20;
|
||||
this.pivotSliders[i].xPosition = guiLeft + bodyPartX;
|
||||
|
||||
int yOffset = 20;
|
||||
if (i != 0)
|
||||
yOffset += 3;
|
||||
yOffset *= i;
|
||||
this.pivotSliders[i].yPosition = guiTop + bodyPartY + 105 + yOffset;
|
||||
this.addSlider(this.pivotSliders[i]);
|
||||
//
|
||||
//rotation - 3 textfields
|
||||
this.addLabel(new GuiNpcLabel(70, "animation.rotations", guiLeft + bodyPartX, guiTop + bodyPartY + 85, 0xFFFFFF));
|
||||
this.addTextField(new GuiNpcTextField(70, this, guiLeft + bodyPartX, guiTop + bodyPartY + 97, 35, 15, editingPart.rotation[0] + ""));
|
||||
this.getTextField(70).floatsOnly = true;
|
||||
this.getTextField(70).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
|
||||
this.addTextField(new GuiNpcTextField(71, this, guiLeft + bodyPartX + 40, guiTop + bodyPartY + 97, 35, 15, editingPart.rotation[1] + ""));
|
||||
this.getTextField(71).floatsOnly = true;
|
||||
this.getTextField(71).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
|
||||
this.addTextField(new GuiNpcTextField(72, this, guiLeft + bodyPartX + 80, guiTop + bodyPartY + 97, 35, 15, editingPart.rotation[2] + ""));
|
||||
this.getTextField(72).floatsOnly = true;
|
||||
this.getTextField(72).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
|
||||
//
|
||||
//pivot - 3 textfields
|
||||
this.addLabel(new GuiNpcLabel(80, "animation.pivots", guiLeft + bodyPartX, guiTop + bodyPartY + 117, 0xFFFFFF));
|
||||
this.addTextField(new GuiNpcTextField(80, this, guiLeft + bodyPartX, guiTop + bodyPartY + 129, 35, 15, editingPart.pivot[0] + ""));
|
||||
this.getTextField(80).floatsOnly = true;
|
||||
this.getTextField(80).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
|
||||
this.addTextField(new GuiNpcTextField(81, this, guiLeft + bodyPartX + 40, guiTop + bodyPartY + 129, 35, 15, editingPart.pivot[1] + ""));
|
||||
this.getTextField(81).floatsOnly = true;
|
||||
this.getTextField(81).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
|
||||
this.addTextField(new GuiNpcTextField(82, this, guiLeft + bodyPartX + 80, guiTop + bodyPartY + 129, 35, 15, editingPart.pivot[2] + ""));
|
||||
this.getTextField(82).floatsOnly = true;
|
||||
this.getTextField(82).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
|
||||
//
|
||||
//customized - button, enables all the following options.
|
||||
this.addLabel(new GuiNpcLabel(83, "animation.customized", guiLeft + bodyPartX, guiTop + bodyPartY + 154, 0xFFFFFF));
|
||||
this.addButton(new GuiNpcButton(83, guiLeft + bodyPartX + 55, guiTop + bodyPartY + 148, 30, 20, new String[]{"gui.yes", "gui.no"}, editingPart.isCustomized() ? 0 : 1));
|
||||
if (editingPart.isCustomized()) {
|
||||
//
|
||||
//speed - textfield
|
||||
this.addLabel(new GuiNpcLabel(84, "stats.speed", guiLeft + bodyPartX, guiTop + bodyPartY + 174, 0xFFFFFF));
|
||||
this.addTextField(new GuiNpcTextField(84, this, guiLeft + bodyPartX + 60, guiTop + bodyPartY + 170, 30, 15, editingPart.speed + ""));
|
||||
this.getTextField(84).floatsOnly = true;
|
||||
this.getTextField(84).setMinMaxDefaultFloat(0, Float.MAX_VALUE, 1.0F);
|
||||
//
|
||||
//smooth - button
|
||||
this.addLabel(new GuiNpcLabel(85, "animation.smoothing", guiLeft + bodyPartX, guiTop + bodyPartY + 194, 0xFFFFFF));
|
||||
this.addButton(new GuiNpcButton(85, guiLeft + bodyPartX + 55, guiTop + bodyPartY + 190, 60, 20, new String[]{"animation.smooth", "animation.linear", "gui.none"}, editingPart.smooth));
|
||||
}
|
||||
|
||||
this.addLabel(new GuiNpcLabel(95, "X", guiLeft + bodyPartX - 10, guiTop + bodyPartY + 112, 0xFFFFFF));
|
||||
this.addLabel(new GuiNpcLabel(96, "Y", guiLeft + bodyPartX - 10, guiTop + bodyPartY + 135, 0xFFFFFF));
|
||||
this.addLabel(new GuiNpcLabel(97, "Z", guiLeft + bodyPartX - 10, guiTop + bodyPartY + 157, 0xFFFFFF));
|
||||
}
|
||||
} else {
|
||||
//
|
||||
//rotation - 3 textfields
|
||||
this.addLabel(new GuiNpcLabel(70, "animation.rotations", guiLeft + bodyPartX, guiTop + bodyPartY + 85, 0xFFFFFF));
|
||||
this.addTextField(new GuiNpcTextField(70, this, guiLeft + bodyPartX, guiTop + bodyPartY + 97, 35, 15, editingPart.rotation[0] + ""));
|
||||
this.getTextField(70).floatsOnly = true;
|
||||
this.getTextField(70).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
|
||||
this.addTextField(new GuiNpcTextField(71, this, guiLeft + bodyPartX + 40, guiTop + bodyPartY + 97, 35, 15, editingPart.rotation[1] + ""));
|
||||
this.getTextField(71).floatsOnly = true;
|
||||
this.getTextField(71).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
|
||||
this.addTextField(new GuiNpcTextField(72, this, guiLeft + bodyPartX + 80, guiTop + bodyPartY + 97, 35, 15, editingPart.rotation[2] + ""));
|
||||
this.getTextField(72).floatsOnly = true;
|
||||
this.getTextField(72).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
|
||||
//
|
||||
//pivot - 3 textfields
|
||||
this.addLabel(new GuiNpcLabel(80, "animation.pivots", guiLeft + bodyPartX, guiTop + bodyPartY + 117, 0xFFFFFF));
|
||||
this.addTextField(new GuiNpcTextField(80, this, guiLeft + bodyPartX, guiTop + bodyPartY + 129, 35, 15, editingPart.pivot[0] + ""));
|
||||
this.getTextField(80).floatsOnly = true;
|
||||
this.getTextField(80).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
|
||||
this.addTextField(new GuiNpcTextField(81, this, guiLeft + bodyPartX + 40, guiTop + bodyPartY + 129, 35, 15, editingPart.pivot[1] + ""));
|
||||
this.getTextField(81).floatsOnly = true;
|
||||
this.getTextField(81).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
|
||||
this.addTextField(new GuiNpcTextField(82, this, guiLeft + bodyPartX + 80, guiTop + bodyPartY + 129, 35, 15, editingPart.pivot[2] + ""));
|
||||
this.getTextField(82).floatsOnly = true;
|
||||
this.getTextField(82).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
|
||||
//
|
||||
//customized - button, enables all the following options.
|
||||
this.addLabel(new GuiNpcLabel(83, "animation.customized", guiLeft + bodyPartX, guiTop + bodyPartY + 154, 0xFFFFFF));
|
||||
this.addButton(new GuiNpcButton(83, guiLeft + bodyPartX + 55, guiTop + bodyPartY + 148, 30, 20, new String[]{"gui.yes", "gui.no"}, editingPart.isCustomized() ? 0 : 1));
|
||||
if (editingPart.isCustomized()) {
|
||||
//
|
||||
//speed - textfield
|
||||
this.addLabel(new GuiNpcLabel(84, "stats.speed", guiLeft + bodyPartX, guiTop + bodyPartY + 174, 0xFFFFFF));
|
||||
this.addTextField(new GuiNpcTextField(84, this, guiLeft + bodyPartX + 60, guiTop + bodyPartY + 170, 30, 15, editingPart.speed + ""));
|
||||
this.getTextField(84).floatsOnly = true;
|
||||
this.getTextField(84).setMinMaxDefaultFloat(0, Float.MAX_VALUE, 1.0F);
|
||||
//
|
||||
//smooth - button
|
||||
this.addLabel(new GuiNpcLabel(85, "animation.smoothing", guiLeft + bodyPartX, guiTop + bodyPartY + 194, 0xFFFFFF));
|
||||
this.addButton(new GuiNpcButton(85, guiLeft + bodyPartX + 55, guiTop + bodyPartY + 190, 60, 20, new String[]{"animation.smooth", "animation.linear", "gui.none"}, editingPart.smooth));
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
} else {
|
||||
this.addLabel(new GuiNpcLabel(50, "animation.addFrame", guiLeft + 270, guiTop + 100, 0xFFFFFF));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
} else {
|
||||
this.addLabel(new GuiNpcLabel(50, "animation.addFrame", guiLeft + 270, guiTop + 100, 0xFFFFFF));
|
||||
}
|
||||
this.addSlider(this.frameSlider);
|
||||
this.frameSlider.xPosition = guiLeft + 62;
|
||||
this.frameSlider.yPosition = guiTop + playPauseY + 197;
|
||||
this.frameSlider.width = 63;
|
||||
|
||||
this.addSlider(this.frameSlider);
|
||||
this.frameSlider.xPosition = guiLeft + 62;
|
||||
this.frameSlider.yPosition = guiTop + playPauseY + 197;
|
||||
this.frameSlider.width = 63;
|
||||
|
||||
for (int i = 0; i < this.visibleFrames; i++) {
|
||||
this.addButton(new GuiTexturedButton(300 + i, "", guiLeft + 130 + i * 7, guiTop + 210, 6, 20, animTexture, 0, 71));
|
||||
for (int i = 0; i < this.visibleFrames; i++) {
|
||||
this.addButton(new GuiTexturedButton(300 + i, "", guiLeft + 130 + i * 7, guiTop + 210, 6, 20, animTexture, 0, 71));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSliders() {
|
||||
FramePart part = this.editingPart();
|
||||
if (part == null) return;
|
||||
if (part == null)
|
||||
return;
|
||||
|
||||
float[] rotations = part.getRotations();
|
||||
float[] pivots = part.getPivots();
|
||||
@@ -391,6 +415,22 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
||||
return editingFrame.frameParts.get(this.editingPart);
|
||||
}
|
||||
|
||||
public boolean isMouseOverRenderer(int x, int y) {
|
||||
if (!allowRotate) {
|
||||
return false;
|
||||
}
|
||||
// Center of the entity rendering
|
||||
int centerX = guiLeft + 190 + xOffset; // Matches l in drawScreen()
|
||||
int centerY = guiTop + 80 + yOffset; // Matches i1 in drawScreen()
|
||||
|
||||
// Define separate buffers for X and Y axes
|
||||
int xBuffer = 75; // Horizontal buffer
|
||||
int yBuffer = 120; // Vertical buffer
|
||||
|
||||
// Check if the mouse is within the buffer area
|
||||
return mouseX >= centerX - xBuffer && mouseX <= centerX + xBuffer && mouseY >= centerY - yBuffer && mouseY <= centerY + yBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guibutton) {
|
||||
super.actionPerformed(guibutton);
|
||||
@@ -406,9 +446,9 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
||||
updateFrameSlider();
|
||||
} else if (guibutton.id == 13 && editingFrame != null) {
|
||||
if (frameIndex < animation.frames.size() - 1) {
|
||||
animation.frames.add(frameIndex + 1, editingFrame.copy());
|
||||
animation.addFrame(frameIndex + 1, editingFrame.copy());
|
||||
} else {
|
||||
animation.frames.add(editingFrame.copy());
|
||||
animation.addFrame(editingFrame.copy());
|
||||
}
|
||||
this.frameIndex = frameIndex + 1;
|
||||
updateFrameSlider();
|
||||
@@ -491,6 +531,10 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
||||
}
|
||||
}
|
||||
|
||||
if (guibutton == toggleGraph) {
|
||||
toggleGraphEditor = !toggleGraphEditor;
|
||||
}
|
||||
|
||||
initGui();
|
||||
}
|
||||
|
||||
@@ -500,9 +544,9 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
||||
|
||||
private void addFrame(Frame frame) {
|
||||
if (frameIndex < animation.frames.size() - 1) {
|
||||
animation.frames.add(frameIndex + 1, frame);
|
||||
animation.addFrame(frameIndex + 1, frame);
|
||||
} else {
|
||||
animation.frames.add(frame);
|
||||
animation.addFrame(frame);
|
||||
}
|
||||
this.frameIndex = frameIndex + 1;
|
||||
updateFrameSlider();
|
||||
@@ -566,7 +610,7 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
||||
animation.name = text.replaceAll("[^a-zA-Z0-9_-]", "_");
|
||||
} else if (textfield.id == 15 && animation != null && animation.frames.size() > 0) {
|
||||
animation.frames.remove(frameIndex);
|
||||
animation.frames.add(textfield.getInteger(), frame);
|
||||
animation.addFrame(textfield.getInteger(), frame);
|
||||
frameIndex = textfield.getInteger();
|
||||
overrideFrame = true;
|
||||
initGui();
|
||||
@@ -577,14 +621,25 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
||||
} else if (textfield.id == 51 && frame != null) {
|
||||
frame.duration = textfield.getInteger();
|
||||
} else if (textfield.id >= 70 && textfield.id <= 73 && part != null) {
|
||||
part.rotation[textfield.id - 70] = textfield.getFloat();
|
||||
int index = textfield.id - 70;
|
||||
float value = textfield.getFloat();
|
||||
part.rotation[index] = value;
|
||||
part.addValue(EnumFrameType.values()[index], value);
|
||||
this.updateSliders();
|
||||
} else if (textfield.id >= 80 && textfield.id <= 83 && part != null) {
|
||||
part.pivot[textfield.id - 80] = textfield.getFloat();
|
||||
int index = textfield.id - 80;
|
||||
float value = textfield.getFloat();
|
||||
part.pivot[index] = value;
|
||||
part.addValue(EnumFrameType.values()[3 + index], value);
|
||||
this.updateSliders();
|
||||
}
|
||||
}
|
||||
|
||||
public void onGuiClosed() {
|
||||
super.onGuiClosed();
|
||||
graphEditor.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (!this.hasSubGui()) {
|
||||
@@ -620,13 +675,17 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
||||
}
|
||||
if (id >= 90 && id < 93) {
|
||||
int value = (int) (360.0F * 2.0F * (guiNpcSlider.sliderValue - 0.5F));
|
||||
part.rotation[id - 90] = value;
|
||||
int index = id - 90;
|
||||
part.rotation[index] = value;
|
||||
part.addValue(EnumFrameType.values()[index], value);
|
||||
guiNpcSlider.setString(value + "");
|
||||
}
|
||||
if (id >= 95 && id < 98) {
|
||||
int value = (int) (100.0F * (guiNpcSlider.sliderValue - 0.5F));
|
||||
guiNpcSlider.setString(value + "");
|
||||
part.pivot[id - 95] = value;
|
||||
int index = id - 95;
|
||||
part.pivot[index] = value;
|
||||
part.addValue(EnumFrameType.values()[3 + index], value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -650,7 +709,12 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
||||
|
||||
@Override
|
||||
public void keyTyped(char par1, int par2) {
|
||||
boolean old = closeOnEsc;
|
||||
if (graphEditor.presetOverlay.showOverlay)
|
||||
closeOnEsc = false;
|
||||
|
||||
super.keyTyped(par1, par2);
|
||||
closeOnEsc = old;
|
||||
|
||||
if (GuiScreen.isCtrlKeyDown() && par2 != 29 && !GuiNpcTextField.isFieldActive()) {
|
||||
switch (par2) {
|
||||
@@ -662,7 +726,6 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
||||
case 47:
|
||||
if (copiedFrame != null) {
|
||||
Frame frame = new Frame(10);
|
||||
frame.parent = this.animation;
|
||||
frame.readFromNBT(copiedFrame.writeToNBT());
|
||||
this.addFrame(frame);
|
||||
this.initGui();
|
||||
|
||||
@@ -38,6 +38,7 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol
|
||||
this.setSave(save);
|
||||
this.xOffset = -148 + 70;
|
||||
this.yOffset = -170 + 137;
|
||||
maxZoom = 120;
|
||||
PacketClient.sendClient(new AnimationsGetPacket());
|
||||
|
||||
AnimationData data = npc.display.animationData;
|
||||
@@ -73,9 +74,8 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol
|
||||
|
||||
if (this.animation.frames.size() > 0) {
|
||||
Frame firstFrame = new Frame();
|
||||
firstFrame.parent = data.animation;
|
||||
firstFrame.readFromNBT(this.animation.frames.get(0).writeToNBT());
|
||||
data.animation.addFrame(firstFrame);
|
||||
firstFrame.readFromNBT(this.animation.frames.get(0).writeToNBT());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,4 +277,20 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMouseOverRenderer(int x, int y) {
|
||||
if (!allowRotate) {
|
||||
return false;
|
||||
}
|
||||
// Center of the entity rendering
|
||||
int centerX = guiLeft + 190 + xOffset; // Matches l in drawScreen()
|
||||
int centerY = guiTop + 130 + yOffset; // Matches i1 in drawScreen()
|
||||
|
||||
// Define separate buffers for X and Y axes
|
||||
int xBuffer = 100; // Horizontal buffer
|
||||
int yBuffer = 90; // Vertical buffer
|
||||
|
||||
// Check if the mouse is within the buffer area
|
||||
return mouseX >= centerX - xBuffer && mouseX <= centerX + xBuffer && mouseY >= centerY - yBuffer && mouseY <= centerY + yBuffer;
|
||||
}
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
package noppes.npcs.client.gui.item;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.player.item.MagicCyclesPacket;
|
||||
import kamkeel.npcs.network.packets.request.magic.MagicGetAllPacket;
|
||||
import kamkeel.npcs.network.packets.request.magic.MagicGetPacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.client.CustomNpcResourceListener;
|
||||
import noppes.npcs.client.gui.GuiMagicCycleMap;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.constants.EnumScrollData;
|
||||
import noppes.npcs.controllers.data.Magic;
|
||||
import noppes.npcs.controllers.data.MagicCycle;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
public class GuiNpcMagicBook extends GuiNPCInterface implements ICustomScrollListener, IScrollData, IGuiData {
|
||||
|
||||
private MagicCycle magicCycle;
|
||||
private GuiMagicCycleMap magicMap;
|
||||
private GuiCustomScroll leftScroll;
|
||||
public HashMap<String, Integer> cycleData = new HashMap<>();
|
||||
|
||||
public GuiNpcMagicBook() {
|
||||
super();
|
||||
xSize = 350;
|
||||
setBackground("menubg.png");
|
||||
closeOnEsc = true;
|
||||
MagicCyclesPacket.GetAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int spacing = 10;
|
||||
int scrollWidth = 120;
|
||||
|
||||
addLabel(new GuiNpcLabel(0, "menu.cycles", guiLeft + 14, guiTop + 10, 0xFFFFFF));
|
||||
|
||||
// --- Left Scroll List ---
|
||||
leftScroll = new GuiCustomScroll(this, 0, 0);
|
||||
leftScroll.guiLeft = guiLeft + spacing;
|
||||
leftScroll.guiTop = guiTop + 22;
|
||||
leftScroll.setSize(scrollWidth, ySize - 32);
|
||||
leftScroll.setList(new ArrayList<>(cycleData.keySet()));
|
||||
addScroll(leftScroll);
|
||||
|
||||
// --- Magic Map (Diagram) on the Right ---
|
||||
if(magicCycle == null)
|
||||
return;
|
||||
|
||||
String displayName = magicCycle.getDisplayName().replace("&", "\u00A7");
|
||||
leftScroll.setSelected(displayName);
|
||||
|
||||
|
||||
int mapX = guiLeft + scrollWidth + 2 * spacing;
|
||||
int mapY = guiTop + 22;
|
||||
int mapWidth = xSize - (scrollWidth + 3 * spacing);
|
||||
int mapHeight = ySize - 32;
|
||||
magicMap = new GuiMagicCycleMap(this, mapX, mapY, mapWidth, mapHeight, magicCycle);
|
||||
addDiagram(0, magicMap);
|
||||
|
||||
int labelY = guiTop + 10;
|
||||
int textWidth = fontRendererObj.getStringWidth(displayName);
|
||||
int labelX = mapX + (mapWidth / 2) - (textWidth / 2);
|
||||
GuiNpcLabel magicLabel = new GuiNpcLabel(1, displayName, labelX, labelY, CustomNpcResourceListener.DefaultTextColor);
|
||||
addLabel(magicLabel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int i) {
|
||||
super.keyTyped(c, i);
|
||||
if (i == 1) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton guibutton) {}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int i, int j, float f) {
|
||||
super.drawScreen(i, j, f);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawBackground(){
|
||||
super.drawBackground();
|
||||
|
||||
int spacing = 10;
|
||||
int scrollWidth = 120;
|
||||
int barHeight = 16; // Same height as the magic map bar
|
||||
int barY = guiTop + 22 - barHeight - 1;
|
||||
|
||||
// Draw dark rectangle above the left scroll (same width as left scroll)
|
||||
if (leftScroll != null) {
|
||||
int leftRectX = guiLeft + spacing;
|
||||
drawRect(leftRectX, barY, leftRectX + scrollWidth, barY + barHeight, 0xFF333333);
|
||||
}
|
||||
|
||||
// Draw dark rectangle above the magic map
|
||||
if (magicMap != null) {
|
||||
int mapX = guiLeft + scrollWidth + 2 * spacing;
|
||||
int mapWidth = xSize - (scrollWidth + 3 * spacing);
|
||||
drawRect(mapX, barY, mapX + mapWidth, barY + barHeight, 0xFF333333);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
|
||||
if (magicMap != null) {
|
||||
magicMap.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||
}
|
||||
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseMovedOrUp(int mouseX, int mouseY, int state) {
|
||||
if (magicMap != null) {
|
||||
magicMap.mouseReleased(mouseX, mouseY, state);
|
||||
}
|
||||
super.mouseMovedOrUp(mouseX, mouseY, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// Implement save logic if needed.
|
||||
}
|
||||
|
||||
// --- ICustomScrollListener Methods ---
|
||||
@Override
|
||||
public void customScrollClicked(int id, int index, int clickType, GuiCustomScroll scroll) {
|
||||
if (scroll == leftScroll) {
|
||||
String selectedName = scroll.getSelected();
|
||||
MagicCyclesPacket.GetCycle(cycleData.get(selectedName));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
||||
// Handle double-click if necessary.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
|
||||
if(type == EnumScrollData.MAGIC_CYCLES){
|
||||
cycleData.clear();
|
||||
cycleData.putAll(data);
|
||||
if (leftScroll != null) {
|
||||
leftScroll.setList(new ArrayList<>(cycleData.keySet()));
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(String selected) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
if (compound.hasKey("MagicCycle")) {
|
||||
magicCycle = new MagicCycle();
|
||||
magicCycle.readNBT(compound.getCompoundTag("MagicCycle"));
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,10 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.NoppesStringUtils;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
import noppes.npcs.client.gui.global.GuiNPCManageLinked;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.LinkedItem;
|
||||
import noppes.npcs.controllers.data.LinkedItemScript;
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.data.EffectScript;
|
||||
import noppes.npcs.controllers.data.PlayerDataScript;
|
||||
|
||||
import java.util.List;
|
||||
@@ -81,9 +80,6 @@ public class GuiScriptPlayers extends GuiScriptInterface {
|
||||
hookList.add(EnumScriptType.PROFILE_CHANGE.function);
|
||||
hookList.add(EnumScriptType.PROFILE_REMOVE.function);
|
||||
hookList.add(EnumScriptType.PROFILE_CREATE.function);
|
||||
hookList.add(EffectScript.ScriptType.OnEffectAdd.function);
|
||||
hookList.add(EffectScript.ScriptType.OnEffectTick.function);
|
||||
hookList.add(EffectScript.ScriptType.OnEffectRemove.function);
|
||||
|
||||
this.handler = this.script;
|
||||
PlayerScriptPacket.Get();
|
||||
|
||||
@@ -18,8 +18,8 @@ import java.util.*;
|
||||
* Abstract GUI class for drawing diagrams with icons (nodes) and connections (arrows).
|
||||
* <p>
|
||||
* This revised version ensures that non‑Chart layouts use the full diagram bounds for positioning
|
||||
* and that curved arrow drawing selects the best control point (using both curveAngle and its negative)
|
||||
* to avoid icons.
|
||||
* (so that the outer icons lie flush with the edges) and that curved arrow drawing selects the
|
||||
* best control point (using both curveAngle and its negative) to avoid icons.
|
||||
*/
|
||||
public abstract class GuiDiagram extends Gui {
|
||||
|
||||
@@ -46,11 +46,6 @@ public abstract class GuiDiagram extends Gui {
|
||||
protected boolean showArrowHeads = true;
|
||||
protected boolean useColorScaling = true;
|
||||
|
||||
// This flag determines how two‑way connections are drawn.
|
||||
// When true, a two‑way connection is drawn as one line with dual arrowheads and combined tooltips.
|
||||
// When false, each direction is drawn as a separate line with its own hitbox and tooltip.
|
||||
protected boolean allowTwoWay = false;
|
||||
|
||||
// --- Layout Options ---
|
||||
protected EnumDiagramLayout layout = EnumDiagramLayout.CIRCULAR;
|
||||
|
||||
@@ -121,10 +116,6 @@ public abstract class GuiDiagram extends Gui {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tooltip for a connection. When allowTwoWay is true the tooltip combines both directions,
|
||||
* otherwise it shows only the current connection's info.
|
||||
*/
|
||||
protected List<String> getConnectionTooltip(DiagramConnection conn) {
|
||||
List<String> tooltip = new ArrayList<>();
|
||||
DiagramIcon iconFrom = getIconById(conn.idFrom);
|
||||
@@ -133,12 +124,10 @@ public abstract class GuiDiagram extends Gui {
|
||||
String nameTo = iconTo != null ? getIconName(iconTo) : "Unknown";
|
||||
tooltip.add(nameFrom + " > " + nameTo + ":");
|
||||
tooltip.add(conn.hoverText);
|
||||
if (allowTwoWay) {
|
||||
DiagramConnection reverse = getConnectionByIds(conn.idTo, conn.idFrom);
|
||||
if (reverse != null) {
|
||||
tooltip.add(nameTo + " > " + nameFrom + ":");
|
||||
tooltip.add(reverse.hoverText);
|
||||
}
|
||||
DiagramConnection reverse = getConnectionByIds(conn.idTo, conn.idFrom);
|
||||
if (reverse != null) {
|
||||
tooltip.add(nameTo + " > " + nameFrom + ":");
|
||||
tooltip.add(reverse.hoverText);
|
||||
}
|
||||
return tooltip;
|
||||
}
|
||||
@@ -205,7 +194,7 @@ public abstract class GuiDiagram extends Gui {
|
||||
return positions;
|
||||
}
|
||||
|
||||
// Square: fill the entire bounds.
|
||||
// Square: fill the entire bounds
|
||||
protected Map<Integer, Point> calculateSquarePositions() {
|
||||
List<DiagramIcon> icons = getIcons();
|
||||
Map<Integer, Point> positions = new HashMap<>();
|
||||
@@ -214,6 +203,7 @@ public abstract class GuiDiagram extends Gui {
|
||||
int n = (int) Math.ceil(Math.sqrt(count));
|
||||
int cellWidth = width / n;
|
||||
int cellHeight = height / n;
|
||||
// Start exactly at the diagram bounds.
|
||||
int startX = x, startY = y;
|
||||
for (int i = 0; i < count; i++) {
|
||||
int row = i / n, col = i % n;
|
||||
@@ -224,18 +214,29 @@ public abstract class GuiDiagram extends Gui {
|
||||
return positions;
|
||||
}
|
||||
|
||||
// Tree: distribute levels vertically and icons horizontally.
|
||||
// Tree: distribute levels vertically and icons horizontally so that the top and bottom icons touch y and y+height.
|
||||
protected Map<Integer, Point> calculateTreePositions() {
|
||||
List<DiagramIcon> icons = getIcons();
|
||||
Map<Integer, Point> positions = new HashMap<>();
|
||||
int count = icons.size();
|
||||
if (count == 0) return positions;
|
||||
// Determine number of levels by a simple breadth-first approach.
|
||||
int levels = (int) Math.ceil(Math.log(count + 1) / Math.log(2));
|
||||
// If only one level, place the icon in the center.
|
||||
for (int level = 0; level < levels; level++) {
|
||||
// Determine number of nodes at this level.
|
||||
int nodesThisLevel = (level == 0) ? 1 : (int) Math.min(Math.pow(2, level), count - (int) Math.pow(2, level) + 1);
|
||||
// Calculate vertical position: if more than one level, linearly space from y to y+height.
|
||||
int posY = (levels == 1) ? y + height / 2 : y + (int) ((height * level) / (levels - 1.0));
|
||||
// Horizontal spacing: if only one node, center it; otherwise, nodes are evenly spaced from x to x+width.
|
||||
for (int i = 0; i < nodesThisLevel; i++) {
|
||||
int posX = (nodesThisLevel == 1) ? x + width / 2 : x + (int) ((width * i) / (nodesThisLevel - 1.0));
|
||||
int posX;
|
||||
if (nodesThisLevel == 1) {
|
||||
posX = x + width / 2;
|
||||
} else {
|
||||
posX = x + (int) ((width * i) / (nodesThisLevel - 1.0));
|
||||
}
|
||||
// Here we assign IDs in order. (You may want to use your own ordering.)
|
||||
int index = (int) (Math.pow(2, level) - 1 + i);
|
||||
if (index < count) {
|
||||
positions.put(icons.get(index).id, new Point(posX, posY));
|
||||
@@ -245,13 +246,14 @@ public abstract class GuiDiagram extends Gui {
|
||||
return positions;
|
||||
}
|
||||
|
||||
// Generated layout methods (unchanged)...
|
||||
// Generated: Break icons into clusters and fill each cluster’s area exactly.
|
||||
protected Map<Integer, Point> calculateGeneratedPositions() {
|
||||
List<DiagramIcon> icons = getIcons();
|
||||
List<DiagramConnection> connections = getConnections();
|
||||
Map<Integer, List<Integer>> graph = buildGraph(icons, connections);
|
||||
List<Set<Integer>> clusters = getConnectedComponents(graph);
|
||||
int clusterCount = clusters.size();
|
||||
// Arrange clusters in a grid that fills the diagram exactly.
|
||||
int gridCols = (int) Math.ceil(Math.sqrt(clusterCount));
|
||||
int gridRows = (int) Math.ceil((double) clusterCount / gridCols);
|
||||
Map<Integer, Point> globalPositions = new HashMap<>();
|
||||
@@ -344,7 +346,8 @@ public abstract class GuiDiagram extends Gui {
|
||||
return sqrt * sqrt == n;
|
||||
}
|
||||
|
||||
// Layout algorithms for clusters (unchanged methods: layoutCycle, layoutTree, layoutSquare, layoutForceDirected)...
|
||||
// --- Layout Algorithms for Clusters ---
|
||||
// Cycle: now use the full available circle.
|
||||
private Map<Integer, Point> layoutCycle(Set<Integer> cluster, int compX, int compY, int compWidth, int compHeight) {
|
||||
Map<Integer, Point> positions = new HashMap<>();
|
||||
if (cluster.isEmpty()) return positions;
|
||||
@@ -361,11 +364,13 @@ public abstract class GuiDiagram extends Gui {
|
||||
return positions;
|
||||
}
|
||||
|
||||
// Tree for clusters: use full comp area.
|
||||
private Map<Integer, Point> layoutTree(Set<Integer> cluster, int compX, int compY, int compWidth, int compHeight,
|
||||
Map<Integer, List<Integer>> fullGraph) {
|
||||
Map<Integer, Point> positions = new HashMap<>();
|
||||
if (cluster.isEmpty()) return positions;
|
||||
|
||||
// Build a subgraph
|
||||
Map<Integer, List<Integer>> subgraph = new HashMap<>();
|
||||
for (Integer id : cluster) {
|
||||
List<Integer> neighbors = new ArrayList<>();
|
||||
@@ -375,7 +380,9 @@ public abstract class GuiDiagram extends Gui {
|
||||
}
|
||||
subgraph.put(id, neighbors);
|
||||
}
|
||||
// Pick a root (lowest id)
|
||||
Integer root = Collections.min(cluster);
|
||||
// Perform BFS to assign levels.
|
||||
Map<Integer, Integer> levelMap = new HashMap<>();
|
||||
Map<Integer, List<Integer>> levels = new HashMap<>();
|
||||
Queue<Integer> queue = new LinkedList<>();
|
||||
@@ -396,6 +403,7 @@ public abstract class GuiDiagram extends Gui {
|
||||
}
|
||||
}
|
||||
int maxLevel = levels.keySet().stream().max(Integer::compare).orElse(0);
|
||||
// Vertical positions: if only one level, center; otherwise span from compY to compY+compHeight.
|
||||
for (Map.Entry<Integer, List<Integer>> entry : levels.entrySet()) {
|
||||
int lvl = entry.getKey();
|
||||
int posY = (maxLevel == 0) ? compY + compHeight / 2 : compY + (int) ((compHeight * lvl) / (maxLevel));
|
||||
@@ -410,6 +418,7 @@ public abstract class GuiDiagram extends Gui {
|
||||
return positions;
|
||||
}
|
||||
|
||||
// Square: fill the available comp area.
|
||||
private Map<Integer, Point> layoutSquare(Set<Integer> cluster, int compX, int compY, int compWidth, int compHeight) {
|
||||
Map<Integer, Point> positions = new HashMap<>();
|
||||
if (cluster.isEmpty()) return positions;
|
||||
@@ -430,6 +439,7 @@ public abstract class GuiDiagram extends Gui {
|
||||
return positions;
|
||||
}
|
||||
|
||||
// Force-directed layout (unchanged)
|
||||
private Map<Integer, Point> layoutForceDirected(Set<Integer> cluster, int compX, int compY, int compWidth, int compHeight,
|
||||
List<DiagramConnection> connections) {
|
||||
Map<Integer, Point> positions = new HashMap<>();
|
||||
@@ -510,7 +520,6 @@ public abstract class GuiDiagram extends Gui {
|
||||
List<DiagramIcon> icons = getIcons();
|
||||
Map<Integer, Point> positions = new HashMap<>();
|
||||
if (icons.isEmpty()) return positions;
|
||||
// Group icons by their manual index.
|
||||
Map<Integer, List<DiagramIcon>> groups = new TreeMap<>();
|
||||
for (DiagramIcon icon : icons) {
|
||||
groups.computeIfAbsent(icon.index, k -> new ArrayList<>()).add(icon);
|
||||
@@ -518,21 +527,13 @@ public abstract class GuiDiagram extends Gui {
|
||||
int centerX = x + width / 2, centerY = y + height / 2;
|
||||
int maxRing = groups.isEmpty() ? 0 : Collections.max(groups.keySet());
|
||||
int maxRadius = (Math.min(width, height) - iconSize) / 2;
|
||||
|
||||
// Adjustable parameters:
|
||||
// spacingExponent controls the non-linear spacing between rings. Increasing this value will push outer rings farther apart.
|
||||
double spacingExponent = 1.5; // default value; adjust as needed
|
||||
// ringMultiplier lets you directly scale the computed radius of each ring.
|
||||
double ringMultiplier = 1.5; // default value; adjust as needed
|
||||
|
||||
// Calculate positions for each ring using a power function and multiplier.
|
||||
double ringSpacing = (maxRing + 1) > 0 ? (double) maxRadius / (maxRing + 1) : 0;
|
||||
for (Map.Entry<Integer, List<DiagramIcon>> entry : groups.entrySet()) {
|
||||
int ring = entry.getKey();
|
||||
List<DiagramIcon> groupIcons = entry.getValue();
|
||||
if (groupIcons.isEmpty()) continue;
|
||||
groupIcons.sort(Comparator.comparingInt(icon -> icon.priority));
|
||||
double normalizedRing = (ring + 1) / (double) (maxRing + 1);
|
||||
double radius = maxRadius * Math.pow(normalizedRing, spacingExponent) * ringMultiplier;
|
||||
double radius = ringSpacing * (ring + 1);
|
||||
int count = groupIcons.size();
|
||||
double startAngle = (ring == 0) ? -Math.PI / 2 : -3 * Math.PI / 4;
|
||||
for (int i = 0; i < count; i++) {
|
||||
@@ -545,7 +546,6 @@ public abstract class GuiDiagram extends Gui {
|
||||
return positions;
|
||||
}
|
||||
|
||||
|
||||
private Map<Integer, Point> calculateSquareManualPositions() {
|
||||
List<DiagramIcon> icons = getIcons();
|
||||
Map<Integer, Point> positions = new HashMap<>();
|
||||
@@ -597,6 +597,7 @@ public abstract class GuiDiagram extends Gui {
|
||||
Map<Integer, Point> positions = new HashMap<>();
|
||||
if (icons.isEmpty()) return positions;
|
||||
int maxLevel = levels.isEmpty() ? 0 : Collections.max(levels.keySet());
|
||||
// If more than one level, span vertically from y to y+height.
|
||||
for (Map.Entry<Integer, List<DiagramIcon>> entry : levels.entrySet()) {
|
||||
int level = entry.getKey();
|
||||
List<DiagramIcon> levelIcons = entry.getValue();
|
||||
@@ -628,7 +629,7 @@ public abstract class GuiDiagram extends Gui {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum distance from the given control point to any icon (except endpoints).
|
||||
* Returns the minimum distance from the given control point to any icon (except the endpoints of the connection).
|
||||
*/
|
||||
private double getMinDistanceToIcon(Point control, DiagramConnection conn) {
|
||||
double minDist = Double.MAX_VALUE;
|
||||
@@ -647,269 +648,92 @@ public abstract class GuiDiagram extends Gui {
|
||||
}
|
||||
|
||||
// --- Arrow Drawing Methods ---
|
||||
/**
|
||||
* Draws a connection line between two endpoints.
|
||||
* If a reverse connection exists and allowTwoWay is false, the line is drawn with a perpendicular offset.
|
||||
*/
|
||||
protected void drawConnectionLine(int x1, int y1, int x2, int y2, DiagramConnection conn, boolean dim) {
|
||||
DiagramConnection reverse = getConnectionByIds(conn.idTo, conn.idFrom);
|
||||
if (!allowTwoWay && reverse != null) {
|
||||
if (x1 > x2 || (x1 == x2 && y1 > y2)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
boolean twoWay = (reverse != null && allowTwoWay);
|
||||
// When allowTwoWay is false and a reverse exists, draw each connection separately.
|
||||
boolean separateTwoWay = (reverse != null && !allowTwoWay);
|
||||
int color = getConnectionColor(conn);
|
||||
if (!useColorScaling) color = 0xFFFFFFFF;
|
||||
if (!curvedArrows) {
|
||||
if (separateTwoWay) {
|
||||
int offsetAmount = 4;
|
||||
double dx = x2 - x1, dy = y2 - y1;
|
||||
double len = Math.sqrt(dx * dx + dy * dy);
|
||||
if (len == 0) len = 1;
|
||||
double offsetX = -dy / len * offsetAmount;
|
||||
double offsetY = dx / len * offsetAmount;
|
||||
if (conn.idFrom >= conn.idTo) {
|
||||
offsetX = -offsetX;
|
||||
offsetY = -offsetY;
|
||||
}
|
||||
int newX1 = x1 + (int) offsetX;
|
||||
int newY1 = y1 + (int) offsetY;
|
||||
int newX2 = x2 + (int) offsetX;
|
||||
int newY2 = y2 + (int) offsetY;
|
||||
int color = getConnectionColor(conn);
|
||||
if (!useColorScaling) {
|
||||
color = 0xFFFFFFFF;
|
||||
}
|
||||
drawColoredLine(newX1, newY1, newX2, newY2, color, dim);
|
||||
} else if (twoWay) {
|
||||
int midX = (x1 + x2) / 2;
|
||||
int midY = (y1 + y2) / 2;
|
||||
int color1 = getConnectionColor(reverse);
|
||||
int color2 = getConnectionColor(conn);
|
||||
if (!useColorScaling) {
|
||||
color1 = color2 = 0xFFFFFFFF;
|
||||
}
|
||||
drawColoredLine(x1, y1, midX, midY, color1, dim);
|
||||
drawColoredLine(midX, midY, x2, y2, color2, dim);
|
||||
} else {
|
||||
int color = getConnectionColor(conn);
|
||||
if (!useColorScaling) {
|
||||
color = 0xFFFFFFFF;
|
||||
}
|
||||
drawColoredLine(x1, y1, x2, y2, color, dim);
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glLineWidth(2.0F);
|
||||
float r = ((color >> 16) & 0xFF) / 255f;
|
||||
float g = ((color >> 8) & 0xFF) / 255f;
|
||||
float b = (color & 0xFF) / 255f;
|
||||
if (dim) {
|
||||
r *= 0.4f;
|
||||
g *= 0.4f;
|
||||
b *= 0.4f;
|
||||
}
|
||||
GL11.glColor4f(r, g, b, 1f);
|
||||
GL11.glBegin(GL11.GL_LINES);
|
||||
GL11.glVertex2i(x1, y1);
|
||||
GL11.glVertex2i(x2, y2);
|
||||
GL11.glEnd();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glPopAttrib();
|
||||
} else {
|
||||
// Curved arrows
|
||||
if (separateTwoWay) {
|
||||
int offsetAmount = 4;
|
||||
double dx = x2 - x1, dy = y2 - y1;
|
||||
double len = Math.sqrt(dx * dx + dy * dy);
|
||||
if (len == 0) len = 1;
|
||||
double normX = -dy / len;
|
||||
double normY = dx / len;
|
||||
double sign = (conn.idFrom < conn.idTo) ? 1 : -1;
|
||||
Point baseControl = computeControlPoint(x1, y1, x2, y2, curveAngle);
|
||||
Point offsetControl = new Point(baseControl.x + (int) (normX * offsetAmount * sign),
|
||||
baseControl.y + (int) (normY * offsetAmount * sign));
|
||||
int segments = 800;
|
||||
int color = getConnectionColor(conn);
|
||||
if (!useColorScaling) {
|
||||
color = 0xFFFFFFFF;
|
||||
}
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_HINT_BIT);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||
GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glLineWidth(2.0F);
|
||||
setColor(color, dim);
|
||||
GL11.glBegin(GL11.GL_LINE_STRIP);
|
||||
for (int i = 0; i <= segments; i++) {
|
||||
double t = (double) i / segments;
|
||||
int bx = (int) ((1 - t) * (1 - t) * x1 + 2 * (1 - t) * t * offsetControl.x + t * t * x2);
|
||||
int by = (int) ((1 - t) * (1 - t) * y1 + 2 * (1 - t) * t * offsetControl.y + t * t * y2);
|
||||
GL11.glVertex2i(bx, by);
|
||||
}
|
||||
GL11.glEnd();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glPopAttrib();
|
||||
} else if (twoWay) {
|
||||
Point cp1 = computeControlPoint(x1, y1, x2, y2, curveAngle);
|
||||
Point cp2 = computeControlPoint(x1, y1, x2, y2, -curveAngle);
|
||||
double d1 = getMinDistanceToIcon(cp1, conn);
|
||||
double d2 = getMinDistanceToIcon(cp2, conn);
|
||||
Point control = (d1 >= d2) ? cp1 : cp2;
|
||||
int segments = 800;
|
||||
int color1 = getConnectionColor(reverse);
|
||||
int color2 = getConnectionColor(conn);
|
||||
if (!useColorScaling) {
|
||||
color1 = color2 = 0xFFFFFFFF;
|
||||
}
|
||||
int halfSegments = segments / 2;
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_HINT_BIT);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||
GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glLineWidth(2.0F);
|
||||
setColor(color1, dim);
|
||||
GL11.glBegin(GL11.GL_LINE_STRIP);
|
||||
for (int i = 0; i <= halfSegments; i++) {
|
||||
double t = (double) i / halfSegments;
|
||||
int bx = (int) ((1 - t) * (1 - t) * x1 + 2 * (1 - t) * t * control.x + t * t * x2);
|
||||
int by = (int) ((1 - t) * (1 - t) * y1 + 2 * (1 - t) * t * control.y + t * t * y2);
|
||||
GL11.glVertex2i(bx, by);
|
||||
}
|
||||
GL11.glEnd();
|
||||
setColor(color2, dim);
|
||||
GL11.glBegin(GL11.GL_LINE_STRIP);
|
||||
for (int i = halfSegments; i <= segments; i++) {
|
||||
double t = (double) i / segments;
|
||||
int bx = (int) ((1 - t) * (1 - t) * x1 + 2 * (1 - t) * t * control.x + t * t * x2);
|
||||
int by = (int) ((1 - t) * (1 - t) * y1 + 2 * (1 - t) * t * control.y + t * t * y2);
|
||||
GL11.glVertex2i(bx, by);
|
||||
}
|
||||
GL11.glEnd();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glPopAttrib();
|
||||
} else {
|
||||
int color = getConnectionColor(conn);
|
||||
if (!useColorScaling) {
|
||||
color = 0xFFFFFFFF;
|
||||
}
|
||||
Point cp = computeControlPoint(x1, y1, x2, y2, curveAngle);
|
||||
int segments = 800;
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_HINT_BIT);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||
GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glLineWidth(2.0F);
|
||||
setColor(color, dim);
|
||||
GL11.glBegin(GL11.GL_LINE_STRIP);
|
||||
for (int i = 0; i <= segments; i++) {
|
||||
double t = (double) i / segments;
|
||||
int bx = (int) ((1 - t) * (1 - t) * x1 + 2 * (1 - t) * t * cp.x + t * t * x2);
|
||||
int by = (int) ((1 - t) * (1 - t) * y1 + 2 * (1 - t) * t * cp.y + t * t * y2);
|
||||
GL11.glVertex2i(bx, by);
|
||||
}
|
||||
GL11.glEnd();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glPopAttrib();
|
||||
// Compute two potential control points and choose the one farther from nearby icons.
|
||||
Point cp1 = computeControlPoint(x1, y1, x2, y2, curveAngle);
|
||||
Point cp2 = computeControlPoint(x1, y1, x2, y2, -curveAngle);
|
||||
double d1 = getMinDistanceToIcon(cp1, conn);
|
||||
double d2 = getMinDistanceToIcon(cp2, conn);
|
||||
Point control = (d1 >= d2) ? cp1 : cp2;
|
||||
int segments = 400;
|
||||
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_HINT_BIT);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||
GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glLineWidth(2.0F);
|
||||
float rr = ((color >> 16) & 0xFF) / 255f;
|
||||
float gg = ((color >> 8) & 0xFF) / 255f;
|
||||
float bb = (color & 0xFF) / 255f;
|
||||
if (dim) {
|
||||
rr *= 0.4f;
|
||||
gg *= 0.4f;
|
||||
bb *= 0.4f;
|
||||
}
|
||||
GL11.glColor4f(rr, gg, bb, 1f);
|
||||
|
||||
GL11.glBegin(GL11.GL_LINE_STRIP);
|
||||
for (int i = 0; i <= segments; i++) {
|
||||
double t = (double) i / segments;
|
||||
int bx = (int) ((1 - t) * (1 - t) * x1 + 2 * (1 - t) * t * control.x + t * t * x2);
|
||||
int by = (int) ((1 - t) * (1 - t) * y1 + 2 * (1 - t) * t * control.y + t * t * y2);
|
||||
GL11.glVertex2i(bx, by);
|
||||
}
|
||||
GL11.glEnd();
|
||||
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Helper method to draw a straight colored line.
|
||||
private void drawColoredLine(int x1, int y1, int x2, int y2, int color, boolean dim) {
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glLineWidth(2.0F);
|
||||
setColor(color, dim);
|
||||
GL11.glBegin(GL11.GL_LINES);
|
||||
GL11.glVertex2i(x1, y1);
|
||||
GL11.glVertex2i(x2, y2);
|
||||
GL11.glEnd();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
|
||||
// Helper to set color with dimming applied.
|
||||
private void setColor(int color, boolean dim) {
|
||||
float r = ((color >> 16) & 0xFF) / 255f;
|
||||
float g = ((color >> 8) & 0xFF) / 255f;
|
||||
float b = (color & 0xFF) / 255f;
|
||||
if (dim) {
|
||||
r *= 0.4f;
|
||||
g *= 0.4f;
|
||||
b *= 0.4f;
|
||||
}
|
||||
GL11.glColor4f(r, g, b, 1f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the arrow head for a connection.
|
||||
* When the connection is drawn separately (two-way with allowTwoWay false),
|
||||
* the arrow head is positioned using the same offset.
|
||||
*/
|
||||
// Fixed drawArrowHead:
|
||||
protected void drawArrowHead(int x1, int y1, int x2, int y2, DiagramConnection conn, boolean dim) {
|
||||
DiagramConnection reverse = getConnectionByIds(conn.idFrom, conn.idTo);
|
||||
if (!allowTwoWay && reverse != null) {
|
||||
if (x1 > x2 || (x1 == x2 && y1 > y2)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
int color = (reverse != null) ? getConnectionColor(reverse) : getConnectionColor(conn);
|
||||
if (!useColorScaling)
|
||||
color = 0xFFFFFFFF;
|
||||
boolean separateTwoWay = (reverse != null && !allowTwoWay);
|
||||
int color = getConnectionColor(conn);
|
||||
if (!useColorScaling) color = 0xFFFFFFFF;
|
||||
double angle;
|
||||
if (!curvedArrows) {
|
||||
if (separateTwoWay) {
|
||||
int offsetAmount = 4;
|
||||
double dx = x2 - x1, dy = y2 - y1;
|
||||
double len = Math.sqrt(dx * dx + dy * dy);
|
||||
if (len == 0) len = 1;
|
||||
double offsetX = -dy / len * offsetAmount;
|
||||
double offsetY = dx / len * offsetAmount;
|
||||
if (conn.idFrom >= conn.idTo) {
|
||||
offsetX = -offsetX;
|
||||
offsetY = -offsetY;
|
||||
}
|
||||
int newX2 = x2 + (int) offsetX;
|
||||
int newY2 = y2 + (int) offsetY;
|
||||
angle = Math.atan2(newY2 - y1, newX2 - x1);
|
||||
x2 = newX2;
|
||||
y2 = newY2;
|
||||
} else {
|
||||
angle = Math.atan2(y2 - y1, x2 - x1);
|
||||
}
|
||||
angle = Math.atan2(y2 - y1, x2 - x1);
|
||||
} else {
|
||||
if (separateTwoWay) {
|
||||
int offsetAmount = 4;
|
||||
double dx = x2 - x1, dy = y2 - y1;
|
||||
double len = Math.sqrt(dx * dx + dy * dy);
|
||||
if (len == 0) len = 1;
|
||||
double normX = -dy / len;
|
||||
double normY = dx / len;
|
||||
double sign = (conn.idFrom < conn.idTo) ? 1 : -1;
|
||||
Point baseControl = computeControlPoint(x1, y1, x2, y2, curveAngle);
|
||||
Point offsetControl = new Point(baseControl.x + (int) (normX * offsetAmount * sign),
|
||||
baseControl.y + (int) (normY * offsetAmount * sign));
|
||||
double t = 0.95;
|
||||
double bx = (1 - t) * (1 - t) * x1 + 2 * (1 - t) * t * offsetControl.x + t * t * x2;
|
||||
double by = (1 - t) * (1 - t) * y1 + 2 * (1 - t) * t * offsetControl.y + t * t * y2;
|
||||
double dBx = 2 * (1 - t) * (offsetControl.x - x1) + 2 * t * (x2 - offsetControl.x);
|
||||
double dBy = 2 * (1 - t) * (offsetControl.y - y1) + 2 * t * (y2 - offsetControl.y);
|
||||
angle = Math.atan2(dBy, dBx);
|
||||
} else {
|
||||
double dx = x2 - x1, dy = y2 - y1;
|
||||
double len = Math.sqrt(dx * dx + dy * dy);
|
||||
if (len == 0) len = 1;
|
||||
Point cp1 = computeControlPoint(x1, y1, x2, y2, curveAngle);
|
||||
Point cp2 = computeControlPoint(x1, y1, x2, y2, -curveAngle);
|
||||
double d1 = getMinDistanceToIcon(cp1, conn);
|
||||
double d2 = getMinDistanceToIcon(cp2, conn);
|
||||
Point control = (d1 >= d2) ? cp1 : cp2;
|
||||
double t = 0.95;
|
||||
double bx = (1 - t) * (1 - t) * x1 + 2 * (1 - t) * t * control.x + t * t * x2;
|
||||
double by = (1 - t) * (1 - t) * y1 + 2 * (1 - t) * t * control.y + t * t * y2;
|
||||
double dBx = 2 * (1 - t) * (control.x - x1) + 2 * t * (x2 - control.x);
|
||||
double dBy = 2 * (1 - t) * (control.y - y1) + 2 * t * (y2 - control.y);
|
||||
angle = Math.atan2(dBy, dBx);
|
||||
}
|
||||
// Compute two control points and choose the one farther from icons.
|
||||
double dx = x2 - x1, dy = y2 - y1;
|
||||
double len = Math.sqrt(dx * dx + dy * dy);
|
||||
if (len == 0) len = 1;
|
||||
Point cp1 = computeControlPoint(x1, y1, x2, y2, curveAngle);
|
||||
Point cp2 = computeControlPoint(x1, y1, x2, y2, -curveAngle);
|
||||
double d1 = getMinDistanceToIcon(cp1, conn);
|
||||
double d2 = getMinDistanceToIcon(cp2, conn);
|
||||
Point control = (d1 >= d2) ? cp1 : cp2;
|
||||
double t = 0.95;
|
||||
double bx = (1 - t) * (1 - t) * x1 + 2 * (1 - t) * t * control.x + t * t * x2;
|
||||
double by = (1 - t) * (1 - t) * y1 + 2 * (1 - t) * t * control.y + t * t * y2;
|
||||
double dBx = 2 * (1 - t) * (control.x - x1) + 2 * t * (x2 - control.x);
|
||||
double dBy = 2 * (1 - t) * (control.y - y1) + 2 * t * (y2 - control.y);
|
||||
angle = Math.atan2(dBy, dBx);
|
||||
}
|
||||
float defenderEdgeX = x2 - (slotSize / 2f) * (float) Math.cos(angle);
|
||||
float defenderEdgeY = y2 - (slotSize / 2f) * (float) Math.sin(angle);
|
||||
@@ -940,6 +764,27 @@ public abstract class GuiDiagram extends Gui {
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
|
||||
// --- Standard Icon Box Drawing ---
|
||||
protected void drawIconBox(int slotX, int slotY, int slotSize, boolean highlighted) {
|
||||
int bg = highlighted ? mixColors(iconBackgroundColor, 0xFFFFFFFF, 0.2f) : iconBackgroundColor;
|
||||
drawRect(slotX, slotY, slotX + slotSize, slotY + slotSize, bg);
|
||||
for (int i = 0; i < iconBorderThickness; i++) {
|
||||
drawHorizontalLine(slotX + i, slotX + slotSize - i, slotY + i, iconBorderColor);
|
||||
drawHorizontalLine(slotX + i, slotX + slotSize - i, slotY + slotSize - 1 - i, iconBorderColor);
|
||||
drawVerticalLine(slotX + i, slotY + i, slotY + slotSize - i, iconBorderColor);
|
||||
drawVerticalLine(slotX + slotSize - 1 - i, slotY + i, slotY + slotSize - i, iconBorderColor);
|
||||
}
|
||||
}
|
||||
|
||||
protected int mixColors(int color1, int color2, float ratio) {
|
||||
int a1 = (color1 >> 24) & 0xFF, r1 = (color1 >> 16) & 0xFF, g1 = (color1 >> 8) & 0xFF, b1 = color1 & 0xFF;
|
||||
int a2 = (color2 >> 24) & 0xFF, r2 = (color2 >> 16) & 0xFF, g2 = (color2 >> 8) & 0xFF, b2 = color2 & 0xFF;
|
||||
int a = (int) (a1 + (a2 - a1) * ratio);
|
||||
int r = (int) (r1 + (r2 - r1) * ratio);
|
||||
int g = (int) (g1 + (g2 - g1) * ratio);
|
||||
int b = (int) (b1 + (b2 - b1) * ratio);
|
||||
return (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
// --- Hit-detection helpers ---
|
||||
private double distanceToBezier(Point start, Point control, Point end, int segments, int px, int py) {
|
||||
@@ -981,6 +826,7 @@ public abstract class GuiDiagram extends Gui {
|
||||
|
||||
// --- CHART Layout Drawing (unchanged) ---
|
||||
private void drawChartDiagram(int mouseX, int mouseY, boolean subGui) {
|
||||
// ... (chart layout code remains unchanged)
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int factor = sr.getScaleFactor();
|
||||
@@ -999,8 +845,8 @@ public abstract class GuiDiagram extends Gui {
|
||||
|
||||
/**
|
||||
* Main method for drawing the diagram.
|
||||
* Applies pan/zoom, draws connections (using adjusted endpoints for separate two-way lines),
|
||||
* icons, and shows tooltips.
|
||||
* For non‑Chart layouts, applies pan/zoom, draws connections (with improved curved hit-detection)
|
||||
* and icons, and shows tooltips.
|
||||
*/
|
||||
public void drawDiagram(int mouseX, int mouseY, boolean subGui) {
|
||||
boolean allowInput = (parent == null || !parent.hasSubGui());
|
||||
@@ -1045,49 +891,18 @@ public abstract class GuiDiagram extends Gui {
|
||||
Point pTo = positions.get(conn.idTo);
|
||||
if (pFrom == null || pTo == null) continue;
|
||||
double dist;
|
||||
// If drawing separate two-way connections, use the offset endpoints for hit detection.
|
||||
boolean separateTwoWay = (getConnectionByIds(conn.idTo, conn.idFrom) != null && !allowTwoWay);
|
||||
if (separateTwoWay) {
|
||||
if (curvedArrows) {
|
||||
int offsetAmount = 4;
|
||||
double dx = pTo.x - pFrom.x, dy = pTo.y - pFrom.y;
|
||||
double len = Math.sqrt(dx * dx + dy * dy);
|
||||
if (len == 0) len = 1;
|
||||
double normX = -dy / len;
|
||||
double normY = dx / len;
|
||||
double sign = (conn.idFrom < conn.idTo) ? 1 : -1;
|
||||
Point baseControl = computeControlPoint(pFrom.x, pFrom.y, pTo.x, pTo.y, curveAngle);
|
||||
Point offsetControl = new Point(baseControl.x + (int) (normX * offsetAmount * sign),
|
||||
baseControl.y + (int) (normY * offsetAmount * sign));
|
||||
dist = distanceToBezier(pFrom, offsetControl, pTo, 200, effectiveMouseX, effectiveMouseY);
|
||||
} else {
|
||||
int offsetAmount = 4;
|
||||
double dx = pTo.x - pFrom.x, dy = pTo.y - pFrom.y;
|
||||
double len = Math.sqrt(dx * dx + dy * dy);
|
||||
if (len == 0) len = 1;
|
||||
double offsetX = -dy / len * offsetAmount;
|
||||
double offsetY = dx / len * offsetAmount;
|
||||
if (conn.idFrom >= conn.idTo) {
|
||||
offsetX = -offsetX;
|
||||
offsetY = -offsetY;
|
||||
}
|
||||
int newX1 = pFrom.x + (int) offsetX;
|
||||
int newY1 = pFrom.y + (int) offsetY;
|
||||
int newX2 = pTo.x + (int) offsetX;
|
||||
int newY2 = pTo.y + (int) offsetY;
|
||||
dist = pointLineDistance(effectiveMouseX, effectiveMouseY, newX1, newY1, newX2, newY2);
|
||||
}
|
||||
if (curvedArrows) {
|
||||
// Compute both potential control points
|
||||
Point cp1 = computeControlPoint(pFrom.x, pFrom.y, pTo.x, pTo.y, curveAngle);
|
||||
Point cp2 = computeControlPoint(pFrom.x, pFrom.y, pTo.x, pTo.y, -curveAngle);
|
||||
// Choose the control point that's farther from interfering icons (as done when drawing)
|
||||
double d1 = getMinDistanceToIcon(cp1, conn);
|
||||
double d2 = getMinDistanceToIcon(cp2, conn);
|
||||
Point control = (d1 >= d2) ? cp1 : cp2;
|
||||
// Use the chosen control point for hit detection
|
||||
dist = distanceToBezier(pFrom, control, pTo, 200, effectiveMouseX, effectiveMouseY);
|
||||
} else {
|
||||
if (curvedArrows) {
|
||||
Point cp1 = computeControlPoint(pFrom.x, pFrom.y, pTo.x, pTo.y, curveAngle);
|
||||
Point cp2 = computeControlPoint(pFrom.x, pFrom.y, pTo.x, pTo.y, -curveAngle);
|
||||
double d1 = getMinDistanceToIcon(cp1, conn);
|
||||
double d2 = getMinDistanceToIcon(cp2, conn);
|
||||
Point control = (d1 >= d2) ? cp1 : cp2;
|
||||
dist = distanceToBezier(pFrom, control, pTo, 200, effectiveMouseX, effectiveMouseY);
|
||||
} else {
|
||||
dist = pointLineDistance(effectiveMouseX, effectiveMouseY, pFrom.x, pFrom.y, pTo.x, pTo.y);
|
||||
}
|
||||
dist = pointLineDistance(effectiveMouseX, effectiveMouseY, pFrom.x, pFrom.y, pTo.x, pTo.y);
|
||||
}
|
||||
if (dist < threshold) {
|
||||
hoveredConnFrom = conn.idFrom;
|
||||
@@ -1095,6 +910,7 @@ public abstract class GuiDiagram extends Gui {
|
||||
selectedIconIds.add(conn.idFrom);
|
||||
selectedIconIds.add(conn.idTo);
|
||||
onConnectionHover(conn);
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1161,28 +977,6 @@ public abstract class GuiDiagram extends Gui {
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawIconBox(int slotX, int slotY, int slotSize, boolean highlighted) {
|
||||
int bg = highlighted ? mixColors(iconBackgroundColor, 0xFFFFFFFF, 0.2f) : iconBackgroundColor;
|
||||
drawRect(slotX, slotY, slotX + slotSize, slotY + slotSize, bg);
|
||||
for (int i = 0; i < iconBorderThickness; i++) {
|
||||
drawHorizontalLine(slotX + i, slotX + slotSize - i, slotY + i, iconBorderColor);
|
||||
drawHorizontalLine(slotX + i, slotX + slotSize - i, slotY + slotSize - 1 - i, iconBorderColor);
|
||||
drawVerticalLine(slotX + i, slotY + i, slotY + slotSize - i, iconBorderColor);
|
||||
drawVerticalLine(slotX + slotSize - 1 - i, slotY + i, slotY + slotSize - i, iconBorderColor);
|
||||
}
|
||||
}
|
||||
|
||||
protected int mixColors(int color1, int color2, float ratio) {
|
||||
int a1 = (color1 >> 24) & 0xFF, r1 = (color1 >> 16) & 0xFF, g1 = (color1 >> 8) & 0xFF, b1 = color1 & 0xFF;
|
||||
int a2 = (color2 >> 24) & 0xFF, r2 = (color2 >> 16) & 0xFF, g2 = (color2 >> 8) & 0xFF, b2 = color2 & 0xFF;
|
||||
int a = (int) (a1 + (a2 - a1) * ratio);
|
||||
int r = (int) (r1 + (r2 - r1) * ratio);
|
||||
int g = (int) (g1 + (g2 - g1) * ratio);
|
||||
int b = (int) (b1 + (b2 - b1) * ratio);
|
||||
return (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
|
||||
// --- Utility Methods ---
|
||||
protected DiagramIcon getIconById(int id) {
|
||||
for (DiagramIcon icon : getIcons()) {
|
||||
@@ -1199,20 +993,20 @@ public abstract class GuiDiagram extends Gui {
|
||||
}
|
||||
|
||||
protected int getConnectionColor(DiagramConnection conn) {
|
||||
float value = Math.max(-1f, Math.min(1f, conn.percent));
|
||||
int r, g, b;
|
||||
if (value >= 0f) {
|
||||
float t = value;
|
||||
r = (int)(144 + (0 - 144) * t);
|
||||
g = (int)(238 + (100 - 238) * t);
|
||||
b = (int)(144 + (0 - 144) * t);
|
||||
} else {
|
||||
float t = -value;
|
||||
r = (int)(255 + (139 - 255) * t);
|
||||
g = (int)(200 + (0 - 200) * t);
|
||||
b = 0;
|
||||
float percent = conn.percent;
|
||||
if (percent <= 0.10f) return 0xFF80FF80;
|
||||
else if (percent <= 0.40f) return 0xFFCCFF66;
|
||||
else if (percent <= 0.50f) return 0xFFFFA500;
|
||||
else {
|
||||
float ratio = (percent - 0.50f) / 0.50f;
|
||||
ratio = Math.min(1f, Math.max(0f, ratio));
|
||||
int r1 = 0xFF, g1 = 0xA5, b1 = 0x00;
|
||||
int r2 = 0xFF, g2 = 0x00, b2 = 0x00;
|
||||
int r = r1 + (int) ((r2 - r1) * ratio);
|
||||
int g = g1 + (int) ((g2 - g1) * ratio);
|
||||
int b = b1 + (int) ((b2 - b1) * ratio);
|
||||
return (0xFF << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
return (0xFF << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
private double pointLineDistance(int px, int py, int x1, int y1, int x2, int y2) {
|
||||
|
||||
@@ -21,7 +21,7 @@ public class GuiModelInterface extends GuiNPCInterface {
|
||||
private GuiNpcButton left, right, zoom, unzoom;
|
||||
|
||||
private static float zoomed = 60;
|
||||
public float minSize = 10, maxSize = 100;
|
||||
public float minZoom = 10, maxZoom = 100;
|
||||
|
||||
public int xOffset = 0, xOffsetButton = 0;
|
||||
public int yOffset = 0, yOffsetButton = 0;
|
||||
@@ -98,16 +98,16 @@ public class GuiModelInterface extends GuiNPCInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
if (Mouse.isButtonDown(0)) {
|
||||
public void drawScreen(int par1, int par2, float partialTicks) {
|
||||
if (Mouse.isButtonDown(0) && drawRenderButtons) {
|
||||
if (this.left.mousePressed(this.mc, par1, par2)) {
|
||||
rotation += par3 * 1.5F;
|
||||
rotation += partialTicks * 1.5F;
|
||||
} else if (this.right.mousePressed(this.mc, par1, par2)) {
|
||||
rotation -= par3 * 1.5F;
|
||||
} else if (this.zoom.mousePressed(this.mc, par1, par2) && zoomed < maxSize) {
|
||||
zoomed += par3 * 1.0F;
|
||||
} else if (this.unzoom.mousePressed(this.mc, par1, par2) && zoomed > minSize) {
|
||||
zoomed -= par3 * 1.0F;
|
||||
rotation -= partialTicks * 1.5F;
|
||||
} else if (this.zoom.mousePressed(this.mc, par1, par2) && zoomed < maxZoom) {
|
||||
zoomed += partialTicks * 1.0F;
|
||||
} else if (this.unzoom.mousePressed(this.mc, par1, par2) && zoomed > minZoom) {
|
||||
zoomed -= partialTicks * 1.0F;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,10 +118,10 @@ public class GuiModelInterface extends GuiNPCInterface {
|
||||
}
|
||||
}
|
||||
|
||||
if (zoomed > maxSize)
|
||||
zoomed = maxSize;
|
||||
if (zoomed < minSize)
|
||||
zoomed = minSize;
|
||||
if (zoomed > maxZoom)
|
||||
zoomed = maxZoom;
|
||||
if (zoomed < minZoom)
|
||||
zoomed = minZoom;
|
||||
|
||||
if (hasSubGui() && !drawNPConSub)
|
||||
return;
|
||||
@@ -156,13 +156,13 @@ public class GuiModelInterface extends GuiNPCInterface {
|
||||
GL11.glRotatef(-(float) Math.atan(f6 / 800F) * 20F, 1.0F, 0.0F, 0.0F);
|
||||
entity.prevRenderYawOffset = entity.renderYawOffset = rotation;
|
||||
entity.prevRotationYaw = entity.rotationYaw = (float) Math.atan(f5 / 80F) * 40F + rotation;
|
||||
entity.rotationPitch = followMouse ? -(float) Math.atan(f6 / 40F) * 20F : 0;
|
||||
entity.rotationPitch = entity.prevRotationPitch = followMouse ? -(float) Math.atan(f6 / 40F) * 20F : 0;
|
||||
entity.prevRotationYawHead = entity.rotationYawHead = followMouse ? entity.rotationYaw : rotation;
|
||||
GL11.glTranslatef(0.0F, entity.yOffset, 1F);
|
||||
RenderManager.instance.playerViewY = 180F;
|
||||
|
||||
try {
|
||||
RenderManager.instance.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
|
||||
RenderManager.instance.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, partialTicks);
|
||||
} catch (Exception e) {
|
||||
playerdata.setEntityClass(null);
|
||||
}
|
||||
@@ -178,7 +178,7 @@ public class GuiModelInterface extends GuiNPCInterface {
|
||||
OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(0.0F, 0f, 500.065F);
|
||||
super.drawScreen(par1, par2, par3);
|
||||
super.drawScreen(par1, par2, partialTicks);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
postRender(entity);
|
||||
|
||||
@@ -22,6 +22,8 @@ public class GuiModelInterface2 extends GuiNPCInterface2 {
|
||||
private GuiNpcButton left, right, zoom, unzoom;
|
||||
|
||||
private static float zoomed = 60;
|
||||
public float minZoom = 10, maxZoom = 100;
|
||||
public boolean allowRotate = true;
|
||||
|
||||
public int xOffset = 0;
|
||||
public int yOffset = 0;
|
||||
@@ -60,21 +62,50 @@ public class GuiModelInterface2 extends GuiNPCInterface2 {
|
||||
|
||||
private long start = -1;
|
||||
|
||||
public boolean isMouseOverRenderer(int x, int y) {
|
||||
if (!allowRotate) {
|
||||
return false;
|
||||
}
|
||||
// Center of the entity rendering
|
||||
int centerX = guiLeft + 190 + xOffset; // Matches l in drawScreen()
|
||||
int centerY = guiTop + 180 + yOffset; // Matches i1 in drawScreen()
|
||||
|
||||
// Define separate buffers for X and Y axes
|
||||
int xBuffer = 100; // Horizontal buffer
|
||||
int yBuffer = 150; // Vertical buffer
|
||||
|
||||
// Check if the mouse is within the buffer area
|
||||
return mouseX >= centerX - xBuffer && mouseX <= centerX + xBuffer && mouseY >= centerY - yBuffer && mouseY <= centerY + yBuffer;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
public void drawScreen(int par1, int par2, float partialTicks) {
|
||||
if (Mouse.isButtonDown(0)) {
|
||||
if (left.mousePressed(mc, par1, par2))
|
||||
rotation += par3 * 2;
|
||||
rotation += partialTicks * 2;
|
||||
else if (right.mousePressed(mc, par1, par2))
|
||||
rotation -= par3 * 2;
|
||||
rotation -= partialTicks * 2;
|
||||
else if (zoom.mousePressed(mc, par1, par2))
|
||||
zoomed += par3 * 2;
|
||||
zoomed += partialTicks * 2;
|
||||
else if (unzoom.mousePressed(mc, par1, par2) && zoomed > 10)
|
||||
zoomed -= par3 * 2;
|
||||
zoomed -= partialTicks * 2;
|
||||
|
||||
}
|
||||
|
||||
super.drawScreen(par1, par2, par3);
|
||||
if (isMouseOverRenderer(par1, par2)) {
|
||||
zoomed += Mouse.getDWheel() * 0.035f;
|
||||
if (Mouse.isButtonDown(0) || Mouse.isButtonDown(1)) {
|
||||
rotation -= Mouse.getDX() * 0.75f;
|
||||
}
|
||||
}
|
||||
|
||||
if (zoomed > maxZoom)
|
||||
zoomed = maxZoom;
|
||||
if (zoomed < minZoom)
|
||||
zoomed = minZoom;
|
||||
|
||||
super.drawScreen(par1, par2, partialTicks);
|
||||
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
|
||||
@@ -105,13 +136,13 @@ public class GuiModelInterface2 extends GuiNPCInterface2 {
|
||||
GL11.glRotatef(-(float) Math.atan(f6 / 80F) * 20F, 1.0F, 0.0F, 0.0F);
|
||||
entity.prevRenderYawOffset = entity.renderYawOffset = rotation;
|
||||
entity.prevRotationYaw = entity.rotationYaw = (float) Math.atan(f5 / 80F) * 40F + rotation;
|
||||
entity.rotationPitch = -(float) Math.atan(f6 / 80F) * 20F;
|
||||
entity.rotationPitch = entity.prevRotationPitch = -(float) Math.atan(f6 / 80F) * 20F;
|
||||
entity.prevRotationYawHead = entity.rotationYawHead = entity.rotationYaw;
|
||||
GL11.glTranslatef(0.0F, entity.yOffset, 0.0F);
|
||||
RenderManager.instance.playerViewY = 180F;
|
||||
|
||||
try {
|
||||
RenderManager.instance.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
|
||||
RenderManager.instance.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, partialTicks);
|
||||
} catch (Exception e) {
|
||||
playerdata.setEntityClass(null);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.CustomNpcResourceListener;
|
||||
import noppes.npcs.client.TextBlockClient;
|
||||
import noppes.npcs.client.gui.util.animation.ViewportGraphEditor;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
@@ -37,6 +38,7 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
protected HashMap<Integer, GuiNpcSlider> sliders = new HashMap<Integer, GuiNpcSlider>();
|
||||
protected HashMap<Integer, GuiScreen> extra = new HashMap<Integer, GuiScreen>();
|
||||
protected HashMap<Integer, GuiScrollWindow> scrollWindows = new HashMap<>();
|
||||
protected HashMap<Integer, ViewportGraphEditor> graphEditors = new HashMap<>();
|
||||
protected HashMap<Integer, GuiDiagram> diagrams = new HashMap<>();
|
||||
|
||||
public static boolean resizingActive = false;
|
||||
@@ -92,6 +94,7 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
scrolls.clear();
|
||||
sliders.clear();
|
||||
scrollWindows.clear();
|
||||
graphEditors.clear();
|
||||
diagrams.clear();
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
}
|
||||
@@ -106,6 +109,13 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
tf.updateCursorCounter();
|
||||
}
|
||||
super.updateScreen();
|
||||
|
||||
for (GuiScrollWindow guiScrollableComponent : scrollWindows.values())
|
||||
guiScrollableComponent.updateScreen();
|
||||
|
||||
for (ViewportGraphEditor graphEditor : graphEditors.values())
|
||||
graphEditor.updateScreen();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,6 +130,10 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
scrollWindows.put(id, gui);
|
||||
}
|
||||
|
||||
public void addGraphEditor(int id, ViewportGraphEditor graph) {
|
||||
graphEditors.put(id, graph);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a GuiDiagram to the interface.
|
||||
* The diagram is initialized with the current resolution and cached.
|
||||
@@ -145,6 +159,9 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
guiScrollableComponent.mouseClicked(i, j, k);
|
||||
}
|
||||
|
||||
for (ViewportGraphEditor graphEditor : graphEditors.values())
|
||||
graphEditor.mouseClicked(i, j, k);
|
||||
|
||||
if (k == 0) {
|
||||
for (GuiCustomScroll scroll : new ArrayList<GuiCustomScroll>(scrolls.values())) {
|
||||
scroll.mouseClicked(i, j, k);
|
||||
@@ -168,6 +185,10 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
subgui.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||
return;
|
||||
}
|
||||
|
||||
for (GuiScrollWindow window : scrollWindows.values())
|
||||
window.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||
|
||||
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||
}
|
||||
|
||||
@@ -202,9 +223,11 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
for (GuiNpcTextField tf : textfields.values())
|
||||
tf.textboxKeyTyped(c, i);
|
||||
|
||||
for (GuiScrollWindow guiScrollableComponent : scrollWindows.values()) {
|
||||
for (GuiScrollWindow guiScrollableComponent : scrollWindows.values())
|
||||
guiScrollableComponent.keyTyped(c, i);
|
||||
}
|
||||
|
||||
for (ViewportGraphEditor graphEditor : graphEditors.values())
|
||||
graphEditor.keyTyped(c, i);
|
||||
|
||||
// Fixes closing sub with escape closes all of its parents
|
||||
boolean enoughTimeSinceSubClosed = Minecraft.getSystemTime() - timeClosedSubGui > 50;
|
||||
@@ -310,16 +333,22 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
for (GuiNpcTextField tf : textfields.values()) {
|
||||
tf.drawTextBox(i, j);
|
||||
}
|
||||
int wheel = Mouse.getDWheel();
|
||||
for (GuiCustomScroll scroll : scrolls.values()) {
|
||||
scroll.updateSubGUI(subGui);
|
||||
scroll.drawScreen(i, j, f, !subGui && scroll.isMouseOver(i, j) ? Mouse.getDWheel() : 0);
|
||||
scroll.drawScreen(i, j, f, !subGui && scroll.isMouseOver(i, j) ? wheel : 0);
|
||||
}
|
||||
for (GuiScreen gui : extra.values())
|
||||
gui.drawScreen(i, j, f);
|
||||
|
||||
// Draw scrollable windows.
|
||||
for (GuiScrollWindow guiScrollableComponent : scrollWindows.values()) {
|
||||
guiScrollableComponent.drawScreen(i, j, f, !subGui && guiScrollableComponent.isMouseOver(i, j) ? Mouse.getDWheel() : 0);
|
||||
guiScrollableComponent.drawScreen(i, j, f, !subGui && guiScrollableComponent.isMouseOver(i, j) ? wheel : 0);
|
||||
}
|
||||
|
||||
for (ViewportGraphEditor graphEditor : graphEditors.values())
|
||||
graphEditor.drawScreen(i, j, f, wheel);
|
||||
|
||||
for (GuiDiagram diagram : diagrams.values()) {
|
||||
diagram.drawDiagram(i, j, subGui);
|
||||
}
|
||||
@@ -442,7 +471,7 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
float f4 = entity.rotationPitch;
|
||||
float f7 = entity.rotationYawHead;
|
||||
float f5 = (float) (guiLeft + x) - mouseX;
|
||||
float f6 = (float) ((guiTop + y) - 50 * scale * zoomed) - mouseY;
|
||||
float f6 = (guiTop + y) - 50 * scale * zoomed - mouseY;
|
||||
int orientation = 0;
|
||||
if (npc != null) {
|
||||
orientation = npc.ais.orientation;
|
||||
@@ -484,8 +513,8 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
public void openLink(String link) {
|
||||
try {
|
||||
Class oclass = Class.forName("java.awt.Desktop");
|
||||
Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object) null, new Object[0]);
|
||||
oclass.getMethod("browse", new Class[]{URI.class}).invoke(object, new Object[]{new URI(link)});
|
||||
Object object = oclass.getMethod("getDesktop", new Class[0]).invoke(null);
|
||||
oclass.getMethod("browse", new Class[]{URI.class}).invoke(object, new URI(link));
|
||||
} catch (Throwable throwable) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public abstract class GuiNPCInterface2 extends GuiNPCInterface {
|
||||
private ResourceLocation background = new ResourceLocation("customnpcs:textures/gui/menubg.png");
|
||||
private GuiNpcMenu menu;
|
||||
private final ResourceLocation background = new ResourceLocation("customnpcs:textures/gui/menubg.png");
|
||||
private final GuiNpcMenu menu;
|
||||
|
||||
public GuiNPCInterface2(EntityNPCInterface npc) {
|
||||
this(npc, -1);
|
||||
|
||||
@@ -11,7 +11,6 @@ public class GuiNpcLabel {
|
||||
public int x, y, color;
|
||||
public boolean enabled = true;
|
||||
public int id;
|
||||
public boolean drawShadow = false;
|
||||
|
||||
public GuiNpcLabel(int id, Object label, int x, int y, int color) {
|
||||
this.id = id;
|
||||
@@ -27,7 +26,7 @@ public class GuiNpcLabel {
|
||||
|
||||
public void drawLabel(GuiScreen gui, FontRenderer fontRenderer) {
|
||||
if (enabled)
|
||||
fontRenderer.drawString(label, x, y, color, drawShadow);
|
||||
fontRenderer.drawString(label, x, y, color);
|
||||
}
|
||||
|
||||
public void center(int width) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import noppes.npcs.util.ValueUtil;
|
||||
|
||||
public class GuiNpcTextField extends GuiTextField {
|
||||
public boolean enabled = true;
|
||||
@@ -19,7 +20,9 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
protected static GuiNpcTextField activeTextfield = null;
|
||||
public boolean canEdit = true;
|
||||
|
||||
private final int[] allowedSpecialChars = {14, 211, 203, 205};
|
||||
private String floatingPrecision = "%.4f"; //4 decimal places
|
||||
|
||||
private final int[] allowedSpecialChars = {0, 1, 3, 14, 8, 22, 24, 199, 211, 203, 205, 207, 211};
|
||||
|
||||
public GuiNpcTextField(int id, GuiScreen parent, FontRenderer fontRenderer, int i, int j, int k, int l, String s) {
|
||||
super(fontRenderer, i, j, k, l);
|
||||
@@ -40,16 +43,18 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
}
|
||||
|
||||
protected boolean charAllowed(char c, int i) {
|
||||
if (!integersOnly || Character.isDigit(c))
|
||||
return true;
|
||||
|
||||
if (integersOnly && getText().isEmpty() && c == '-')
|
||||
return true;
|
||||
|
||||
for (int j : allowedSpecialChars)
|
||||
if (j == i)
|
||||
if (j == c)
|
||||
return true;
|
||||
|
||||
String s = getText();
|
||||
boolean isNumbersOnly = integersOnly || floatsOnly || doublesOnly;
|
||||
boolean isDecimal = !integersOnly && c == '.' && !s.contains(".");
|
||||
boolean isNegative = isNumbersOnly && c == '-' && (getSelectionEnd() == 0 || !s.contains("-") && getCursorPosition() == 0);
|
||||
|
||||
if (!isNumbersOnly || isNegative || isDecimal || Character.isDigit(c))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -118,7 +123,7 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
activeTextfield = this;
|
||||
}
|
||||
|
||||
public void unFocused() {
|
||||
public void toDefaults() {
|
||||
if (integersOnly && !doublesOnly && !floatsOnly) {
|
||||
if (isEmpty() || !isInteger())
|
||||
setText(def + "");
|
||||
@@ -127,6 +132,9 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
else if (getInteger() > max)
|
||||
setText(max + "");
|
||||
} else if (doublesOnly && !floatsOnly) {
|
||||
if (floatingPrecision != null)
|
||||
setText(ValueUtil.format(floatingPrecision, getDouble()));
|
||||
|
||||
if (isEmpty() || !isDouble())
|
||||
setText(defDouble + "");
|
||||
else if (getDouble() < minDouble)
|
||||
@@ -134,6 +142,9 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
else if (getDouble() > maxDouble)
|
||||
setText(maxDouble + "");
|
||||
} else if (floatsOnly) {
|
||||
if (floatingPrecision != null)
|
||||
setText(ValueUtil.format(floatingPrecision, getFloat()));
|
||||
|
||||
if (isEmpty() || !isFloat())
|
||||
setText(defFloat + "");
|
||||
else if (getFloat() < minFloat)
|
||||
@@ -141,6 +152,10 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
else if (getFloat() > maxFloat)
|
||||
setText(maxFloat + "");
|
||||
}
|
||||
}
|
||||
|
||||
public void unFocused() {
|
||||
toDefaults();
|
||||
setCursorPositionZero();
|
||||
if (listener != null)
|
||||
listener.unFocused(this);
|
||||
@@ -155,22 +170,25 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
super.drawTextBox();
|
||||
}
|
||||
|
||||
public void setMinMaxDefault(int min, int max, int def) {
|
||||
public GuiNpcTextField setMinMaxDefault(int min, int max, int def) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.def = def;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setMinMaxDefaultDouble(double min, double max, double def) {
|
||||
public GuiNpcTextField setMinMaxDefaultDouble(double min, double max, double def) {
|
||||
minDouble = min;
|
||||
maxDouble = max;
|
||||
defDouble = def;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setMinMaxDefaultFloat(float min, float max, float def) {
|
||||
public GuiNpcTextField setMinMaxDefaultFloat(float min, float max, float def) {
|
||||
minFloat = min;
|
||||
maxFloat = max;
|
||||
defFloat = def;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static void unfocus() {
|
||||
@@ -200,5 +218,26 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setFloatingPrecision(int decimalPlaces) {
|
||||
floatingPrecision = "%." + decimalPlaces + "f";
|
||||
}
|
||||
|
||||
public void setInt(int value) {
|
||||
setText(ValueUtil.clamp(value, min, max) + "");
|
||||
}
|
||||
|
||||
public void setFloat(float value) {
|
||||
value = ValueUtil.clamp(value, minFloat, maxFloat);
|
||||
setText(ValueUtil.format(floatingPrecision, value));
|
||||
}
|
||||
|
||||
public void setDouble(double value) {
|
||||
value = ValueUtil.clamp(value, minDouble, maxDouble);
|
||||
setText(ValueUtil.format(floatingPrecision, value));
|
||||
}
|
||||
|
||||
public boolean isNumbersOnly() {
|
||||
return integersOnly || floatsOnly || doublesOnly;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -113,6 +113,9 @@ public class GuiScrollWindow extends GuiScreen implements ITextfieldListener, IC
|
||||
public void mouseEvent(int i, int j, int k) {
|
||||
}
|
||||
|
||||
public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guibutton) {
|
||||
@@ -266,7 +269,7 @@ public class GuiScrollWindow extends GuiScreen implements ITextfieldListener, IC
|
||||
super.drawDefaultBackground();
|
||||
}
|
||||
|
||||
protected void setClip(int x, int y, int width, int height) {
|
||||
public void setClip(int x, int y, int width, int height) {
|
||||
if (scaledResolution == null)
|
||||
return;
|
||||
int scaleFactor = scaledResolution.getScaleFactor();
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class GuiUtil {
|
||||
|
||||
public static void setScissorClip(int x, int y, int width, int height) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int scale = res.getScaleFactor();
|
||||
|
||||
|
||||
// Adjust position to Top-Left origin (OpenGL window/screen space uses bottom-left origin)
|
||||
y = mc.displayHeight - y * scale;
|
||||
height *= scale;
|
||||
|
||||
// Set clip
|
||||
GL11.glScissor(x * scale, y - height, width * scale, height);
|
||||
}
|
||||
|
||||
public static void drawHorizontalLine(double y, double startX, double endX, int color) {
|
||||
if (endX < startX) {
|
||||
double i1 = startX;
|
||||
startX = endX;
|
||||
endX = i1;
|
||||
}
|
||||
|
||||
drawRectD(startX, y, endX + 1, y + 1, color);
|
||||
}
|
||||
|
||||
public static void drawVerticalLine(double x, double startY, double endY, int color) {
|
||||
if (endY < startY) {
|
||||
double i1 = startY;
|
||||
startY = endY;
|
||||
endY = i1;
|
||||
}
|
||||
|
||||
drawRectD(x, startY + 1, x + 1, endY, color);
|
||||
}
|
||||
|
||||
public static void drawRectD(double left, double top, double right, double bottom) {
|
||||
double j1;
|
||||
|
||||
if (left < right) {
|
||||
j1 = left;
|
||||
left = right;
|
||||
right = j1;
|
||||
}
|
||||
|
||||
if (top < bottom) {
|
||||
j1 = top;
|
||||
top = bottom;
|
||||
bottom = j1;
|
||||
}
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.addVertex(left, bottom, 0.0D);
|
||||
tessellator.addVertex(right, bottom, 0.0D);
|
||||
tessellator.addVertex(right, top, 0.0D);
|
||||
tessellator.addVertex(left, top, 0.0D);
|
||||
tessellator.draw();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
}
|
||||
|
||||
|
||||
public static void drawRectD(double left, double top, double right, double bottom, int color) {
|
||||
float f3 = (float) (color >> 24 & 255) / 255.0F;
|
||||
float f = (float) (color >> 16 & 255) / 255.0F;
|
||||
float f1 = (float) (color >> 8 & 255) / 255.0F;
|
||||
float f2 = (float) (color & 255) / 255.0F;
|
||||
GL11.glColor4f(f, f1, f2, f3);
|
||||
drawRectD(left, top, right, bottom);
|
||||
}
|
||||
|
||||
public static void drawGradientRect(int left, int top, int right, int bottom, int startColor, int endColor) {
|
||||
double zLevel = 0;
|
||||
|
||||
float f = (float) (startColor >> 24 & 255) / 255.0F;
|
||||
float f1 = (float) (startColor >> 16 & 255) / 255.0F;
|
||||
float f2 = (float) (startColor >> 8 & 255) / 255.0F;
|
||||
float f3 = (float) (startColor & 255) / 255.0F;
|
||||
float f4 = (float) (endColor >> 24 & 255) / 255.0F;
|
||||
float f5 = (float) (endColor >> 16 & 255) / 255.0F;
|
||||
float f6 = (float) (endColor >> 8 & 255) / 255.0F;
|
||||
float f7 = (float) (endColor & 255) / 255.0F;
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
|
||||
GL11.glShadeModel(GL11.GL_SMOOTH);
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setColorRGBA_F(f1, f2, f3, f);
|
||||
tessellator.addVertex(right, top, zLevel);
|
||||
tessellator.addVertex(left, top, zLevel);
|
||||
tessellator.setColorRGBA_F(f5, f6, f7, f4);
|
||||
tessellator.addVertex(left, bottom, zLevel);
|
||||
tessellator.addVertex(right, bottom, zLevel);
|
||||
tessellator.draw();
|
||||
GL11.glShadeModel(GL11.GL_FLAT);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
public static void drawTexturedModalRect(double x, double y, double width, double height, int textureX, int textureY) {
|
||||
double zLevel = 0;
|
||||
float f = 1 / 256f;
|
||||
float f1 = 1 / 256f;
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.addVertexWithUV(x + 0, y + height, zLevel, (float) (textureX) * f, (float) (textureY + height) * f1);
|
||||
tessellator.addVertexWithUV(x + width, y + height, zLevel, (float) (textureX + width) * f, (float) (textureY + height) * f1);
|
||||
tessellator.addVertexWithUV(x + width, y + 0, zLevel, (float) (textureX + width) * f, (float) (textureY) * f1);
|
||||
tessellator.addVertexWithUV(x + 0, y + 0, zLevel, (float) (textureX) * f, (float) (textureY) * f1);
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
public static void setMouse(int guiX, int guiY) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
|
||||
int factor = scaledResolution.getScaleFactor();
|
||||
|
||||
Mouse.setCursorPosition(guiX * factor, mc.displayHeight - (guiY * factor));
|
||||
}
|
||||
|
||||
public static void setMouseX(int guiX) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
|
||||
int factor = scaledResolution.getScaleFactor();
|
||||
Mouse.setCursorPosition(guiX * factor, Mouse.getY());
|
||||
}
|
||||
|
||||
public static void setMouseY(int guiY) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
|
||||
int factor = scaledResolution.getScaleFactor();
|
||||
Mouse.setCursorPosition(Mouse.getX(), mc.displayHeight - (guiY * factor));
|
||||
}
|
||||
|
||||
public static double preciseMouseX() {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
|
||||
double width = scaledResolution.getScaledWidth();
|
||||
return Mouse.getX() * width / mc.displayWidth;
|
||||
}
|
||||
|
||||
public static double preciseMouseY() {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
|
||||
double height = scaledResolution.getScaledHeight();
|
||||
return height - Mouse.getY() * height / mc.displayHeight - 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package noppes.npcs.client.gui.util.animation;
|
||||
|
||||
import noppes.npcs.client.gui.util.GuiNPCInterface;
|
||||
import noppes.npcs.client.gui.util.animation.panel.PanelActiveFrame;
|
||||
import noppes.npcs.client.gui.util.animation.panel.PanelFrameType;
|
||||
import noppes.npcs.constants.animation.EnumFrameType;
|
||||
|
||||
public class AnimationGraphEditor extends ViewportGraphEditor {
|
||||
|
||||
public GridPointManager pointManager;
|
||||
public PanelFrameType frameTypePanel = new PanelFrameType(this);
|
||||
public PanelActiveFrame activeFramePanel = new PanelActiveFrame(this);
|
||||
|
||||
public AnimationGraphEditor(GuiNPCInterface parent) {
|
||||
super(parent);
|
||||
pointManager = new GridPointManager(this);
|
||||
|
||||
}
|
||||
|
||||
public void initGui(int startX, int startY, int endX, int endY) {
|
||||
super.initGui(startX, startY, endX, endY);
|
||||
frameTypePanel.initGui(startX - 70, startY, startX, startY + 78);
|
||||
activeFramePanel.initGui(startX - 70, startY + 79, startX, endY-1);
|
||||
}
|
||||
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks, int wheel) {
|
||||
frameTypePanel.draw(wheel);
|
||||
if (pointManager.selectedPoint != null)
|
||||
activeFramePanel.draw(wheel);
|
||||
grid.draw(mouseX, mouseY, partialTicks, wheel);
|
||||
pointManager.draw(mouseX, mouseY, partialTicks);
|
||||
presetOverlay.draw(mouseX, mouseY, wheel);
|
||||
|
||||
if (Cursors.currentCursor() != null)
|
||||
Cursors.currentCursor().draw(mouseX, mouseY);
|
||||
|
||||
}
|
||||
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
super.mouseClicked(mouseX, mouseY, button);
|
||||
frameTypePanel.mouseClicked(mouseX, mouseY, button);
|
||||
if (pointManager.selectedPoint != null)
|
||||
activeFramePanel.mouseClicked(mouseX, mouseY, button);
|
||||
pointManager.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
public void keyTyped(char c, int i) {
|
||||
super.keyTyped(c, i);
|
||||
frameTypePanel.keyTyped(c, i);
|
||||
if (pointManager.selectedPoint != null)
|
||||
activeFramePanel.keyTyped(c, i);
|
||||
pointManager.keyTyped(c, i);
|
||||
}
|
||||
|
||||
public EnumFrameType getSelectedType() {
|
||||
return frameTypePanel.selectedElement.type;
|
||||
}
|
||||
|
||||
public void setSelectedType(EnumFrameType type) {
|
||||
frameTypePanel.list.forEach(element -> {
|
||||
if(element.type == type)
|
||||
frameTypePanel.selectedElement = element;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package noppes.npcs.client.gui.util.animation;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.client.gui.util.GuiUtil;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.input.Cursor;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public enum Cursors {
|
||||
|
||||
MOVE(0, 0, 0, 0, 19, 19, 0.5f), SLIDE(0, 0, 0, 20, 16, 8, 0.66f), EMPTY(0, 0, 0, 0, 0, 0, 0);
|
||||
|
||||
|
||||
public int offsetX, offsetY, textureX, textureY, width, height;
|
||||
public float scale;
|
||||
|
||||
Cursors(int offsetX, int offsetY, int textureX, int textureY, int width, int height, float scale) {
|
||||
|
||||
this.textureX = textureX;
|
||||
this.textureY = textureY;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.offsetX = -width / 2;
|
||||
this.offsetY = offsetY;
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
public void draw(double mouseX, double mouseY) {
|
||||
offsetX = width / 2;
|
||||
offsetY = height / 2;
|
||||
double screenX = (mouseX / scale - offsetX);
|
||||
double screenY = (mouseY / scale - offsetY);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glScalef(scale, scale, 1);
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE);
|
||||
GuiUtil.drawTexturedModalRect(screenX, screenY, width, height, textureX, textureY);
|
||||
GL11.glPopMatrix();
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
}
|
||||
|
||||
private static Cursors currentCursor;
|
||||
public static Supplier<Boolean> condition;
|
||||
|
||||
public static void setCursor(Cursors cursor, Supplier<Boolean> con) {
|
||||
try {
|
||||
Cursor c = null;
|
||||
if (cursor != null)
|
||||
c = new Cursor(1, 1, 0, 0, 1, BufferUtils.createIntBuffer(1), null);
|
||||
Mouse.setNativeCursor(c);
|
||||
} catch (LWJGLException e) {
|
||||
}
|
||||
currentCursor = cursor;
|
||||
condition = con;
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
setCursor(null, null);
|
||||
condition = null;
|
||||
}
|
||||
|
||||
public static void tick() {
|
||||
if (condition != null && !condition.get())
|
||||
reset();
|
||||
}
|
||||
|
||||
public static Cursors currentCursor() {
|
||||
return currentCursor;
|
||||
}
|
||||
|
||||
private static ResourceLocation TEXTURE = new ResourceLocation("customnpcs:textures/gui/cursors.png");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,393 @@
|
||||
package noppes.npcs.client.gui.util.animation;
|
||||
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import noppes.npcs.client.gui.util.GuiUtil;
|
||||
import noppes.npcs.client.gui.util.animation.keys.GraphEditorKeyPresets;
|
||||
import noppes.npcs.client.gui.util.animation.keys.KeyPreset;
|
||||
import noppes.npcs.util.ValueUtil;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
public class Grid {
|
||||
ViewportGraphEditor parent;
|
||||
public int startX, startY, width, height; // Positioning
|
||||
public int endX, endY; // Positioning
|
||||
public int yAxisHeight = 12;
|
||||
|
||||
public int mouseX, mouseY;
|
||||
|
||||
public float zoomX = 20f, targetZoomX = 20f, zoomY = 1f, targetZoomY = 1f; //Zoom smoothness
|
||||
public float panX = 0, panY = 0, targetPanX, targetPanY; // pan offsets
|
||||
public int startPanX, startPanY;
|
||||
public boolean smoothenPanX, smoothenPanY;
|
||||
public int subDivisionX = 1, subDivisionY = 2;
|
||||
|
||||
public boolean isDragging, isResetting;
|
||||
public boolean centerAroundMouse = true;
|
||||
|
||||
public Grid(ViewportGraphEditor parent) {
|
||||
this.parent = parent;
|
||||
keys();
|
||||
}
|
||||
|
||||
public void keys() {
|
||||
GraphEditorKeyPresets keys = parent.keys;
|
||||
|
||||
keys.RESET_GRID.setTask((pressType) -> {
|
||||
if (pressType == KeyPreset.PRESS) {
|
||||
if (!isResetting) {
|
||||
if (xDown()) {
|
||||
targetPanX = 0;
|
||||
targetZoomX = 20;
|
||||
smoothenPanX = true;
|
||||
} else if (yDown()) {
|
||||
targetPanY = -((height) * subDivisionY / 2);
|
||||
targetZoomY = 1.0f;
|
||||
smoothenPanY = true;
|
||||
} else {
|
||||
targetPanY = -((height) * subDivisionY / 2);
|
||||
targetPanX = 0;
|
||||
targetZoomX = 20;
|
||||
targetZoomY = 1.0f;
|
||||
smoothenPanX = smoothenPanY = true;
|
||||
}
|
||||
isResetting = true;
|
||||
centerAroundMouse = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
keys.PAN_GRID.setTask((pressType) -> {
|
||||
if (pressType == KeyPreset.PRESS) {
|
||||
isDragging = true;
|
||||
startPanX = mouseX;
|
||||
startPanY = mouseY;
|
||||
} else if (pressType == KeyPreset.RELEASE)
|
||||
isDragging = false;
|
||||
});
|
||||
}
|
||||
|
||||
public void init(int startX, int startY, int endX, int endY) {
|
||||
this.startX = startX;
|
||||
this.startY = startY;
|
||||
this.endX = endX;
|
||||
this.endY = endY;
|
||||
|
||||
this.width = endX - this.startX;
|
||||
this.height = endY - this.startY;
|
||||
|
||||
panY = -(height * subDivisionY / 2);
|
||||
}
|
||||
|
||||
public void draw(int mouseX, int mouseY, float partialTicks, int wheel) {
|
||||
this.mouseX = mouseX;
|
||||
this.mouseY = mouseY;
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Panning
|
||||
|
||||
if (isDragging && parent.isWithin(mouseX, mouseY) && !isResetting) {
|
||||
if (xDown())
|
||||
panX -= (mouseX - startPanX) / zoomX;
|
||||
else if (yDown())
|
||||
panY -= (mouseY - startPanY) / zoomY;
|
||||
else {
|
||||
panX -= (mouseX - startPanX) / zoomX;
|
||||
panY -= (mouseY - startPanY) / zoomY * subDivisionY;
|
||||
}
|
||||
startPanX = mouseX;
|
||||
startPanY = mouseY;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Zoom logic
|
||||
if (wheel != 0 && !parent.presetOverlay.showOverlay&& isMouseOver(mouseX,mouseY)) {
|
||||
float xRate = zoomX < 15 ? 1.1f : 1.25f;
|
||||
float yRate = zoomY < 15 ? 1.1f : 1.25f;
|
||||
|
||||
if (xDown())
|
||||
targetZoomX = ValueUtil.clamp(wheel > 0 ? targetZoomX * xRate : targetZoomX / xRate, 0.025f, 100);
|
||||
else if (yDown())
|
||||
targetZoomY = ValueUtil.clamp(wheel > 0 ? targetZoomY * yRate : targetZoomY / yRate, 0.025f, 100);
|
||||
else {
|
||||
targetZoomX = ValueUtil.clamp(wheel > 0 ? targetZoomX * xRate : targetZoomX / xRate, 0.025f, 100);
|
||||
targetZoomY = ValueUtil.clamp(wheel > 0 ? targetZoomY * yRate : targetZoomY / yRate, 0.025f, 100);
|
||||
}
|
||||
}
|
||||
|
||||
if (zoomX != targetZoomX || zoomY != targetZoomY)
|
||||
zoom(mouseX, mouseY, wheel);
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Reset logic
|
||||
if (isResetting) {
|
||||
if (zoomX == targetZoomX && zoomY == targetZoomY && (smoothenPanX ? panX == targetPanX : smoothenPanY ? panY == targetPanY : true)) {
|
||||
isResetting = smoothenPanX = smoothenPanY = false;
|
||||
centerAroundMouse = true;
|
||||
}
|
||||
|
||||
float rate = 0.1f;
|
||||
if (smoothenPanX && panX != targetPanX) {
|
||||
panX = ValueUtil.lerp(panX, targetPanX, rate);
|
||||
if (Math.abs(panX - targetPanX) < 0.1)
|
||||
panX = targetPanX;
|
||||
}
|
||||
|
||||
if (smoothenPanY && panY != targetPanY) {
|
||||
panY = ValueUtil.lerp(panY, targetPanY, rate);
|
||||
if (Math.abs(panY - targetPanY) < 0.1)
|
||||
panY = targetPanY;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////
|
||||
Gui.drawRect(startX, startY - yAxisHeight, endX, startY, 0xFF161616); //header
|
||||
GuiUtil.drawGradientRect(startX, startY, endX, endY, 0xFF303030, 0xFF303030);
|
||||
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
GuiUtil.setScissorClip(startX, startY, width, height);
|
||||
GL11.glDepthMask(false);
|
||||
drawLines(mouseX, mouseY);
|
||||
GL11.glDepthMask(true);
|
||||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
public boolean isMouseOver(int mouseX, int mouseY) {
|
||||
return mouseX >= startX && mouseX <= startX + width && mouseY >= startY && mouseY <= startY + height;
|
||||
}
|
||||
|
||||
public void zoom(int mouseX, int mouseY, int wheel) {
|
||||
///////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////
|
||||
//Zooms in on mouse point
|
||||
double beforeWorldX = worldX(mouseX - startX);
|
||||
double beforeWorldY = worldY(mouseY - startY);
|
||||
|
||||
float rate = isResetting ? 0.1f : 0.05f;
|
||||
zoomX = ValueUtil.lerp(zoomX, targetZoomX, rate);
|
||||
zoomY = ValueUtil.lerp(zoomY, targetZoomY, rate);
|
||||
|
||||
// Snap to exact target value
|
||||
if (Math.abs(zoomX - targetZoomX) < 0.001)
|
||||
zoomX = targetZoomX;
|
||||
if (Math.abs(zoomY - targetZoomY) < 0.001)
|
||||
zoomY = targetZoomY;
|
||||
|
||||
double afterWorldX = worldX(mouseX - startX);
|
||||
double afterWorldY = worldY(mouseY - startY);
|
||||
|
||||
if (centerAroundMouse) {
|
||||
if (xDown())
|
||||
panX += beforeWorldX - afterWorldX;
|
||||
else if (yDown())
|
||||
panY += beforeWorldY - afterWorldY;
|
||||
else {
|
||||
panX += beforeWorldX - afterWorldX;
|
||||
panY += beforeWorldY - afterWorldY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drawLines(int mouseX, int mouseY) {
|
||||
int darkGray = 0xFF1a1a1a; // Major grid
|
||||
int lightGray = 0xFF2a2a2a; // Minor grid
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
// Vertical
|
||||
double stepX = getStepX();
|
||||
double firstGridX = Math.floor((panX) / stepX) * stepX;
|
||||
for (double x = firstGridX, i = 0; x <= worldX(endX); x += stepX / 5, i++) {
|
||||
boolean isMajor = i % 5 == 0;
|
||||
double screenX = screenX(x);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(startX, 0, 0);
|
||||
|
||||
GuiUtil.drawVerticalLine(screenX, startY, endY, isMajor ? darkGray : lightGray);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
//Expand boundaries of scissor clip
|
||||
GuiUtil.setScissorClip(startX, startY - yAxisHeight, width, height + yAxisHeight);
|
||||
for (double x = firstGridX; x <= worldX(endX); x += stepX)
|
||||
drawXValue((int) screenX(x), (int) x);
|
||||
|
||||
//Reset clip
|
||||
GuiUtil.setScissorClip(startX, startY, width, height);
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
// Horizontal
|
||||
double stepY = getStepY();
|
||||
double firstGridY = Math.floor((panY) / stepY) * stepY;
|
||||
for (double y = firstGridY, i = 0; y <= worldY(endY); y += stepY / 5, i++) {
|
||||
boolean isMajor = i % 5 == 0;
|
||||
double screenY = screenY(y);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(0, startY, 0);
|
||||
GuiUtil.drawHorizontalLine(screenY, startX, endX, isMajor ? darkGray : lightGray);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
for (double y = firstGridY; y <= worldY(endY); y += stepY)
|
||||
drawYValue((int) screenY(y), (int) -y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
public double getStepX() {
|
||||
double stepSize = 0;
|
||||
if (zoomX < 0.1) // 0-1000
|
||||
stepSize = 1000;
|
||||
else if (zoomX < 0.2) // 0-500
|
||||
stepSize = 500;
|
||||
else if (zoomX < 0.5) // 0-200
|
||||
stepSize = 200;
|
||||
else if (zoomX <= 1) // 0-100
|
||||
stepSize = 100;
|
||||
else if (zoomX < 1.5) //0-50
|
||||
stepSize = 50;
|
||||
else if (zoomX < 3) //0-20
|
||||
stepSize = 20;
|
||||
else if (zoomX < 4.5) //0-10
|
||||
stepSize = 10;
|
||||
else if (zoomX < 10) //0-5
|
||||
stepSize = 5;
|
||||
else if (zoomX < 18) //0-2 For Default reset
|
||||
stepSize = 2;
|
||||
else if (zoomX <= 100) //0-1
|
||||
stepSize = 1;
|
||||
return stepSize;
|
||||
}
|
||||
|
||||
public double getStepY() {
|
||||
double stepSize = 0;
|
||||
if (zoomY < 0.1) // 0-1000
|
||||
stepSize = 1000;
|
||||
else if (zoomY < 0.2) // 0-500
|
||||
stepSize = 500;
|
||||
else if (zoomY < 0.5) // 0-200
|
||||
stepSize = 200;
|
||||
else if (zoomY < 0.9) // 0-100 For Default reset
|
||||
stepSize = 100;
|
||||
else if (zoomY < 1.5) //0-50
|
||||
stepSize = 50;
|
||||
else if (zoomY < 3) //0-20
|
||||
stepSize = 20;
|
||||
else if (zoomY < 4.5) //0-10
|
||||
stepSize = 10;
|
||||
else if (zoomY < 10) //0-5
|
||||
stepSize = 5;
|
||||
else if (zoomY < 20) //0-2
|
||||
stepSize = 2;
|
||||
else if (zoomY <= 100) //0-1
|
||||
stepSize = 1;
|
||||
return stepSize;
|
||||
}
|
||||
|
||||
public void drawXValue(int screenX, int value) {
|
||||
GL11.glPushMatrix();
|
||||
float scale = 0.75f;
|
||||
int adjustedX = (int) ((screenX + 1) / scale); // Offset to the left of grid line
|
||||
int adjustedY = (int) ((startY - yAxisHeight + 4) / scale); // Adjust Y position
|
||||
|
||||
GL11.glTranslatef(startX, 0, 1f);
|
||||
GL11.glScalef(scale, scale, 1f);
|
||||
parent.drawString(String.valueOf(value), adjustedX, adjustedY, 0xFFA0A0A0);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
public void drawYValue(int screenY, int value) {
|
||||
GL11.glPushMatrix();
|
||||
float scale = 0.5f;
|
||||
int adjustedX = (int) ((startX + 10) / scale); // Offset to the left of grid line
|
||||
int adjustedY = (int) ((screenY - 1) / scale); // Adjust Y position
|
||||
|
||||
GL11.glTranslatef(0, startY, 1f);
|
||||
GL11.glScalef(scale, scale, 1f);
|
||||
parent.drawString(String.valueOf(value), adjustedX, adjustedY, 0xFFFFFF);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void keyTyped(char c, int i) {
|
||||
|
||||
}
|
||||
|
||||
public boolean xDown() {
|
||||
return parent.keys.LOCK_X.isDown;
|
||||
}
|
||||
|
||||
public boolean yDown() {
|
||||
return parent.keys.LOCK_Y.isDown;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
// Double
|
||||
public double worldX(double screenX) {
|
||||
return screenX * subDivisionX / zoomX + panX;
|
||||
}
|
||||
|
||||
public double worldY(double screenY) {
|
||||
return screenY * subDivisionY / zoomY + panY;
|
||||
}
|
||||
|
||||
public double screenX(double worldX) {
|
||||
return (worldX - panX) * zoomX / subDivisionX;
|
||||
}
|
||||
|
||||
public double screenY(double worldY) {
|
||||
return (worldY - panY) * zoomY / subDivisionY;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
// Float
|
||||
public double worldX(float screenX) {
|
||||
return screenX * subDivisionX / zoomX + panX;
|
||||
}
|
||||
|
||||
public double worldY(float screenY) {
|
||||
return screenY * subDivisionY / zoomY + panY;
|
||||
}
|
||||
|
||||
public double screenX(float worldX) {
|
||||
return (worldX - panX) * zoomX / subDivisionX;
|
||||
}
|
||||
|
||||
public double screenY(float worldY) {
|
||||
return (worldY - panY) * zoomY / subDivisionY;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
// Int
|
||||
public double worldX(int screenX) {
|
||||
return screenX * subDivisionX / zoomX + panX;
|
||||
}
|
||||
|
||||
public double worldY(int screenY) {
|
||||
return screenY * subDivisionY / zoomY + panY;
|
||||
}
|
||||
|
||||
public double screenX(int worldX) {
|
||||
return (worldX - panX) * zoomX / subDivisionX;
|
||||
}
|
||||
|
||||
public double screenY(int worldY) {
|
||||
return (worldY - panY) * zoomY / subDivisionY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,527 @@
|
||||
package noppes.npcs.client.gui.util.animation;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.client.gui.util.GuiUtil;
|
||||
import noppes.npcs.client.gui.util.animation.keys.GraphEditorKeyPresets;
|
||||
import noppes.npcs.client.gui.util.animation.keys.KeyPreset;
|
||||
import noppes.npcs.client.utils.Color;
|
||||
import noppes.npcs.constants.animation.EnumFrameType;
|
||||
import noppes.npcs.util.Ease;
|
||||
import noppes.npcs.util.ValueUtil;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public class GridPointManager {
|
||||
public AnimationGraphEditor graph;
|
||||
public Grid grid;
|
||||
public GraphEditorKeyPresets keys;
|
||||
|
||||
public HashMap<EnumFrameType, TreeMap<Double, Point>> typePoints = new HashMap<>();
|
||||
public List<Point> highlightedPoints = new ArrayList<>();
|
||||
public Point selectedPoint;
|
||||
public Playhead playhead = new Playhead(0);
|
||||
|
||||
public boolean isFreeTransforming;
|
||||
public double ftGrabX, ftGrabY; //where point is grabbed on free transforming
|
||||
|
||||
public GridPointManager(AnimationGraphEditor graph) {
|
||||
this.graph = graph;
|
||||
this.grid = graph.grid;
|
||||
keys = grid.parent.keys;
|
||||
keys();
|
||||
}
|
||||
|
||||
public void keys() {
|
||||
|
||||
keys.SELECT_POINT.setTask((pressType) -> {
|
||||
if (pressType == KeyPreset.PRESS) {
|
||||
forEachActive((pointType, point) -> {
|
||||
if (point.isMouseAbove(grid.mouseX, grid.mouseY)) {
|
||||
setSelectedPoint(point);
|
||||
graph.setSelectedType(pointType);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
keys.ADD_POINT.setTask((pressType) -> {
|
||||
if (pressType == KeyPreset.PRESS) {
|
||||
// if (!highlightedTypes.contains(type))
|
||||
// highlightedTypes.add(type);
|
||||
|
||||
TreeMap<Double, Point> points = pointsOf(graph.getSelectedType());
|
||||
Point point = points != null ? points.get((double) playhead.worldX) : null; //check if it exists
|
||||
if (point == null)
|
||||
point = addPoint(graph.getSelectedType(), playhead.worldX, 0); // worldX(mouseX - startX), worldY(mouseY - startY)
|
||||
|
||||
setSelectedPoint(point);
|
||||
}
|
||||
});
|
||||
|
||||
keys.DELETE_POINT.setTask((pressType) -> {
|
||||
if ((pressType == KeyPreset.PRESS) && selectedPoint != null && !grid.isDragging) {
|
||||
deletePoint(selectedPoint.type, selectedPoint.worldX);
|
||||
}
|
||||
});
|
||||
|
||||
keys.FREE_TRANSFORM.setTask((pressType) -> {
|
||||
if (pressType == KeyPreset.PRESS && selectedPoint != null) {
|
||||
if (isFreeTransforming) {
|
||||
selectedPoint.set(ftGrabX, ftGrabY);
|
||||
ftGrabX = ftGrabY = 0;
|
||||
} else {
|
||||
ftGrabX = selectedPoint.worldX;
|
||||
ftGrabY = selectedPoint.worldY;
|
||||
Cursors.setCursor(Cursors.MOVE, () -> selectedPoint != null && isFreeTransforming);
|
||||
}
|
||||
|
||||
isFreeTransforming = !isFreeTransforming;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
if (button == 0 && selectedPoint != null && !isFreeTransforming) {
|
||||
if (grid.parent.isWithin(mouseX, mouseY) && !selectedPoint.isMouseAbove(mouseX, mouseY))
|
||||
setSelectedPoint(null);
|
||||
}
|
||||
|
||||
if (button == 0 && isFreeTransforming) {
|
||||
selectedPoint.updateKey();
|
||||
// Cursors.reset();
|
||||
isFreeTransforming = false;
|
||||
}
|
||||
|
||||
playhead.mouseClicked(mouseX, mouseY, button);
|
||||
forEachActive((type, point) -> {
|
||||
point.mouseClicked(mouseX, mouseY, button);
|
||||
});
|
||||
}
|
||||
|
||||
public void updateTypeValues(double x) {
|
||||
// if (x != playhead.worldX)
|
||||
// return;
|
||||
graph.frameTypePanel.updateTypeValues(playhead.worldX);
|
||||
}
|
||||
|
||||
public Point addPoint(EnumFrameType type, double x, double y) {
|
||||
return addPoint(type, new Point(type, x, y));
|
||||
}
|
||||
|
||||
public Point addPoint(EnumFrameType type, Point point) {
|
||||
TreeMap<Double, Point> points = pointsOf(type);
|
||||
if (points == null) {
|
||||
points = new TreeMap<>();
|
||||
typePoints.put(type, points);
|
||||
}
|
||||
|
||||
points.put(point.worldX, point);
|
||||
updateTypeValues(point.worldX);
|
||||
return point;
|
||||
}
|
||||
|
||||
public void deletePoint(EnumFrameType type, double x) {
|
||||
TreeMap<Double, Point> points = pointsOf(type);
|
||||
if (points == null)
|
||||
return;
|
||||
|
||||
Point point = points.remove(x);
|
||||
updateTypeValues(x);
|
||||
if (point == selectedPoint)
|
||||
setSelectedPoint(null);
|
||||
}
|
||||
|
||||
public Point getPoint(EnumFrameType type, double x) {
|
||||
TreeMap<Double, Point> points = pointsOf(type);
|
||||
if (points == null)
|
||||
return null;
|
||||
|
||||
return points.get(x);
|
||||
}
|
||||
|
||||
|
||||
public TreeMap<Double, Point> pointsOf(EnumFrameType type) {
|
||||
return typePoints.get(type);
|
||||
}
|
||||
|
||||
public void forEach(BiConsumer<EnumFrameType, Point> consumer) {
|
||||
for (Map.Entry<EnumFrameType, TreeMap<Double, Point>> entry : typePoints.entrySet()) {
|
||||
EnumFrameType type = entry.getKey();
|
||||
|
||||
|
||||
for (Map.Entry<Double, Point> points : entry.getValue().entrySet()) {
|
||||
Point point = points.getValue();
|
||||
consumer.accept(type, point);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void forEachActive(BiConsumer<EnumFrameType, Point> consumer) {
|
||||
for (Map.Entry<EnumFrameType, TreeMap<Double, Point>> entry : typePoints.entrySet()) {
|
||||
EnumFrameType type = entry.getKey();
|
||||
|
||||
// if (!highlightedTypes.contains(type))
|
||||
// continue;
|
||||
|
||||
for (Map.Entry<Double, Point> points : entry.getValue().entrySet()) {
|
||||
Point point = points.getValue();
|
||||
consumer.accept(type, point);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setSelectedPoint(Point point) {
|
||||
if (selectedPoint != null)
|
||||
selectedPoint.highlighted = false;
|
||||
|
||||
this.selectedPoint = point;
|
||||
|
||||
if (point != null)
|
||||
point.highlighted = true;
|
||||
}
|
||||
|
||||
public Point getPrevious(Point point) {
|
||||
return getPrevious(point.type, point.worldX);
|
||||
}
|
||||
|
||||
public Point getPrevious(EnumFrameType type, double x) {
|
||||
TreeMap<Double, Point> points = pointsOf(type);
|
||||
if (points == null)
|
||||
return null;
|
||||
|
||||
Map.Entry<Double, Point> entry = points.lowerEntry(x);
|
||||
if (entry != null)
|
||||
return entry.getValue();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Point getNext(Point point) {
|
||||
return getNext(point.type, point.worldX);
|
||||
}
|
||||
|
||||
public Point getNext(EnumFrameType type, double x) {
|
||||
TreeMap<Double, Point> points = pointsOf(type);
|
||||
if (points == null)
|
||||
return null;
|
||||
|
||||
Map.Entry<Double, Point> entry = points.higherEntry(x);
|
||||
if (entry != null)
|
||||
return entry.getValue();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public double getValueBetweenPointsAt(Point from, Point to, double at) {
|
||||
float lerpFactor = (float) ((at - from.worldX) / (to.worldX - from.worldX));
|
||||
return - ValueUtil.lerp(from.worldY, to.worldY, Ease.INOUTQUINT.apply(lerpFactor));
|
||||
}
|
||||
|
||||
public void drawEasedCurve(Point from, Point to) {
|
||||
if (from == null || to == null)
|
||||
return;
|
||||
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||
GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
|
||||
GL11.glLineWidth(3F);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(grid.startX, grid.startY, 0);
|
||||
from.type.getColor().multiply(from.type == graph.getSelectedType() ? 1 : 0.55f).glColor();
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawing(GL11.GL_LINE_STRIP);
|
||||
|
||||
|
||||
for (float t = 0; t <= 1; t += 0.01) {
|
||||
float easedT = Ease.INOUTQUINT.apply(t);
|
||||
double xt = ValueUtil.lerp(from.screenX() + 0.5, to.screenX() + 0.5, t);
|
||||
double yt = ValueUtil.lerp(from.screenY() + 0.5, to.screenY() + 0.5, easedT);
|
||||
|
||||
tessellator.addVertex(xt, yt, 0);
|
||||
}
|
||||
|
||||
tessellator.draw();
|
||||
GL11.glPopMatrix();
|
||||
|
||||
GL11.glLineWidth(1F);
|
||||
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
public void draw(int mouseX, int mouseY, float partialTicks) {
|
||||
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Free transform logic
|
||||
if (isFreeTransforming && selectedPoint != null) {
|
||||
boolean shift = KeyPreset.isShiftKeyDown();
|
||||
if (grid.xDown())
|
||||
selectedPoint.setX(Math.round(grid.worldX(GuiUtil.preciseMouseX() - grid.startX)));
|
||||
else if (grid.yDown()) {
|
||||
double value = grid.worldY(GuiUtil.preciseMouseY() - grid.startY);
|
||||
selectedPoint.setY(shift ? (int) value : value);
|
||||
} else {
|
||||
double y = grid.worldY(GuiUtil.preciseMouseY() - grid.startY);
|
||||
selectedPoint.set(Math.round(grid.worldX(GuiUtil.preciseMouseX() - grid.startX)), shift ? (int) y : y);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
playhead.draw(mouseX, mouseY, partialTicks);
|
||||
|
||||
forEachActive((type, point) -> {
|
||||
drawEasedCurve(point, getNext(point));
|
||||
point.draw(mouseX, mouseY, partialTicks);
|
||||
});
|
||||
if (selectedPoint != null)
|
||||
selectedPoint.draw(mouseX, mouseY, partialTicks);
|
||||
|
||||
|
||||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Pans grid while free transforming
|
||||
// MUST BE DONE AT THE VERY END -> CHANGES CURSOR POSITION WITHOUT
|
||||
// CHANGING GuiScreen.drawScreen(mouseX,mouseY) VALUES
|
||||
if (isFreeTransforming) {
|
||||
if (mouseX < grid.startX) {
|
||||
int deltaX = mouseX - grid.startX;
|
||||
grid.panX += deltaX / grid.zoomX;
|
||||
GuiUtil.setMouseX(grid.startX - 1);
|
||||
}
|
||||
if (mouseX > grid.endX) {
|
||||
int deltaX = mouseX - grid.endX;
|
||||
grid.panX += (deltaX / grid.zoomX);
|
||||
GuiUtil.setMouseX(grid.endX + 1);
|
||||
}
|
||||
if (mouseY < grid.startY) {
|
||||
int deltaY = mouseY - grid.startY;
|
||||
grid.panY += deltaY / grid.zoomY;
|
||||
GuiUtil.setMouseY(grid.startY);
|
||||
}
|
||||
if (mouseY > grid.endY) {
|
||||
int deltaY = mouseY - grid.endY;
|
||||
grid.panY += deltaY / grid.zoomY;
|
||||
GuiUtil.setMouseY(grid.endY + 2);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
public void keyTyped(char c, int key) {
|
||||
}
|
||||
|
||||
private static ResourceLocation TEXTURE = new ResourceLocation("customnpcs:textures/gui/animation.png");
|
||||
|
||||
public class Point {
|
||||
public EnumFrameType type;
|
||||
public double worldX, worldY;
|
||||
public boolean highlighted;
|
||||
|
||||
public double previousX;
|
||||
|
||||
public Point(EnumFrameType type, double worldX, double worldY) {
|
||||
this.type = type;
|
||||
this.worldX = previousX = worldX;
|
||||
this.worldY = worldY;
|
||||
}
|
||||
|
||||
public void setX(double x) {
|
||||
worldX = (int) x;
|
||||
updateTypeValues(worldX);
|
||||
}
|
||||
|
||||
public void setY(double y) {
|
||||
worldY = y;
|
||||
updateTypeValues(worldX);
|
||||
}
|
||||
|
||||
public void set(double x, double y) {
|
||||
setX(x);
|
||||
setY(y);
|
||||
}
|
||||
|
||||
public void updateKey() {
|
||||
TreeMap<Double, Point> points = pointsOf(type);
|
||||
if (points == null)
|
||||
return;
|
||||
|
||||
points.remove(previousX);
|
||||
points.put(worldX, this);
|
||||
previousX = worldX;
|
||||
}
|
||||
|
||||
public void draw(int mouseX, int mouseY, float partialTicks) {
|
||||
float scale = 0.1f;
|
||||
int textureWidth = 32, textureHeight = 32;
|
||||
float offsetX = (textureHeight / 2) * scale - 0.5f, offsetY = (textureHeight / 2) * scale - 0.5f;
|
||||
double screenX = screenX() / scale, screenY = screenY() / scale;
|
||||
|
||||
grid.parent.mc.getTextureManager().bindTexture(TEXTURE);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
new Color(highlighted ? 0xffbe33 : 0xbfbfbf, 1).glColor();
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(grid.startX - offsetX, grid.startY - offsetY, 0);
|
||||
GL11.glScalef(scale, scale, 1);
|
||||
GuiUtil.drawTexturedModalRect(screenX, screenY, textureWidth, textureHeight, 256 - textureWidth, 256 - textureHeight);
|
||||
|
||||
GL11.glPopMatrix();
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
}
|
||||
|
||||
public boolean isMouseAbove(int mouseX, int mouseY) {
|
||||
int rMX = mouseX - grid.startX, rMY = mouseY - grid.startY; //relative to grid
|
||||
float scale = 0.1f;
|
||||
float textureWidth = (32), textureHeight = (32);
|
||||
float offsetX = (textureWidth / 2) * scale - 0.5f, offsetY = (textureHeight / 2) * scale - 0.5f;
|
||||
|
||||
int screenX = (int) (screenX() - offsetX);
|
||||
int screenY = (int) ((screenY()) - offsetY);
|
||||
|
||||
return rMX >= screenX && rMX < screenX + textureWidth * scale && rMY >= screenY && rMY < screenY + textureHeight * scale;
|
||||
}
|
||||
|
||||
public double screenX() {
|
||||
|
||||
return grid.screenX(worldX);
|
||||
}
|
||||
|
||||
public double screenY() {
|
||||
return grid.screenY(worldY);
|
||||
}
|
||||
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
}
|
||||
}
|
||||
|
||||
public class Playhead {
|
||||
public int worldX;
|
||||
public boolean isDragging;
|
||||
|
||||
public Playhead(int currentX) {
|
||||
this.worldX = currentX;
|
||||
}
|
||||
|
||||
public void draw(int mouseX, int mouseY, float partialTicks) {
|
||||
// Dragging
|
||||
if (isDragging && !Mouse.isButtonDown(0))
|
||||
isDragging = false;
|
||||
|
||||
if (isDragging)
|
||||
setX(Math.round(grid.worldX(GuiUtil.preciseMouseX() - grid.startX)));
|
||||
|
||||
//Expand clip boundary
|
||||
GuiUtil.setScissorClip(grid.startX, grid.startY - grid.yAxisHeight, grid.width, grid.height + grid.yAxisHeight);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
// Head lines
|
||||
double screenX = screenX();
|
||||
float height = grid.endY - grid.startY;
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(grid.startX + screenX, grid.startY, 0);
|
||||
GL11.glDepthMask(false);
|
||||
GuiUtil.drawVerticalLine(-1, 0, height, 0xFF212121);
|
||||
GuiUtil.drawVerticalLine(0, -5, height, 0xFF4772b3);
|
||||
GuiUtil.drawVerticalLine(1, 0, height, 0xFF212121);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
// Head texture
|
||||
FontRenderer fontRenderer = grid.parent.getFontRenderer();
|
||||
float textureScaleX = 0.5f, textureScaleY = 0.5f;
|
||||
|
||||
// Texture width dynamically scales with string width
|
||||
int defaultWidth = 6, width = fontRenderer.getStringWidth(worldX + "");
|
||||
if (width / defaultWidth > 1)
|
||||
textureScaleX += width / defaultWidth * 0.125;
|
||||
|
||||
int textureWidth = 25, textureHeight = 17;
|
||||
float offset = (textureWidth / 2) * textureScaleX;
|
||||
float screenY = grid.startY - grid.yAxisHeight;
|
||||
|
||||
grid.parent.mc.getTextureManager().bindTexture(TEXTURE);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
new Color(0x426dae, 1).glColor();
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(grid.startX, 0, 0);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(-offset, 0, 0);
|
||||
GL11.glScalef(textureScaleX, textureScaleY, 1);
|
||||
|
||||
GuiUtil.drawTexturedModalRect(screenX / textureScaleX, (screenY + 2) / textureScaleY, textureWidth, textureHeight, 228, 199);
|
||||
|
||||
GL11.glPopMatrix();
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
// Head value
|
||||
float vScale = 0.75f;
|
||||
double valueScreenX = (screenX + 1) / vScale;
|
||||
double valueScreenY = (screenY + 4) / vScale;
|
||||
GL11.glScalef(vScale, vScale, 1);
|
||||
grid.parent.drawString(String.valueOf(worldX), (int) valueScreenX, (int) valueScreenY, 0xFFccd7e9);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
//Reset clip
|
||||
GuiUtil.setScissorClip(grid.startX, grid.startY, grid.width, grid.height);
|
||||
}
|
||||
|
||||
public boolean isMouseAbove(int mouseX, int mouseY) {
|
||||
int rMX = mouseX - grid.startX, rMY = mouseY - grid.startY; //relative to grid
|
||||
float scale = 0.5f;
|
||||
float textureWidth = (25 * scale), textureHeight = (17 * scale);
|
||||
float offsetX = (textureWidth / 2) * scale;
|
||||
|
||||
int screenX = (int) Math.round(screenX() - (offsetX / scale));
|
||||
int screenY = -grid.yAxisHeight + 2;
|
||||
|
||||
return rMX >= screenX && rMX <= screenX + textureWidth && rMY >= screenY && rMY < screenY + textureHeight;
|
||||
}
|
||||
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
|
||||
if (button == 0 && mouseX >= grid.startX && mouseX <= grid.endX && mouseY >= grid.startY - grid.yAxisHeight && mouseY <= grid.startY) {
|
||||
setX(Math.round(grid.worldX(GuiUtil.preciseMouseX() - grid.startX)));
|
||||
updateTypeValues(worldX);
|
||||
isDragging = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void setX(double x) {
|
||||
this.worldX = (int) x;
|
||||
updateTypeValues(worldX);
|
||||
}
|
||||
|
||||
public double screenX() {
|
||||
return grid.screenX(worldX);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,419 @@
|
||||
package noppes.npcs.client.gui.util.animation;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.client.gui.util.GuiUtil;
|
||||
import noppes.npcs.client.gui.util.animation.keys.KeyPreset;
|
||||
import noppes.npcs.client.gui.util.animation.keys.KeyPresetManager;
|
||||
import noppes.npcs.client.utils.Color;
|
||||
import noppes.npcs.util.ValueUtil;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class OverlayKeyPresetViewer {
|
||||
public static final ResourceLocation TEXTURE = new ResourceLocation("customnpcs:textures/gui/keypreset_highres.png");
|
||||
|
||||
public int startX, startY, endX, endY, width, height;
|
||||
public int mouseX, mouseY;
|
||||
public boolean showOverlay;
|
||||
|
||||
public int elementSpacing = 5, yStartSpacing = 5;
|
||||
public float scale = 0.75f;
|
||||
public Scrollable scroll = new Scrollable();
|
||||
|
||||
public KeyPresetManager manager;
|
||||
public OverlayButton viewButton = new OverlayButton();
|
||||
public LinkedList<PresetElement> list = new LinkedList<>();
|
||||
|
||||
private final FontRenderer font = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
public OverlayKeyPresetViewer(KeyPresetManager manager) {
|
||||
this.manager = manager;
|
||||
|
||||
manager.keys.forEach((key) -> {
|
||||
PresetElement element = new PresetElement(key);
|
||||
list.add(element);
|
||||
});
|
||||
}
|
||||
|
||||
public void initGui(int startX, int startY, int endX, int endY) {
|
||||
this.startX = startX;
|
||||
this.startY = startY;
|
||||
this.endX = endX;
|
||||
this.endY = endY;
|
||||
this.width = endX - startX;
|
||||
this.height = endY - startY;
|
||||
scroll.init();
|
||||
}
|
||||
|
||||
public void draw(int mouseX, int mouseY, int wheel) {
|
||||
this.mouseX = mouseX;
|
||||
this.mouseY = mouseY;
|
||||
boolean aboveButton = viewButton.isMouseAbove(mouseX, mouseY);
|
||||
boolean aboveOverlay = isMouseAbove(mouseX, mouseY);
|
||||
|
||||
if (aboveButton)
|
||||
showOverlay = true;
|
||||
|
||||
if (showOverlay) {
|
||||
drawOverlay(wheel);
|
||||
|
||||
if (!aboveOverlay && !aboveButton)
|
||||
showOverlay = false;
|
||||
}
|
||||
|
||||
viewButton.drawButton();
|
||||
}
|
||||
|
||||
public void drawOverlay(int wheel) {
|
||||
scroll.update(wheel);
|
||||
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
GuiUtil.drawGradientRect(startX, startY, endX, endY, 0x88000000, 0x88303030);
|
||||
if (scroll.maxScroll > 0)
|
||||
scroll.drawBar();
|
||||
|
||||
GuiUtil.setScissorClip(startX, startY, scroll.maxScroll > 0 ? width - scroll.barWidth : width, height);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef((startX + 2), startY + yStartSpacing - scroll.scrollY, 0);
|
||||
|
||||
for (int i = 0, height = 0; i < list.size(); i++) {
|
||||
PresetElement element = list.get(i);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glScalef(scale, scale, 1);
|
||||
GL11.glTranslatef(0, Math.round(height / scale), 0);
|
||||
element.drawDescription();
|
||||
GL11.glPopMatrix();
|
||||
|
||||
element.drawBox(height);
|
||||
height += element.getHeight();
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
public void keyTyped(char c, int i) {
|
||||
if (!showOverlay)
|
||||
return;
|
||||
|
||||
list.forEach((element) -> {
|
||||
if (element.isEditing)
|
||||
element.keyTyped(i);
|
||||
});
|
||||
}
|
||||
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
if (!showOverlay)
|
||||
return;
|
||||
|
||||
list.forEach((element) -> {
|
||||
if (!element.isMouseAboveBox(mouseX, mouseY)) {
|
||||
if (element.isEditing)
|
||||
element.cancelEdit();
|
||||
} else
|
||||
element.boxClicked(button);
|
||||
|
||||
if (element.isMouseAboveReset(mouseX, mouseY) && !element.key.isDefault()) {
|
||||
element.key.defaultState.writeTo(element.key.currentState);
|
||||
manager.save();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isMouseAbove(int mouseX, int mouseY) {
|
||||
if (scroll.isMouseDragging)
|
||||
return true;
|
||||
|
||||
return mouseX >= startX && mouseX < endX && mouseY >= startY && mouseY < endY;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return (int) (width / scale);
|
||||
}
|
||||
|
||||
public class Scrollable {
|
||||
private float scrollY, targetScrollY, maxScroll;
|
||||
private int totalHeight, scrollbarHeight, barWidth = 2;
|
||||
private float heightFactor, scrollFactor;
|
||||
|
||||
private boolean isMouseDragging;
|
||||
private int startDragY;
|
||||
|
||||
public Scrollable() {
|
||||
}
|
||||
|
||||
public void init() {
|
||||
totalHeight = 0;
|
||||
for (PresetElement element : list)
|
||||
totalHeight += element.getHeight();
|
||||
|
||||
totalHeight -= yStartSpacing;
|
||||
scroll.maxScroll = Math.max(0, totalHeight - height);
|
||||
|
||||
heightFactor = height / totalHeight;
|
||||
scrollbarHeight = Math.max((int) (height * heightFactor), 20);
|
||||
scrollFactor = (height - yStartSpacing - scrollbarHeight) / maxScroll;
|
||||
}
|
||||
|
||||
public void update(int wheel) {
|
||||
if (wheel != 0 && isMouseAbove(mouseX, mouseY))
|
||||
targetScrollY = ValueUtil.clamp(targetScrollY - wheel / 15, 0, maxScroll);
|
||||
|
||||
|
||||
if (Mouse.isButtonDown(0)) {
|
||||
if (!isMouseDragging && isMouseAboveBar(mouseX, mouseY)) {
|
||||
isMouseDragging = true;
|
||||
startDragY = (int) (mouseY - scrollY * scrollFactor);
|
||||
}
|
||||
} else
|
||||
isMouseDragging = false;
|
||||
|
||||
if (isMouseDragging)
|
||||
scrollY = targetScrollY = ValueUtil.clamp((mouseY - startDragY) / scrollFactor, 0, maxScroll);
|
||||
|
||||
if (scrollY != targetScrollY) {
|
||||
scrollY = ValueUtil.lerp(scrollY, targetScrollY, 0.1f);
|
||||
|
||||
if (Math.abs(scrollY - targetScrollY) < 0.001) // Snap to exact target value
|
||||
scrollY = targetScrollY;
|
||||
}
|
||||
|
||||
scrollY = ValueUtil.clamp(scrollY, 0, maxScroll);
|
||||
}
|
||||
|
||||
public void drawBar() {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(endX - barWidth - 2, startY + yStartSpacing + scrollY * scrollFactor, 0);
|
||||
GuiUtil.drawRectD(0, 0, barWidth, scrollbarHeight, (isMouseAboveBar(mouseX, mouseY) || isMouseDragging) ? 0xffbababa : 0xff767676);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
public boolean isMouseAboveBar(int mouseX, int mouseY) {
|
||||
int barX = endX - barWidth - 2;
|
||||
int barY = (int) (startY + yStartSpacing + scrollY * scrollFactor);
|
||||
|
||||
return mouseX >= barX && mouseX < barX + barWidth && mouseY >= barY && mouseY < barY + scrollbarHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public class PresetElement {
|
||||
public KeyPreset key;
|
||||
public boolean isEditing;
|
||||
public float boxScreenX, boxScreenY;
|
||||
|
||||
public KeyPreset.KeyState newState = new KeyPreset.KeyState();
|
||||
|
||||
public PresetElement(KeyPreset key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public void drawDescription() {
|
||||
String name = String.format("> %s", key.name);
|
||||
font.drawString(name, 0, 0, 0xffffff);
|
||||
|
||||
if (!key.shouldConflict)
|
||||
font.drawString("(Conflict-free)", font.getStringWidth(name) + 5, 0, 0xface40);
|
||||
|
||||
String description = String.format("- %s", key.description);
|
||||
font.drawSplitString(description, 9, font.FONT_HEIGHT, getMaxStringWidth() - 9, 0x888888);
|
||||
}
|
||||
|
||||
public void drawBox(int offsetY) {
|
||||
////////////////////////////////////////////
|
||||
////////////////////////////////////////////
|
||||
//Box texture
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
float boxScaleX = 1.75f;
|
||||
float boxWidth = 32 * boxScaleX;
|
||||
boxScreenX = getMaxStringWidth() * scale + 8; //remove scaling from maxStringWidth
|
||||
GL11.glScalef(boxScaleX, 1, 0);
|
||||
|
||||
if (isEditing)
|
||||
new Color(0x4772b3, 1).glColor();
|
||||
else if (isMouseAboveBox(mouseX, mouseY))
|
||||
new Color(0x656565, 1).glColor();
|
||||
else
|
||||
new Color(0x545454, 1).glColor();
|
||||
GuiUtil.drawTexturedModalRect(boxScreenX / boxScaleX, boxScreenY = offsetY - 5, 32, 20, 0, 492);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
//Reset box
|
||||
boolean isDefault = key.isDefault();
|
||||
float resetWidth = 10;
|
||||
float resetScreenX = boxScreenX + boxWidth + 2;
|
||||
|
||||
if (isMouseAboveReset(mouseX, mouseY) && !isDefault)
|
||||
new Color(0x656565, 1).glColor();
|
||||
else
|
||||
new Color(0x545454, 1).glColor();
|
||||
GuiUtil.drawTexturedModalRect(resetScreenX, boxScreenY, 10, 20, 33, 492);
|
||||
|
||||
////////////////////////////////////////////
|
||||
////////////////////////////////////////////
|
||||
//Key name
|
||||
String name = getBoxKeyName();
|
||||
float nameWidth = font.getStringWidth(name);
|
||||
float nameScale = scale;
|
||||
float nameBoxRatio = nameWidth * scale / boxWidth;
|
||||
|
||||
GL11.glPushMatrix();
|
||||
if (nameBoxRatio > 0.9) {
|
||||
nameScale /= nameWidth / boxWidth / 1.2f;
|
||||
GL11.glTranslatef(0, nameBoxRatio * 0.5f, 0);
|
||||
}
|
||||
|
||||
float nameX = boxScreenX + boxWidth / 2 - (nameWidth / 2 * nameScale);
|
||||
float nameY = offsetY + 11.5f - (font.FONT_HEIGHT / 2);
|
||||
GL11.glScalef(nameScale, nameScale, 1);
|
||||
GL11.glTranslatef(nameX / nameScale, nameY / nameScale, 1);
|
||||
font.drawStringWithShadow(name, 0, 0, conflicts() ? 0xff5555 : 0xffffffff);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
//Reset letter
|
||||
char letter = 'X';
|
||||
float letterX = resetScreenX + (resetWidth / 2) - (font.getCharWidth(letter) / 2 * scale) + 0.25f;
|
||||
GL11.glPushMatrix();
|
||||
GL11.glScalef(scale, scale, 1);
|
||||
GL11.glTranslatef(letterX / scale, nameY / scale, 1);
|
||||
font.drawStringWithShadow(String.valueOf(letter), 0, 0, isDefault ? 0xff8a8a8a : 0xffffffff);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
////////////////////////////////////////////
|
||||
////////////////////////////////////////////
|
||||
}
|
||||
|
||||
public void boxClicked(int button) {
|
||||
if (isEditing)
|
||||
setKey(-100 + button);
|
||||
else if (button == 0)
|
||||
isEditing = true;
|
||||
}
|
||||
|
||||
public void keyTyped(int typedKey) {
|
||||
if (typedKey == 1) {
|
||||
setKey(0);
|
||||
return;
|
||||
}
|
||||
|
||||
newState.setState(newState.keyCode, KeyPreset.isCtrlKeyDown(), KeyPreset.isAltKeyDown(), KeyPreset.isShiftKeyDown());
|
||||
if (KeyPreset.isNotCtrlAltShift(typedKey))
|
||||
setKey(typedKey);
|
||||
}
|
||||
|
||||
public void setKey(int keyCode) {
|
||||
if (keyCode == 0)
|
||||
newState.clear();
|
||||
|
||||
newState.keyCode = keyCode;
|
||||
newState.writeTo(key.currentState);
|
||||
cancelEdit();
|
||||
manager.save();
|
||||
}
|
||||
|
||||
public void cancelEdit() {
|
||||
newState.clear();
|
||||
isEditing = false;
|
||||
}
|
||||
|
||||
public boolean conflicts() {
|
||||
return list.stream().anyMatch(element -> key.shouldConflict && element.key.shouldConflict && element.key != this.key && element.key.equals(this.key));
|
||||
}
|
||||
|
||||
public String getBoxKeyName() {
|
||||
if (isEditing) {
|
||||
String modifiers = "";
|
||||
if (KeyPreset.isCtrlKeyDown())
|
||||
modifiers += "CTRL ";
|
||||
if (KeyPreset.isAltKeyDown())
|
||||
modifiers += "ALT ";
|
||||
if (KeyPreset.isShiftKeyDown())
|
||||
modifiers += "SHIFT ";
|
||||
|
||||
return !modifiers.isEmpty() ? modifiers : "Press a key";
|
||||
}
|
||||
|
||||
return key.currentState.getName();
|
||||
}
|
||||
|
||||
public boolean isMouseAboveBox(int mouseX, int mouseY) {
|
||||
mouseX -= startX + 2;
|
||||
mouseY -= startY + 5 - scroll.scrollY;
|
||||
|
||||
float boxScaleX = 1.75f;
|
||||
float screenY = boxScreenY + 10;
|
||||
|
||||
return mouseX >= boxScreenX && mouseX < boxScreenX + 32 * boxScaleX && mouseY >= screenY && mouseY < screenY + 10;
|
||||
}
|
||||
|
||||
public boolean isMouseAboveReset(int mouseX, int mouseY) {
|
||||
mouseX -= startX + 2;
|
||||
mouseY -= startY + 5 - scroll.scrollY;
|
||||
|
||||
float boxScaleX = 1.75f;
|
||||
float resetWidth = 10, boxWidth = 32 * boxScaleX;
|
||||
float screenX = boxScreenX + boxWidth + 2;
|
||||
float screenY = boxScreenY + 10;
|
||||
|
||||
return mouseX >= screenX && mouseX < screenX + resetWidth && mouseY >= screenY && mouseY < screenY + 10;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
List<String> wrappedDescription = font.listFormattedStringToWidth(String.format("- %s", key.description), getMaxStringWidth());
|
||||
|
||||
int nameHeight = font.FONT_HEIGHT;
|
||||
int translations = font.FONT_HEIGHT;
|
||||
int descriptionHeight = wrappedDescription.size() * (font.FONT_HEIGHT);
|
||||
|
||||
return Math.round((nameHeight + descriptionHeight + translations) * scale) + elementSpacing;
|
||||
}
|
||||
|
||||
public int getMaxStringWidth() {
|
||||
return (int) (getWidth() * 2.5f / 4);
|
||||
}
|
||||
}
|
||||
|
||||
public class OverlayButton {
|
||||
public int startX, startY, endX, width, height;
|
||||
public int textureWidth = 252, textureHeight = 109;
|
||||
public float scale = 0.25f;
|
||||
|
||||
public OverlayButton() {
|
||||
}
|
||||
|
||||
public void initGui(int endX, int startY) {
|
||||
this.endX = endX;
|
||||
this.startY = startY;
|
||||
|
||||
startX = (int) (endX - textureWidth * scale / 2);
|
||||
}
|
||||
|
||||
public void drawButton() {
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE);
|
||||
|
||||
double screenX = startX / scale, screenY = startY / scale;
|
||||
int oldMinFilter = GL11.glGetTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
float color = 0.55f;
|
||||
GL11.glColor4f(color, color, color, 1);
|
||||
GL11.glScalef(scale, scale, 1);
|
||||
GuiUtil.drawTexturedModalRect(screenX, screenY, textureWidth, textureHeight, 0, 0);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, oldMinFilter);
|
||||
}
|
||||
|
||||
public boolean isMouseAbove(int mouseX, int mouseY) {
|
||||
return mouseX >= startX && mouseX < startX + textureWidth * scale / 2 && mouseY >= startY - 4 && mouseY < startY + textureHeight * scale / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package noppes.npcs.client.gui.util.animation;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import noppes.npcs.client.gui.util.GuiNPCInterface;
|
||||
import noppes.npcs.client.gui.util.GuiUtil;
|
||||
import noppes.npcs.client.gui.util.animation.keys.GraphEditorKeyPresets;
|
||||
|
||||
public class ViewportGraphEditor {
|
||||
public Minecraft mc = Minecraft.getMinecraft();
|
||||
public GuiNPCInterface parent;
|
||||
|
||||
public int startX, startY, endX, endY, width, height;
|
||||
|
||||
public GraphEditorKeyPresets keys = new GraphEditorKeyPresets();
|
||||
public OverlayKeyPresetViewer presetOverlay = new OverlayKeyPresetViewer(keys);
|
||||
|
||||
public Grid grid = new Grid(this);
|
||||
|
||||
public ViewportGraphEditor(GuiNPCInterface parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void initGui(int startX, int startY, int endX, int endY) {
|
||||
this.startX = startX;
|
||||
this.startY = startY;
|
||||
this.endX = endX;
|
||||
this.endY = endY;
|
||||
this.width = endX - this.startX;
|
||||
this.height = endY - this.startY;
|
||||
|
||||
grid.init(this.startX, this.startY, endX, endY);
|
||||
presetOverlay.initGui(endX - (width / 2) - 37, startY + (height / 4), endX, endY);
|
||||
presetOverlay.viewButton.initGui(endX + 1, endY + 2);
|
||||
}
|
||||
|
||||
public void updateScreen() {
|
||||
keys.tick();
|
||||
}
|
||||
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks, int wheel) {
|
||||
grid.draw(mouseX, mouseY, partialTicks, wheel);
|
||||
presetOverlay.draw(mouseX, mouseY, wheel);
|
||||
}
|
||||
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
grid.mouseClicked(mouseX, mouseY, button);
|
||||
presetOverlay.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
public void keyTyped(char c, int i) {
|
||||
grid.keyTyped(c, i);
|
||||
presetOverlay.keyTyped(c, i);
|
||||
}
|
||||
|
||||
public boolean isWithin(int mouseX, int mouseY) {
|
||||
if (parent.hasSubGui())
|
||||
return false;
|
||||
|
||||
return mouseX >= startX && mouseX <= startX + width && mouseY >= startY && mouseY <= startY + height;
|
||||
}
|
||||
|
||||
public void drawString(String text, int x, int y, int color) {
|
||||
parent.drawCenteredString(getFontRenderer(), text, x, y, color);
|
||||
}
|
||||
|
||||
public FontRenderer getFontRenderer() {
|
||||
return parent.getFontRenderer();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (Cursors.currentCursor() != null)
|
||||
Cursors.reset();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package noppes.npcs.client.gui.util.animation.keys;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class GraphEditorKeyPresets extends KeyPresetManager {
|
||||
|
||||
////////////////////
|
||||
//Grid controls
|
||||
public final KeyPreset PAN_GRID = add("Pan Grid").setDefaultState(KeyPreset.RIGHT_MOUSE, false, false, false).setDescription("Holding pans the grid with mouse cursor");
|
||||
public final KeyPreset LOCK_X = add("Lock X Axis").setDefaultState(Keyboard.KEY_X, false, false, false).setDescription("Holding locks the X axis while zooming or panning").shouldConflict(false);
|
||||
public final KeyPreset LOCK_Y = add("Lock Y Axis").setDefaultState(Keyboard.KEY_Y, false, false, false).setDescription("Holding locks the Y axis while zooming or panning").shouldConflict(false);
|
||||
public final KeyPreset RESET_GRID = add("Reset Grid").setDefaultState(Keyboard.KEY_R, false, false, false).setDescription("Resets the grid's XY scale and translation to the origins");
|
||||
|
||||
|
||||
////////////////////
|
||||
//Grid Point controls
|
||||
public final KeyPreset SELECT_POINT = add("Select Point").setDefaultState(KeyPreset.LEFT_MOUSE, false, false, false).setDescription("Select point under cursor");
|
||||
public final KeyPreset ADD_POINT = add("Add Point").setDefaultState(Keyboard.KEY_Z, false, false, false).setDescription("Add a new point at the play-head's X");
|
||||
public final KeyPreset DELETE_POINT = add("Delete Point").setDefaultState(Keyboard.KEY_X, true, false, false).setDescription("Delete selected point");
|
||||
public final KeyPreset FREE_TRANSFORM = add("Free Transform").setDefaultState(Keyboard.KEY_G, false, false, false).setDescription("Freely transform the selected point with the mouse").markDone(this);
|
||||
|
||||
public GraphEditorKeyPresets() {
|
||||
super("graph_editor");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
package noppes.npcs.client.gui.util.animation.keys;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class KeyPreset {
|
||||
/**
|
||||
* @field SINGLE_PRESS => on releasing before 5 ticks press time
|
||||
* @field PRESS_RELEASE => on pressing and releasing
|
||||
*/
|
||||
public static final int PRESS = 0, HOLD = 1, RELEASE = 2, SINGLE_PRESS = 3, PRESS_RELEASE = 4;
|
||||
|
||||
public KeyState defaultState = new KeyState();
|
||||
public KeyState currentState = new KeyState();
|
||||
|
||||
public String name, description;
|
||||
public boolean shouldConflict = true;
|
||||
public Consumer<Integer> task;
|
||||
|
||||
public int pressTime;
|
||||
public boolean isDown;
|
||||
|
||||
|
||||
public KeyPreset(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public KeyPreset setDefaultState(int keyCode, boolean hasCtrl, boolean hasAlt, boolean hasShift) {
|
||||
defaultState.setState(keyCode, hasCtrl, hasAlt, hasShift);
|
||||
currentState.setState(keyCode, hasCtrl, hasAlt, hasShift);
|
||||
return this;
|
||||
}
|
||||
|
||||
public KeyPreset setDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public KeyPreset setTask(Consumer<Integer> task) {
|
||||
this.task = task;
|
||||
return this;
|
||||
}
|
||||
|
||||
public KeyPreset shouldConflict(boolean shouldConflict) {
|
||||
this.shouldConflict = shouldConflict;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
int keyCode = keyCode();
|
||||
if (keyCode == -1 || keyCode == 0)
|
||||
return;
|
||||
|
||||
boolean isDown = isMouseKey() ? Mouse.isButtonDown(keyCode + 100) : Keyboard.isKeyDown(keyCode);
|
||||
isDown = isDown && (hasCtrl() ? isCtrlKeyDown() : true) && (hasAlt() ? isAltKeyDown() : true && (hasShift() ? isShiftKeyDown() : true));
|
||||
|
||||
setDown(isDown);
|
||||
}
|
||||
|
||||
public void setDown(boolean down) {
|
||||
if (down && !isDown)
|
||||
onAction(PRESS, PRESS_RELEASE);
|
||||
|
||||
if (!down && isDown) {
|
||||
if (pressTime <= 5)
|
||||
onAction(SINGLE_PRESS);
|
||||
|
||||
onAction(RELEASE, PRESS_RELEASE);
|
||||
pressTime = 0;
|
||||
}
|
||||
|
||||
if (isDown || down) //to fire in both press & release
|
||||
onAction(HOLD);
|
||||
|
||||
if (isDown)
|
||||
pressTime++;
|
||||
|
||||
this.isDown = down;
|
||||
}
|
||||
|
||||
public KeyPreset onAction(int... pressTypes) {
|
||||
if (task != null) {
|
||||
for (int pressType : pressTypes)
|
||||
this.task.accept(pressType);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isDefault() {
|
||||
return currentState.equals(defaultState);
|
||||
}
|
||||
|
||||
public boolean isMouseKey() {
|
||||
return keyCode() < -1;
|
||||
}
|
||||
|
||||
public int keyCode() {
|
||||
return currentState.keyCode;
|
||||
}
|
||||
|
||||
public boolean hasCtrl() {
|
||||
return currentState.hasCtrl;
|
||||
}
|
||||
|
||||
public boolean hasAlt() {
|
||||
return currentState.hasAlt;
|
||||
}
|
||||
|
||||
public boolean hasShift() {
|
||||
return currentState.hasShift;
|
||||
}
|
||||
|
||||
public String getKeyName() {
|
||||
return currentState.getName();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
currentState.clear();
|
||||
}
|
||||
|
||||
//call on the last key added, to load saved presets
|
||||
public KeyPreset markDone(KeyPresetManager manager) {
|
||||
manager.load();
|
||||
return this;
|
||||
}
|
||||
|
||||
public void writeToNbt(NBTTagCompound c) {
|
||||
c.setTag(name, currentState.writeToNbt());
|
||||
}
|
||||
|
||||
public void readFromNbt(NBTTagCompound compound) {
|
||||
currentState.readFromNbt(compound.getCompoundTag(name));
|
||||
}
|
||||
|
||||
public boolean equals(Object preset) {
|
||||
if (preset == this)
|
||||
return true;
|
||||
|
||||
if (preset instanceof KeyPreset) {
|
||||
KeyPreset key = (KeyPreset) preset;
|
||||
return key.currentState.equals(currentState);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static class KeyState {
|
||||
public int keyCode = -1;
|
||||
public boolean hasCtrl, hasAlt, hasShift;
|
||||
|
||||
public void setState(int keyCode, boolean hasCtrl, boolean hasAlt, boolean hasShift) {
|
||||
this.keyCode = keyCode;
|
||||
this.hasCtrl = hasCtrl;
|
||||
this.hasAlt = hasAlt;
|
||||
this.hasShift = hasShift;
|
||||
}
|
||||
|
||||
public void readFrom(KeyState state) {
|
||||
keyCode = state.keyCode;
|
||||
hasCtrl = state.hasCtrl;
|
||||
hasShift = state.hasShift;
|
||||
hasAlt = state.hasAlt;
|
||||
}
|
||||
|
||||
public void writeTo(KeyState state) {
|
||||
state.setState(keyCode, hasCtrl, hasAlt, hasShift);
|
||||
}
|
||||
|
||||
public boolean hasState() {
|
||||
return keyCode != -1;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.keyCode = -1;
|
||||
hasCtrl = hasAlt = hasShift = false;
|
||||
}
|
||||
|
||||
public boolean equals(Object preset) {
|
||||
if (preset == this)
|
||||
return true;
|
||||
|
||||
if (preset instanceof KeyState) {
|
||||
KeyState state = (KeyState) preset;
|
||||
return state.keyCode == keyCode && state.hasCtrl == hasCtrl && state.hasAlt == hasAlt && state.hasShift == hasShift;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNbt() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setInteger("keyCode", keyCode);
|
||||
compound.setBoolean("hasCtrl", hasCtrl);
|
||||
compound.setBoolean("hasShift", hasShift);
|
||||
compound.setBoolean("hasAlt", hasAlt);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void readFromNbt(NBTTagCompound compound) {
|
||||
this.keyCode = compound.getInteger("keyCode");
|
||||
this.hasCtrl = compound.getBoolean("hasCtrl");
|
||||
this.hasShift = compound.getBoolean("hasShift");
|
||||
this.hasAlt = compound.getBoolean("hasAlt");
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
int code = keyCode;
|
||||
String name = "";
|
||||
|
||||
if (code == LEFT_MOUSE)
|
||||
name = "Left Mouse";
|
||||
else if (code == RIGHT_MOUSE)
|
||||
name = "Right Mouse";
|
||||
else if (code == MIDDLE_MOUSE)
|
||||
name = "Middle Mouse";
|
||||
else {
|
||||
name = code == -1 ? "" : GameSettings.getKeyDisplayString(code);
|
||||
if (name.contains("Button"))
|
||||
name = name.replace("Button", "Mouse");
|
||||
}
|
||||
|
||||
return (hasCtrl ? "CTRL " : "") + (hasAlt ? "ALT " : "") + (hasShift ? "SHIFT " : "") + name;
|
||||
}
|
||||
}
|
||||
|
||||
public static final int LEFT_MOUSE = -100, RIGHT_MOUSE = -99, MIDDLE_MOUSE = -98, MOUSE_4 = -97, MOUSE_5 = -96;
|
||||
|
||||
public static boolean isCtrlKeyDown() {
|
||||
return Minecraft.isRunningOnMac ? Keyboard.isKeyDown(219) || Keyboard.isKeyDown(220) : Keyboard.isKeyDown(29) || Keyboard.isKeyDown(157);
|
||||
}
|
||||
|
||||
public static boolean isAltKeyDown() {
|
||||
return Keyboard.isKeyDown(56) || Keyboard.isKeyDown(184);
|
||||
}
|
||||
|
||||
public static boolean isShiftKeyDown() {
|
||||
return Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54);
|
||||
}
|
||||
|
||||
public static boolean isNotCtrlAltShift(int key) {
|
||||
return key != 219 && key != 220 && key != 29 && key != 157 && key != 42 && key != 54 && key != 56 && key != 184;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package noppes.npcs.client.gui.util.animation.keys;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.util.NBTJsonUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class KeyPresetManager {
|
||||
public List<KeyPreset> keys = new ArrayList<>();
|
||||
public String fileName;
|
||||
|
||||
public KeyPresetManager(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public KeyPreset add(String name) {
|
||||
KeyPreset preset = new KeyPreset(name);
|
||||
keys.add(preset);
|
||||
return preset;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
for (KeyPreset key : keys)
|
||||
key.tick();
|
||||
}
|
||||
|
||||
|
||||
public void load() {
|
||||
try {
|
||||
File dir = getDir();
|
||||
File file = new File(dir, fileName + ".json");
|
||||
if (!file.exists())
|
||||
return;
|
||||
|
||||
NBTTagCompound compound = NBTJsonUtil.LoadFile(file);
|
||||
for (KeyPreset key : keys)
|
||||
key.readFromNbt(compound);
|
||||
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
try {
|
||||
File dir = getDir();
|
||||
String filename = fileName + ".json";
|
||||
|
||||
File newFile = new File(dir, filename + "_new");
|
||||
File originalFile = new File(dir, filename);
|
||||
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for (KeyPreset key : keys)
|
||||
key.writeToNbt(compound);
|
||||
|
||||
NBTJsonUtil.SaveFile(newFile, compound);
|
||||
|
||||
if (originalFile.exists())
|
||||
originalFile.delete();
|
||||
|
||||
newFile.renameTo(originalFile);
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
}
|
||||
|
||||
public File getDir() {
|
||||
File dir = new File(CustomNpcs.Dir, "keypresets");
|
||||
if (!dir.exists())
|
||||
dir.mkdir();
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package noppes.npcs.client.gui.util.animation.panel;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import noppes.npcs.client.gui.util.GuiUtil;
|
||||
import noppes.npcs.client.gui.util.animation.AnimationGraphEditor;
|
||||
import noppes.npcs.client.gui.util.animation.GridPointManager;
|
||||
import noppes.npcs.client.gui.util.animation.OverlayKeyPresetViewer;
|
||||
import noppes.npcs.client.utils.Color;
|
||||
import noppes.npcs.util.ValueUtil;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class PanelActiveFrame {
|
||||
public AnimationGraphEditor graph;
|
||||
|
||||
public int startX, startY, endX, endY, width, height;
|
||||
public float scale = 0.6f;
|
||||
|
||||
public PanelTextBox frame = new PanelTextBox() {
|
||||
public void finishEdit(byte operation) {
|
||||
super.finishEdit(operation);
|
||||
GridPointManager.Point p = graph.pointManager.selectedPoint;
|
||||
if (p != null) {
|
||||
p.setX(text.getDouble());
|
||||
p.updateKey();
|
||||
}
|
||||
}
|
||||
}.setDoublesOnly(0, 0, 9999);
|
||||
|
||||
public PanelTextBox value = new PanelTextBox() {
|
||||
public void finishEdit(byte operation) {
|
||||
super.finishEdit(operation);
|
||||
GridPointManager.Point p = graph.pointManager.selectedPoint;
|
||||
if (p != null)
|
||||
p.setY(-text.getDouble());
|
||||
}
|
||||
}.setDoublesOnly(0, -9999, 9999);
|
||||
|
||||
public PanelActiveFrame(AnimationGraphEditor graph) {
|
||||
this.graph = graph;
|
||||
frame.text.width = value.text.width = 70;
|
||||
}
|
||||
|
||||
public void initGui(int startX, int startY, int endX, int endY) {
|
||||
this.startX = startX;
|
||||
this.startY = startY;
|
||||
this.endX = endX;
|
||||
this.endY = endY;
|
||||
this.width = endX - startX;
|
||||
this.height = endY - startY;
|
||||
}
|
||||
|
||||
public void keyTyped(char c, int i) {
|
||||
frame.type(c, i);
|
||||
value.type(c, i);
|
||||
}
|
||||
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
frame.click(mouseX - startX, mouseY - startY, button);
|
||||
value.click(mouseX - startX, mouseY - startY, button);
|
||||
}
|
||||
|
||||
public void draw(int wheel) {
|
||||
int mouseX = graph.parent.mouseX, mouseY = graph.parent.mouseY;
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(startX, startY + 1, 0);
|
||||
// GuiUtil.drawRectD(0, 0, width - 1, height, 0xff3d3d3d);
|
||||
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
new Color(0X2D2D2D,0.75F).glColor();
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(OverlayKeyPresetViewer.TEXTURE);
|
||||
GuiUtil.drawTexturedModalRect(0, -38, 88, 77, 44, 435);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glScalef(scale, scale, 1);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glRotatef(-90,0,0,1);
|
||||
graph.getFontRenderer().drawString("Active frame", -62, -14, 0xdddddd);
|
||||
GuiUtil.drawHorizontalLine(-6,-62,-2,0xffdddddd);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
|
||||
// GL11.glTranslatef(0, 17, 0);
|
||||
graph.getFontRenderer().drawString("Easing", 9, 3, 0xb1b1b1);
|
||||
GL11.glTranslatef(0, 17, 0);
|
||||
graph.getFontRenderer().drawString("-Type", 9, 0, 0xb1b1b1);
|
||||
GL11.glTranslatef(0, 18, 0);
|
||||
graph.getFontRenderer().drawString("Frame", 9, 0, 0xb1b1b1);
|
||||
|
||||
GL11.glTranslatef(0, 15, 0);
|
||||
graph.getFontRenderer().drawString("Value", 9, 0, 0xb1b1b1);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
GridPointManager.Point p = graph.pointManager.selectedPoint;
|
||||
if (p != null) {
|
||||
if (!frame.isEditing())
|
||||
frame.text.setText(ValueUtil.format(p.worldX));
|
||||
if (!value.isEditing())
|
||||
value.text.setText(ValueUtil.format(-p.worldY));
|
||||
}
|
||||
|
||||
frame.screenX = 29; //remove scaling from maxStringWidth
|
||||
frame.screenY = 11;
|
||||
frame.boxScaleX = 1.2f;
|
||||
frame.textScale = scale;
|
||||
|
||||
boolean isAboveFrame = frame.isMouseAbove(mouseX - startX, mouseY - startY);
|
||||
frame.boxColor = new Color(frame.isEditing() ? 0x111111 : isAboveFrame ? 0x797979 : 0x545454);
|
||||
frame.draw(mouseX - startX,mouseY - startY, graph.mc.fontRenderer, wheel);
|
||||
|
||||
value.screenX = 29; //remove scaling from maxStringWidth
|
||||
value.screenY = 20;
|
||||
value.boxScaleX = 1.2f;
|
||||
value.textScale = scale;
|
||||
boolean isAboveValue = value.isMouseAbove(mouseX - startX, mouseY - startY);
|
||||
value.boxColor = new Color(value.isEditing() ? 0x111111 : isAboveValue ? 0x797979 : 0x545454);
|
||||
value.draw(mouseX - startX, mouseY - startY, graph.mc.fontRenderer, wheel);
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
public boolean isMouseAbove(int mouseX, int mouseY) {
|
||||
return mouseX >= startX && mouseX < endX && mouseY >= startY && mouseY < endY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
package noppes.npcs.client.gui.util.animation.panel;
|
||||
|
||||
import noppes.npcs.client.gui.util.GuiUtil;
|
||||
import noppes.npcs.client.gui.util.animation.AnimationGraphEditor;
|
||||
import noppes.npcs.client.gui.util.animation.GridPointManager;
|
||||
import noppes.npcs.client.utils.Color;
|
||||
import noppes.npcs.constants.animation.EnumFrameType;
|
||||
import noppes.npcs.util.ValueUtil;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class PanelFrameType {
|
||||
public AnimationGraphEditor graph;
|
||||
|
||||
public int startX, startY, endX, endY, width, height;
|
||||
public float scale = 0.6f;
|
||||
public int elementHeight = 11, elementSpacing = 2;
|
||||
|
||||
public LinkedList<Element> list = new LinkedList<>();
|
||||
public Element selectedElement;
|
||||
public List<EnumFrameType> highlightedTypes = new ArrayList<>();
|
||||
|
||||
|
||||
public PanelFrameType(AnimationGraphEditor graph) {
|
||||
this.graph = graph;
|
||||
|
||||
for (EnumFrameType type : EnumFrameType.values())
|
||||
list.add(new Element(type));
|
||||
|
||||
selectedElement = list.get(0);
|
||||
}
|
||||
|
||||
public void updateTypeValues(double playheadX) {
|
||||
list.forEach(e -> {
|
||||
String value = "0";
|
||||
GridPointManager.Point onHead = graph.pointManager.getPoint(e.type, playheadX);
|
||||
if (onHead != null)
|
||||
value = ValueUtil.format(onHead.worldY != 0 ? -onHead.worldY : 0);
|
||||
else {
|
||||
GridPointManager.Point beforeHead = graph.pointManager.getPrevious(e.type, playheadX);
|
||||
GridPointManager.Point afterHead = graph.pointManager.getNext(e.type, playheadX);
|
||||
if (beforeHead != null && afterHead != null) {
|
||||
double easedValue = graph.pointManager.getValueBetweenPointsAt(beforeHead, afterHead, playheadX);
|
||||
value = ValueUtil.format(easedValue);
|
||||
}
|
||||
}
|
||||
|
||||
e.box.text.setText(value);
|
||||
});
|
||||
}
|
||||
public void initGui(int startX, int startY, int endX, int endY) {
|
||||
this.startX = startX;
|
||||
this.startY = startY;
|
||||
this.endX = endX;
|
||||
this.endY = endY;
|
||||
this.width = endX - startX;
|
||||
this.height = endY - startY;
|
||||
}
|
||||
|
||||
public void draw(int wheel) {
|
||||
GuiUtil.drawRectD(startX - 1, startY, endX, endY, 0xff1d1d1d);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(startX, startY + 1, 0);
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Element element = list.get(i);
|
||||
element.draw(i, wheel);
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
|
||||
}
|
||||
|
||||
public void keyTyped(char c, int i) {
|
||||
list.forEach((element) -> {
|
||||
element.box.type(c, i);
|
||||
});
|
||||
}
|
||||
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
list.forEach((element) -> {
|
||||
if (element.isMouseAbove(mouseX, mouseY) && button == 0)
|
||||
selectedElement = element;
|
||||
|
||||
element.box.click(mouseX - startX, mouseY - startY, button);
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isMouseAbove(int mouseX, int mouseY) {
|
||||
return mouseX >= startX && mouseX < endX && mouseY >= startY && mouseY < endY;
|
||||
}
|
||||
|
||||
public class Element {
|
||||
public EnumFrameType type;
|
||||
public float elementStartY;
|
||||
|
||||
public PanelTextBox box = new PanelTextBox() {
|
||||
public void finishEdit(byte operation) {
|
||||
super.finishEdit(operation);
|
||||
graph.pointManager.setSelectedPoint(graph.pointManager.addPoint(type, graph.pointManager.playhead.worldX, -text.getDouble()));
|
||||
}
|
||||
}.setDoublesOnly(0, -9999, 9999);
|
||||
|
||||
public Element(EnumFrameType key) {
|
||||
this.type = key;
|
||||
}
|
||||
|
||||
public boolean isMouseAbove(int mouseX, int mouseY) {
|
||||
mouseX -= startX;
|
||||
mouseY -= startY;
|
||||
|
||||
return mouseX >= 0 && mouseX < box.screenX - 3 && mouseY >= elementStartY && mouseY < elementStartY + elementHeight + elementSpacing;
|
||||
}
|
||||
|
||||
public void draw(int index, int wheel) {
|
||||
////////////////////////////////////////////
|
||||
////////////////////////////////////////////
|
||||
//Type names
|
||||
elementStartY = index * (elementHeight + elementSpacing) / 1;
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(0, elementStartY, 0);
|
||||
GuiUtil.drawRectD(0, 0, width - 1, elementHeight, 0xaa000000); //type black bg
|
||||
|
||||
boolean selected = selectedElement == this;
|
||||
type.getColor().multiply(selected ? 1 : 0.5f).glColor();
|
||||
GuiUtil.drawRectD(0, 0, 3, elementHeight); //type color
|
||||
|
||||
GL11.glScalef(scale, scale, 1);
|
||||
GL11.glTranslatef(0, elementHeight / 2, 0);
|
||||
String name = String.format("%s", type.toString());
|
||||
int color = selected ? 0xd79520 : isMouseAbove(graph.grid.mouseX, graph.grid.mouseY) ? 0xffffff : 0x9a9a9a;
|
||||
|
||||
graph.getFontRenderer().drawString(name, 7, 0, color);
|
||||
|
||||
GL11.glPopMatrix();
|
||||
|
||||
////////////////////////////////////////////
|
||||
////////////////////////////////////////////
|
||||
//Box
|
||||
boolean isEditing = box.isEditing();
|
||||
box.screenX = width / 1.25F * scale + 8; //remove scaling from maxStringWidth
|
||||
box.screenY = elementStartY - 7.5f;
|
||||
box.textScale = scale;
|
||||
boolean isAboveFrame = box.isMouseAbove(graph.grid.mouseX - startX, graph.grid.mouseY - startY);
|
||||
|
||||
if (graph.pointManager.getPoint(type, graph.pointManager.playhead.worldX) != null)
|
||||
box.boxColor = isEditing ? new Color(0x83752a).multiply(0.65f) : new Color(isAboveFrame ? 0xd1b727 : 0x83752a);
|
||||
else
|
||||
box.boxColor = isEditing ? new Color(0x467d2a).multiply(0.65f) : new Color(isAboveFrame ? 0x5fc729 : 0x467d2a);
|
||||
|
||||
box.draw(graph.grid.mouseX - startX, graph.grid.mouseY - startY, graph.mc.fontRenderer, wheel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package noppes.npcs.client.gui.util.animation.panel;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.client.gui.util.GuiUtil;
|
||||
import noppes.npcs.client.gui.util.animation.OverlayKeyPresetViewer;
|
||||
import noppes.npcs.client.gui.util.animation.keys.KeyPreset;
|
||||
import noppes.npcs.client.utils.Color;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class PanelTextBox {
|
||||
|
||||
public int mouseX, mouseY;
|
||||
public float screenX, screenY, textScreenX, textScale;
|
||||
public float boxScaleX = 0.85f, boxScaleY = 0.85f;
|
||||
public GuiNpcTextField text;
|
||||
public Color boxColor;
|
||||
|
||||
private boolean isEditing;
|
||||
|
||||
private FontRenderer font;
|
||||
|
||||
public PanelTextBox() {
|
||||
text = new GuiNpcTextField(0, null, 0, 0, 45, 10, "0");
|
||||
text.setEnableBackgroundDrawing(false);
|
||||
}
|
||||
|
||||
public PanelTextBox setDoublesOnly(double def, double min, double max) {
|
||||
text.setDoublesOnly();
|
||||
text.setMinMaxDefaultDouble(min, max, def);
|
||||
text.setFloatingPrecision(2);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void draw(int mouseX, int mouseY, FontRenderer font, int wheel) {
|
||||
this.mouseX = mouseX;
|
||||
this.mouseY = mouseY;
|
||||
|
||||
if (this.font == null)
|
||||
this.font = font;
|
||||
|
||||
if (Mouse.isButtonDown(0) && isEditing && text.isFocused())
|
||||
setCursorPositionToMouse(mouseX);
|
||||
|
||||
boolean mouseAbove = isMouseAbove(mouseX, mouseY);
|
||||
if (mouseAbove && wheel != 0) {
|
||||
if (text.isDouble()) {
|
||||
double presets = KeyPreset.isAltKeyDown() ? 45 : KeyPreset.isCtrlKeyDown() ? 10 : KeyPreset.isShiftKeyDown() ? 0.1 : 1;
|
||||
double value = text.getDouble() + Math.copySign(presets, wheel);
|
||||
text.setDouble(value);
|
||||
finishEdit(M_WHEEL);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////
|
||||
////////////////////////////////////////////
|
||||
//Box texture
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(OverlayKeyPresetViewer.TEXTURE);
|
||||
GL11.glPushMatrix();
|
||||
float boxWidth = 32 * boxScaleX;
|
||||
GL11.glScalef(boxScaleX, boxScaleY, 0);
|
||||
|
||||
//Box grey background
|
||||
new Color(0x3d3d3d, 1).glColor();
|
||||
// GuiUtil.drawTexturedModalRect(screenX / boxScaleX, screenY / boxScaleY, 32, 20, 0, 492);
|
||||
|
||||
//Box color
|
||||
if (boxColor != null)
|
||||
boxColor.glColor();
|
||||
GL11.glPushMatrix();
|
||||
float s = 0.945f, s2 = 0.875f;
|
||||
GL11.glScalef(s, s2, 0);
|
||||
GuiUtil.drawTexturedModalRect(screenX / boxScaleX / s + 1, screenY / boxScaleY / s2 + 2.25f, 32, 20, 0, 492);
|
||||
GL11.glPopMatrix();
|
||||
GL11.glPopMatrix();
|
||||
|
||||
////////////////////////////////////////////
|
||||
////////////////////////////////////////////
|
||||
// Box text
|
||||
float textWidth = font.getStringWidth(text.getText());
|
||||
float textX = screenX + 2;
|
||||
float centeredTextX = (screenX) + boxWidth / 2 - textWidth / 2 * textScale;
|
||||
textScreenX = text.isFocused() || textWidth * textScale >= boxWidth ? textX : centeredTextX;
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glScalef(textScale, textScale, 1);
|
||||
GL11.glTranslatef(textScreenX / textScale, (screenY + 10.5f) / textScale, 0);
|
||||
text.drawTextBox();
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
public boolean isMouseAbove(int mouseX, int mouseY) {
|
||||
float screenY = (this.screenY + 9);
|
||||
|
||||
return mouseX >= screenX && mouseX < screenX + 32 * boxScaleX && mouseY >= screenY && mouseY < screenY + 10 * boxScaleY;
|
||||
}
|
||||
|
||||
public void setCursorPositionToMouse(int mouseX) {
|
||||
int relativeMX = (int) (mouseX - textScreenX);
|
||||
int pos = relativeMX > 0 ? 1 : -1;
|
||||
|
||||
text.setCursorPosition(font.trimStringToWidth(text.getText(), (int) (relativeMX / textScale)).length() + text.lineScrollOffset + pos);
|
||||
}
|
||||
|
||||
public boolean isEditing() {
|
||||
return isEditing;
|
||||
}
|
||||
|
||||
public static byte ENTER_KEY = 0, CLICK_OUT = 1, M_WHEEL = 2;
|
||||
|
||||
public void finishEdit(byte operation) {
|
||||
if (operation == M_WHEEL)
|
||||
return;
|
||||
|
||||
text.toDefaults();
|
||||
text.setFocused(false);
|
||||
isEditing = false;
|
||||
}
|
||||
|
||||
public void type(char c, int i) {
|
||||
if (!isEditing())
|
||||
return;
|
||||
|
||||
if (i == 28) {
|
||||
finishEdit(ENTER_KEY);
|
||||
} else
|
||||
text.textboxKeyTyped(c, i);
|
||||
}
|
||||
|
||||
public void click(int mouseX, int mouseY, int button) {
|
||||
if (!isMouseAbove(mouseX, mouseY)) {
|
||||
if (isEditing())
|
||||
finishEdit(CLICK_OUT);
|
||||
} else {
|
||||
if (button == 0) {
|
||||
text.setFocused(true);
|
||||
text.setCursorPositionEnd();
|
||||
isEditing = true;
|
||||
} else if (button == 1) {
|
||||
text.setText(text.isNumbersOnly() ? "0" : "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -319,9 +319,7 @@ public class RenderCNPCPlayer extends RenderPlayer {
|
||||
// Render the arm
|
||||
this.modelBipedMain.onGround = 0.0F;
|
||||
this.modelBipedMain.setRotationAngles(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F, player);
|
||||
|
||||
if(this.modelBipedMain.bipedRightArm != null)
|
||||
this.modelBipedMain.bipedRightArm.render(0.0625F);
|
||||
this.modelBipedMain.bipedRightArm.render(0.0625F);
|
||||
|
||||
postRenderOverlay();
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ public class ItemToolRenderer implements IItemRenderer {
|
||||
private static final ResourceLocation RES_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png");
|
||||
private static final ResourceLocation PAINTBRUSH_HANDLE = new ResourceLocation("customnpcs", "textures/items/npcBrushHandle.png");
|
||||
private static final ResourceLocation PAINTBRUSH_BRUSH = new ResourceLocation("customnpcs", "textures/items/npcBrushHair.png");
|
||||
private static final ResourceLocation HAMMER = new ResourceLocation("customnpcs", "textures/items/npcToolHammer.png");
|
||||
private static final ResourceLocation MAGIC_BOOK = new ResourceLocation("customnpcs", "textures/items/npcToolMagicBook.png");
|
||||
|
||||
private static final ResourceLocation HAMMER = new ResourceLocation("customnpcs", "textures/items/npcHammer.png");
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
@@ -78,10 +78,8 @@ public class ItemToolRenderer implements IItemRenderer {
|
||||
float blue = (color & 0xFF) / 255.0F;
|
||||
GL11.glColor3f(red, green, blue);
|
||||
renderEntityCustomItem(itemStack, entityItem, PAINTBRUSH_BRUSH);
|
||||
} else if (itemStack.getItemDamage() == 0){
|
||||
} else {
|
||||
renderEntityCustomItem(itemStack, entityItem, HAMMER);
|
||||
} else if (itemStack.getItemDamage() == 2){
|
||||
renderEntityCustomItem(itemStack, entityItem, MAGIC_BOOK);
|
||||
}
|
||||
GL11.glPopMatrix();
|
||||
return;
|
||||
@@ -114,14 +112,10 @@ public class ItemToolRenderer implements IItemRenderer {
|
||||
GL11.glPushMatrix();
|
||||
renderItem3d(entityLivingBase, itemStack, PAINTBRUSH_BRUSH);
|
||||
GL11.glPopMatrix();
|
||||
} else if (itemStack.getItemDamage() == 0){
|
||||
} else {
|
||||
GL11.glPushMatrix();
|
||||
renderItem3d(entityLivingBase, itemStack, HAMMER);
|
||||
GL11.glPopMatrix();
|
||||
} else if (itemStack.getItemDamage() == 2){
|
||||
GL11.glPushMatrix();
|
||||
renderItem3d(entityLivingBase, itemStack, MAGIC_BOOK);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
@@ -297,12 +291,9 @@ public class ItemToolRenderer implements IItemRenderer {
|
||||
float blue = (color & 0xFF) / 255.0F;
|
||||
textureManager.bindTexture(PAINTBRUSH_BRUSH);
|
||||
renderCustomItemSlot(0, 0, 16, 16, red, green, blue);
|
||||
} else if (itemStack.getItemDamage() == 0){
|
||||
} else {
|
||||
textureManager.bindTexture(HAMMER);
|
||||
renderCustomItemSlot(0, 0, 16, 16, 1.0f, 1.0f, 1.0f);
|
||||
} else if (itemStack.getItemDamage() == 2){
|
||||
textureManager.bindTexture(MAGIC_BOOK);
|
||||
renderCustomItemSlot(0, 0, 16, 16, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
package noppes.npcs.client.utils;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class Color {
|
||||
public int color;
|
||||
public float alpha;
|
||||
|
||||
public Color(int color) {
|
||||
setColor(color, 1);
|
||||
}
|
||||
|
||||
public Color(int color, float alpha) {
|
||||
setColor(color, alpha);
|
||||
}
|
||||
|
||||
public Color(int red, int green, int blue, float alpha) {
|
||||
setColor(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
public void setColor(int color, float alpha) {
|
||||
this.color = color;
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
public void setColor(int red, int green, int blue, float alpha) {
|
||||
this.color = (red << 16) + (green << 8) + blue;
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
public static Color lerpRGBA(Color color1, Color color2, float fraction) {
|
||||
fraction = Math.min(fraction, 1f);
|
||||
int red = (int) (color1.getRed() + ((color2.getRed() - color1.getRed()) * fraction));
|
||||
int green = (int) (color1.getGreen() + ((color2.getGreen() - color1.getGreen()) * fraction));
|
||||
int blue = (int) (color1.getBlue() + ((color2.getBlue() - color1.getBlue()) * fraction));
|
||||
float newAlpha = color1.alpha + ((color2.alpha - color1.alpha) * fraction);
|
||||
int newColor = (red << 16) + (green << 8) + blue;
|
||||
return new Color(newColor, newAlpha);
|
||||
}
|
||||
|
||||
public Color lerpRGBA(Color color2, float fraction) {
|
||||
return Color.lerpRGBA(this, color2, fraction);
|
||||
}
|
||||
|
||||
public Color multiply(float multi) {
|
||||
if (multi == 1)
|
||||
return this.clone();
|
||||
|
||||
int r = (int) ((getRed() * multi));
|
||||
int g = (int) ((getGreen() * multi));
|
||||
int b = (int) ((getBlue() * multi));
|
||||
float a = alpha * multi;
|
||||
return new Color((r << 16) + (g << 8) + b, a);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void glColor() {
|
||||
GL11.glColor4f(getRedF(), getGreenF(), getBlueF(), alpha);
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound, String name) {
|
||||
compound.setInteger(name + "Color", color);
|
||||
compound.setFloat(name + "Alpha", alpha);
|
||||
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound, String name) {
|
||||
setColor(compound.getInteger(name + "Color"), compound.getFloat(name + "Alpha"));
|
||||
}
|
||||
|
||||
public int getRed() {
|
||||
return (color >> 16 & 0xFF);
|
||||
}
|
||||
|
||||
public float getRedF() {
|
||||
return (float) (color >> 16 & 0xFF) / 255f;
|
||||
}
|
||||
|
||||
public int getGreen() {
|
||||
return (color >> 8 & 0xFF);
|
||||
}
|
||||
|
||||
public float getGreenF() {
|
||||
return (float) (color >> 8 & 0xFF) / 255f;
|
||||
}
|
||||
|
||||
public int getBlue() {
|
||||
return (color & 0xFF);
|
||||
}
|
||||
|
||||
public float getBlueF() {
|
||||
return (float) (color & 0xFF) / 255f;
|
||||
}
|
||||
|
||||
public static String getColor(int color) {
|
||||
String str;
|
||||
for (str = Integer.toHexString(color); str.length() < 6; str = "0" + str) {
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static String getColor(int color, float alpha) {
|
||||
String str = getColor(color);
|
||||
return str + " | " + (int) (alpha * 255);
|
||||
}
|
||||
|
||||
public Color clone() {
|
||||
return new Color(color, alpha);
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,5 @@ public enum EnumGuiType {
|
||||
CustomGui,
|
||||
ScriptItem,
|
||||
ScriptBlock,
|
||||
Paintbrush,
|
||||
MagicBook;
|
||||
Paintbrush;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package noppes.npcs.constants.animation;
|
||||
|
||||
import noppes.npcs.client.utils.Color;
|
||||
|
||||
public enum EnumFrameType {
|
||||
ROTATION_X(0xffff3352), ROTATION_Y(0xff8bdc00), ROTATION_Z(0xff2890ff), PIVOT_X(0xffff00), PIVOT_Y(0x00ffff), PIVOT_Z(0xff00ff);
|
||||
|
||||
public int color;
|
||||
|
||||
EnumFrameType(int color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return new Color(color, 1);
|
||||
}
|
||||
}
|
||||
@@ -251,6 +251,7 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
CustomEffect parent = get(id, index);
|
||||
if (parent != null) {
|
||||
PlayerEffect playerEffect = new PlayerEffect(id, duration, level, index);
|
||||
playerEffect.index = index;
|
||||
currentEffects.put(new EffectKey(id, index), playerEffect);
|
||||
parent.onAdded(player, playerEffect);
|
||||
}
|
||||
@@ -518,9 +519,7 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
|
||||
@Override
|
||||
public int getEffectDuration(IPlayer player, ICustomEffect effect) {
|
||||
if(effect == null)
|
||||
return -1;
|
||||
return getEffectDuration(player, effect.getID(), effect.getIndex());
|
||||
return getEffectDuration(player, effect.getID());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,7 +10,6 @@ import noppes.npcs.CustomItems;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.api.handler.IMagicHandler;
|
||||
import noppes.npcs.constants.EnumDiagramLayout;
|
||||
import noppes.npcs.controllers.data.Magic;
|
||||
import noppes.npcs.controllers.data.MagicAssociation;
|
||||
import noppes.npcs.controllers.data.MagicCycle;
|
||||
@@ -100,55 +99,26 @@ public class MagicController implements IMagicHandler {
|
||||
arcane.setItem(new ItemStack(CustomItems.spellArcane));
|
||||
|
||||
// Insiders
|
||||
earth.interactions.put(air.id, -0.50f);
|
||||
air.interactions.put(earth.id, 0.50f);
|
||||
|
||||
water.interactions.put(earth.id, -0.50f);
|
||||
earth.interactions.put(water.id, 0.50f);
|
||||
|
||||
fire.interactions.put(water.id, -0.50f);
|
||||
water.interactions.put(fire.id, 0.50f);
|
||||
|
||||
air.interactions.put(fire.id, -0.50f);
|
||||
fire.interactions.put(air.id, 0.50f);
|
||||
earth.interactions.put(air.id, 0.60f);
|
||||
water.interactions.put(earth.id, 0.60f);
|
||||
fire.interactions.put(water.id, 0.60f);
|
||||
air.interactions.put(fire.id, 0.60f);
|
||||
|
||||
// Outsiders
|
||||
dark.interactions.put(nature.id, -0.50f);
|
||||
nature.interactions.put(dark.id, 0.50f);
|
||||
|
||||
nature.interactions.put(holy.id, -0.50f);
|
||||
holy.interactions.put(nature.id, 0.50f);
|
||||
|
||||
holy.interactions.put(arcane.id, -0.50f);
|
||||
arcane.interactions.put(holy.id, 0.50f);
|
||||
|
||||
arcane.interactions.put(dark.id, -0.50f);
|
||||
dark.interactions.put(arcane.id, 0.50f);
|
||||
dark.interactions.put(nature.id, 0.60f);
|
||||
nature.interactions.put(holy.id, 0.60f);
|
||||
holy.interactions.put(arcane.id, 0.60f);
|
||||
arcane.interactions.put(dark.id, 0.60f);
|
||||
|
||||
// Cross Interactions
|
||||
earth.interactions.put(nature.id, -0.25f);
|
||||
nature.interactions.put(earth.id, 0.25f);
|
||||
|
||||
water.interactions.put(holy.id, -0.25f);
|
||||
holy.interactions.put(water.id, 0.25f);
|
||||
|
||||
fire.interactions.put(arcane.id, -0.25f);
|
||||
arcane.interactions.put(fire.id, 0.25f);
|
||||
|
||||
air.interactions.put(dark.id, -0.25f);
|
||||
dark.interactions.put(air.id, 0.25f);
|
||||
|
||||
dark.interactions.put(fire.id, -0.25f);
|
||||
fire.interactions.put(dark.id, 0.25f);
|
||||
|
||||
nature.interactions.put(air.id, -0.25f);
|
||||
air.interactions.put(nature.id, 0.25f);
|
||||
|
||||
holy.interactions.put(earth.id, -0.25f);
|
||||
earth.interactions.put(holy.id, 0.25f);
|
||||
|
||||
arcane.interactions.put(water.id, -0.25f);
|
||||
water.interactions.put(arcane.id, 0.25f);
|
||||
earth.interactions.put(nature.id, 0.30f);
|
||||
water.interactions.put(holy.id, 0.30f);
|
||||
fire.interactions.put(arcane.id, 0.30f);
|
||||
air.interactions.put(dark.id, 0.30f);
|
||||
dark.interactions.put(fire.id, 0.30f);
|
||||
nature.interactions.put(air.id, 0.30f);
|
||||
holy.interactions.put(earth.id, 0.30f);
|
||||
arcane.interactions.put(water.id, 0.30f);
|
||||
|
||||
// Add them to the registry
|
||||
magics.put(earth.id, earth);
|
||||
@@ -163,8 +133,7 @@ public class MagicController implements IMagicHandler {
|
||||
MagicCycle defaultCycle = new MagicCycle();
|
||||
defaultCycle.id = getUnusedCycleId();
|
||||
defaultCycle.name = "Universal";
|
||||
defaultCycle.layout = EnumDiagramLayout.CIRCULAR_MANUAL;
|
||||
defaultCycle.displayName = "&6Elementa Cycle";
|
||||
defaultCycle.displayName = "Elementa Cycle";
|
||||
cycles.put(defaultCycle.id, defaultCycle);
|
||||
|
||||
// Add magic associations using your old index and priority values:
|
||||
|
||||
@@ -54,6 +54,14 @@ public class Animation implements IAnimation {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
public boolean hasFrame(int index) {
|
||||
return index >= 0 && index < frames.size();
|
||||
}
|
||||
|
||||
public IFrame getFrame(int index) {
|
||||
return hasFrame(index) ? frames.get(index) : null;
|
||||
}
|
||||
|
||||
public IFrame currentFrame() {
|
||||
return currentFrame < frames.size() ? frames.get(currentFrame) : null;
|
||||
}
|
||||
@@ -76,12 +84,22 @@ public class Animation implements IAnimation {
|
||||
}
|
||||
|
||||
public IAnimation addFrame(IFrame frame) {
|
||||
this.frames.add((Frame) frame);
|
||||
return this;
|
||||
return addFrame((Frame) frame);
|
||||
}
|
||||
|
||||
public IAnimation addFrame(int index, IFrame frame) {
|
||||
this.frames.add(index, (Frame) frame);
|
||||
return addFrame(index, (Frame) frame);
|
||||
}
|
||||
|
||||
public IAnimation addFrame(Frame frame) {
|
||||
frame.setParent(this);
|
||||
this.frames.add(frame);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAnimation addFrame(int index, Frame frame) {
|
||||
frame.setParent(this);
|
||||
this.frames.add(index, frame);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -192,7 +210,7 @@ public class Animation implements IAnimation {
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
NBTTagCompound item = list.getCompoundTagAt(i);
|
||||
Frame frame = new Frame();
|
||||
frame.parent = this;
|
||||
frame.setParent(this);
|
||||
frame.readFromNBT(item);
|
||||
frames.add(frame);
|
||||
}
|
||||
@@ -230,6 +248,18 @@ public class Animation implements IAnimation {
|
||||
return compound;
|
||||
}
|
||||
|
||||
public int getCurrentTick() {
|
||||
int time = 0;
|
||||
for (int i = 0; i < this.frames.size(); i++) {
|
||||
if (i >= this.currentFrame) {
|
||||
break;
|
||||
}
|
||||
time += this.frames.get(i).getDuration();
|
||||
}
|
||||
time += this.currentFrameTime;
|
||||
return time;
|
||||
}
|
||||
|
||||
public boolean increaseTime() {
|
||||
if (paused)
|
||||
return false;
|
||||
|
||||
@@ -3,7 +3,6 @@ package noppes.npcs.controllers.data;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.handler.data.ICustomEffect;
|
||||
@@ -182,62 +181,48 @@ public class CustomEffect implements ICustomEffect {
|
||||
|
||||
public void onAdded(EntityPlayer player, PlayerEffect playerEffect) {
|
||||
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
|
||||
if(playerEffect.index == 0){
|
||||
PlayerEvent.EffectEvent.Added event = new PlayerEvent.EffectEvent.Added(iPlayer, playerEffect);
|
||||
|
||||
if (onAddedConsumer != null)
|
||||
onAddedConsumer.accept(event);
|
||||
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
script.callScript(EffectScript.ScriptType.OnEffectAdd, event);
|
||||
PlayerEvent.EffectEvent.Added event = new PlayerEvent.EffectEvent.Added(iPlayer, playerEffect);
|
||||
if (onAddedConsumer != null) onAddedConsumer.accept(event);
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
EventHooks.onEffectAdded(iPlayer, playerEffect);
|
||||
script.callScript(EffectScript.ScriptType.OnAdd, event);
|
||||
}
|
||||
|
||||
public void onTick(EntityPlayer player, PlayerEffect playerEffect) {
|
||||
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
|
||||
if(playerEffect.index == 0){
|
||||
PlayerEvent.EffectEvent.Ticked event = new PlayerEvent.EffectEvent.Ticked(iPlayer, playerEffect);
|
||||
PlayerEvent.EffectEvent.Ticked event = new PlayerEvent.EffectEvent.Ticked(iPlayer, playerEffect);
|
||||
|
||||
if (onTickConsumer != null) {
|
||||
onTickConsumer.accept(event);
|
||||
}
|
||||
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
script.callScript(EffectScript.ScriptType.OnEffectTick, event);
|
||||
if (onTickConsumer != null) {
|
||||
onTickConsumer.accept(event);
|
||||
}
|
||||
|
||||
EventHooks.onEffectTick(iPlayer, playerEffect);
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
script.callScript(EffectScript.ScriptType.OnTick, event);
|
||||
}
|
||||
|
||||
public void onRemoved(EntityPlayer player, PlayerEffect playerEffect, PlayerEvent.EffectEvent.ExpirationType type) {
|
||||
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
|
||||
|
||||
if(playerEffect.index == 0){
|
||||
PlayerEvent.EffectEvent.Removed event = new PlayerEvent.EffectEvent.Removed(iPlayer, playerEffect, type);
|
||||
PlayerEvent.EffectEvent.Removed event = new PlayerEvent.EffectEvent.Removed(iPlayer, playerEffect, type);
|
||||
|
||||
if (onRemovedConsumer != null) {
|
||||
onRemovedConsumer.accept(event);
|
||||
}
|
||||
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
script.callScript(EffectScript.ScriptType.OnEffectRemove, event);
|
||||
if (onRemovedConsumer != null) {
|
||||
onRemovedConsumer.accept(event);
|
||||
}
|
||||
|
||||
EventHooks.onEffectRemove(iPlayer, playerEffect, type);
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
script.callScript(EffectScript.ScriptType.OnRemove, event);
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(boolean saveScripts) {
|
||||
|
||||
@@ -165,9 +165,9 @@ public class EffectScript implements INpcScriptHandler {
|
||||
}
|
||||
|
||||
public enum ScriptType {
|
||||
OnEffectAdd("onEffectAdd"),
|
||||
OnEffectTick("onEffectTick"),
|
||||
OnEffectRemove("onEffectRemove");
|
||||
OnAdd("onAdded"),
|
||||
OnTick("onTick"),
|
||||
OnRemove("onRemove");
|
||||
|
||||
public final String function;
|
||||
|
||||
|
||||
@@ -9,9 +9,8 @@ import noppes.npcs.constants.EnumAnimationPart;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class Frame implements IFrame {
|
||||
public Animation parent;
|
||||
private Animation parent;
|
||||
public HashMap<EnumAnimationPart, FramePart> frameParts = new HashMap<>();
|
||||
public int duration = 0;
|
||||
|
||||
@@ -36,16 +35,42 @@ public class Frame implements IFrame {
|
||||
this.customized = true;
|
||||
}
|
||||
|
||||
public int getStartTick() {
|
||||
int time = 0;
|
||||
for (int i = 0; i < parent.frames.size(); i++) {
|
||||
Frame f = parent.frames.get(i);
|
||||
if (f == this)
|
||||
break;
|
||||
|
||||
time += f.getDuration();
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setParent(Animation parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public Animation getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public HashMap<EnumAnimationPart, FramePart> getFrameMap() {
|
||||
return frameParts;
|
||||
}
|
||||
|
||||
public void addPart(EnumAnimationPart key, FramePart frame) {
|
||||
frame.setParent(parent);
|
||||
frameParts.put(key, frame);
|
||||
}
|
||||
|
||||
public IFramePart[] getParts() {
|
||||
return frameParts.values().toArray(new IFramePart[0]);
|
||||
}
|
||||
|
||||
public IFrame addPart(IFramePart partConfig) {
|
||||
this.frameParts.put(((FramePart) partConfig).getPart(), (FramePart) partConfig);
|
||||
((FramePart) partConfig).setParent(parent);
|
||||
addPart(((FramePart) partConfig).getPart(), (FramePart) partConfig);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -150,6 +175,7 @@ public class Frame implements IFrame {
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
NBTTagCompound item = list.getCompoundTagAt(i);
|
||||
FramePart framePart = new FramePart();
|
||||
framePart.setParent(parent);
|
||||
framePart.readFromNBT(item);
|
||||
if (!framePart.customized) {
|
||||
framePart.smooth = this.smooth;
|
||||
@@ -184,7 +210,7 @@ public class Frame implements IFrame {
|
||||
Frame frame = new Frame(this.duration);
|
||||
HashMap<EnumAnimationPart, FramePart> frameParts = this.frameParts;
|
||||
for (Map.Entry<EnumAnimationPart, FramePart> entry : frameParts.entrySet()) {
|
||||
frame.frameParts.put(entry.getKey(), entry.getValue().copy());
|
||||
frame.addPart(entry.getKey(), entry.getValue().copy());
|
||||
}
|
||||
frame.parent = this.parent;
|
||||
frame.duration = this.duration;
|
||||
|
||||
Loaded 100 of 120 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user