Skip to content
Closed
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
7 changes: 5 additions & 2 deletions engine/src/main/java/org/destinationsol/SolApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public void play(boolean tut, String shipName, boolean isNewGame, WorldConfig wo

factionDisplay = new FactionDisplay(context.get(SolCam.class));
nuiManager.removeScreen(menuScreens.loading);
inputManager.setScreen(this, solGame.getScreens().mainGameScreen);
inputManager.setScreen(this, solGame.getScreens().oldMainGameScreen);
}

public SolInputManager getInputManager() {
Expand Down Expand Up @@ -402,9 +402,12 @@ public SolLayouts getLayouts() {

public void finishGame() {
solGame.onGameEnd(context);
solGame = null;

// TODO: remove the following line when all screens have been ported to use NUI
inputManager.setScreen(this, null);
inputManager.update(this); // Force an update to remove all the InputManager UI screens

solGame = null;
nuiManager.pushScreen(menuScreens.main);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private Pilot createPilot(SolGame game, boolean isMouseControl) {
if (isMouseControl) {
return new AiPilot(new BeaconDestProvider(), true, Faction.LAANI, false, "you", Const.AI_DET_DIST);
} else {
return new UiControlledPilot(game.getScreens().getMainGameScreen().getShipControl());
return new UiControlledPilot(game.getScreens().getOldMainGameScreen().getShipControl());
}
}

Expand Down
2 changes: 1 addition & 1 deletion engine/src/main/java/org/destinationsol/game/SolCam.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void applyPos(float posX, float posY) {
}

private void applyInput(SolGame game) {
MainGameScreen screen = game.getScreens().mainGameScreen;
MainGameScreen screen = game.getScreens().oldMainGameScreen;
boolean d = screen.isCameraDown();
boolean u = screen.isCameraUp();
boolean l = screen.isCameraLeft();
Expand Down
18 changes: 2 additions & 16 deletions engine/src/main/java/org/destinationsol/game/SolGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.destinationsol.Const;
import org.destinationsol.GameOptions;
import org.destinationsol.SolApplication;
import org.destinationsol.assets.Assets;
import org.destinationsol.assets.sound.OggSoundManager;
import org.destinationsol.assets.sound.SpecialSounds;
import org.destinationsol.common.DebugCol;
Expand Down Expand Up @@ -68,12 +67,9 @@
import org.destinationsol.ui.TutorialManager;
import org.destinationsol.ui.UiDrawer;
import org.destinationsol.ui.Waypoint;
import org.destinationsol.ui.nui.screens.MainGameScreen;
import org.destinationsol.util.InjectionHelper;
import org.destinationsol.world.GalaxyBuilder;
import org.terasology.gestalt.assets.ResourceUrn;
import org.terasology.gestalt.entitysystem.entity.EntityRef;
import org.terasology.nui.asset.UIElement;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -82,9 +78,6 @@
import java.util.TreeMap;

public class SolGame {
private static final String NUI_MAIN_GAME_SCREEN_DESKTOP_URI = "engine:mainGameScreen_desktop";
private static final String NUI_MAIN_GAME_SCREEN_MOBILE_URI = "engine:mainGameScreen_mobile";

private final GameScreens gameScreens;
private final SolCam solCamReference;
private final ObjectManager objectManager;
Expand Down Expand Up @@ -117,7 +110,6 @@ public class SolGame {
private final PlanetConfigManager planetConfigManager;
private final MazeConfigManager mazeConfigManager;
private final BeltConfigManager beltConfigManager;
private final MainGameScreen mainGameScreen;
private Hero hero;
private float timeStep;
private float time;
Expand Down Expand Up @@ -163,14 +155,8 @@ public SolGame(String shipName, boolean isTutorial, boolean isNewGame, CommonDra
gameScreens = new GameScreens(solApplication, context);

boolean isMobile = solApplication.isMobile();
if (!isMobile) {
mainGameScreen = (MainGameScreen) solApplication.getNuiManager().createScreen(NUI_MAIN_GAME_SCREEN_DESKTOP_URI);
} else {
mainGameScreen = (MainGameScreen) solApplication.getNuiManager().createScreen(NUI_MAIN_GAME_SCREEN_MOBILE_URI);
}

if (isTutorial) {
tutorialManager = new TutorialManager(gameScreens, mainGameScreen, isMobile, solApplication.getOptions(), this);
tutorialManager = new TutorialManager(gameScreens, gameScreens.mainGameScreen, isMobile, solApplication.getOptions(), this);
context.put(TutorialManager.class, tutorialManager);
} else {
tutorialManager = null;
Expand Down Expand Up @@ -296,7 +282,7 @@ public void run() {
}
}, 0, 30);
gameScreens.consoleScreen.init(this);
solApplication.getNuiManager().pushScreen(mainGameScreen);
solApplication.getNuiManager().pushScreen(gameScreens.mainGameScreen);
if (isTutorial) {
tutorialManager.start();
}
Expand Down
32 changes: 30 additions & 2 deletions engine/src/main/java/org/destinationsol/game/item/ItemManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,36 @@ public List<ItemConfig> parseItems(String items) {
return result;
}

/**
* Returns a sample for the specified item. The name should be in the {@link org.terasology.gestalt.assets.ResourceUrn} format.
* @param name the name of the item to sample.
* @return the sample, if present, or null.
*/
public SolItem getExample(String name) {
return myM.get(name);
SolItem example = myM.get(name);
if (example == null) {
// TODO: Temporary hacky way!
try {
if (name.endsWith("Charge")) {
AbilityCharge.Config.load(name, this, myTypes);
} else if (name.endsWith("Armor")) {
Armor.Config.load(name, this, soundManager, myTypes);
} else if (name.endsWith("Clip")) {
Clip.Config.load(name, this, myTypes);
} else if (name.endsWith("Shield") || name.endsWith("shield")) {
Shield.Config.load(name, this, soundManager, myTypes);
} else {
Gun.Config.load(name, this, soundManager, myTypes);
}
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("The JSON of " + name + " is missing, or has malformed, a required parameter" + e.getMessage().split(":")[1]);
} catch (SerializationException e) {
throw new SerializationException("The JSON of " + name + " has invalid syntax at " + e.getMessage().split(" near")[0].split("on ")[1]);
}

example = myM.get(name);
}
return example;
}

public Engine.Config getEngineConfig(String engineName) {
Expand All @@ -192,7 +220,7 @@ public SolItem random() {

public void registerItem(SolItem example) {
String code = example.getCode();
SolItem existing = getExample(code);
SolItem existing = myM.get(code);
if (existing != null) {
throw new AssertionError("2 item types registered for item code " + code + ":\n" + existing + " and " + example);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class BorderDrawer {
private final ArrayList<PlanetProximityIndicator> planetProximityIndicators;
private final Vector2 myTmpVec = new Vector2();

BorderDrawer() {
public BorderDrawer() {
displayDimensions = SolApplication.displayDimensions;

TextureAtlas.AtlasRegion texture = Assets.getAtlasRegion("engine:uiPlanetProximityIndicator");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,44 @@

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.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", "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();

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 @@ -47,28 +67,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().mainGameScreen);
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,16 +28,31 @@
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.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", "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 @@ -52,38 +66,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().mainGameScreen);
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
Loading