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

Convert MapScreen and WaypointCreationScreen to NUI #669

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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void drawFactionNames(SolGame game, UiDrawer uiDrawer, SolInputManager in
isPressed = !isPressed;
}
// angle must be zero as the camera angles on planets mess up the text display
if (isPressed && camera.getAngle() == 0 && !inputManager.isScreenOn(game.getScreens().mapScreen)) {
if (isPressed && camera.getAngle() == 0 && !game.getSolApplication().getNuiManager().hasScreen(game.getScreens().mapScreen)) {
for (SolObject obj : objManager.getObjects()) {
if (obj instanceof SolShip) {
SolShip ship = (SolShip) obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,49 @@

package org.destinationsol.game.screens;

import org.destinationsol.GameOptions;
import org.destinationsol.SolApplication;
import org.destinationsol.game.FactionInfo;
import org.destinationsol.game.Hero;
import org.destinationsol.game.SolGame;
import org.destinationsol.game.item.ItemContainer;
import org.destinationsol.game.item.SolItem;
import org.destinationsol.game.ship.SolShip;
import org.destinationsol.ui.SolInputManager;
import org.destinationsol.ui.SolUiControl;
import org.destinationsol.ui.nui.screens.InventoryScreen;
import org.destinationsol.ui.nui.screens.TalkScreen;
import org.destinationsol.ui.nui.widgets.UIWarnButton;
import org.terasology.nui.backends.libgdx.GDXInputUtil;
import org.terasology.nui.widgets.UIButton;

/**
* This screen allows you to purchase items for the hero's ship.
* The purchased items are moved to the hero's inventory and the cost deducted from the hero's money.
*/
public class BuyItemsScreen extends InventoryOperationsScreen {
public final SolUiControl buyControl;
private final UIButton[] actionButtons = new UIButton[1];

@Override
public void initialise(SolApplication solApplication, InventoryScreen inventoryScreen) {
UIWarnButton buyButton = new UIWarnButton();
buyButton.setText("Buy");
buyButton.setKey(GDXInputUtil.GDXToNuiKey(solApplication.getOptions().getKeyBuyItem()));
buyButton.subscribe(button -> {
SolGame game = solApplication.getGame();
Hero hero = game.getHero();
TalkScreen talkScreen = game.getScreens().talkScreen;
SolShip target = talkScreen.getTarget();
SolItem selectedItem = inventoryScreen.getSelectedItem();
if (selectedItem == null) {
return;
}

BuyItemsScreen(InventoryScreen inventoryScreen, GameOptions gameOptions) {
buyControl = new SolUiControl(inventoryScreen.itemCtrl(0), true, gameOptions.getKeyBuyItem());
buyControl.setDisplayName("Buy");
controls.add(buyControl);
target.getTradeContainer().getItems().remove(selectedItem);
hero.getItemContainer().add(selectedItem);
hero.setMoney(hero.getMoney() - selectedItem.getPrice());
FactionInfo.setDisposition(target.getFactionID(), 1);

inventoryScreen.updateItemRows();
});
actionButtons[0] = buyButton;
}

@Override
Expand All @@ -48,28 +72,27 @@ public String getHeader() {
}

@Override
public void updateCustom(SolApplication solApplication, SolInputManager.InputPointer[] inputPointers, boolean clickedOutside) {
public UIButton[] getActionButtons() {
return actionButtons;
}

public UIWarnButton getBuyControl() {
return (UIWarnButton) actionButtons[0];
}

@Override
public void update(SolApplication solApplication, InventoryScreen inventoryScreen) {
SolGame game = solApplication.getGame();
InventoryScreen is = game.getScreens().inventoryScreen;
Hero hero = game.getHero();
TalkScreen talkScreen = game.getScreens().talkScreen;
SolShip target = talkScreen.getTarget();
if (talkScreen.isTargetFar(hero)) {
solApplication.getInputManager().setScreen(solApplication, game.getScreens().oldMainGameScreen);
solApplication.getNuiManager().removeScreen(inventoryScreen);
return;
}
SolItem selItem = is.getSelectedItem();
SolItem selItem = inventoryScreen.getSelectedItem();
boolean enabled = selItem != null && hero.getMoney() >= selItem.getPrice() && hero.getItemContainer().canAdd(selItem);
buyControl.setDisplayName(enabled ? "Buy" : "---");
buyControl.setEnabled(enabled);
if (!enabled) {
return;
}
if (buyControl.isJustOff()) {
target.getTradeContainer().getItems().remove(selItem);
hero.getItemContainer().add(selItem);
hero.setMoney(hero.getMoney() - selItem.getPrice());
FactionInfo.setDisposition(target.getFactionID(), 1);
}
UIButton buyButton = actionButtons[0];
buyButton.setText(enabled ? "Buy" : "---");
buyButton.setEnabled(enabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.destinationsol.game.screens;

import com.badlogic.gdx.math.Vector2;
import org.destinationsol.GameOptions;
import org.destinationsol.SolApplication;
import org.destinationsol.game.Hero;
import org.destinationsol.game.SolGame;
Expand All @@ -29,17 +28,33 @@
import org.destinationsol.game.ship.SolShip;
import org.destinationsol.game.ship.hulls.Hull;
import org.destinationsol.game.ship.hulls.HullConfig;
import org.destinationsol.ui.SolInputManager;
import org.destinationsol.ui.SolUiControl;
import org.destinationsol.ui.nui.screens.InventoryScreen;
import org.destinationsol.ui.nui.screens.TalkScreen;
import org.destinationsol.ui.nui.widgets.KeyActivatedButton;
import org.terasology.nui.backends.libgdx.GDXInputUtil;
import org.terasology.nui.widgets.UIButton;

/**
* This screen allows you to purchase a new ship for the hero.
* The hero's previous ship will be replaced with the purchased ship and the cost deducted from the hero's money.
*/
public class ChangeShipScreen extends InventoryOperationsScreen {
private final SolUiControl changeControl;
private final UIButton[] actionButtons = new UIButton[1];

@Override
public void initialise(SolApplication solApplication, InventoryScreen inventoryScreen) {
KeyActivatedButton changeButton = new KeyActivatedButton();
changeButton.setText("Change");
changeButton.setKey(GDXInputUtil.GDXToNuiKey(solApplication.getOptions().getKeyChangeShip()));
changeButton.subscribe(button -> {
SolGame game = solApplication.getGame();
Hero hero = game.getHero();
SolItem selectedItem = inventoryScreen.getSelectedItem();

ChangeShipScreen(InventoryScreen inventoryScreen, GameOptions gameOptions) {
changeControl = new SolUiControl(inventoryScreen.itemCtrl(0), true, gameOptions.getKeyChangeShip());
changeControl.setDisplayName("Change");
controls.add(changeControl);
hero.setMoney(hero.getMoney() - selectedItem.getPrice());
changeShip(game, hero, (ShipItem) selectedItem);
});
actionButtons[0] = changeButton;
}

@Override
Expand All @@ -53,38 +68,39 @@ public String getHeader() {
}

@Override
public void updateCustom(SolApplication solApplication, SolInputManager.InputPointer[] inputPointers, boolean clickedOutside) {
public UIButton[] getActionButtons() {
return actionButtons;
}

@Override
public void update(SolApplication solApplication, InventoryScreen inventoryScreen) {
SolGame game = solApplication.getGame();
InventoryScreen is = game.getScreens().inventoryScreen;
Hero hero = game.getHero();
TalkScreen talkScreen = game.getScreens().talkScreen;
if (talkScreen.isTargetFar(hero)) {
solApplication.getInputManager().setScreen(solApplication, game.getScreens().oldMainGameScreen);
return;
}
SolItem selItem = is.getSelectedItem();

UIButton changeButton = actionButtons[0];

SolItem selItem = inventoryScreen.getSelectedItem();
if (selItem == null) {
changeControl.setDisplayName("---");
changeControl.setEnabled(false);
changeButton.setText("---");
changeButton.setEnabled(false);
return;
}
boolean enabled = hasMoneyToBuyShip(hero, selItem);
boolean sameShip = isSameShip(hero, selItem);
if (enabled && !sameShip) {
changeControl.setDisplayName("Change");
changeControl.setEnabled(true);
changeButton.setText("Change");
changeButton.setEnabled(true);
} else if (enabled && sameShip) {
changeControl.setDisplayName("Have it");
changeControl.setEnabled(false);
return;
changeButton.setText("Have it");
changeButton.setEnabled(false);
} else {
changeControl.setDisplayName("---");
changeControl.setEnabled(false);
return;
}
if (changeControl.isJustOff()) {
hero.setMoney(hero.getMoney() - selItem.getPrice());
changeShip(game, hero, (ShipItem) selItem);
changeButton.setText("---");
changeButton.setEnabled(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,68 +15,95 @@
*/
package org.destinationsol.game.screens;

import org.destinationsol.GameOptions;
import org.destinationsol.SolApplication;
import org.destinationsol.game.SolGame;
import org.destinationsol.game.item.ItemContainer;
import org.destinationsol.game.item.MercItem;
import org.destinationsol.game.item.SolItem;
import org.destinationsol.game.ship.SolShip;
import org.destinationsol.ui.SolInputManager;
import org.destinationsol.ui.SolUiControl;
import org.destinationsol.ui.nui.NUIManager;
import org.destinationsol.ui.nui.screens.InventoryScreen;
import org.destinationsol.ui.nui.widgets.KeyActivatedButton;
import org.terasology.nui.backends.libgdx.GDXInputUtil;
import org.terasology.nui.widgets.UIButton;

/**
* This screen shows an overview of all the mercenaries that the hero has hired.
* You can manage each mercenary's independent inventory from here, as well as selecting their equipped items.
*/
public class ChooseMercenaryScreen extends InventoryOperationsScreen {
private final SolUiControl giveControl;
private final SolUiControl takeControl;
private final SolUiControl equipControl;
private final UIButton[] actionButtons = new UIButton[3];
private final ItemContainer EMPTY_ITEM_CONTAINER = new ItemContainer();

ChooseMercenaryScreen(InventoryScreen inventoryScreen, GameOptions gameOptions) {
giveControl = new SolUiControl(inventoryScreen.itemCtrl(0), true, gameOptions.getKeyShoot());
giveControl.setDisplayName("Give Items");
controls.add(giveControl);
public ChooseMercenaryScreen() {
}

@Override
public void initialise(SolApplication solApplication, InventoryScreen inventoryScreen) {
KeyActivatedButton giveButton = new KeyActivatedButton();
giveButton.setText("Give Items");
giveButton.setKey(GDXInputUtil.GDXToNuiKey(solApplication.getOptions().getKeyShoot()));
giveButton.subscribe(button -> {
SolItem selectedItem = inventoryScreen.getSelectedItem();
SolInputManager inputManager = solApplication.getInputManager();
NUIManager nuiManager = solApplication.getNuiManager();

SolShip solship = ((MercItem) selectedItem).getSolShip();
inputManager.setScreen(solApplication, solApplication.getGame().getScreens().oldMainGameScreen);
nuiManager.removeScreen(inventoryScreen);
inventoryScreen.getGiveItems().setTarget(solship);
inventoryScreen.setOperations(inventoryScreen.getGiveItems());
nuiManager.pushScreen(inventoryScreen);
});
actionButtons[0] = giveButton;

KeyActivatedButton takeButton = new KeyActivatedButton();
takeButton.setText("Take Items");
takeButton.setKey(GDXInputUtil.GDXToNuiKey(solApplication.getOptions().getKeyShoot2()));
takeButton.subscribe(button -> {
SolItem selectedItem = inventoryScreen.getSelectedItem();
SolInputManager inputManager = solApplication.getInputManager();
NUIManager nuiManager = solApplication.getNuiManager();

takeControl = new SolUiControl(inventoryScreen.itemCtrl(1), true, gameOptions.getKeyShoot2());
takeControl.setDisplayName("Take Items");
controls.add(takeControl);

equipControl = new SolUiControl(inventoryScreen.itemCtrl(2), true, gameOptions.getKeyDrop());
equipControl.setDisplayName("Equip Items");
controls.add(equipControl);
SolShip solship = ((MercItem) selectedItem).getSolShip();
inputManager.setScreen(solApplication, solApplication.getGame().getScreens().oldMainGameScreen);
inventoryScreen.getTakeItems().setTarget(solship);
nuiManager.removeScreen(inventoryScreen);
inventoryScreen.setOperations(inventoryScreen.getTakeItems());
nuiManager.pushScreen(inventoryScreen);
});
actionButtons[1] = takeButton;

KeyActivatedButton equipButton = new KeyActivatedButton();
equipButton.setText("Equip Items");
equipButton.setKey(GDXInputUtil.GDXToNuiKey(solApplication.getOptions().getKeyDrop()));
equipButton.subscribe(button -> {
SolItem selectedItem = inventoryScreen.getSelectedItem();
SolInputManager inputManager = solApplication.getInputManager();
NUIManager nuiManager = solApplication.getNuiManager();

SolShip solship = ((MercItem) selectedItem).getSolShip();
inputManager.setScreen(solApplication, solApplication.getGame().getScreens().oldMainGameScreen);
nuiManager.removeScreen(inventoryScreen);
inventoryScreen.getShowInventory().setTarget(solship);
inventoryScreen.setOperations(inventoryScreen.getShowInventory());
nuiManager.pushScreen(inventoryScreen);
});
actionButtons[2] = equipButton;
}

@Override
public void updateCustom(SolApplication solApplication, SolInputManager.InputPointer[] inputPointers, boolean clickedOutside) {
SolGame game = solApplication.getGame();
InventoryScreen is = game.getScreens().inventoryScreen;
SolInputManager inputMan = solApplication.getInputManager();
GameScreens screens = game.getScreens();
SolItem selItem = is.getSelectedItem();
boolean selNull = selItem != null;
public void update(SolApplication solApplication, InventoryScreen inventoryScreen) {
boolean selNull = inventoryScreen.getSelectedItem() != null;

giveControl.setEnabled(selNull);
takeControl.setEnabled(selNull);
equipControl.setEnabled(selNull);
UIButton giveButton = actionButtons[0];
UIButton takeButton = actionButtons[1];
UIButton equipButton = actionButtons[2];

if (giveControl.isJustOff() && selNull) {
SolShip solship = ((MercItem) selItem).getSolShip();
inputMan.setScreen(solApplication, screens.oldMainGameScreen);
is.giveItemsScreen.setTarget(solship);
is.setOperations(is.giveItemsScreen);
inputMan.addScreen(solApplication, is);
} else if (takeControl.isJustOff() && selNull) {
SolShip solship = ((MercItem) selItem).getSolShip();
inputMan.setScreen(solApplication, screens.oldMainGameScreen);
is.takeItems.setTarget(solship);
is.setOperations(is.takeItems);
inputMan.addScreen(solApplication, is);
} else if (equipControl.isJustOff() && selNull) {
SolShip solship = ((MercItem) selItem).getSolShip();
inputMan.setScreen(solApplication, screens.oldMainGameScreen);
is.showInventory.setTarget(solship);
is.setOperations(is.showInventory);
inputMan.addScreen(solApplication, is);
}
giveButton.setEnabled(selNull);
takeButton.setEnabled(selNull);
equipButton.setEnabled(selNull);
}

@Override
Expand All @@ -95,4 +122,8 @@ public String getHeader() {
return "Mercenaries:";
}

@Override
public UIButton[] getActionButtons() {
return actionButtons;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import org.destinationsol.ui.SolLayouts;
import org.destinationsol.ui.nui.screens.MenuScreen;
import org.destinationsol.ui.nui.screens.TalkScreen;
import org.destinationsol.ui.nui.screens.InventoryScreen;
import org.destinationsol.ui.nui.screens.MapScreen;
import org.destinationsol.ui.nui.screens.WaypointCreationScreen;

import javax.inject.Inject;

Expand All @@ -44,14 +47,15 @@ public GameScreens(SolApplication cmp, Context context) {
boolean isMobile = cmp.isMobile();
if (!isMobile) {
mainGameScreen = (org.destinationsol.ui.nui.screens.MainGameScreen) cmp.getNuiManager().createScreen(NUI_MAIN_GAME_SCREEN_DESKTOP_URI);
mapScreen = (MapScreen) cmp.getNuiManager().createScreen("engine:mapScreen_desktop");
} else {
mainGameScreen = (org.destinationsol.ui.nui.screens.MainGameScreen) cmp.getNuiManager().createScreen(NUI_MAIN_GAME_SCREEN_MOBILE_URI);
mapScreen = (MapScreen) cmp.getNuiManager().createScreen("engine:mapScreen_mobile");
}
mapScreen = new MapScreen(rightPaneLayout, cmp.isMobile(), cmp.getOptions());
menuScreen = (MenuScreen) cmp.getNuiManager().createScreen("engine:menuScreen");
inventoryScreen = new InventoryScreen(cmp.getOptions());
inventoryScreen = (InventoryScreen) cmp.getNuiManager().createScreen("engine:inventoryScreen");
talkScreen = (TalkScreen) cmp.getNuiManager().createScreen("engine:talkScreen");
waypointCreationScreen = new WaypointCreationScreen(layouts.menuLayout, cmp.getOptions(), mapScreen);
waypointCreationScreen = (WaypointCreationScreen) cmp.getNuiManager().createScreen("engine:waypointCreationScreen");
consoleScreen = new ConsoleScreen(context.get(Console.class));
}

Expand Down
Loading