Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inventory and spellview modifications #211

Merged
merged 12 commits into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/FUNDING.yml

This file was deleted.

1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ jdk:
- openjdk12

script:
- ./gradlew clean
- ./gradlew compileJava
59 changes: 58 additions & 1 deletion client/src/game/managers/AOInputProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,24 @@ private void doActions(int keycode) {
// Toggle between Windowed Mode and Fullscreen.
gui.toggleFullscreen();
break;
case Input.Keys.NUM_1:
useq(0);
break;
case Input.Keys.NUM_2:
useq(1);
break;
case Input.Keys.NUM_3:
useq(2);
break;
case Input.Keys.NUM_4:
useq(3);
break;
case Input.Keys.NUM_5:
useq(4);
break;
case Input.Keys.NUM_6:
useq(5);
break;
}
}

Expand Down Expand Up @@ -208,6 +226,43 @@ private void doAlternativeActions(int keycode) {
// Toggle between Windowed Mode and Fullscreen.
gui.toggleFullscreen();
break;
case Input.Keys.NUM_1:
useq(0);
break;
case Input.Keys.NUM_2:
useq(1);
break;
case Input.Keys.NUM_3:
useq(2);
break;
case Input.Keys.NUM_4:
useq(3);
break;
case Input.Keys.NUM_5:
useq(4);
break;
case Input.Keys.NUM_6:
useq(5);
break;
}
}

private void useq(int x) {
int base;
if (Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT) || Gdx.input.isKeyPressed(Input.Keys.SHIFT_RIGHT )) {
if (gui.getActionBar ().getState().equals("INVENTORY")) {
if (gui.getInventory ( ).getSelected ( ).isEmpty ( )) {
base = 0;
} else {
base = gui.getInventory ( ).selectedIndex ( );
}
gui.getInventoryQuickBar ( ).addItemsIQB ( base, x );
}
if (gui.getActionBar ().getState().equals("SPELL")) {
gui.getSpellView ( ).addSpelltoSpellview ( gui.getSpellViewExpanded ( ).getSelected ( ), x );
}
} else {
GameScreen.getClient().sendToAll(new ItemActionRequest(gui.getInventoryQuickBar ().getGBases(x)));
}
}

Expand Down Expand Up @@ -261,11 +316,13 @@ private void toggleMeditate() {
}

private void toggleInventory() {
gui.getInventory().setVisible(!gui.getInventory().isVisible());
gui.getInventoryQuickBar ().setVisible(!gui.getInventoryQuickBar ().isVisible());
gui.getActionBar ().setExpandButtonVisible();
}

private void toggleSpells() {
gui.getSpellView().setVisible(!gui.getSpellView().isVisible());
gui.getActionBar ().setExpandButtonVisible();
}

}
2 changes: 2 additions & 0 deletions client/src/game/screens/GameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public static void setPlayer(int player) {
GameScreen.player = player;
world.getSystem(GUI.class).getInventory().updateUserInventory(0);
world.getSystem(GUI.class).getSpellView().updateSpells();
world.getSystem(GUI.class).getSpellViewExpanded ().updateSpells();

}

public static KryonetClientMarshalStrategy getClient() {
Expand Down
68 changes: 63 additions & 5 deletions client/src/game/ui/ActionBar.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
package game.ui;

import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.actions.VisibleAction;
import com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import game.ui.SwitchButtons.ActionSwitchListener;
import game.ui.SwitchButtons.State;
import game.utils.Skins;


public class ActionBar extends Table implements ActionSwitchListener {

private static final float PAD_TOP = -17f;
private final ClickListener mouseListener;
private SwitchButtons buttons;
private SpellView spellView;
private SpellViewExpanded spellViewExpanded;
private Inventory inventory;
private InventoryQuickBar inventoryQuickBar;
private ImageTextButton expandButton;
private String currentState = "INVENTORY";

ActionBar() {
super(Skins.COMODORE_SKIN);
Expand All @@ -22,29 +31,61 @@ public class ActionBar extends Table implements ActionSwitchListener {
buttons.addListener(mouseListener);
spellView = new SpellView();
inventory = new Inventory();
inventoryQuickBar =new InventoryQuickBar ();
spellViewExpanded = new SpellViewExpanded ();
expandButton = new ImageTextButton ("-", Skins.COMODORE_SKIN, "inventory-expand-collapse");
expandButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
getInventory ().setVisible(!getInventory ().isVisible ());
getSpellViewExpanded ().setVisible ( !getSpellViewExpanded ().isVisible () );
if (getInventory ().isVisible ()){
expandButton.setText ( "-" );
}else{
expandButton.setText ( "+" );
}

}
});

add(buttons).top().row();
add().top();
add(buttons).top().right ().row();
add(inventory).padTop(PAD_TOP);
add( inventoryQuickBar ).padTop(PAD_TOP).right ().row ();
add().top();
add( expandButton ).right ().padTop (-10f);
}

@Override
public void notify(State state) {
switch (state) {
case SPELLS:
clear();
add().top();
add(buttons).top().right().row();
add(spellView).padTop(PAD_TOP).right();
add( spellViewExpanded ).padTop(PAD_TOP).right ();
add(spellView).padTop(PAD_TOP).right().row ();
add();
add( expandButton ).padTop (-10f).right ();
expandButton.setVisible(spellView.isVisible ());
currentState = "SPELL";
break;
case INVENTORY:
clear();
add(buttons).top().row();
add(inventory).padTop(PAD_TOP);
add().top();
add(buttons).top().right ().row();
add(inventory).padTop(PAD_TOP).right ();
add( inventoryQuickBar ).padTop(PAD_TOP).right ().row ();
add();
add( expandButton ).padTop (-10f).right () ;
expandButton.setVisible(inventoryQuickBar.isVisible ());
currentState = "INVENTORY";
break;
}
}

public boolean isOver() {
return getInventory().isOver() || getSpellView().isOver() || mouseListener.isOver();
return getInventory().isOver() || getSpellView().isOver() || getInventoryQuickBar ().isOver() || getSpellViewExpanded ().isOver () || mouseListener.isOver() || expandButton.isOver ();
}

public void toggle() {
Expand All @@ -59,11 +100,28 @@ protected SpellView getSpellView() {
return spellView;
}

public InventoryQuickBar getInventoryQuickBar() {
return inventoryQuickBar;
}

public SpellViewExpanded getSpellViewExpanded(){
return spellViewExpanded;
}


public void scrolled(int amount) {
if (getInventory().isOver()) {
getInventory().scrolled(amount);
} else if (getSpellView().isOver()) {
// TODO
}
}

public void setExpandButtonVisible() {
expandButton.setVisible (!expandButton.isVisible ());
}

public String getState() {
return currentState;
}
}
9 changes: 8 additions & 1 deletion client/src/game/ui/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public ActionBar getActionBar() {
public Inventory getInventory() {
return actionBar.getInventory();
}
public InventoryQuickBar getInventoryQuickBar() {
return actionBar.getInventoryQuickBar ();
}

public DialogText getDialog() {
return dialog;
Expand All @@ -78,6 +81,10 @@ public SpellView getSpellView() {
return getActionBar().getSpellView();
}

public SpellViewExpanded getSpellViewExpanded(){
return getActionBar ().getSpellViewExpanded ();
}

public void takeScreenshot() {
AOAssetManager assetManager = AOGame.getGlobalAssetManager();
String screenshotPath = "Screenshots/Screenshot-" + LocalDateTime.now() + ".png";
Expand Down Expand Up @@ -149,7 +156,7 @@ private Table createUserStatus(Table table) {

private Table createActionBar(Table table) {
actionBar = new ActionBar();
table.add(actionBar).right().expandY();
table.add(actionBar).right().expandY().expandX ();
return actionBar;
}

Expand Down
39 changes: 31 additions & 8 deletions client/src/game/ui/Inventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import entity.character.info.Inventory.Item;
Expand All @@ -18,6 +17,8 @@
import shared.network.inventory.InventoryUpdate;
import shared.network.inventory.ItemActionRequest;
import shared.objects.types.Obj;
import shared.objects.types.SpellObj;
import shared.objects.types.Type;

import java.util.ArrayList;
import java.util.Optional;
Expand All @@ -27,28 +28,33 @@

public class Inventory extends Window {

static final int COLUMNS = 6;
private static final int ROWS = 1;
static final int COLUMNS = 5;
private static final int ROWS = 4;
private static final int SIZE = COLUMNS * ROWS;
private final ClickListener mouseListener;
private int base;
private GUI gui;

private ArrayList<Slot> slots;
private Optional<Slot> selected = Optional.empty();
private Optional<Slot> dragging = Optional.empty();
private Optional<Slot> origin = Optional.empty();
private InventoryQuickBar inventoryQuickBar;

Inventory() {
super("", Skins.COMODORE_SKIN, "inventory");
int columnsCounter = 1;
setMovable(false);
slots = new ArrayList<>();
for (int i = 0; i < SIZE; i++) {
Slot newSlot = new Slot();
slots.add(newSlot);
add(slots.get(i)).width(Slot.SIZE).height(Slot.SIZE).row();
if (i < SIZE - 1) {
add(new Image(getSkin().getDrawable("separator"))).row();
add(slots.get(i)).width(Slot.SIZE).height(Slot.SIZE);
if (columnsCounter > ROWS -1) {
row();
columnsCounter = 0;
}
columnsCounter++;
}
mouseListener = getMouseListener();
addListener(mouseListener);
Expand All @@ -72,6 +78,7 @@ public void clicked(InputEvent event, float x, float y) {
slot.getItem().ifPresent(item -> {
if (getTapCount() >= 2) {
GameScreen.getClient().sendToAll(new ItemActionRequest(slots.indexOf(slot)));
addSpellSVE(slot);
}
});
});
Expand Down Expand Up @@ -187,12 +194,28 @@ public Optional<Slot> getSelected() {

public int selectedIndex() {
assert (selected.isPresent());
return slots.indexOf(selected.get());
return base + slots.indexOf(selected.get());
}

private int draggingIndex() {
assert (dragging.isPresent());
return slots.indexOf(dragging.get());
return base + slots.indexOf(dragging.get());
}


private void addSpellSVE(Slot slot){ //funcion provisoria hasta q encuentre como hacerlo a desde el servidor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podes tomar como ejemplo cuando se agarra un item

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok gracias despues le echo un ojo a ver si puedo resolver esto con mis escasos conocimientos y neuronas XD

Optional< Item > item = slot.getItem ();
int objID = item.map ( item1 -> item1.objId ).orElse ( -1 );
ObjectHandler objectHandler = WorldUtils.getWorld().orElse(null).getSystem(ObjectHandler.class);
Optional<Obj> object = objectHandler.getObject(objID);
object.ifPresent(obj -> {
if (obj.getType().equals (Type.SPELL)) {
SpellObj spellObj = (SpellObj) obj;
if (E (GameScreen.getPlayer ()).charHeroHeroId () != 0 ) {
GameScreen.world.getSystem (GUI.class).getSpellViewExpanded ().newSpellAdd (spellObj.getSpellIndex ());
}
}
});
}

public boolean isOver() {
Expand Down
Loading