Skip to content

Commit 4a7cff3

Browse files
committed
Merge PR #121 by @Avalancs - tutorial improvement.
2 parents a810a86 + 6a7bb8f commit 4a7cff3

File tree

3 files changed

+78
-10
lines changed

3 files changed

+78
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public SolGame(SolApplication cmp, boolean usePrevShip, TextureManager textureMa
108108
myDraMan = new DraMan(drawer);
109109
myCam = new SolCam(drawer.r);
110110
myScreens = new GameScreens(drawer.r, cmp);
111-
myTutorialManager = tut ? new TutorialManager(commonDrawer.r, myScreens, cmp.isMobile(), cmp.getOptions()) : null;
111+
myTutorialManager = tut ? new TutorialManager(commonDrawer.r, myScreens, cmp.isMobile(), cmp.getOptions(), this) : null;
112112
myTextureManager = textureManager;
113113
myFarBackgroundManagerOld = new FarBackgroundManagerOld(myTextureManager);
114114
myShipBuilder = new ShipBuilder();

main/src/org/destinationsol/game/screens/InventoryScreen.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,22 @@ public InventoryOperations getOperations() {
325325
public int getPage() {
326326
return myPage;
327327
}
328+
329+
public List<SolUiControl> getEquippedItemUIControlsForTutorial(SolGame game) {
330+
List<SolUiControl> controls = new ArrayList<>();
331+
ItemContainer ic = myOperations.getItems(game);
332+
if (ic == null) return controls;
333+
334+
for (int i = 0; i < itemCtrls.length; i++) {
335+
int groupIdx = myPage * Const.ITEM_GROUPS_PER_PAGE + i;
336+
int groupCount = ic.groupCount();
337+
if (groupCount <= groupIdx) continue;
338+
SolUiControl itemCtrl = itemCtrls[i];
339+
List<SolItem> group = ic.getGroup(groupIdx);
340+
SolItem item = group.get(0);
341+
if (myOperations.isUsing(game, item))
342+
controls.add(itemCtrl);
343+
}
344+
return controls;
345+
}
328346
}

main/src/org/destinationsol/ui/TutorialManager.java

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@
1919
import com.badlogic.gdx.math.Rectangle;
2020
import org.destinationsol.GameOptions;
2121
import org.destinationsol.common.SolColor;
22-
import org.destinationsol.game.screens.GameScreens;
23-
import org.destinationsol.game.screens.MainScreen;
24-
import org.destinationsol.game.screens.ShipKbControl;
25-
import org.destinationsol.game.screens.ShipMixedControl;
22+
import org.destinationsol.game.SolGame;
23+
import org.destinationsol.game.item.SolItem;
24+
import org.destinationsol.game.screens.*;
2625

2726
import java.util.ArrayList;
27+
import java.util.List;
2828

2929
public class TutorialManager {
3030
private final Rectangle myBg;
3131
private final ArrayList<Step> mySteps;
3232

3333
private int myStepIdx;
3434

35-
public TutorialManager(float r, GameScreens screens, boolean mobile, GameOptions gameOptions) {
35+
public TutorialManager(float r, GameScreens screens, boolean mobile, GameOptions gameOptions, SolGame game) {
3636
float bgW = r * .5f;
3737
float bgH = .2f;
3838
myBg = new Rectangle(r/2 - bgW/2, 1 - bgH, bgW, bgH);
@@ -127,10 +127,17 @@ public TutorialManager(float r, GameScreens screens, boolean mobile, GameOptions
127127
screens.inventoryScreen.showInventory.dropCtrl);
128128
}
129129

130+
// Extra step to make sure an equipped item is selected before asking player to unequip
131+
if(screens.inventoryScreen.getSelectedItem() == null ||
132+
(screens.inventoryScreen.getSelectedItem() != null && screens.inventoryScreen.getSelectedItem().isEquipped() == 0)) {
133+
s(new SelectEquippedItemStep(
134+
"Select an equipped item\n(note the text \"using\")", screens.inventoryScreen, game));
135+
}
136+
130137
if (mobile) {
131-
s("Unequip some item\nthat is used now", screens.inventoryScreen.showInventory.eq1Ctrl);
138+
s("Unequip the item\nthat is used now", screens.inventoryScreen.showInventory.eq1Ctrl);
132139
} else {
133-
s("Unequip some item\nthat is used now (" + gameOptions.getKeyEquipName() + " key)",
140+
s("Unequip the item\nthat is used now (" + gameOptions.getKeyEquipName() + " key)",
134141
screens.inventoryScreen.showInventory.eq1Ctrl);
135142
}
136143

@@ -209,11 +216,14 @@ private void s(String text, SolUiControl ctrl) {
209216
private void s(String text, SolUiControl ctrl, boolean checkOn) {
210217
mySteps.add(new Step(text, ctrl, checkOn));
211218
}
219+
private void s(Step step) {
220+
mySteps.add(step);
221+
}
212222

213223
public void update() {
214224
Step step = mySteps.get(myStepIdx);
215-
step.ctrl.enableWarn();
216-
if (step.checkOn ? step.ctrl.isOn() : step.ctrl.isJustOff()) {
225+
step.highlight();
226+
if (step.canProgressToNextStep()) {
217227
myStepIdx++;
218228
}
219229
}
@@ -239,5 +249,45 @@ public Step(String text, SolUiControl ctrl, boolean checkOn) {
239249
this.ctrl = ctrl;
240250
this.checkOn = checkOn;
241251
}
252+
253+
// highlight control that needs to be pressed
254+
public void highlight() {
255+
if(ctrl != null) ctrl.enableWarn();
256+
}
257+
258+
public boolean canProgressToNextStep() {
259+
if(checkOn) {
260+
return ctrl.isOn();
261+
} else {
262+
return ctrl.isJustOff();
263+
}
264+
}
265+
}
266+
267+
public static class SelectEquippedItemStep extends Step {
268+
InventoryScreen inventoryScreen;
269+
SolGame game;
270+
271+
public SelectEquippedItemStep(String text, InventoryScreen inventoryScreen, SolGame game) {
272+
super(text, null, true);
273+
this.inventoryScreen = inventoryScreen;
274+
this.game = game;
275+
}
276+
277+
@Override
278+
public boolean canProgressToNextStep() {
279+
SolItem selected = inventoryScreen.getSelectedItem();
280+
if(selected != null && selected.isEquipped() != 0) return true;
281+
return false;
282+
}
283+
284+
// Highlight all equipped items on opened inventory page
285+
@Override
286+
public void highlight() {
287+
List<SolUiControl> equippedItemControls = inventoryScreen.getEquippedItemUIControlsForTutorial(game);
288+
for(SolUiControl control : equippedItemControls) {
289+
control.enableWarn();
290+
}
291+
}
242292
}
243293
}

0 commit comments

Comments
 (0)