From 98eb2052bfb10ebd70781c4a686692d85b1555ea Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sun, 9 Aug 2015 04:32:18 -0400 Subject: [PATCH] v0.3.1: rings and artifacts can now be switched around more easily with two full misc slots --- .../items/artifacts/Artifact.java | 43 ++++++++++++++++--- .../items/rings/Ring.java | 34 ++++++++++++--- 2 files changed, 65 insertions(+), 12 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java index 4d62ac9ea..f5a0617b3 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java @@ -21,6 +21,7 @@ package com.shatteredpixel.shatteredpixeldungeon.items.artifacts; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; @@ -28,6 +29,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.KindofMisc; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; +import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions; import com.watabou.utils.Bundle; import com.watabou.utils.Random; @@ -42,6 +44,10 @@ public class Artifact extends KindofMisc { private static final String TXT_TO_STRING_LVL = "%s%+d"; private static final String TXT_TO_STRING_LVL_CHARGE = "%s%+d (%d/%d)"; + private static final String TXT_UNEQUIP_TITLE = "Unequip one item"; + private static final String TXT_UNEQUIP_MESSAGE = + "You can only wear two misc items at a time."; + protected Buff passiveBuff; protected Buff activeBuff; @@ -76,19 +82,42 @@ public class Artifact extends KindofMisc { } @Override - public boolean doEquip( Hero hero ) { + public boolean doEquip( final Hero hero ) { - if (hero.belongings.misc1 != null && hero.belongings.misc2 != null) { - - GLog.w("you can only wear 2 misc items at a time"); - return false; - - } else if ((hero.belongings.misc1 != null && hero.belongings.misc1.getClass() == this.getClass()) + if ((hero.belongings.misc1 != null && hero.belongings.misc1.getClass() == this.getClass()) || (hero.belongings.misc2 != null && hero.belongings.misc2.getClass() == this.getClass())){ GLog.w("you cannot wear two of the same artifact"); return false; + } else if (hero.belongings.misc1 != null && hero.belongings.misc2 != null) { + + final KindofMisc m1 = hero.belongings.misc1; + final KindofMisc m2 = hero.belongings.misc2; + final Artifact art = this; + + ShatteredPixelDungeon.scene().add( + new WndOptions(TXT_UNEQUIP_TITLE, TXT_UNEQUIP_MESSAGE, + Utils.capitalize(m1.toString()), + Utils.capitalize(m2.toString())) { + + @Override + protected void onSelect(int index) { + + KindofMisc equipped = (index == 0 ? m1 : m2); + if (equipped.doUnequip(hero, true, false)) { + int slot = Dungeon.quickslot.getSlot( art ); + doEquip(hero); + if (slot != -1) { + Dungeon.quickslot.setSlot( slot, art ); + updateQuickslot(); + } + } + } + }); + + return false; + } else { if (hero.belongings.misc1 == null) { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java index 4ae19763f..59af25966 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import com.shatteredpixel.shatteredpixeldungeon.Badges; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.items.KindofMisc; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; @@ -33,6 +34,8 @@ import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.ItemStatusHandler; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; +import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; +import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions; import com.watabou.utils.Bundle; import com.watabou.utils.Random; @@ -44,6 +47,10 @@ public class Ring extends KindofMisc { private static final String TXT_IDENTIFY = "you are now familiar enough with your %s to identify it. It is %s."; + + private static final String TXT_UNEQUIP_TITLE = "Unequip one item"; + private static final String TXT_UNEQUIP_MESSAGE = + "You can only wear two misc items at a time."; protected Buff buff; @@ -114,13 +121,30 @@ public class Ring extends KindofMisc { } @Override - public boolean doEquip( Hero hero ) { - + public boolean doEquip( final Hero hero ) { + if (hero.belongings.misc1 != null && hero.belongings.misc2 != null) { - - GLog.w( "you can only wear 2 misc items at a time" ); + + final KindofMisc m1 = hero.belongings.misc1; + final KindofMisc m2 = hero.belongings.misc2; + + ShatteredPixelDungeon.scene().add( + new WndOptions(TXT_UNEQUIP_TITLE, TXT_UNEQUIP_MESSAGE, + Utils.capitalize(m1.toString()), + Utils.capitalize(m2.toString())) { + + @Override + protected void onSelect(int index) { + + KindofMisc equipped = (index == 0 ? m1 : m2); + if (equipped.doUnequip(hero, true, false)) { + doEquip(hero); + } + } + }); + return false; - + } else { if (hero.belongings.misc1 == null) {