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 the talk screen to NUI #667

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 @@ -26,6 +26,7 @@
import org.destinationsol.game.ship.SolShip;
import org.destinationsol.ui.SolInputManager;
import org.destinationsol.ui.SolUiControl;
import org.destinationsol.ui.nui.screens.TalkScreen;

public class BuyItemsScreen extends InventoryOperationsScreen {
public final SolUiControl buyControl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.destinationsol.game.ship.hulls.HullConfig;
import org.destinationsol.ui.SolInputManager;
import org.destinationsol.ui.SolUiControl;
import org.destinationsol.ui.nui.screens.TalkScreen;

public class ChangeShipScreen extends InventoryOperationsScreen {
private final SolUiControl changeControl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.destinationsol.game.context.Context;
import org.destinationsol.ui.SolLayouts;
import org.destinationsol.ui.nui.screens.MenuScreen;
import org.destinationsol.ui.nui.screens.TalkScreen;

import javax.inject.Inject;

Expand Down Expand Up @@ -49,7 +50,7 @@ public GameScreens(SolApplication cmp, Context context) {
mapScreen = new MapScreen(rightPaneLayout, cmp.isMobile(), cmp.getOptions());
menuScreen = (MenuScreen) cmp.getNuiManager().createScreen("engine:menuScreen");
inventoryScreen = new InventoryScreen(cmp.getOptions());
talkScreen = new TalkScreen(layouts.menuLayout, cmp.getOptions());
talkScreen = (TalkScreen) cmp.getNuiManager().createScreen("engine:talkScreen");
waypointCreationScreen = new WaypointCreationScreen(layouts.menuLayout, cmp.getOptions(), mapScreen);
consoleScreen = new ConsoleScreen(context.get(Console.class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.destinationsol.mercenary.MercenaryUtils;
import org.destinationsol.ui.SolInputManager;
import org.destinationsol.ui.SolUiControl;
import org.destinationsol.ui.nui.screens.TalkScreen;

public class HireShipsScreen extends InventoryOperationsScreen {
private final SolUiControl hireControl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.destinationsol.game.ship.SolShip;
import org.destinationsol.ui.SolInputManager;
import org.destinationsol.ui.SolUiControl;
import org.destinationsol.ui.nui.screens.TalkScreen;

public class SellItems extends InventoryOperationsScreen {
private static float PERC = .8f;
Expand Down
128 changes: 0 additions & 128 deletions engine/src/main/java/org/destinationsol/game/screens/TalkScreen.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ public void start() {
}

if (mouseCtrl || mobile) {
addStep("See what there is to buy", screens.talkScreen.buyControl, true);
addStep("See what there is to buy", screens.talkScreen.getBuyButton(), true);
} else {
addStep("See what there is to buy\n(" + gameOptions.getKeyBuyMenuName() + " key)", screens.talkScreen.buyControl, true);
addStep("See what there is to buy\n(" + gameOptions.getKeyBuyMenuName() + " key)", screens.talkScreen.getBuyButton(), true);
}

if (mobile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.destinationsol.game.planet.Planet;
import org.destinationsol.game.screens.BorderDrawer;
import org.destinationsol.game.screens.GameScreens;
import org.destinationsol.game.screens.TalkScreen;
import org.destinationsol.game.screens.ZoneNameAnnouncer;
import org.destinationsol.game.ship.SolShip;
import org.destinationsol.ui.SolInputManager;
Expand Down Expand Up @@ -941,9 +940,11 @@ private void onTalkButtonClicked(UIWidget widget) {
GameScreens gameScreens = game.getScreens();

solInputManager.setScreen(solApplication, gameScreens.oldMainGameScreen);
if (!solInputManager.isScreenOn(gameScreens.talkScreen)) {
if (!nuiManager.hasScreen(gameScreens.talkScreen)) {
gameScreens.talkScreen.setTarget(talkTarget);
solInputManager.addScreen(solApplication, gameScreens.talkScreen);
nuiManager.pushScreen(gameScreens.talkScreen);
} else {
nuiManager.removeScreen(gameScreens.talkScreen);
}
}

Expand Down
148 changes: 148 additions & 0 deletions engine/src/main/java/org/destinationsol/ui/nui/screens/TalkScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* Copyright 2021 The Terasology Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.destinationsol.ui.nui.screens;

import org.destinationsol.SolApplication;
import org.destinationsol.game.Hero;
import org.destinationsol.game.screens.InventoryScreen;
import org.destinationsol.game.ship.SolShip;
import org.destinationsol.game.ship.hulls.HullConfig;
import org.destinationsol.ui.nui.NUIScreenLayer;
import org.destinationsol.ui.nui.widgets.KeyActivatedButton;
import org.destinationsol.ui.nui.widgets.UIWarnButton;
import org.terasology.nui.backends.libgdx.GDXInputUtil;

import javax.inject.Inject;

/**
* The talk screen allows the player to perform actions at a station.
* At the moment, the player can buy and sell items from here, purchase new ships or hire mercenaries.
*/
public class TalkScreen extends NUIScreenLayer {
public static final float MAX_TALK_DIST = 1f;
private final SolApplication solApplication;
private UIWarnButton buyButton;
private KeyActivatedButton changeShipButton;
private KeyActivatedButton hireButton;
private SolShip target;

@Inject
public TalkScreen(SolApplication solApplication) {
this.solApplication = solApplication;
}

@Override
public void initialise() {
KeyActivatedButton sellButton = find("sellButton", KeyActivatedButton.class);
sellButton.setKey(GDXInputUtil.GDXToNuiKey(solApplication.getOptions().getKeySellMenu()));
sellButton.subscribe(button -> {
InventoryScreen inventoryScreen = solApplication.getGame().getScreens().inventoryScreen;
inventoryScreen.setOperations(inventoryScreen.sellItems);
nuiManager.removeScreen(this);
solApplication.getInputManager().addScreen(solApplication, inventoryScreen);
});

buyButton = find("buyButton", UIWarnButton.class);
buyButton.setKey(GDXInputUtil.GDXToNuiKey(solApplication.getOptions().getKeyBuyMenu()));
buyButton.subscribe(button -> {
InventoryScreen inventoryScreen = solApplication.getGame().getScreens().inventoryScreen;
inventoryScreen.setOperations(inventoryScreen.buyItemsScreen);
nuiManager.removeScreen(this);
solApplication.getInputManager().addScreen(solApplication, inventoryScreen);
});

changeShipButton = find("changeShipButton", KeyActivatedButton.class);
changeShipButton.setKey(GDXInputUtil.GDXToNuiKey(solApplication.getOptions().getKeyChangeShipMenu()));
changeShipButton.subscribe(button -> {
InventoryScreen inventoryScreen = solApplication.getGame().getScreens().inventoryScreen;
inventoryScreen.setOperations(inventoryScreen.changeShipScreen);
nuiManager.removeScreen(this);
solApplication.getInputManager().addScreen(solApplication, inventoryScreen);
});

hireButton = find("hireButton", KeyActivatedButton.class);
hireButton.setKey(GDXInputUtil.GDXToNuiKey(solApplication.getOptions().getKeyHireShipMenu()));
hireButton.subscribe(button -> {
InventoryScreen inventoryScreen = solApplication.getGame().getScreens().inventoryScreen;
inventoryScreen.setOperations(inventoryScreen.hireShipsScreen);
nuiManager.removeScreen(this);
solApplication.getInputManager().addScreen(solApplication, inventoryScreen);
});

KeyActivatedButton closeButton = find("closeButton", KeyActivatedButton.class);
closeButton.setKey(GDXInputUtil.GDXToNuiKey(solApplication.getOptions().getKeyClose()));
closeButton.subscribe(button -> {
nuiManager.removeScreen(this);
});
}

@Override
public void onAdded() {
boolean isStation = target.getHull().config.getType() == HullConfig.Type.STATION;
changeShipButton.setEnabled(isStation);
hireButton.setEnabled(isStation);
}

@Override
public void update(float delta) {
super.update(delta);

if (isTargetFar(solApplication.getGame().getHero())) {
nuiManager.removeScreen(this);
}
}

/**
* Returns the button pressed to open the buy items screen.
*
* This is exposed directly for use in the tutorial.
* @return the buy items button
*/
public UIWarnButton getBuyButton() {
return buyButton;
}

/**
* Returns the current ship being talked to.
* @return the current ship being talked to
*/
public SolShip getTarget() {
return target;
}

/**
* Assigns the ship to talk to
* @param target the ship to talk to
*/
public void setTarget(SolShip target) {
this.target = target;
}

/**
* Returns true if the target is within communicating range.
* @return true, if the target is within communicating range, otherwise false
*/
public boolean isTargetFar(Hero hero) {
if (hero.isTranscendent() || target == null || target.getLife() <= 0) {
return true;
}

float distance = target.getPosition().dst(hero.getPosition()) - hero.getHull().config.getApproxRadius() - target.getHull().config.getApproxRadius();

return (MAX_TALK_DIST < distance);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"inherit": "engine:mainGameScreen",
"families": {
"talkScreenButton": {
"elements": {
"UIButton": {
"max-width": 320,
"max-height": 256
}
},
"font": "engine:main#1"
},
"talkScreenMenuBox": {
"max-width": 320,
"max-height": 800,
"elements": {
"UIBox": {
"background": "engine:background"
}
}
}
}
}
Loading