Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
-Added comments to TutorialHandler, closes #19
  • Loading branch information
Scribble authored and PancakeTAS committed Dec 17, 2020
1 parent 61cdd18 commit 774d02f
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/main/java/de/scribble/lp/tasmod/tutorial/TutorialHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

/**
* Renders an interactive tutorial to the game overlay.
*
* @author ScribbleLP
*
*/
public class TutorialHandler {

public static boolean istutorial;
Expand All @@ -25,16 +31,23 @@ public class TutorialHandler {

public TutorialHandler() {
}

public TutorialHandler(int state) {
this.state=state;
}

public void setState(int state) {
cooldown=cooldowntime;
this.state = state;
}

public int getState() {
return state;
}
/**
* Get the current text depending on the state
* @return String[]
*/
public String[] getTutorialText() {
String[] textout;
switch (state) {
Expand Down Expand Up @@ -80,6 +93,9 @@ public String[] getTutorialText() {
}
return textout;
}
/**
* Checks for an action that advances or closes the tutorial
*/
private void checkForKeys() {
switch (state) {
case 0:
Expand All @@ -90,7 +106,7 @@ private void checkForKeys() {
case 8:
case 11:

if(Keyboard.isKeyDown(Keyboard.KEY_RETURN)&&cooldown==0) {
if(Keyboard.isKeyDown(Keyboard.KEY_RETURN)&&cooldown==0) { //Checking for presses on the physical keyboard, since tickrate 0 is a thing
advanceState();
}
break;
Expand All @@ -113,11 +129,19 @@ private void checkForKeys() {
break;
}
}
/**
* Advances the tutorial state and adds cooldown
*/
public void advanceState() {
cooldown=cooldowntime;
state++;
}
Minecraft mc= Minecraft.getMinecraft();

/**
* Main rendering event. This is needed so it can function in tickrate 0
* @param event
*/
@SubscribeEvent
public void drawStuff(RenderGameOverlayEvent.Post event) {
if (istutorial) {
Expand All @@ -129,17 +153,20 @@ public void drawStuff(RenderGameOverlayEvent.Post event) {
int width = scaled.getScaledWidth();
int height = scaled.getScaledHeight();
String[] text = getTutorialText();
for (int i = 0; i < text.length; i++) {


for (int i = 0; i < text.length; i++) { //For every new element in the string array, a new line is created.
String tex = text[i];
new Gui().drawString(mc.fontRenderer, tex, width - mc.fontRenderer.getStringWidth(tex) - 10,
10 + 10 * i, 0xFFFFFF);
10 + 10 * i, 0xFFFFFF); //Drawing the text on the screen
}

if (cooldown != 0) {
cooldown--;
cooldown--; //Decreasing the cooldown of the button cooldown until it reaches 0
}
}
}
//Every String in one place... maybe later with translations
private final String[] text1={"1. Hi, welcome to this InTeRaCtIvE tutorial on how to use this mod.",
"",
"If you have already enough of this text,",
Expand Down

0 comments on commit 774d02f

Please sign in to comment.