1515 */
1616package org .destinationsol .game .screens ;
1717
18- import org .destinationsol .GameOptions ;
1918import org .destinationsol .SolApplication ;
2019import org .destinationsol .game .SolGame ;
2120import org .destinationsol .game .item .ItemContainer ;
2221import org .destinationsol .game .item .MercItem ;
2322import org .destinationsol .game .item .SolItem ;
2423import org .destinationsol .game .ship .SolShip ;
2524import org .destinationsol .ui .SolInputManager ;
26- import org .destinationsol .ui .SolUiControl ;
25+ import org .destinationsol .ui .nui .NUIManager ;
26+ import org .destinationsol .ui .nui .screens .InventoryScreen ;
27+ import org .destinationsol .ui .nui .widgets .KeyActivatedButton ;
28+ import org .terasology .nui .backends .libgdx .GDXInputUtil ;
29+ import org .terasology .nui .widgets .UIButton ;
2730
31+ /**
32+ * This screen shows an overview of all the mercenaries that the hero has hired.
33+ * You can manage each mercenary's independent inventory from here, as well as selecting their equipped items.
34+ */
2835public class ChooseMercenaryScreen extends InventoryOperationsScreen {
29- private final SolUiControl giveControl ;
30- private final SolUiControl takeControl ;
31- private final SolUiControl equipControl ;
36+ private final UIButton [] actionButtons = new UIButton [3 ];
3237 private final ItemContainer EMPTY_ITEM_CONTAINER = new ItemContainer ();
3338
34- ChooseMercenaryScreen (InventoryScreen inventoryScreen , GameOptions gameOptions ) {
35- giveControl = new SolUiControl (inventoryScreen .itemCtrl (0 ), true , gameOptions .getKeyShoot ());
36- giveControl .setDisplayName ("Give Items" );
37- controls .add (giveControl );
39+ public ChooseMercenaryScreen () {
40+ }
41+
42+ @ Override
43+ public void initialise (SolApplication solApplication , InventoryScreen inventoryScreen ) {
44+ KeyActivatedButton giveButton = new KeyActivatedButton ();
45+ giveButton .setText ("Give Items" );
46+ giveButton .setKey (GDXInputUtil .GDXToNuiKey (solApplication .getOptions ().getKeyShoot ()));
47+ giveButton .subscribe (button -> {
48+ SolItem selectedItem = inventoryScreen .getSelectedItem ();
49+ SolInputManager inputManager = solApplication .getInputManager ();
50+ NUIManager nuiManager = solApplication .getNuiManager ();
51+
52+ SolShip solship = ((MercItem ) selectedItem ).getSolShip ();
53+ inputManager .setScreen (solApplication , solApplication .getGame ().getScreens ().oldMainGameScreen );
54+ nuiManager .removeScreen (inventoryScreen );
55+ inventoryScreen .getGiveItems ().setTarget (solship );
56+ inventoryScreen .setOperations (inventoryScreen .getGiveItems ());
57+ nuiManager .pushScreen (inventoryScreen );
58+ });
59+ actionButtons [0 ] = giveButton ;
60+
61+ KeyActivatedButton takeButton = new KeyActivatedButton ();
62+ takeButton .setText ("Take Items" );
63+ takeButton .setKey (GDXInputUtil .GDXToNuiKey (solApplication .getOptions ().getKeyShoot2 ()));
64+ takeButton .subscribe (button -> {
65+ SolItem selectedItem = inventoryScreen .getSelectedItem ();
66+ SolInputManager inputManager = solApplication .getInputManager ();
67+ NUIManager nuiManager = solApplication .getNuiManager ();
3868
39- takeControl = new SolUiControl (inventoryScreen .itemCtrl (1 ), true , gameOptions .getKeyShoot2 ());
40- takeControl .setDisplayName ("Take Items" );
41- controls .add (takeControl );
42-
43- equipControl = new SolUiControl (inventoryScreen .itemCtrl (2 ), true , gameOptions .getKeyDrop ());
44- equipControl .setDisplayName ("Equip Items" );
45- controls .add (equipControl );
69+ SolShip solship = ((MercItem ) selectedItem ).getSolShip ();
70+ inputManager .setScreen (solApplication , solApplication .getGame ().getScreens ().oldMainGameScreen );
71+ inventoryScreen .getTakeItems ().setTarget (solship );
72+ nuiManager .removeScreen (inventoryScreen );
73+ inventoryScreen .setOperations (inventoryScreen .getTakeItems ());
74+ nuiManager .pushScreen (inventoryScreen );
75+ });
76+ actionButtons [1 ] = takeButton ;
77+
78+ KeyActivatedButton equipButton = new KeyActivatedButton ();
79+ equipButton .setText ("Equip Items" );
80+ equipButton .setKey (GDXInputUtil .GDXToNuiKey (solApplication .getOptions ().getKeyDrop ()));
81+ equipButton .subscribe (button -> {
82+ SolItem selectedItem = inventoryScreen .getSelectedItem ();
83+ SolInputManager inputManager = solApplication .getInputManager ();
84+ NUIManager nuiManager = solApplication .getNuiManager ();
85+
86+ SolShip solship = ((MercItem ) selectedItem ).getSolShip ();
87+ inputManager .setScreen (solApplication , solApplication .getGame ().getScreens ().oldMainGameScreen );
88+ nuiManager .removeScreen (inventoryScreen );
89+ inventoryScreen .getShowInventory ().setTarget (solship );
90+ inventoryScreen .setOperations (inventoryScreen .getShowInventory ());
91+ nuiManager .pushScreen (inventoryScreen );
92+ });
93+ actionButtons [2 ] = equipButton ;
4694 }
4795
4896 @ Override
49- public void updateCustom (SolApplication solApplication , SolInputManager .InputPointer [] inputPointers , boolean clickedOutside ) {
50- SolGame game = solApplication .getGame ();
51- InventoryScreen is = game .getScreens ().inventoryScreen ;
52- SolInputManager inputMan = solApplication .getInputManager ();
53- GameScreens screens = game .getScreens ();
54- SolItem selItem = is .getSelectedItem ();
55- boolean selNull = selItem != null ;
97+ public void update (SolApplication solApplication , InventoryScreen inventoryScreen ) {
98+ boolean selNull = inventoryScreen .getSelectedItem () != null ;
5699
57- giveControl . setEnabled ( selNull ) ;
58- takeControl . setEnabled ( selNull ) ;
59- equipControl . setEnabled ( selNull ) ;
100+ UIButton giveButton = actionButtons [ 0 ] ;
101+ UIButton takeButton = actionButtons [ 1 ] ;
102+ UIButton equipButton = actionButtons [ 2 ] ;
60103
61- if (giveControl .isJustOff () && selNull ) {
62- SolShip solship = ((MercItem ) selItem ).getSolShip ();
63- inputMan .setScreen (solApplication , screens .oldMainGameScreen );
64- is .giveItemsScreen .setTarget (solship );
65- is .setOperations (is .giveItemsScreen );
66- inputMan .addScreen (solApplication , is );
67- } else if (takeControl .isJustOff () && selNull ) {
68- SolShip solship = ((MercItem ) selItem ).getSolShip ();
69- inputMan .setScreen (solApplication , screens .oldMainGameScreen );
70- is .takeItems .setTarget (solship );
71- is .setOperations (is .takeItems );
72- inputMan .addScreen (solApplication , is );
73- } else if (equipControl .isJustOff () && selNull ) {
74- SolShip solship = ((MercItem ) selItem ).getSolShip ();
75- inputMan .setScreen (solApplication , screens .oldMainGameScreen );
76- is .showInventory .setTarget (solship );
77- is .setOperations (is .showInventory );
78- inputMan .addScreen (solApplication , is );
79- }
104+ giveButton .setEnabled (selNull );
105+ takeButton .setEnabled (selNull );
106+ equipButton .setEnabled (selNull );
80107 }
81108
82109 @ Override
@@ -95,4 +122,8 @@ public String getHeader() {
95122 return "Mercenaries:" ;
96123 }
97124
125+ @ Override
126+ public UIButton [] getActionButtons () {
127+ return actionButtons ;
128+ }
98129}
0 commit comments