Spell HUD rewrite and retexturing:

- Replaces the old hardcoded drawing methods with a new json-based system with support for multiple inbuilt and resource pack-defined skins.
- Adds a config option for choosing the spell HUD skin, along with a custom config GUI screen allowing the user to select from a list of available skins with a preview of the currently selected skin.
- Replaces the HUD texture file with a spell_hud subfolder, containing all the necessary textures and json files for the 12 inbuilt skins.
- Adds a subtle sound effect and scroling animation when switching spells
- Reorganises the control event code into a single handler class and converts this class and the spell HUD class to static event handlers.
- Fixes the HUD position option which got broken in the previous spell HUD commit
This commit is contained in:
Electroblob
2018-07-02 22:33:09 +01:00
parent b7cd3db8bc
commit af01beb583
42 changed files with 1393 additions and 223 deletions
@@ -4,6 +4,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Set;
import electroblob.wizardry.item.ItemWand;
import electroblob.wizardry.registry.Spells;
import electroblob.wizardry.registry.WizardryItems;
import electroblob.wizardry.spell.Spell;
@@ -116,50 +117,82 @@ public final class WandHelper {
return Spells.none;
}
/** Returns the spell after the currently selected spell for the given wand, or the 'none' spell if the wand has no
* spell data. */
public static Spell getNextSpell(ItemStack wand){
Spell[] spells = getSpells(wand);
if(wand.getTagCompound() != null){
return spells[getNextSpellIndex(wand)];
}
return Spells.none;
}
/** Returns the spell before the currently selected spell for the given wand, or the 'none' spell if the wand has no
* spell data. */
public static Spell getPreviousSpell(ItemStack wand){
Spell[] spells = getSpells(wand);
if(wand.getTagCompound() != null){
return spells[getPreviousSpellIndex(wand)];
}
return Spells.none;
}
/** Selects the next spell in this wand's list of spells. */
public static void selectNextSpell(ItemStack wand){
// 5 here because if the spell array doesn't exist, the wand can't possibly have attunement upgrades
if(getSpells(wand).length < 0) setSpells(wand, new Spell[5]);
if(getSpells(wand).length < 0) setSpells(wand, new Spell[ItemWand.BASE_SPELL_SLOTS]);
if(wand.getTagCompound() != null){
int numberOfSpells = getSpells(wand).length;
int selectedSpell = wand.getTagCompound().getInteger(SELECTED_SPELL_KEY);
// Greater than or equal to so that if attunement upgrades are somehow removed by NBT modification it just
// resets.
if(selectedSpell >= numberOfSpells - 1){
selectedSpell = 0;
}else{
selectedSpell++;
}
wand.getTagCompound().setInteger(SELECTED_SPELL_KEY, selectedSpell);
wand.getTagCompound().setInteger(SELECTED_SPELL_KEY, getNextSpellIndex(wand));
}
}
/** Selects the previous spell in this wand's list of spells. */
public static void selectPreviousSpell(ItemStack wand){
// 5 here because if the spell array doesn't exist, the wand can't possibly have attunement upgrades
if(getSpells(wand).length < 0) setSpells(wand, new Spell[5]);
// This cannot possibly be null here, and yet I am getting an NPE...
if(getSpells(wand).length < 0) setSpells(wand, new Spell[ItemWand.BASE_SPELL_SLOTS]);
if(wand.getTagCompound() != null){
int numberOfSpells = getSpells(wand).length;
int selectedSpell = wand.getTagCompound().getInteger(SELECTED_SPELL_KEY);
if(selectedSpell <= 0){
selectedSpell = numberOfSpells - 1;
}else{
selectedSpell--;
}
wand.getTagCompound().setInteger(SELECTED_SPELL_KEY, selectedSpell);
wand.getTagCompound().setInteger(SELECTED_SPELL_KEY, getPreviousSpellIndex(wand));
}
}
private static int getNextSpellIndex(ItemStack wand){
int numberOfSpells = getSpells(wand).length;
int spellIndex = wand.getTagCompound().getInteger(SELECTED_SPELL_KEY);
// Greater than or equal to so that if attunement upgrades are somehow removed by NBT modification it just
// resets.
if(spellIndex >= numberOfSpells - 1){
spellIndex = 0;
}else{
spellIndex++;
}
return spellIndex;
}
private static int getPreviousSpellIndex(ItemStack wand){
int numberOfSpells = getSpells(wand).length;
int spellIndex = wand.getTagCompound().getInteger(SELECTED_SPELL_KEY);
if(spellIndex <= 0){
spellIndex = numberOfSpells - 1;
}else{
spellIndex--;
}
return spellIndex;
}
/**
* Returns an array of the cooldowns for each spell bound to the given wand. As of Wizardry 1.1, this array is not
@@ -210,6 +243,28 @@ public final class WandHelper {
// Don't need to check if the tag compound is null since the above check is equivalent.
return cooldowns[wand.getTagCompound().getInteger(SELECTED_SPELL_KEY)];
}
/** Returns the given wand's cooldown for the spell after the currently selected spell, or 0 if the wand has no
* cooldown data. */
public static int getNextCooldown(ItemStack wand){
int[] cooldowns = getCooldowns(wand);
if(cooldowns.length == 0) return 0;
// Don't need to check if the tag compound is null since the above check is equivalent.
return cooldowns[getNextSpellIndex(wand)];
}
/** Returns the given wand's cooldown for the spell before the currently selected spell, or 0 if the wand has no
* cooldown data. */
public static int getPreviousCooldown(ItemStack wand){
int[] cooldowns = getCooldowns(wand);
if(cooldowns.length == 0) return 0;
// Don't need to check if the tag compound is null since the above check is equivalent.
return cooldowns[getPreviousSpellIndex(wand)];
}
/** Sets the given wand's cooldown for the currently selected spell. */
public static void setCurrentCooldown(ItemStack wand, int cooldown){