Skip to content

Commit 3043c3d

Browse files
authored
Merge pull request #672 from MovingBlocks/nui-ported-screens
Ported the majority of UIs to NUI
2 parents 042f715 + c676e05 commit 3043c3d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+3740
-1741
lines changed

engine/src/main/java/org/destinationsol/FactionDisplay.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void drawFactionNames(SolGame game, UiDrawer uiDrawer, SolInputManager in
4444
isPressed = !isPressed;
4545
}
4646
// angle must be zero as the camera angles on planets mess up the text display
47-
if (isPressed && camera.getAngle() == 0 && !inputManager.isScreenOn(game.getScreens().mapScreen)) {
47+
if (isPressed && camera.getAngle() == 0 && !game.getSolApplication().getNuiManager().hasScreen(game.getScreens().mapScreen)) {
4848
for (SolObject obj : objManager.getObjects()) {
4949
if (obj instanceof SolShip) {
5050
SolShip ship = (SolShip) obj;

engine/src/main/java/org/destinationsol/SolApplication.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ public void play(boolean tut, String shipName, boolean isNewGame, WorldConfig wo
362362

363363
factionDisplay = new FactionDisplay(gameContext.getBean(SolCam.class));
364364
nuiManager.removeScreen(menuScreens.loading);
365-
inputManager.setScreen(this, solGame.getScreens().mainGameScreen);
365+
inputManager.setScreen(this, solGame.getScreens().oldMainGameScreen);
366366
}
367367

368368
public SolInputManager getInputManager() {
@@ -402,9 +402,11 @@ public SolLayouts getLayouts() {
402402

403403
public void finishGame() {
404404
solGame.onGameEnd(gameContext.getBean(Context.class));
405-
solGame = null;
406405
// TODO: remove the following line when all screens have been ported to use NUI
407406
inputManager.setScreen(this, null);
407+
inputManager.update(this); // Force an update to remove all the InputManager UI screens
408+
409+
solGame = null;
408410
nuiManager.pushScreen(menuScreens.main);
409411
entityCreated = false;
410412
}

engine/src/main/java/org/destinationsol/game/PlayerCreator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private Pilot createPilot(SolGame game, boolean isMouseControl) {
185185
if (isMouseControl) {
186186
return new AiPilot(new BeaconDestProvider(), true, Faction.LAANI, false, "you", Const.AI_DET_DIST);
187187
} else {
188-
return new UiControlledPilot(game.getScreens().getMainGameScreen().getShipControl());
188+
return new UiControlledPilot(game.getScreens().getOldMainGameScreen().getShipControl());
189189
}
190190
}
191191

engine/src/main/java/org/destinationsol/game/SolCam.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void applyPos(float posX, float posY) {
177177
}
178178

179179
private void applyInput(SolGame game) {
180-
MainGameScreen screen = game.getScreens().mainGameScreen;
180+
MainGameScreen screen = game.getScreens().oldMainGameScreen;
181181
boolean d = screen.isCameraDown();
182182
boolean u = screen.isCameraUp();
183183
boolean l = screen.isCameraLeft();

engine/src/main/java/org/destinationsol/game/SolGame.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.destinationsol.ContextWrapper;
2323
import org.destinationsol.GameOptions;
2424
import org.destinationsol.SolApplication;
25-
import org.destinationsol.assets.Assets;
2625
import org.destinationsol.assets.sound.OggSoundManager;
2726
import org.destinationsol.assets.sound.SpecialSounds;
2827
import org.destinationsol.common.DebugCol;
@@ -68,10 +67,8 @@
6867
import org.destinationsol.ui.nui.screens.MainGameScreen;
6968
import org.destinationsol.world.GalaxyBuilder;
7069
import org.terasology.context.exception.BeanNotFoundException;
71-
import org.terasology.gestalt.assets.ResourceUrn;
7270
import org.terasology.gestalt.di.BeanContext;
7371
import org.terasology.gestalt.entitysystem.entity.EntityRef;
74-
import org.terasology.nui.asset.UIElement;
7572

7673
import javax.inject.Inject;
7774
import java.util.ArrayList;
@@ -266,7 +263,7 @@ public void run() {
266263
}
267264
}, 0, 30);
268265
gameScreens.consoleScreen.init(this);
269-
solApplication.getNuiManager().pushScreen(mainGameScreen);
266+
solApplication.getNuiManager().pushScreen(gameScreens.mainGameScreen);
270267
tutorialManager.ifPresent(TutorialManager::start);
271268
}
272269

@@ -340,10 +337,11 @@ public void onGameEnd(Context context) {
340337
} catch (Exception e) {
341338
e.printStackTrace();
342339
}
343-
344-
// TODO: Remove this when context is reset after each game
345-
context.get(EntitySystemManager.class).getEntityManager().allEntities().forEach(EntityRef::delete);
346340
}
341+
342+
// TODO: Remove this when context is reset after each game
343+
context.get(EntitySystemManager.class).getEntityManager().allEntities().forEach(EntityRef::delete);
344+
347345
FactionInfo.clearValues();
348346
try {
349347
objectManager.close();

engine/src/main/java/org/destinationsol/game/item/ItemManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ public void fillContainer(ItemContainer itemContainer, String items) {
7878
}
7979
}
8080

81+
public ItemConfig parseItem(String item) {
82+
List<ItemConfig> items = parseItems(item);
83+
if (items.isEmpty()) {
84+
return null;
85+
}
86+
return items.get(0);
87+
}
88+
8189
public List<ItemConfig> parseItems(String items) {
8290
ArrayList<ItemConfig> result = new ArrayList<>();
8391

engine/src/main/java/org/destinationsol/game/screens/BorderDrawer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class BorderDrawer {
5656
private final ArrayList<PlanetProximityIndicator> planetProximityIndicators;
5757
private final Vector2 myTmpVec = new Vector2();
5858

59-
BorderDrawer() {
59+
public BorderDrawer() {
6060
displayDimensions = SolApplication.displayDimensions;
6161

6262
TextureAtlas.AtlasRegion texture = Assets.getAtlasRegion("engine:uiPlanetProximityIndicator");

engine/src/main/java/org/destinationsol/game/screens/BuyItemsScreen.java

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,49 @@
1616

1717
package org.destinationsol.game.screens;
1818

19-
import org.destinationsol.GameOptions;
2019
import org.destinationsol.SolApplication;
2120
import org.destinationsol.game.FactionInfo;
2221
import org.destinationsol.game.Hero;
2322
import org.destinationsol.game.SolGame;
2423
import org.destinationsol.game.item.ItemContainer;
2524
import org.destinationsol.game.item.SolItem;
2625
import org.destinationsol.game.ship.SolShip;
27-
import org.destinationsol.ui.SolInputManager;
28-
import org.destinationsol.ui.SolUiControl;
26+
import org.destinationsol.ui.nui.screens.InventoryScreen;
27+
import org.destinationsol.ui.nui.screens.TalkScreen;
28+
import org.destinationsol.ui.nui.widgets.UIWarnButton;
29+
import org.terasology.nui.backends.libgdx.GDXInputUtil;
30+
import org.terasology.nui.widgets.UIButton;
2931

32+
/**
33+
* This screen allows you to purchase items for the hero's ship.
34+
* The purchased items are moved to the hero's inventory and the cost deducted from the hero's money.
35+
*/
3036
public class BuyItemsScreen extends InventoryOperationsScreen {
31-
public final SolUiControl buyControl;
37+
private final UIButton[] actionButtons = new UIButton[1];
38+
39+
@Override
40+
public void initialise(SolApplication solApplication, InventoryScreen inventoryScreen) {
41+
UIWarnButton buyButton = new UIWarnButton();
42+
buyButton.setText("Buy");
43+
buyButton.setKey(GDXInputUtil.GDXToNuiKey(solApplication.getOptions().getKeyBuyItem()));
44+
buyButton.subscribe(button -> {
45+
SolGame game = solApplication.getGame();
46+
Hero hero = game.getHero();
47+
TalkScreen talkScreen = game.getScreens().talkScreen;
48+
SolShip target = talkScreen.getTarget();
49+
SolItem selectedItem = inventoryScreen.getSelectedItem();
50+
if (selectedItem == null) {
51+
return;
52+
}
3253

33-
BuyItemsScreen(InventoryScreen inventoryScreen, GameOptions gameOptions) {
34-
buyControl = new SolUiControl(inventoryScreen.itemCtrl(0), true, gameOptions.getKeyBuyItem());
35-
buyControl.setDisplayName("Buy");
36-
controls.add(buyControl);
54+
target.getTradeContainer().getItems().remove(selectedItem);
55+
hero.getItemContainer().add(selectedItem);
56+
hero.setMoney(hero.getMoney() - selectedItem.getPrice());
57+
FactionInfo.setDisposition(target.getFactionID(), 1);
58+
59+
inventoryScreen.updateItemRows();
60+
});
61+
actionButtons[0] = buyButton;
3762
}
3863

3964
@Override
@@ -47,28 +72,27 @@ public String getHeader() {
4772
}
4873

4974
@Override
50-
public void updateCustom(SolApplication solApplication, SolInputManager.InputPointer[] inputPointers, boolean clickedOutside) {
75+
public UIButton[] getActionButtons() {
76+
return actionButtons;
77+
}
78+
79+
public UIWarnButton getBuyControl() {
80+
return (UIWarnButton) actionButtons[0];
81+
}
82+
83+
@Override
84+
public void update(SolApplication solApplication, InventoryScreen inventoryScreen) {
5185
SolGame game = solApplication.getGame();
52-
InventoryScreen is = game.getScreens().inventoryScreen;
5386
Hero hero = game.getHero();
5487
TalkScreen talkScreen = game.getScreens().talkScreen;
55-
SolShip target = talkScreen.getTarget();
5688
if (talkScreen.isTargetFar(hero)) {
57-
solApplication.getInputManager().setScreen(solApplication, game.getScreens().mainGameScreen);
89+
solApplication.getNuiManager().removeScreen(inventoryScreen);
5890
return;
5991
}
60-
SolItem selItem = is.getSelectedItem();
92+
SolItem selItem = inventoryScreen.getSelectedItem();
6193
boolean enabled = selItem != null && hero.getMoney() >= selItem.getPrice() && hero.getItemContainer().canAdd(selItem);
62-
buyControl.setDisplayName(enabled ? "Buy" : "---");
63-
buyControl.setEnabled(enabled);
64-
if (!enabled) {
65-
return;
66-
}
67-
if (buyControl.isJustOff()) {
68-
target.getTradeContainer().getItems().remove(selItem);
69-
hero.getItemContainer().add(selItem);
70-
hero.setMoney(hero.getMoney() - selItem.getPrice());
71-
FactionInfo.setDisposition(target.getFactionID(), 1);
72-
}
94+
UIButton buyButton = actionButtons[0];
95+
buyButton.setText(enabled ? "Buy" : "---");
96+
buyButton.setEnabled(enabled);
7397
}
7498
}

engine/src/main/java/org/destinationsol/game/screens/ChangeShipScreen.java

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.destinationsol.game.screens;
1717

1818
import com.badlogic.gdx.math.Vector2;
19-
import org.destinationsol.GameOptions;
2019
import org.destinationsol.SolApplication;
2120
import org.destinationsol.game.Hero;
2221
import org.destinationsol.game.SolGame;
@@ -29,16 +28,33 @@
2928
import org.destinationsol.game.ship.SolShip;
3029
import org.destinationsol.game.ship.hulls.Hull;
3130
import org.destinationsol.game.ship.hulls.HullConfig;
32-
import org.destinationsol.ui.SolInputManager;
33-
import org.destinationsol.ui.SolUiControl;
31+
import org.destinationsol.ui.nui.screens.InventoryScreen;
32+
import org.destinationsol.ui.nui.screens.TalkScreen;
33+
import org.destinationsol.ui.nui.widgets.KeyActivatedButton;
34+
import org.terasology.nui.backends.libgdx.GDXInputUtil;
35+
import org.terasology.nui.widgets.UIButton;
3436

37+
/**
38+
* This screen allows you to purchase a new ship for the hero.
39+
* The hero's previous ship will be replaced with the purchased ship and the cost deducted from the hero's money.
40+
*/
3541
public class ChangeShipScreen extends InventoryOperationsScreen {
36-
private final SolUiControl changeControl;
42+
private final UIButton[] actionButtons = new UIButton[1];
43+
44+
@Override
45+
public void initialise(SolApplication solApplication, InventoryScreen inventoryScreen) {
46+
KeyActivatedButton changeButton = new KeyActivatedButton();
47+
changeButton.setText("Change");
48+
changeButton.setKey(GDXInputUtil.GDXToNuiKey(solApplication.getOptions().getKeyChangeShip()));
49+
changeButton.subscribe(button -> {
50+
SolGame game = solApplication.getGame();
51+
Hero hero = game.getHero();
52+
SolItem selectedItem = inventoryScreen.getSelectedItem();
3753

38-
ChangeShipScreen(InventoryScreen inventoryScreen, GameOptions gameOptions) {
39-
changeControl = new SolUiControl(inventoryScreen.itemCtrl(0), true, gameOptions.getKeyChangeShip());
40-
changeControl.setDisplayName("Change");
41-
controls.add(changeControl);
54+
hero.setMoney(hero.getMoney() - selectedItem.getPrice());
55+
changeShip(game, hero, (ShipItem) selectedItem);
56+
});
57+
actionButtons[0] = changeButton;
4258
}
4359

4460
@Override
@@ -52,38 +68,39 @@ public String getHeader() {
5268
}
5369

5470
@Override
55-
public void updateCustom(SolApplication solApplication, SolInputManager.InputPointer[] inputPointers, boolean clickedOutside) {
71+
public UIButton[] getActionButtons() {
72+
return actionButtons;
73+
}
74+
75+
@Override
76+
public void update(SolApplication solApplication, InventoryScreen inventoryScreen) {
5677
SolGame game = solApplication.getGame();
57-
InventoryScreen is = game.getScreens().inventoryScreen;
5878
Hero hero = game.getHero();
5979
TalkScreen talkScreen = game.getScreens().talkScreen;
6080
if (talkScreen.isTargetFar(hero)) {
61-
solApplication.getInputManager().setScreen(solApplication, game.getScreens().mainGameScreen);
81+
solApplication.getInputManager().setScreen(solApplication, game.getScreens().oldMainGameScreen);
6282
return;
6383
}
64-
SolItem selItem = is.getSelectedItem();
84+
85+
UIButton changeButton = actionButtons[0];
86+
87+
SolItem selItem = inventoryScreen.getSelectedItem();
6588
if (selItem == null) {
66-
changeControl.setDisplayName("---");
67-
changeControl.setEnabled(false);
89+
changeButton.setText("---");
90+
changeButton.setEnabled(false);
6891
return;
6992
}
7093
boolean enabled = hasMoneyToBuyShip(hero, selItem);
7194
boolean sameShip = isSameShip(hero, selItem);
7295
if (enabled && !sameShip) {
73-
changeControl.setDisplayName("Change");
74-
changeControl.setEnabled(true);
96+
changeButton.setText("Change");
97+
changeButton.setEnabled(true);
7598
} else if (enabled && sameShip) {
76-
changeControl.setDisplayName("Have it");
77-
changeControl.setEnabled(false);
78-
return;
99+
changeButton.setText("Have it");
100+
changeButton.setEnabled(false);
79101
} else {
80-
changeControl.setDisplayName("---");
81-
changeControl.setEnabled(false);
82-
return;
83-
}
84-
if (changeControl.isJustOff()) {
85-
hero.setMoney(hero.getMoney() - selItem.getPrice());
86-
changeShip(game, hero, (ShipItem) selItem);
102+
changeButton.setText("---");
103+
changeButton.setEnabled(false);
87104
}
88105
}
89106

0 commit comments

Comments
 (0)