v2.2.0: moved ItemButton out of WndBlackSmith

This commit is contained in:
Evan Debenham
2023-08-18 12:29:34 -04:00
parent caaa820038
commit 4a8d4f2288
4 changed files with 110 additions and 78 deletions

View File

@@ -62,12 +62,12 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.GhostSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.ui.BossHealthBar;
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.IconTitle;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBlacksmith;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndQuest;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndUseItem;
import com.watabou.noosa.Game;
@@ -862,8 +862,8 @@ public class DriedRose extends Artifact {
private static final float BTN_GAP = 12;
private static final int WIDTH = 116;
private WndBlacksmith.ItemButton btnWeapon;
private WndBlacksmith.ItemButton btnArmor;
private ItemButton btnWeapon;
private ItemButton btnArmor;
WndGhostHero(final DriedRose rose){
@@ -879,7 +879,7 @@ public class DriedRose extends Artifact {
message.setPos(0, titlebar.bottom() + GAP);
add( message );
btnWeapon = new WndBlacksmith.ItemButton(){
btnWeapon = new ItemButton(){
@Override
protected void onClick() {
if (rose.weapon != null){
@@ -945,7 +945,7 @@ public class DriedRose extends Artifact {
}
add( btnWeapon );
btnArmor = new WndBlacksmith.ItemButton(){
btnArmor = new ItemButton(){
@Override
protected void onClick() {
if (rose.armor != null){

View File

@@ -0,0 +1,90 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2023 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Component;
//essentially a RedButton version of ItemSlot
public class ItemButton extends Component {
protected NinePatch bg;
protected ItemSlot slot;
@Override
protected void createChildren() {
super.createChildren();
bg = Chrome.get(Chrome.Type.RED_BUTTON);
add(bg);
slot = new ItemSlot() {
@Override
protected void onPointerDown() {
bg.brightness(1.2f);
Sample.INSTANCE.play(Assets.Sounds.CLICK);
}
@Override
protected void onPointerUp() {
bg.resetColor();
}
@Override
protected void onClick() {
ItemButton.this.onClick();
}
};
slot.enable(true);
add(slot);
}
protected void onClick() {}
@Override
protected void layout() {
super.layout();
bg.x = x;
bg.y = y;
bg.size( width, height );
slot.setRect( x + 2, y + 2, width - 4, height - 4 );
}
public Item item(){
return slot.item;
}
public void item( Item item ) {
slot.item( item );
}
public void clear(){
slot.clear();
}
}

View File

@@ -21,8 +21,6 @@
package com.shatteredpixel.shatteredpixeldungeon.windows;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Blacksmith;
@@ -31,13 +29,10 @@ import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot;
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Component;
public class WndBlacksmith extends Window {
@@ -90,7 +85,7 @@ public class WndBlacksmith extends Window {
btnReforge = new RedButton( Messages.get(this, "reforge") ) {
@Override
protected void onClick() {
Blacksmith.upgrade( btnItem1.item, btnItem2.item );
Blacksmith.upgrade( btnItem1.item(), btnItem2.item() );
hide();
}
};
@@ -124,8 +119,8 @@ public class WndBlacksmith extends Window {
if (item != null && btnPressed.parent != null) {
btnPressed.item( item );
if (btnItem1.item != null && btnItem2.item != null) {
String result = Blacksmith.verify( btnItem1.item, btnItem2.item );
if (btnItem1.item() != null && btnItem2.item() != null) {
String result = Blacksmith.verify( btnItem1.item(), btnItem2.item() );
if (result != null) {
GameScene.show( new WndMessage( result ) );
btnReforge.enable( false );
@@ -136,59 +131,5 @@ public class WndBlacksmith extends Window {
}
}
};
public static class ItemButton extends Component {
protected NinePatch bg;
protected ItemSlot slot;
public Item item = null;
@Override
protected void createChildren() {
super.createChildren();
bg = Chrome.get( Chrome.Type.RED_BUTTON);
add( bg );
slot = new ItemSlot() {
@Override
protected void onPointerDown() {
bg.brightness( 1.2f );
Sample.INSTANCE.play( Assets.Sounds.CLICK );
}
@Override
protected void onPointerUp() {
bg.resetColor();
}
@Override
protected void onClick() {
ItemButton.this.onClick();
}
};
slot.enable(true);
add( slot );
}
protected void onClick() {}
@Override
protected void layout() {
super.layout();
bg.x = x;
bg.y = y;
bg.size( width, height );
slot.setRect( x + 2, y + 2, width - 4, height - 4 );
}
public void item( Item item ) {
slot.item( this.item = item );
}
public void clear(){
slot.clear();
}
}
}

View File

@@ -31,6 +31,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.InterlevelScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
@@ -47,9 +48,9 @@ public class WndResurrect extends Window {
public static Object instance;
private WndBlacksmith.ItemButton btnItem1;
private WndBlacksmith.ItemButton btnItem2;
private WndBlacksmith.ItemButton btnPressed;
private ItemButton btnItem1;
private ItemButton btnItem2;
private ItemButton btnPressed;
RedButton btnContinue;
@@ -70,7 +71,7 @@ public class WndResurrect extends Window {
message.setPos(0, titlebar.bottom() + GAP);
add( message );
btnItem1 = new WndBlacksmith.ItemButton() {
btnItem1 = new ItemButton() {
@Override
protected void onClick() {
btnPressed = btnItem1;
@@ -81,7 +82,7 @@ public class WndResurrect extends Window {
btnItem1.setRect( (WIDTH - BTN_GAP) / 2 - BTN_SIZE, message.bottom() + BTN_GAP, BTN_SIZE, BTN_SIZE );
add( btnItem1 );
btnItem2 = new WndBlacksmith.ItemButton() {
btnItem2 = new ItemButton() {
@Override
protected void onClick() {
btnPressed = btnItem2;
@@ -101,11 +102,11 @@ public class WndResurrect extends Window {
ankh.detach(Dungeon.hero.belongings.backpack);
if (btnItem1.item != null){
btnItem1.item.keptThoughLostInvent = true;
if (btnItem1.item() != null){
btnItem1.item().keptThoughLostInvent = true;
}
if (btnItem2.item != null){
btnItem2.item.keptThoughLostInvent = true;
if (btnItem2.item() != null){
btnItem2.item().keptThoughLostInvent = true;
}
InterlevelScene.mode = InterlevelScene.Mode.RESURRECT;
@@ -136,7 +137,7 @@ public class WndResurrect extends Window {
if (item != null && btnPressed.parent != null) {
btnPressed.item( item );
if (btnItem1.item == btnItem2.item){
if (btnItem1.item() == btnItem2.item()){
if (btnPressed == btnItem1){
btnItem2.clear();
} else {