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

Ported the majority of UIs to NUI #672

Merged
merged 14 commits into from
Dec 4, 2022
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
6 changes: 4 additions & 2 deletions engine/src/main/java/org/destinationsol/SolApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public void play(boolean tut, String shipName, boolean isNewGame, WorldConfig wo

factionDisplay = new FactionDisplay(gameContext.getBean(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,11 @@ public SolLayouts getLayouts() {

public void finishGame() {
solGame.onGameEnd(gameContext.getBean(Context.class));
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);
entityCreated = false;
}
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 @@ -177,7 +177,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
12 changes: 5 additions & 7 deletions engine/src/main/java/org/destinationsol/game/SolGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.destinationsol.ContextWrapper;
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,10 +67,8 @@
import org.destinationsol.ui.nui.screens.MainGameScreen;
import org.destinationsol.world.GalaxyBuilder;
import org.terasology.context.exception.BeanNotFoundException;
import org.terasology.gestalt.assets.ResourceUrn;
import org.terasology.gestalt.di.BeanContext;
import org.terasology.gestalt.entitysystem.entity.EntityRef;
import org.terasology.nui.asset.UIElement;

import javax.inject.Inject;
import java.util.ArrayList;
Expand Down Expand Up @@ -266,7 +263,7 @@ public void run() {
}
}, 0, 30);
gameScreens.consoleScreen.init(this);
solApplication.getNuiManager().pushScreen(mainGameScreen);
solApplication.getNuiManager().pushScreen(gameScreens.mainGameScreen);
tutorialManager.ifPresent(TutorialManager::start);
}

Expand Down Expand Up @@ -340,10 +337,11 @@ public void onGameEnd(Context context) {
} catch (Exception e) {
e.printStackTrace();
}

// TODO: Remove this when context is reset after each game
context.get(EntitySystemManager.class).getEntityManager().allEntities().forEach(EntityRef::delete);
}

// TODO: Remove this when context is reset after each game
context.get(EntitySystemManager.class).getEntityManager().allEntities().forEach(EntityRef::delete);

FactionInfo.clearValues();
try {
objectManager.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public void fillContainer(ItemContainer itemContainer, String items) {
}
}

public ItemConfig parseItem(String item) {
List<ItemConfig> items = parseItems(item);
if (items.isEmpty()) {
return null;
}
return items.get(0);
}

public List<ItemConfig> parseItems(String items) {
ArrayList<ItemConfig> result = new ArrayList<>();

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,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 @@ -47,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().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,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 @@ -52,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().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