1616package org .destinationsol .ui ;
1717
1818import com .badlogic .gdx .Gdx ;
19- import com .badlogic .gdx .math .Rectangle ;
2019import org .destinationsol .GameOptions ;
21- import org .destinationsol .common .SolColor ;
2220import org .destinationsol .game .SolGame ;
2321import org .destinationsol .game .UpdateAwareSystem ;
2422import org .destinationsol .game .item .SolItem ;
2523import org .destinationsol .game .screens .GameScreens ;
2624import org .destinationsol .game .screens .MainGameScreen ;
2725import org .destinationsol .game .screens .ShipMixedControl ;
28- import org .destinationsol .ui .nui .screens .InventoryScreen ;
26+ import org .destinationsol .ui .nui .NUIManager ;
27+ import org .destinationsol .ui .nui .NUIScreenLayer ;
28+ import org .destinationsol .ui .nui .screens .TutorialScreen ;
2929import org .destinationsol .ui .nui .screens .UIShipControlsScreen ;
3030import org .destinationsol .ui .nui .widgets .UIWarnButton ;
3131
3535import java .util .List ;
3636
3737public class TutorialManager implements UpdateAwareSystem {
38- private final Rectangle background ;
38+ private final NUIManager nuiManager ;
39+ private final TutorialScreen tutorialScreen ;
3940 private final ArrayList <Step > steps ;
4041 private final GameScreens screens ;
4142 private final GameOptions gameOptions ;
4243 private final Provider <SolGame > game ;
43- private final DisplayDimensions displayDimensions ;
4444
4545 private int stepIndex ;
4646
4747 @ Inject
48- public TutorialManager (GameScreens screens , GameOptions gameOptions , Provider <SolGame > game , DisplayDimensions displayDimensions ) {
48+ public TutorialManager (GameScreens screens , GameOptions gameOptions , Provider <SolGame > game , NUIManager nuiManager ) {
4949 this .screens = screens ;
5050 this .gameOptions = gameOptions ;
5151 this .game = game ;
52- this .displayDimensions = displayDimensions ;
52+ this .nuiManager = nuiManager ;
53+ this .tutorialScreen = (TutorialScreen ) nuiManager .createScreen ("engine:tutorialScreen" );
5354
54- float backgroundW = displayDimensions .getRatio () * .5f ;
55- float backgroundH = .2f ;
56- background = new Rectangle (displayDimensions .getRatio () / 2 - backgroundW / 2 , 1 - backgroundH , backgroundW , backgroundH );
5755 steps = new ArrayList <>();
5856 stepIndex = 0 ;
5957 }
@@ -124,10 +122,10 @@ public void start() {
124122 }
125123
126124 if (mobile ) {
127- addStep ("Close the map" , screens .mapScreen .getCloseButton (), true );
125+ addScreenCloseStep ("Close the map" , screens .mapScreen .getCloseButton (), screens . mapScreen );
128126 } else {
129- addStep ("Close the map\n (" + gameOptions .getKeyMapName () + " or " + gameOptions .getKeyCloseName () + " keys)" ,
130- screens .mapScreen .getCloseButton (), true );
127+ addScreenCloseStep ("Close the map\n (" + gameOptions .getKeyMapName () + " or " + gameOptions .getKeyCloseName () + " keys)" ,
128+ screens .mapScreen .getCloseButton (), screens . mapScreen );
131129 }
132130
133131 UIWarnButton inventoryButton = nuiMain .getInventoryButton ();
@@ -177,9 +175,9 @@ public void start() {
177175 }
178176
179177 if (mobile ) {
180- addStep ("Close the inventory\n (Touch the screen outside inventory)" , screens .inventoryScreen .getCloseButton (), true );
178+ addScreenCloseStep ("Close the inventory\n (Touch the screen outside inventory)" , screens .inventoryScreen .getCloseButton (), screens . inventoryScreen );
181179 } else {
182- addStep ("Close the inventory (" + gameOptions .getKeyCloseName () + " key)" , screens .inventoryScreen .getCloseButton (), true );
180+ addScreenCloseStep ("Close the inventory (" + gameOptions .getKeyCloseName () + " key)" , screens .inventoryScreen .getCloseButton (), screens . inventoryScreen );
183181 }
184182
185183 if (mouseCtrl ) {
@@ -210,9 +208,9 @@ public void start() {
210208 }
211209
212210 if (mobile ) {
213- addStep ("Close the Buy screen\n (Touch the screen outside inventory)" , screens .inventoryScreen .getCloseButton (), true );
211+ addScreenCloseStep ("Close the Buy screen\n (Touch the screen outside inventory)" , screens .inventoryScreen .getCloseButton (), screens . inventoryScreen );
214212 } else {
215- addStep ("Close the Buy screen\n (" + gameOptions .getKeyCloseName () + " key)" , screens .inventoryScreen .getCloseButton (), true );
213+ addScreenCloseStep ("Close the Buy screen\n (" + gameOptions .getKeyCloseName () + " key)" , screens .inventoryScreen .getCloseButton (), screens . inventoryScreen );
216214 }
217215
218216 if (mouseCtrl ) {
@@ -243,7 +241,9 @@ public void start() {
243241 addStep ("Buy new ships, hire mercenaries\n " + shootKey2 , nuiShootCtrl );
244242 addStep ("Tutorial is complete and will exit now!\n " + shootKey2 , nuiShootCtrl );
245243 }
244+
246245 steps .get (0 ).start ();
246+ tutorialScreen .setTutorialText (steps .get (0 ).text );
247247 }
248248
249249 private void addStep (String text , SolUiControl ctrl ) {
@@ -270,28 +270,33 @@ private void addStep(Step step) {
270270 steps .add (step );
271271 }
272272
273+ private void addScreenCloseStep (String text , UIWarnButton ctrl , NUIScreenLayer uiScreen ) {
274+ steps .add (new NuiScreenCloseStep (text , ctrl , nuiManager , uiScreen ));
275+ }
276+
273277 @ Override
274278 public void update (SolGame game , float timeStep ) {
279+ if (nuiManager .getTopScreen () != tutorialScreen ) {
280+ if (nuiManager .hasScreen (tutorialScreen )) {
281+ tutorialScreen .moveToTop ();
282+ } else {
283+ nuiManager .pushScreen (tutorialScreen );
284+ }
285+ }
286+
275287 Step step = steps .get (stepIndex );
276288 step .highlight ();
277289 if (step .canProgressToNextStep ()) {
278290 stepIndex ++;
279291 if (stepIndex < steps .size ()) {
280292 steps .get (stepIndex ).start ();
293+ tutorialScreen .setTutorialText (steps .get (stepIndex ).text );
281294 }
282- }
283- }
284295
285- public void draw ( UiDrawer uiDrawer ) {
286- if ( isFinished ()) {
287- return ;
296+ if ( isFinished () ) {
297+ game . getSolApplication (). finishGame ();
298+ }
288299 }
289- Step step = steps .get (stepIndex );
290- uiDrawer .draw (background , SolColor .UI_BG_LIGHT );
291- uiDrawer .drawLine (background .x , background .y , 0 , background .width , SolColor .WHITE );
292- uiDrawer .drawLine (background .x + background .width , background .y , 90 , background .height , SolColor .WHITE );
293- uiDrawer .drawLine (background .x , background .y , 90 , background .height , SolColor .WHITE );
294- uiDrawer .drawString (step .text , displayDimensions .getRatio () / 2 , background .y + background .height / 2 , FontSize .TUT , true , SolColor .WHITE );
295300 }
296301
297302 public boolean isFinished () {
@@ -367,11 +372,30 @@ public boolean canProgressToNextStep() {
367372 }
368373 }
369374
375+ public static class NuiScreenCloseStep extends NuiStep {
376+ private final NUIManager nuiManager ;
377+ private final NUIScreenLayer uiScreen ;
378+
379+ public NuiScreenCloseStep (String text , UIWarnButton closeButton , NUIManager nuiManager , NUIScreenLayer uiScreen ) {
380+ super (text , closeButton , true );
381+ this .nuiManager = nuiManager ;
382+ this .uiScreen = uiScreen ;
383+ }
384+
385+ @ Override
386+ public boolean canProgressToNextStep () {
387+ if (super .canProgressToNextStep ()) {
388+ return true ;
389+ }
390+ return !nuiManager .hasScreen (uiScreen );
391+ }
392+ }
393+
370394 public static class SelectEquippedItemStep extends Step {
371- InventoryScreen inventoryScreen ;
395+ org . destinationsol . ui . nui . screens . InventoryScreen inventoryScreen ;
372396 SolGame game ;
373397
374- public SelectEquippedItemStep (String text , InventoryScreen inventoryScreen , SolGame game ) {
398+ public SelectEquippedItemStep (String text , org . destinationsol . ui . nui . screens . InventoryScreen inventoryScreen , SolGame game ) {
375399 super (text , null , true );
376400 this .inventoryScreen = inventoryScreen ;
377401 this .game = game ;
0 commit comments