chore: Some minor changes
This commit is contained in:
5
.idea/misc.xml
generated
5
.idea/misc.xml
generated
@@ -1,6 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="EntryPointsManager">
|
<component name="EntryPointsManager">
|
||||||
|
<list size="3">
|
||||||
|
<item index="0" class="java.lang.String" itemvalue="cz.jzitnik.annotations.EventHandler" />
|
||||||
|
<item index="1" class="java.lang.String" itemvalue="cz.jzitnik.annotations.ui.KeyboardPressHandler" />
|
||||||
|
<item index="2" class="java.lang.String" itemvalue="cz.jzitnik.annotations.ui.MouseHandler" />
|
||||||
|
</list>
|
||||||
<writeAnnotations>
|
<writeAnnotations>
|
||||||
<writeAnnotation name="cz.jzitnik.annotations.injectors.InjectConfig" />
|
<writeAnnotation name="cz.jzitnik.annotations.injectors.InjectConfig" />
|
||||||
<writeAnnotation name="cz.jzitnik.annotations.injectors.InjectDependency" />
|
<writeAnnotation name="cz.jzitnik.annotations.injectors.InjectDependency" />
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import cz.jzitnik.game.GameState;
|
|||||||
import cz.jzitnik.utils.DependencyManager;
|
import cz.jzitnik.utils.DependencyManager;
|
||||||
import cz.jzitnik.utils.GlobalIOHandlerRepository;
|
import cz.jzitnik.utils.GlobalIOHandlerRepository;
|
||||||
import cz.jzitnik.utils.events.AbstractEventHandler;
|
import cz.jzitnik.utils.events.AbstractEventHandler;
|
||||||
import cz.jzitnik.utils.events.EventManager;
|
|
||||||
|
|
||||||
@EventHandler(KeyboardPressEvent.class)
|
@EventHandler(KeyboardPressEvent.class)
|
||||||
public class KeyboardPressEventHandler extends AbstractEventHandler<KeyboardPressEvent> {
|
public class KeyboardPressEventHandler extends AbstractEventHandler<KeyboardPressEvent> {
|
||||||
@@ -16,9 +15,6 @@ public class KeyboardPressEventHandler extends AbstractEventHandler<KeyboardPres
|
|||||||
super(dm);
|
super(dm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@InjectDependency
|
|
||||||
private EventManager eventManager;
|
|
||||||
|
|
||||||
@InjectState
|
@InjectState
|
||||||
private GameState gameState;
|
private GameState gameState;
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,6 @@ public class MainRoom extends GameRoom {
|
|||||||
addObject(chest);
|
addObject(chest);
|
||||||
|
|
||||||
Zombie zombie = new Zombie(resourceManager, new RoomCords(100, 100));
|
Zombie zombie = new Zombie(resourceManager, new RoomCords(100, 100));
|
||||||
addMob(zombie);
|
//addMob(zombie);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,9 @@ import com.googlecode.lanterna.TextColor;
|
|||||||
import cz.jzitnik.annotations.Dependency;
|
import cz.jzitnik.annotations.Dependency;
|
||||||
import cz.jzitnik.annotations.injectors.InjectDependency;
|
import cz.jzitnik.annotations.injectors.InjectDependency;
|
||||||
import cz.jzitnik.annotations.injectors.InjectState;
|
import cz.jzitnik.annotations.injectors.InjectState;
|
||||||
import cz.jzitnik.annotations.ui.MouseHandler;
|
import cz.jzitnik.annotations.ui.*;
|
||||||
import cz.jzitnik.annotations.ui.MouseHandlerType;
|
|
||||||
import cz.jzitnik.annotations.ui.Render;
|
|
||||||
import cz.jzitnik.annotations.ui.UI;
|
|
||||||
import cz.jzitnik.events.InventoryRerender;
|
import cz.jzitnik.events.InventoryRerender;
|
||||||
|
import cz.jzitnik.events.KeyboardPressEvent;
|
||||||
import cz.jzitnik.events.MouseAction;
|
import cz.jzitnik.events.MouseAction;
|
||||||
import cz.jzitnik.game.GameState;
|
import cz.jzitnik.game.GameState;
|
||||||
import cz.jzitnik.game.ResourceManager;
|
import cz.jzitnik.game.ResourceManager;
|
||||||
@@ -108,6 +106,19 @@ public class Inventory {
|
|||||||
offsetX = (maxX / 2) - (INVENTORY_WIDTH / 2);
|
offsetX = (maxX / 2) - (INVENTORY_WIDTH / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@KeyboardPressHandler(character = 'q')
|
||||||
|
@KeyboardPressHandler(character = 'Q')
|
||||||
|
public boolean handleItemDrop(KeyboardPressEvent ignored) {
|
||||||
|
if (inventoryState.selectedItem == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("Dropping item!");
|
||||||
|
// TODO: Dropping items on a ground
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@MouseHandler(MouseHandlerType.CLICK)
|
@MouseHandler(MouseHandlerType.CLICK)
|
||||||
public boolean handleClick(MouseAction mouseAction) {
|
public boolean handleClick(MouseAction mouseAction) {
|
||||||
inventoryState.onNextDragTakeItemOnIndex = -1;
|
inventoryState.onNextDragTakeItemOnIndex = -1;
|
||||||
@@ -149,6 +160,10 @@ public class Inventory {
|
|||||||
inventoryState.isGonnaDoubleClick = false;
|
inventoryState.isGonnaDoubleClick = false;
|
||||||
inventoryState.selectedItem = -1;
|
inventoryState.selectedItem = -1;
|
||||||
|
|
||||||
|
if (inventory[itemClickedOnIndex] == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (inventory[itemClickedOnIndex].getType() instanceof InteractableItem item) {
|
if (inventory[itemClickedOnIndex].getType() instanceof InteractableItem item) {
|
||||||
switch (item.interact(dependencyManager, stateManager)) {
|
switch (item.interact(dependencyManager, stateManager)) {
|
||||||
case CLEAR_ITEM -> {
|
case CLEAR_ITEM -> {
|
||||||
|
|||||||
@@ -131,16 +131,16 @@ public class Grid {
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getItemIndexAt(int x, int y) {
|
|
||||||
return getItemIndexAt(x, y, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates which item index corresponds to the given x/y coordinates relative to the Grid's top-left.
|
* Calculates which item index corresponds to the given x/y coordinates relative to the Grid's top-left.
|
||||||
* @param x X coordinate relative to the Grid (0 is left edge of the outer border)
|
* @param x X coordinate relative to the Grid (0 is left edge of the outer border)
|
||||||
* @param y Y coordinate relative to the Grid (0 is top edge of the outer border)
|
* @param y Y coordinate relative to the Grid (0 is top edge of the outer border)
|
||||||
* @return The index of the item, or -1 if the click was on a border/background/out of bounds.
|
* @return The index of the item, or -1 if the click was on a border/background/out of bounds.
|
||||||
*/
|
*/
|
||||||
|
public int getItemIndexAt(int x, int y) {
|
||||||
|
return getItemIndexAt(x, y, false);
|
||||||
|
}
|
||||||
|
|
||||||
public int getItemIndexAt(int x, int y, boolean ignoreInnerBorder) {
|
public int getItemIndexAt(int x, int y, boolean ignoreInnerBorder) {
|
||||||
if (x < 0 || x >= gridWidth || y < 0 || y >= gridHeight) {
|
if (x < 0 || x >= gridWidth || y < 0 || y >= gridHeight) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package cz.jzitnik.utils;
|
|||||||
|
|
||||||
import cz.jzitnik.annotations.Dependency;
|
import cz.jzitnik.annotations.Dependency;
|
||||||
import cz.jzitnik.annotations.State;
|
import cz.jzitnik.annotations.State;
|
||||||
import cz.jzitnik.annotations.injectors.InjectDependency;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.reflections.Reflections;
|
import org.reflections.Reflections;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user