Enable disarming already armed equipment
This commit is contained in:
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@@ -2,11 +2,14 @@ package com.bartlomiejpluta.demo.gui;
|
||||
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.gui.*;
|
||||
import com.bartlomiejpluta.base.api.input.Key;
|
||||
import com.bartlomiejpluta.base.api.input.KeyAction;
|
||||
import com.bartlomiejpluta.base.api.input.KeyEvent;
|
||||
import com.bartlomiejpluta.base.lib.gui.HOptionChoice;
|
||||
import com.bartlomiejpluta.base.lib.gui.Label;
|
||||
import com.bartlomiejpluta.base.lib.gui.VGridOptionChoice;
|
||||
import com.bartlomiejpluta.base.lib.gui.VOptionChoice;
|
||||
import com.bartlomiejpluta.demo.entity.Player;
|
||||
import com.bartlomiejpluta.demo.runner.DemoRunner;
|
||||
import com.bartlomiejpluta.demo.world.item.Item;
|
||||
import com.bartlomiejpluta.demo.world.item.Useable;
|
||||
import com.bartlomiejpluta.demo.world.potion.Medicament;
|
||||
@@ -14,7 +17,7 @@ import com.bartlomiejpluta.demo.world.weapon.MeleeWeapon;
|
||||
import com.bartlomiejpluta.demo.world.weapon.RangedWeapon;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
@@ -22,20 +25,26 @@ import static java.lang.String.format;
|
||||
public class EquipmentWindow extends DecoratedWindow {
|
||||
private final Player player;
|
||||
|
||||
private final Window eqItemMenuWindow;
|
||||
private final Window popupMenuWindow;
|
||||
private final Button useBtn;
|
||||
private final Button dropBtn;
|
||||
private final Button cancelBtn;
|
||||
private final VOptionChoice eqItemMenu;
|
||||
private final VOptionChoice popupMenu;
|
||||
|
||||
@Ref("eq")
|
||||
private VGridOptionChoice eqGrid;
|
||||
@Ref("layout")
|
||||
private HOptionChoice layout;
|
||||
|
||||
@Ref("equipment")
|
||||
private VGridOptionChoice equipment;
|
||||
|
||||
@Ref("inventory")
|
||||
private VGridOptionChoice inventory;
|
||||
|
||||
@Ref("weapon")
|
||||
private ItemIconView weapon;
|
||||
private ItemIconView weaponSlot;
|
||||
|
||||
@Ref("ammo")
|
||||
private ItemIconView ammo;
|
||||
private ItemIconView ammoSlot;
|
||||
|
||||
@Ref("item-name")
|
||||
private Label nameLbl;
|
||||
@@ -43,14 +52,26 @@ public class EquipmentWindow extends DecoratedWindow {
|
||||
@Ref("item-details")
|
||||
private Label detailsLbl;
|
||||
|
||||
|
||||
public EquipmentWindow(Context context, GUI gui, Map<String, Component> refs) {
|
||||
super(context, gui, refs);
|
||||
this.player = context.getGlobal("player", Player.class);
|
||||
this.eqItemMenuWindow = gui.inflateWindow(A.widgets.eq_item_menu.uid);
|
||||
this.eqItemMenu = eqItemMenuWindow.reference("menu", VOptionChoice.class);
|
||||
this.useBtn = eqItemMenuWindow.reference("use", Button.class);
|
||||
this.dropBtn = eqItemMenuWindow.reference("drop", Button.class);
|
||||
this.cancelBtn = eqItemMenuWindow.reference("cancel", Button.class);
|
||||
this.popupMenuWindow = gui.inflateWindow(A.widgets.eq_item_menu.uid);
|
||||
this.popupMenu = popupMenuWindow.reference("menu", VOptionChoice.class);
|
||||
this.useBtn = popupMenuWindow.reference("use", Button.class);
|
||||
this.dropBtn = popupMenuWindow.reference("drop", Button.class);
|
||||
this.cancelBtn = popupMenuWindow.reference("cancel", Button.class);
|
||||
|
||||
addEventListener(KeyEvent.TYPE, this::handleKey);
|
||||
}
|
||||
|
||||
private void handleKey(KeyEvent event) {
|
||||
if (event.getKey() == Key.KEY_TAB && event.getAction() == KeyAction.PRESS) {
|
||||
layout.selectNext();
|
||||
layout.focus();
|
||||
updateItemDetails(((VGridOptionChoice) layout.getSelectedComponent()).getSelectedComponent());
|
||||
event.consume();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,41 +79,53 @@ public class EquipmentWindow extends DecoratedWindow {
|
||||
super.onOpen(manager, args);
|
||||
|
||||
cancelBtn.setAction(manager::close);
|
||||
eqGrid.setOnSelect(this::updateItemDetails);
|
||||
inventory.setOnSelect(this::updateItemDetails);
|
||||
equipment.setOnSelect(this::updateItemDetails);
|
||||
|
||||
updateEquipment();
|
||||
|
||||
eqGrid.select(0, 0);
|
||||
eqGrid.focus();
|
||||
layout.select(1);
|
||||
layout.focus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(WindowManager manager) {
|
||||
super.onClose(manager);
|
||||
layout.blur();
|
||||
}
|
||||
|
||||
private void updateEquipment() {
|
||||
var i = 0;
|
||||
for (var child : eqGrid.getChildren()) {
|
||||
for (var child : inventory.getChildren()) {
|
||||
var slot = (ItemIconView) child;
|
||||
slot.setItem(player.getEquipmentItem(i++));
|
||||
slot.setAction(handleClick(slot));
|
||||
slot.setAction(this::handleInventoryClick);
|
||||
}
|
||||
|
||||
weapon.setItem(player.getWeapon());
|
||||
ammo.setItem(player.getAmmunition());
|
||||
weaponSlot.setItem(player.getWeapon());
|
||||
weaponSlot.setAction(handleEquipmentClick(() -> {
|
||||
player.setWeapon(null);
|
||||
updateEquipment();
|
||||
manager.close();
|
||||
}));
|
||||
|
||||
ammoSlot.setItem(player.getAmmunition());
|
||||
ammoSlot.setAction(handleEquipmentClick(() -> {
|
||||
player.setAmmunition(null);
|
||||
updateEquipment();
|
||||
manager.close();
|
||||
}));
|
||||
}
|
||||
|
||||
private Consumer<Item> handleClick(ItemIconView slot) {
|
||||
return item -> {
|
||||
useBtn.setText(getButtonTitle(item));
|
||||
eqItemMenu.select(0);
|
||||
eqItemMenu.focus();
|
||||
private BiConsumer<ItemIconView, Item> handleEquipmentClick(Runnable deequip) {
|
||||
return (slot, item) -> {
|
||||
useBtn.setText("Disarm");
|
||||
popupMenu.select(0);
|
||||
popupMenu.focus();
|
||||
|
||||
manager.open(eqItemMenuWindow);
|
||||
manager.open(popupMenuWindow);
|
||||
|
||||
if (item instanceof Useable useable) {
|
||||
useBtn.setAction(() -> {
|
||||
useable.use(player);
|
||||
updateEquipment();
|
||||
manager.close();
|
||||
});
|
||||
}
|
||||
useBtn.setAction(deequip);
|
||||
|
||||
dropBtn.setAction(() -> {
|
||||
player.dropItemFromEquipment(item);
|
||||
@@ -103,6 +136,29 @@ public class EquipmentWindow extends DecoratedWindow {
|
||||
};
|
||||
}
|
||||
|
||||
private void handleInventoryClick(ItemIconView slot, Item item) {
|
||||
useBtn.setText(getButtonTitle(item));
|
||||
popupMenu.select(0);
|
||||
popupMenu.focus();
|
||||
|
||||
manager.open(popupMenuWindow);
|
||||
|
||||
if (item instanceof Useable useable) {
|
||||
useBtn.setAction(() -> {
|
||||
useable.use(player);
|
||||
updateEquipment();
|
||||
manager.close();
|
||||
});
|
||||
}
|
||||
|
||||
dropBtn.setAction(() -> {
|
||||
player.dropItemFromEquipment(item);
|
||||
slot.setItem(null);
|
||||
updateItemDetails(slot);
|
||||
manager.close();
|
||||
});
|
||||
}
|
||||
|
||||
private void updateItemDetails(Component slot) {
|
||||
var item = ((ItemIconView) slot).getItem();
|
||||
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
package com.bartlomiejpluta.demo.gui;
|
||||
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.gui.Component;
|
||||
import com.bartlomiejpluta.base.api.gui.GUI;
|
||||
import com.bartlomiejpluta.base.api.gui.Inflatable;
|
||||
import com.bartlomiejpluta.base.api.gui.Ref;
|
||||
import com.bartlomiejpluta.base.api.gui.*;
|
||||
import com.bartlomiejpluta.base.lib.gui.VOptionChoice;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class GameMenuWindow extends DecoratedWindow implements Inflatable {
|
||||
public class GameMenuWindow extends DecoratedWindow {
|
||||
|
||||
@Ref("menu")
|
||||
private VOptionChoice menu;
|
||||
|
||||
@Ref("resume_game")
|
||||
@Getter
|
||||
@@ -29,7 +30,9 @@ public class GameMenuWindow extends DecoratedWindow implements Inflatable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInflate() {
|
||||
resumeGameBtn.focus();
|
||||
public void onOpen(WindowManager manager, Object[] args) {
|
||||
super.onOpen(manager, args);
|
||||
menu.select(0);
|
||||
menu.focus();
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,14 @@ package com.bartlomiejpluta.demo.gui;
|
||||
|
||||
import A.fonts;
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.gui.Color;
|
||||
import com.bartlomiejpluta.base.api.gui.Component;
|
||||
import com.bartlomiejpluta.base.api.gui.GUI;
|
||||
import com.bartlomiejpluta.base.api.gui.*;
|
||||
import com.bartlomiejpluta.base.api.icon.Icon;
|
||||
import com.bartlomiejpluta.base.api.input.Key;
|
||||
import com.bartlomiejpluta.base.api.input.KeyAction;
|
||||
import com.bartlomiejpluta.base.api.input.KeyEvent;
|
||||
import com.bartlomiejpluta.base.api.screen.Screen;
|
||||
import com.bartlomiejpluta.base.lib.gui.IconView;
|
||||
import com.bartlomiejpluta.demo.util.IconUtil;
|
||||
import com.bartlomiejpluta.demo.world.item.Item;
|
||||
import com.bartlomiejpluta.demo.world.item.ItemStack;
|
||||
import lombok.Getter;
|
||||
@@ -18,9 +17,10 @@ import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public class ItemIconView extends IconView {
|
||||
private final GUI gui;
|
||||
private final Color normal;
|
||||
private final Color hover;
|
||||
private final Color textColor;
|
||||
@@ -28,11 +28,18 @@ public class ItemIconView extends IconView {
|
||||
@Getter
|
||||
private Item item;
|
||||
|
||||
private IconSet placeholderIconSet;
|
||||
private Paint placeholderIconPaint;
|
||||
|
||||
private int placeholderIconSetRow;
|
||||
private int placeholderIconSetColumn;
|
||||
|
||||
@Setter
|
||||
private Consumer<Item> action;
|
||||
private BiConsumer<ItemIconView, Item> action;
|
||||
|
||||
public ItemIconView(Context context, GUI gui, Map<String, Component> refs) {
|
||||
super(context, gui, refs);
|
||||
this.gui = gui;
|
||||
this.normal = gui.createColor();
|
||||
this.hover = gui.createColor();
|
||||
this.textColor = gui.createColor();
|
||||
@@ -71,10 +78,19 @@ public class ItemIconView extends IconView {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Attribute("placeholder")
|
||||
public void setPlaceholderIcon(String icon) {
|
||||
this.placeholderIconPaint = gui.createPaint();
|
||||
var parts = icon.split(",");
|
||||
this.placeholderIconSet = gui.getIconSet(A.iconsets.get(parts[0]).uid);
|
||||
this.placeholderIconSetRow = Integer.parseInt(parts[1]);
|
||||
this.placeholderIconSetColumn = Integer.parseInt(parts[2]);
|
||||
}
|
||||
|
||||
private void handleKeyEvent(KeyEvent event) {
|
||||
if (event.getKey() == Key.KEY_ENTER && event.getAction() == KeyAction.PRESS && item != null && action != null) {
|
||||
event.consume();
|
||||
action.accept(item);
|
||||
action.accept(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +112,12 @@ public class ItemIconView extends IconView {
|
||||
gui.fill();
|
||||
gui.closePath();
|
||||
|
||||
if (item == null && placeholderIconSet != null) {
|
||||
gui.icon(this.x, this.y, 2, 2, 0, 0.2f, placeholderIconSet, placeholderIconSetRow, placeholderIconSetColumn, placeholderIconPaint);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
super.draw(screen, gui);
|
||||
|
||||
if (item != null && item instanceof ItemStack stack) {
|
||||
|
||||
@@ -46,6 +46,8 @@ public class LootWindow extends DecoratedWindow implements Inflatable {
|
||||
|
||||
this.loot = (Item[]) args[0];
|
||||
this.titleLbl.setText((String) args[1]);
|
||||
this.lootMenu.select(0, 0);
|
||||
this.lootMenu.focus();
|
||||
updateSlots();
|
||||
}
|
||||
|
||||
@@ -57,7 +59,7 @@ public class LootWindow extends DecoratedWindow implements Inflatable {
|
||||
this.loot = null;
|
||||
}
|
||||
|
||||
private void handleClick(Item item) {
|
||||
private void handleClick(ItemIconView slot, Item item) {
|
||||
if (item == null) {
|
||||
return;
|
||||
}
|
||||
@@ -66,7 +68,7 @@ public class LootWindow extends DecoratedWindow implements Inflatable {
|
||||
for (int i = 0; i < Enemy.MAX_LOOT; i++) {
|
||||
if (loot[i] == item) {
|
||||
loot[i] = null;
|
||||
slots[i].setItem(null);
|
||||
slot.setItem(null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
package com.bartlomiejpluta.demo.gui;
|
||||
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.gui.Component;
|
||||
import com.bartlomiejpluta.base.api.gui.GUI;
|
||||
import com.bartlomiejpluta.base.api.gui.Inflatable;
|
||||
import com.bartlomiejpluta.base.api.gui.Ref;
|
||||
import com.bartlomiejpluta.base.api.gui.*;
|
||||
import com.bartlomiejpluta.base.lib.gui.VOptionChoice;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class StartMenuWindow extends DecoratedWindow implements Inflatable {
|
||||
public class StartMenuWindow extends DecoratedWindow {
|
||||
|
||||
@Ref("new_game")
|
||||
@Getter
|
||||
@@ -28,7 +25,8 @@ public class StartMenuWindow extends DecoratedWindow implements Inflatable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInflate() {
|
||||
public void onOpen(WindowManager manager, Object[] args) {
|
||||
super.onOpen(manager, args);
|
||||
menu.select(0);
|
||||
menu.focus();
|
||||
}
|
||||
|
||||
@@ -39,6 +39,6 @@ public class Ammunition extends StackableItem implements Useable {
|
||||
|
||||
@Override
|
||||
public String usageName() {
|
||||
return "Equip";
|
||||
return "Arm";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,6 @@ public class MeleeWeapon extends BaseItem implements Weapon {
|
||||
|
||||
@Override
|
||||
public String usageName() {
|
||||
return "Equip";
|
||||
return "Arm";
|
||||
}
|
||||
}
|
||||
@@ -97,6 +97,6 @@ public class RangedWeapon extends BaseItem implements Weapon {
|
||||
|
||||
@Override
|
||||
public String usageName() {
|
||||
return "Equip";
|
||||
return "Arm";
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
fontSize="30f">Game Menu
|
||||
</base:Label>
|
||||
|
||||
<base:VOptionChoice width="relative">
|
||||
<base:VOptionChoice ref="menu" width="relative">
|
||||
<demo:Button
|
||||
ref="resume_game"
|
||||
font="A.fonts.roboto_regular.uid"
|
||||
|
||||
@@ -12,38 +12,40 @@
|
||||
<base:Label
|
||||
font="A.fonts.roboto_regular.uid"
|
||||
width="relative"
|
||||
alignment="top|center"
|
||||
alignment="top|left"
|
||||
red="1f"
|
||||
green="1f"
|
||||
blue="1f"
|
||||
alpha="0.5f"
|
||||
fontSize="30f">Equipment
|
||||
fontSize="30f">Inventory & Equipment
|
||||
</base:Label>
|
||||
|
||||
<base:HLayout>
|
||||
<base:VGridLayout columns="2" padding="20f" width="250f">
|
||||
<demo:ItemIconView ref="weapon" margin="5f"/>
|
||||
<demo:ItemIconView ref="ammo" margin="5f"/>
|
||||
</base:VGridLayout>
|
||||
<base:HLayout margin="0f" padding="0f">
|
||||
<base:HOptionChoice ref="layout">
|
||||
<base:VGridOptionChoice ref="equipment" columns="2" width="auto">
|
||||
<demo:ItemIconView ref="weapon" placeholder="Generic,5,10" margin="5f"/>
|
||||
<demo:ItemIconView ref="ammo" placeholder="Generic,8,10" margin="5f"/>
|
||||
</base:VGridOptionChoice>
|
||||
|
||||
<base:VGridOptionChoice ref="eq" columns="4" width="auto" height="auto">
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
</base:VGridOptionChoice>
|
||||
<base:VGridOptionChoice ref="inventory" columns="4" width="auto" height="auto">
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
<demo:ItemIconView margin="5f"/>
|
||||
</base:VGridOptionChoice>
|
||||
</base:HOptionChoice>
|
||||
|
||||
<base:VLayout height="relative" padding="20f" width="250f">
|
||||
<base:Label ref="item-name"
|
||||
@@ -63,7 +65,6 @@
|
||||
margin="5f"/>
|
||||
|
||||
</base:VLayout>
|
||||
|
||||
</base:HLayout>
|
||||
</base:VLayout>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user