1616package org .destinationsol .game .screens ;
1717
1818import com .badlogic .gdx .math .Vector2 ;
19- import org .destinationsol .GameOptions ;
2019import org .destinationsol .SolApplication ;
2120import org .destinationsol .game .Hero ;
2221import org .destinationsol .game .SolGame ;
2928import org .destinationsol .game .ship .SolShip ;
3029import org .destinationsol .game .ship .hulls .Hull ;
3130import 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+ */
3541public 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