v1.2.0: on-screen inventory now integrates with autotargeting
This commit is contained in:
parent
508d7248f9
commit
7367248aa4
|
@ -1239,6 +1239,7 @@ public class GameScene extends PixelScene {
|
|||
public static void ready() {
|
||||
selectCell( defaultCellListener );
|
||||
QuickSlotButton.cancel();
|
||||
InventoryPane.cancelTargeting();
|
||||
if (scene != null && scene.toolbar != null) scene.toolbar.examining = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
|
|||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
|
||||
|
@ -32,6 +34,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.bags.ScrollHolder;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.items.bags.VelvetPouch;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndUseItem;
|
||||
|
@ -81,6 +84,13 @@ public class InventoryPane extends Component {
|
|||
|
||||
private boolean lastEnabled = true;
|
||||
|
||||
private static Image crossB;
|
||||
private static Image crossM;
|
||||
|
||||
private static boolean targeting = false;
|
||||
private static InventorySlot targetingSlot = null;
|
||||
public static Char lastTarget = null;
|
||||
|
||||
public InventoryPane(){
|
||||
super();
|
||||
instance = this;
|
||||
|
@ -118,17 +128,37 @@ public class InventoryPane extends Component {
|
|||
InventorySlot btn = new InventorySlot(null){
|
||||
@Override
|
||||
protected void onClick() {
|
||||
if (lastBag != item && !lastBag.contains(item) && !item.isEquipped(Dungeon.hero)){
|
||||
updateInventory();
|
||||
return;
|
||||
}
|
||||
|
||||
if (targeting){
|
||||
if (targetingSlot == this){
|
||||
int cell = QuickSlotButton.autoAim(lastTarget, item());
|
||||
|
||||
if (cell != -1){
|
||||
GameScene.handleCell(cell);
|
||||
} else {
|
||||
//couldn't auto-aim, just target the position and hope for the best.
|
||||
GameScene.handleCell( lastTarget.pos );
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
cancelTargeting();
|
||||
}
|
||||
}
|
||||
|
||||
//any windows opened as a consequence of this button should be centered on the inventory
|
||||
GameScene.lastOffset = new Point((int)InventoryPane.this.centerX() - camera.width/2,
|
||||
(int)InventoryPane.this.centerY() - camera.height/2);
|
||||
if (lastBag != item && !lastBag.contains(item) && !item.isEquipped(Dungeon.hero)){
|
||||
updateInventory();
|
||||
} else if (selector != null) {
|
||||
if (selector != null) {
|
||||
WndBag.ItemSelector activating = selector;
|
||||
selector = null;
|
||||
activating.onSelect( item );
|
||||
updateInventory();
|
||||
} else {
|
||||
targetingSlot = this;
|
||||
GameScene.show(new WndUseItem( null, item ));
|
||||
}
|
||||
}
|
||||
|
@ -158,17 +188,37 @@ public class InventoryPane extends Component {
|
|||
InventorySlot btn = new InventorySlot(null){
|
||||
@Override
|
||||
protected void onClick() {
|
||||
if (lastBag != item && !lastBag.contains(item) && !item.isEquipped(Dungeon.hero)){
|
||||
updateInventory();
|
||||
return;
|
||||
}
|
||||
|
||||
if (targeting){
|
||||
if (targetingSlot == this){
|
||||
int cell = QuickSlotButton.autoAim(lastTarget, item());
|
||||
|
||||
if (cell != -1){
|
||||
GameScene.handleCell(cell);
|
||||
} else {
|
||||
//couldn't auto-aim, just target the position and hope for the best.
|
||||
GameScene.handleCell( lastTarget.pos );
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
cancelTargeting();
|
||||
}
|
||||
}
|
||||
|
||||
//any windows opened as a consequence of this button should be centered on the inventory
|
||||
GameScene.lastOffset = new Point((int)InventoryPane.this.centerX() - camera.width/2,
|
||||
(int)InventoryPane.this.centerY() - camera.height/2);
|
||||
if (lastBag != item && !lastBag.contains(item) && !item.isEquipped(Dungeon.hero)){
|
||||
updateInventory();
|
||||
} else if (selector != null) {
|
||||
if (selector != null) {
|
||||
WndBag.ItemSelector activating = selector;
|
||||
selector = null;
|
||||
activating.onSelect( item );
|
||||
updateInventory();
|
||||
} else {
|
||||
targetingSlot = this;
|
||||
GameScene.show(new WndUseItem( null, item ));
|
||||
}
|
||||
}
|
||||
|
@ -184,6 +234,13 @@ public class InventoryPane extends Component {
|
|||
add(btn);
|
||||
}
|
||||
|
||||
crossB = Icons.TARGET.get();
|
||||
crossB.visible = false;
|
||||
add( crossB );
|
||||
|
||||
crossM = new Image();
|
||||
crossM.copy( crossB );
|
||||
|
||||
lastEnabled = true;
|
||||
updateInventory();
|
||||
|
||||
|
@ -352,6 +409,40 @@ public class InventoryPane extends Component {
|
|||
return selector != null;
|
||||
}
|
||||
|
||||
public static void useTargeting(){
|
||||
if (lastTarget != null &&
|
||||
Actor.chars().contains( lastTarget ) &&
|
||||
lastTarget.isAlive() &&
|
||||
lastTarget.alignment != Char.Alignment.ALLY &&
|
||||
Dungeon.level.heroFOV[lastTarget.pos]) {
|
||||
|
||||
targeting = true;
|
||||
CharSprite sprite = lastTarget.sprite;
|
||||
|
||||
if (sprite.parent != null) {
|
||||
sprite.parent.addToFront(crossM);
|
||||
crossM.point(sprite.center(crossM));
|
||||
}
|
||||
|
||||
crossB.point(targetingSlot.sprite.center(crossB));
|
||||
crossB.visible = true;
|
||||
|
||||
} else {
|
||||
|
||||
lastTarget = null;
|
||||
targeting = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void cancelTargeting(){
|
||||
if (targeting){
|
||||
crossB.visible = false;
|
||||
crossM.remove();
|
||||
targeting = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void update() {
|
||||
super.update();
|
||||
|
|
|
@ -292,6 +292,7 @@ public class QuickSlotButton extends Button {
|
|||
lastTarget = target;
|
||||
|
||||
TargetHealthIndicator.instance.target( target );
|
||||
InventoryPane.lastTarget = target;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ package com.shatteredpixel.shatteredpixeldungeon.windows;
|
|||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.InventoryPane;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
|
||||
|
||||
|
@ -54,6 +55,9 @@ public class WndUseItem extends WndInfoItem {
|
|||
item.execute( Dungeon.hero, action );
|
||||
}
|
||||
Item.updateQuickslot();
|
||||
if (action == item.defaultAction && item.usesTargeting && owner == null){
|
||||
InventoryPane.useTargeting();
|
||||
}
|
||||
}
|
||||
};
|
||||
btn.setSize( btn.reqWidth(), BUTTON_HEIGHT );
|
||||
|
|
Loading…
Reference in New Issue
Block a user