v3.1.0: implemented a custom note button for WndUseItem
This commit is contained in:
+18
-6
@@ -38,6 +38,7 @@ import com.shatteredpixel.shatteredpixeldungeon.windows.WndJournalItem;
|
|||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndTextInput;
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndTextInput;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndTitledMessage;
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndTitledMessage;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndUseItem;
|
||||||
import com.watabou.utils.Reflection;
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -265,7 +266,7 @@ public class CustomNoteButton extends IconButton {
|
|||||||
|
|
||||||
public static class CustomNoteWindow extends WndJournalItem {
|
public static class CustomNoteWindow extends WndJournalItem {
|
||||||
|
|
||||||
public CustomNoteWindow(Notes.CustomRecord rec) {
|
public CustomNoteWindow(Notes.CustomRecord rec, Window parentWindow) {
|
||||||
super(rec.icon(), rec.title(), rec.desc());
|
super(rec.icon(), rec.title(), rec.desc());
|
||||||
|
|
||||||
RedButton title = new RedButton( Messages.get(CustomNoteWindow.class, "edit_title") ){
|
RedButton title = new RedButton( Messages.get(CustomNoteWindow.class, "edit_title") ){
|
||||||
@@ -283,7 +284,13 @@ public class CustomNoteButton extends IconButton {
|
|||||||
if (positive && !text.isEmpty()){
|
if (positive && !text.isEmpty()){
|
||||||
rec.editText(text, rec.desc());
|
rec.editText(text, rec.desc());
|
||||||
CustomNoteWindow.this.hide();
|
CustomNoteWindow.this.hide();
|
||||||
ShatteredPixelDungeon.scene().addToFront(new CustomNoteWindow(rec));
|
if (parentWindow instanceof WndUseItem){
|
||||||
|
WndUseItem newParent = new WndUseItem(((WndUseItem) parentWindow).owner, ((WndUseItem) parentWindow).item);
|
||||||
|
GameScene.show(newParent);
|
||||||
|
GameScene.show(new CustomNoteWindow(rec, newParent));
|
||||||
|
} else {
|
||||||
|
GameScene.show(new CustomNoteWindow(rec, parentWindow));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -308,7 +315,7 @@ public class CustomNoteButton extends IconButton {
|
|||||||
if (positive){
|
if (positive){
|
||||||
rec.editText(rec.title(), text);
|
rec.editText(rec.title(), text);
|
||||||
CustomNoteWindow.this.hide();
|
CustomNoteWindow.this.hide();
|
||||||
ShatteredPixelDungeon.scene().addToFront(new CustomNoteWindow(rec));
|
GameScene.show(new CustomNoteWindow(rec, parentWindow));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -330,7 +337,11 @@ public class CustomNoteButton extends IconButton {
|
|||||||
if (index == 0){
|
if (index == 0){
|
||||||
Notes.remove(rec);
|
Notes.remove(rec);
|
||||||
CustomNoteWindow.this.hide();
|
CustomNoteWindow.this.hide();
|
||||||
ShatteredPixelDungeon.scene().addToFront(new WndJournal());
|
if (parentWindow instanceof WndJournal || parentWindow == null){
|
||||||
|
ShatteredPixelDungeon.scene().addToFront(new WndJournal());
|
||||||
|
} else if (parentWindow instanceof WndUseItem){
|
||||||
|
GameScene.show(new WndUseItem(((WndUseItem) parentWindow).owner, ((WndUseItem) parentWindow).item));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -371,8 +382,9 @@ public class CustomNoteButton extends IconButton {
|
|||||||
NOTE_SELECT_INSTANCE.onBackPressed();
|
NOTE_SELECT_INSTANCE.onBackPressed();
|
||||||
}
|
}
|
||||||
hide();
|
hide();
|
||||||
ShatteredPixelDungeon.scene().addToFront(new WndJournal());
|
WndJournal wnd = new WndJournal();
|
||||||
ShatteredPixelDungeon.scene().addToFront(new CustomNoteWindow(note));
|
ShatteredPixelDungeon.scene().addToFront(wnd);
|
||||||
|
ShatteredPixelDungeon.scene().addToFront(new CustomNoteWindow(note, wnd));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+109
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* Pixel Dungeon
|
||||||
|
* Copyright (C) 2012-2015 Oleg Dolya
|
||||||
|
*
|
||||||
|
* Shattered Pixel Dungeon
|
||||||
|
* Copyright (C) 2014-2025 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.Dungeon;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.journal.Notes;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.SupporterScene;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.services.payment.Payment;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndTextInput;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndTitledMessage;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndUseItem;
|
||||||
|
|
||||||
|
public class ItemJournalButton extends IconButton {
|
||||||
|
|
||||||
|
Item item;
|
||||||
|
Window parentWnd;
|
||||||
|
|
||||||
|
public ItemJournalButton(Item item, Window parentWnd){
|
||||||
|
super(Icons.JOURNAL.get());
|
||||||
|
this.item = item;
|
||||||
|
this.parentWnd = parentWnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onClick() {
|
||||||
|
|
||||||
|
customNote();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void customNote(){
|
||||||
|
Notes.CustomRecord note = null;
|
||||||
|
if (item instanceof EquipableItem){
|
||||||
|
note = Notes.findCustomRecord(((EquipableItem) item).customNoteID);
|
||||||
|
}
|
||||||
|
if (note == null) {
|
||||||
|
note = Notes.findCustomRecord(item.getClass());
|
||||||
|
}
|
||||||
|
//TODO custom note functionality for rings doesn't really work atm, need to let them have equip-specific notes
|
||||||
|
if (note == null){
|
||||||
|
if (Notes.getRecords(Notes.CustomRecord.class).size() >= Notes.customRecordLimit()){
|
||||||
|
GameScene.show(new WndTitledMessage(Icons.INFO.get(),
|
||||||
|
Messages.get(CustomNoteButton.class, "limit_title"),
|
||||||
|
Messages.get(CustomNoteButton.class, "limit_text")));
|
||||||
|
} else {
|
||||||
|
note = new Notes.CustomRecord(item, "", "");
|
||||||
|
note.assignID();
|
||||||
|
if (item instanceof EquipableItem){
|
||||||
|
((EquipableItem) item).customNoteID = note.ID();
|
||||||
|
}
|
||||||
|
addNote(parentWnd, note, Messages.get(CustomNoteButton.class, "new_inv"),
|
||||||
|
Messages.get(CustomNoteButton.class, "new_item_title", Messages.titleCase(item.name())));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
GameScene.show(new CustomNoteButton.CustomNoteWindow(note, parentWnd));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addNote(Window parentWindow, Notes.CustomRecord note, String promptTitle, String prompttext){
|
||||||
|
GameScene.show(new WndTextInput(promptTitle,
|
||||||
|
prompttext,
|
||||||
|
"",
|
||||||
|
50,
|
||||||
|
false,
|
||||||
|
Messages.get(CustomNoteButton.CustomNoteWindow.class, "confirm"),
|
||||||
|
Messages.get(CustomNoteButton.CustomNoteWindow.class, "cancel")){
|
||||||
|
@Override
|
||||||
|
public void onSelect(boolean positive, String text) {
|
||||||
|
if (positive && !text.isEmpty()){
|
||||||
|
Notes.add(note);
|
||||||
|
note.editText(text, "");
|
||||||
|
if (parentWindow != null) {
|
||||||
|
parentWindow.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
hide();
|
||||||
|
if (parentWindow instanceof WndUseItem){
|
||||||
|
GameScene.show(new WndUseItem(((WndUseItem) parentWindow).owner, ((WndUseItem) parentWindow).item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -503,7 +503,7 @@ public class WndJournal extends WndTabbed {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onClick(float x, float y) {
|
public boolean onClick(float x, float y) {
|
||||||
if (inside(x, y)) {
|
if (inside(x, y)) {
|
||||||
GameScene.show(new CustomNoteButton.CustomNoteWindow(rec));
|
GameScene.show(new CustomNoteButton.CustomNoteWindow(rec, WndJournal.INSTANCE));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
+23
-12
@@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.windows;
|
|||||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.InventoryPane;
|
import com.shatteredpixel.shatteredpixeldungeon.ui.InventoryPane;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemJournalButton;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
|
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
|
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
|
||||||
|
|
||||||
@@ -34,44 +35,54 @@ public class WndUseItem extends WndInfoItem {
|
|||||||
private static final float BUTTON_HEIGHT = 16;
|
private static final float BUTTON_HEIGHT = 16;
|
||||||
|
|
||||||
private static final float GAP = 2;
|
private static final float GAP = 2;
|
||||||
|
|
||||||
|
public Window owner;
|
||||||
|
public Item item;
|
||||||
|
|
||||||
public WndUseItem( final Window owner, final Item item ) {
|
public WndUseItem( final Window owner, final Item item ) {
|
||||||
|
|
||||||
super(item);
|
super(item);
|
||||||
|
|
||||||
|
this.owner = owner;
|
||||||
|
this.item = item;
|
||||||
|
|
||||||
float y = height;
|
float y = height;
|
||||||
|
|
||||||
if (Dungeon.hero.isAlive() && Dungeon.hero.belongings.contains(item)) {
|
if (Dungeon.hero.isAlive() && Dungeon.hero.belongings.contains(item)) {
|
||||||
y += GAP;
|
y += GAP;
|
||||||
ArrayList<RedButton> buttons = new ArrayList<>();
|
ArrayList<RedButton> buttons = new ArrayList<>();
|
||||||
for (final String action : item.actions( Dungeon.hero )) {
|
for (final String action : item.actions(Dungeon.hero)) {
|
||||||
|
|
||||||
RedButton btn = new RedButton( item.actionName(action, Dungeon.hero), 8 ) {
|
RedButton btn = new RedButton(item.actionName(action, Dungeon.hero), 8) {
|
||||||
@Override
|
@Override
|
||||||
protected void onClick() {
|
protected void onClick() {
|
||||||
hide();
|
hide();
|
||||||
if (owner != null && owner.parent != null) owner.hide();
|
if (owner != null && owner.parent != null) owner.hide();
|
||||||
if (Dungeon.hero.isAlive() && Dungeon.hero.belongings.contains(item)){
|
if (Dungeon.hero.isAlive() && Dungeon.hero.belongings.contains(item)) {
|
||||||
item.execute( Dungeon.hero, action );
|
item.execute(Dungeon.hero, action);
|
||||||
}
|
}
|
||||||
Item.updateQuickslot();
|
Item.updateQuickslot();
|
||||||
if (action.equals(item.defaultAction()) && item.usesTargeting && owner == null){
|
if (action.equals(item.defaultAction()) && item.usesTargeting && owner == null) {
|
||||||
InventoryPane.useTargeting();
|
InventoryPane.useTargeting();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
btn.setSize( btn.reqWidth(), BUTTON_HEIGHT );
|
btn.setSize(btn.reqWidth(), BUTTON_HEIGHT);
|
||||||
buttons.add(btn);
|
buttons.add(btn);
|
||||||
add( btn );
|
add(btn);
|
||||||
|
|
||||||
if (action.equals(item.defaultAction())) {
|
if (action.equals(item.defaultAction())) {
|
||||||
btn.textColor( TITLE_COLOR );
|
btn.textColor(TITLE_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
y = layoutButtons(buttons, width, y);
|
y = layoutButtons(buttons, width, y);
|
||||||
|
|
||||||
|
ItemJournalButton btn = new ItemJournalButton(item, this);
|
||||||
|
btn.setRect(width - 16, 0, 16, 16);
|
||||||
|
add(btn);
|
||||||
}
|
}
|
||||||
|
|
||||||
resize( width, (int)(y) );
|
resize( width, (int)(y) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user