Skip to content

Commit

Permalink
Fix GameDialog-related bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Hitonoriol committed Aug 5, 2021
1 parent 1c1048d commit 0c0c284
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 42 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ gradle.startParameter.showStacktrace = org.gradle.api.logging.configuration.Show
allprojects {
apply plugin: "eclipse"

version = 'v0.49.16.1a'
version = 'v0.49.16.2a'

ext {
appName = "MadSand"
Expand Down
21 changes: 4 additions & 17 deletions core/src/hitonoriol/madsand/dialog/DialogChainGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;

import hitonoriol.madsand.Gui;
import hitonoriol.madsand.lua.Lua;
Expand Down Expand Up @@ -69,26 +67,15 @@ private TextButton generateDialog(String dialogBody, GameDialog dialog) { // ret
buttonTokens = buttonString.split(DIALOG_BTN_SCRIPT_DELIMITER); // [Button Text @ lua code]
scriptButton = new TextButton(buttonTokens[0], Gui.skin);
final String buttonScriptString = buttonTokens[1];

dialog.addButton(scriptButton);
scriptButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
dialog.hide();
Lua.execute(buttonScriptString);
}
Gui.setAction(scriptButton, () -> {
dialog.hide();
Lua.execute(buttonScriptString);
});

} else {
nextDialogButton.setText(buttonString);
dialog.addButton(nextDialogButton);
nextDialogButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
dialog.hide();
}
});

Gui.setAction(nextDialogButton, () -> dialog.hide());
}
}

Expand Down
47 changes: 25 additions & 22 deletions core/src/hitonoriol/madsand/dialog/GameDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Align;

import hitonoriol.madsand.Gui;
Expand All @@ -34,6 +33,7 @@ public class GameDialog extends Dialog {
protected Label textLbl;
protected TextButton proceedButton;
protected Stage stage;
private boolean hasNext = false;
private float cWidth = -1, cHeight = -1;

public GameDialog(String title, String text, Stage stage) {
Expand Down Expand Up @@ -116,10 +116,11 @@ public void centerTitle() {
@Override
public boolean remove() {
boolean ret = super.remove();
TimeUtils.scheduleTask(() -> {
Gui.gameResumeFocus(this);
Gui.overlay.refreshActionButton();
}, Gui.DELAY);
if (!hasNext)
TimeUtils.scheduleTask(() -> {
Gui.gameResumeFocus(this);
Gui.overlay.refreshActionButton();
}, Gui.DELAY);
return ret;
}

Expand All @@ -132,12 +133,13 @@ public Dialog show(Stage stage) {
return ret;
}

public void chainReply(TextButton replyButton, final GameDialog nextDialog) {
replyButton.addListener(new ChangeListener() {
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
hide();
nextDialog.show(stage);
}
protected void chainReply(TextButton replyButton, final GameDialog nextDialog) {
if (!hasNext)
hasNext = true;

Gui.setAction(replyButton, () -> {
hide();
nextDialog.show(stage);
});
}

Expand All @@ -149,22 +151,13 @@ public void chainReply(String btnText, GameDialog nextDialog) {

public void addOkButton(String text) {
TextButton okBtn = new TextButton(text, Gui.skin);
okBtn.addListener(new ChangeListener() {
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
hide();
}
});
Gui.setAction(okBtn, () -> hide());
addButton(okBtn);
}

public void addLuaButton(String buttonText, String luaCode) {
TextButton button = new TextButton(buttonText, Gui.skin);
button.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Lua.execute(luaCode);
}
});
Gui.setAction(button, () -> Lua.execute(luaCode));
addButton(button);
}

Expand Down Expand Up @@ -264,6 +257,10 @@ protected void ignoreKeyboard() {
addListener(inputCanceller);
}

protected boolean keyboardIgnored() {
return getListeners().contains(inputCanceller, true);
}

public static GameDialog generateDialogChain(String text, Stage stage) {
return new DialogChainGenerator(text).generate(stage);
}
Expand All @@ -289,5 +286,11 @@ public boolean keyUp(InputEvent event, int keycode) {
event.cancel();
return true;
}

@Override
public boolean keyDown(InputEvent event, int keycode) {
event.cancel();
return true;
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private String npcInteractionString(AbstractNpc npc) {
}

public void refresh() {
if ((Gui.isGameUnfocused() && !isVisible()) || Keyboard.inputIgnored()) {
if (Gui.dialogActive || (Gui.isGameUnfocused() && !isVisible()) || Keyboard.inputIgnored()) {
hideButton();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public void open() {
}

public void close() {
Gui.overlay.showTooltip();
if (!Gui.dialogActive)
Gui.overlay.showTooltip();
setVisible(false);
Gui.gameUnfocused = false;
}
Expand Down

0 comments on commit 0c0c284

Please sign in to comment.