mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-02-21 20:18:14 +07:00
Added support for item details label
Added support for item details label Changed constructor of ItemGrid to GameScreen from Player
This commit is contained in:
parent
fc35851f0f
commit
c657c1e3e0
@ -2,8 +2,10 @@ package gdx.diablo.item;
|
||||
|
||||
import com.badlogic.gdx.assets.AssetDescriptor;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
@ -24,6 +26,8 @@ import gdx.diablo.codec.util.BBox;
|
||||
import gdx.diablo.codec.util.BitStream;
|
||||
import gdx.diablo.entity.Player;
|
||||
import gdx.diablo.graphics.PaletteIndexedBatch;
|
||||
import gdx.diablo.graphics.PaletteIndexedColorDrawable;
|
||||
import gdx.diablo.widget.Label;
|
||||
|
||||
import static gdx.diablo.item.Quality.SET;
|
||||
|
||||
@ -83,6 +87,8 @@ public class Item extends Actor implements Disposable {
|
||||
public Index charColormap;
|
||||
public int charColorIndex;
|
||||
|
||||
public Details details;
|
||||
|
||||
public static Item loadFromStream(BitStream bitStream) {
|
||||
return new Item().read(bitStream);
|
||||
}
|
||||
@ -90,8 +96,15 @@ public class Item extends Actor implements Disposable {
|
||||
private Item() {
|
||||
addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
//...
|
||||
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
|
||||
super.enter(event, x, y, pointer, fromActor);
|
||||
if (isOver()) System.out.println("OVER");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
|
||||
super.exit(event, x, y, pointer, toActor);
|
||||
if (!isOver()) System.out.println("!OVER");
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -177,6 +190,7 @@ public class Item extends Actor implements Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
details = new Details();
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -186,6 +200,7 @@ public class Item extends Actor implements Disposable {
|
||||
Diablo.assets.load(invFileDescriptor);
|
||||
Diablo.assets.finishLoadingAsset(invFileDescriptor);
|
||||
invFile = Diablo.assets.get(invFileDescriptor);
|
||||
resize();
|
||||
|
||||
invColormap = Diablo.colormaps.get(base.InvTrans);
|
||||
String invColor = getInvColor();
|
||||
@ -561,4 +576,57 @@ public class Item extends Actor implements Disposable {
|
||||
return (pack & RUNEWORD_EXTRA_MASK) >>> RUNEWORD_EXTRA_SHIFT;
|
||||
}
|
||||
}
|
||||
|
||||
public class Details extends Table {
|
||||
private static final float SPACING = 2;
|
||||
private static final float PADDING = 6;
|
||||
|
||||
Label name;
|
||||
Label type;
|
||||
|
||||
Details() {
|
||||
setBackground(new PaletteIndexedColorDrawable(Diablo.colors.modal75));
|
||||
pad(PADDING);
|
||||
|
||||
BitmapFont font = Diablo.fonts.font16;
|
||||
name = new Label(Item.this.getName(), font);
|
||||
type = new Label(base.name, font);
|
||||
switch (quality) {
|
||||
case LOW:
|
||||
case NORMAL:
|
||||
case HIGH:
|
||||
if ((flags & RUNEWORD) == RUNEWORD)
|
||||
name.setColor(Diablo.colors.gold);
|
||||
if ((flags & (ETHEREAL|SOCKETED)) != 0)
|
||||
type.setColor(Diablo.colors.grey);
|
||||
break;
|
||||
case MAGIC:
|
||||
name.setColor(Diablo.colors.blue);
|
||||
type.setColor(Diablo.colors.blue);
|
||||
break;
|
||||
case SET:
|
||||
name.setColor(Diablo.colors.green);
|
||||
type.setColor(Diablo.colors.green);
|
||||
break;
|
||||
case RARE:
|
||||
name.setColor(Diablo.colors.yellow);
|
||||
type.setColor(Diablo.colors.yellow);
|
||||
break;
|
||||
case UNIQUE:
|
||||
name.setColor(Diablo.colors.gold);
|
||||
type.setColor(Diablo.colors.gold);
|
||||
break;
|
||||
case CRAFTED:
|
||||
name.setColor(Diablo.colors.orange);
|
||||
type.setColor(Diablo.colors.orange);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
add(name).center().space(SPACING).row();
|
||||
if (quality.ordinal() > Quality.MAGIC.ordinal() || (flags & RUNEWORD) == RUNEWORD)
|
||||
add(type).center().space(SPACING).row();
|
||||
pack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -257,7 +257,7 @@ public class InventoryPanel extends WidgetGroup implements Disposable {
|
||||
}
|
||||
});
|
||||
|
||||
ItemGrid grid = new ItemGrid(gameScreen.player, inventory);
|
||||
ItemGrid grid = new ItemGrid(gameScreen, inventory);
|
||||
grid.populate(gameScreen.player.getInventory());
|
||||
grid.setPosition(
|
||||
inventory.gridLeft - inventory.invLeft,
|
||||
@ -382,9 +382,7 @@ public class InventoryPanel extends WidgetGroup implements Disposable {
|
||||
}
|
||||
|
||||
if (isOver && item != null && cursorItem == null) {
|
||||
//Item.Details label = item.label;
|
||||
//label.setPosition(getX() + getWidth() / 2 - label.getWidth() / 2, getY() - label.getHeight());
|
||||
//label.draw(b, a);
|
||||
gameScreen.setDetails(item.details, item, InventoryPanel.this, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class StashPanel extends WidgetGroup implements Disposable {
|
||||
|
||||
inventory = Diablo.files.inventory.get("Big Bank Page 1");
|
||||
|
||||
ItemGrid grid = new ItemGrid(gameScreen.player, inventory);
|
||||
ItemGrid grid = new ItemGrid(gameScreen, inventory);
|
||||
//grid.populate(gameScreen.player.getStash());
|
||||
grid.setPosition(
|
||||
inventory.gridLeft - inventory.invLeft,
|
||||
|
@ -41,6 +41,7 @@ import gdx.diablo.entity.Entity;
|
||||
import gdx.diablo.entity.Player;
|
||||
import gdx.diablo.graphics.PaletteIndexedBatch;
|
||||
import gdx.diablo.graphics.PaletteIndexedColorDrawable;
|
||||
import gdx.diablo.item.Item;
|
||||
import gdx.diablo.key.MappedKey;
|
||||
import gdx.diablo.key.MappedKeyStateAdapter;
|
||||
import gdx.diablo.map.DT1.Tile;
|
||||
@ -98,6 +99,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
||||
InputProcessor inputProcessorTest;
|
||||
final Array<Actor> labels = new Array<>();
|
||||
NpcMenu menu;
|
||||
Actor details;
|
||||
|
||||
public TextArea input;
|
||||
TextArea output;
|
||||
@ -462,6 +464,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
||||
|
||||
b.setProjectionMatrix(Diablo.viewport.getCamera().combined);
|
||||
|
||||
details = null;
|
||||
stage.act();
|
||||
stage.draw();
|
||||
|
||||
@ -477,6 +480,10 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
||||
b.begin();
|
||||
for (Actor label : labels) label.draw(b, 1);
|
||||
b.end();
|
||||
} else if (menu == null && details != null) {
|
||||
b.begin();
|
||||
details.draw(b, 1);
|
||||
b.end();
|
||||
}
|
||||
}
|
||||
|
||||
@ -599,6 +606,38 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
||||
}
|
||||
}
|
||||
|
||||
public void setDetails(Actor details, Item item, Actor parent, Actor slot) {
|
||||
if (this.details != details) {
|
||||
this.details = details;
|
||||
|
||||
if (slot != null) {
|
||||
details.setPosition(slot.getX() + slot.getWidth() / 2, slot.getY() + slot.getHeight(), Align.bottom | Align.center);
|
||||
tmpVec2.set(details.getX(), details.getY());
|
||||
parent.localToStageCoordinates(tmpVec2);
|
||||
tmpVec2.x = MathUtils.clamp(tmpVec2.x, 0, Diablo.VIRTUAL_WIDTH - details.getWidth());
|
||||
tmpVec2.y = MathUtils.clamp(tmpVec2.y, 0, Diablo.VIRTUAL_HEIGHT - details.getHeight());
|
||||
details.setPosition(tmpVec2.x, tmpVec2.y);
|
||||
tmpVec2.set(slot.getX(), slot.getY());
|
||||
parent.localToStageCoordinates(tmpVec2);
|
||||
if (details.getY() < tmpVec2.y + slot.getHeight()) {
|
||||
details.setPosition(slot.getX() + slot.getWidth() / 2, slot.getY(), Align.top | Align.center);
|
||||
tmpVec2.set(details.getX(), details.getY());
|
||||
parent.localToStageCoordinates(tmpVec2);
|
||||
tmpVec2.x = MathUtils.clamp(tmpVec2.x, 0, Diablo.VIRTUAL_WIDTH - details.getWidth());
|
||||
tmpVec2.y = MathUtils.clamp(tmpVec2.y, 0, Diablo.VIRTUAL_HEIGHT - details.getHeight());
|
||||
details.setPosition(tmpVec2.x, tmpVec2.y);
|
||||
}
|
||||
} else {
|
||||
details.setPosition(item.getX() + item.getWidth() / 2, item.getY(), Align.top | Align.center);
|
||||
tmpVec2.set(details.getX(), details.getY());
|
||||
parent.localToStageCoordinates(tmpVec2);
|
||||
tmpVec2.x = MathUtils.clamp(tmpVec2.x, 0, Diablo.VIRTUAL_WIDTH - details.getWidth());
|
||||
tmpVec2.y = MathUtils.clamp(tmpVec2.y, 0, Diablo.VIRTUAL_HEIGHT - details.getHeight());
|
||||
details.setPosition(tmpVec2.x, tmpVec2.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public NpcMenu getMenu() {
|
||||
return menu;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import gdx.diablo.codec.excel.ItemEntry;
|
||||
import gdx.diablo.entity.Player;
|
||||
import gdx.diablo.graphics.PaletteIndexedBatch;
|
||||
import gdx.diablo.item.Item;
|
||||
import gdx.diablo.screen.GameScreen;
|
||||
|
||||
public class ItemGrid extends Group {
|
||||
private static final String TAG = "ItemGrid";
|
||||
@ -41,6 +42,7 @@ public class ItemGrid extends Group {
|
||||
|
||||
final ObjectSet<Actor> hits = new ObjectSet<>(8, 1);
|
||||
|
||||
final GameScreen gameScreen;
|
||||
final Player player;
|
||||
|
||||
boolean blocked = true;
|
||||
@ -49,12 +51,13 @@ public class ItemGrid extends Group {
|
||||
Vector2 grid = new Vector2();
|
||||
Vector2 itemSize = new Vector2();
|
||||
|
||||
public ItemGrid(Player player, Inventory.Entry inv) {
|
||||
this(player, inv.gridX, inv.gridY, inv.gridBoxWidth, inv.gridBoxHeight);
|
||||
public ItemGrid(GameScreen gameScreen, Inventory.Entry inv) {
|
||||
this(gameScreen, inv.gridX, inv.gridY, inv.gridBoxWidth, inv.gridBoxHeight);
|
||||
}
|
||||
|
||||
public ItemGrid(Player player, int width, int height, int boxWidth, int boxHeight) {
|
||||
this.player = player;
|
||||
public ItemGrid(GameScreen gameScreen, int width, int height, int boxWidth, int boxHeight) {
|
||||
this.gameScreen = gameScreen;
|
||||
this.player = gameScreen.player;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.boxWidth = boxWidth;
|
||||
@ -293,6 +296,9 @@ public class ItemGrid extends Group {
|
||||
b.draw(fill, getX(), getY(), getWidth(), getHeight());
|
||||
b.resetBlendMode();
|
||||
item.draw(b, 1);
|
||||
if (clickListener.isOver() && Diablo.cursor.getItem() == null) {
|
||||
gameScreen.setDetails(item.details, item, ItemGrid.this, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user