Big map update 9

Nicer dialogs with word wrapping.
This commit is contained in:
Magpie
2022-04-16 17:14:06 +02:00
parent 5a157d7947
commit 6d06c0787f
2 changed files with 30 additions and 29 deletions

View File

@@ -8,8 +8,9 @@ public class DialogData {
public EffectData[] effect; //List of effects to cause when the dialog shows. public EffectData[] effect; //List of effects to cause when the dialog shows.
public ConditionData[] condition; //List of conditions for the action to show. public ConditionData[] condition; //List of conditions for the action to show.
public String name; //Text to display when action is listed as a button. public String name; //Text to display when action is listed as a button.
public String locname; //References a localized string for the button labels.
public String text; //The text body. public String text; //The text body.
public String loctext; //References a localized string. public String loctext; //References a localized string for the text body.
public DialogData[] options; // public DialogData[] options; //
static public class EffectData { static public class EffectData {

View File

@@ -1,11 +1,14 @@
package forge.adventure.util; package forge.adventure.util;
import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Json; import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.SerializationException; import com.badlogic.gdx.utils.SerializationException;
import forge.Forge; import forge.Forge;
import forge.adventure.data.DialogData; import forge.adventure.data.DialogData;
import forge.adventure.stage.MapStage; import forge.adventure.stage.MapStage;
import forge.util.Localizer;
/** /**
* MapDialog * MapDialog
* Implements a dialogue/event tree for dialogs. * Implements a dialogue/event tree for dialogs.
@@ -15,7 +18,7 @@ public class MapDialog {
private final MapStage stage; private final MapStage stage;
private Array<DialogData> data; private Array<DialogData> data;
private final int parentID; private final int parentID;
private final float WIDTH = 260f;
static private final String defaultJSON = "[\n" + static private final String defaultJSON = "[\n" +
" {\n" + " {\n" +
" \"effect\":[],\n" + " \"effect\":[],\n" +
@@ -46,30 +49,27 @@ public class MapDialog {
} }
} }
private void loadDialog(DialogData dialog) { private void loadDialog(DialogData dialog) { //Displays a dialog with dialogue and possible choices.
setEffects(dialog.effect); setEffects(dialog.effect);
stage.getDialog().getContentTable().clear(); Dialog D = stage.getDialog();
stage.getDialog().getButtonTable().clear(); Localizer L = Forge.getLocalizer();
String text; D.getContentTable().clear(); D.getButtonTable().clear(); //Clear tables to start fresh.
if(dialog.loctext != null && !dialog.loctext.isEmpty()){ //Check for localized string, otherwise print text. String text; //Check for localized string (locname), otherwise print text.
text = Forge.getLocalizer().getMessage(dialog.loctext); if(dialog.loctext != null && !dialog.loctext.isEmpty()) text = L.getMessage(dialog.loctext);
} else { else text = dialog.text;
text = dialog.text; Label A = Controls.newLabel(text);
} A.setWrap(true);
D.getContentTable().add(A).width(WIDTH); //Add() returns a Cell, which is what the width is being applied to.
int charCount = 0;
stage.getDialog().text(text);
if(dialog.options != null) { if(dialog.options != null) {
for(DialogData option:dialog.options) { for(DialogData option:dialog.options) {
if( isConditionOk(option.condition) ) { if( isConditionOk(option.condition) ) {
charCount += option.name.length(); String name; //Get localized label if present.
if(charCount > 35){ //Gross hack. if(option.locname != null && !option.locname.isEmpty()) name = L.getMessage(option.locname);
stage.getDialog().getButtonTable().row(); else name = option.name;
charCount = 0; TextButton B = Controls.newTextButton(name,() -> loadDialog(option));
} B.getLabel().setWrap(true); //We want this to wrap in case it's a wordy choice.
stage.getDialog().getButtonTable().add(Controls.newTextButton(option.name,() -> loadDialog(option))); D.getButtonTable().add(B).width(WIDTH - 10); //The button table also returns a Cell when adding.
D.getButtonTable().row(); //Add a row. Tried to allow a few per row but it was a bit erratic.
} }
} }
stage.showDialog(); stage.showDialog();
@@ -90,23 +90,23 @@ public class MapDialog {
void setEffects(DialogData.EffectData[] data) { void setEffects(DialogData.EffectData[] data) {
if(data==null) return; if(data==null) return;
for(DialogData.EffectData E:data) { for(DialogData.EffectData E:data) {
if (E.removeItem != null){ if (E.removeItem != null){ //Removes an item from the player's inventory.
Current.player().removeItem(E.removeItem); Current.player().removeItem(E.removeItem);
} }
if (E.addItem != null){ if (E.addItem != null){ //Gives an item to the player.
Current.player().addItem(E.addItem); Current.player().addItem(E.addItem);
} }
if (E.deleteMapObject != 0){ if (E.deleteMapObject != 0){ //Removes a dummy object from the map.
if(E.deleteMapObject < 0) stage.deleteObject(parentID); if(E.deleteMapObject < 0) stage.deleteObject(parentID);
else stage.deleteObject(E.deleteMapObject); else stage.deleteObject(E.deleteMapObject);
} }
if (E.battleWithActorID != 0){ if (E.battleWithActorID != 0){ //Starts a battle with the given enemy ID.
if(E.battleWithActorID < 0) stage.beginDuel(stage.getEnemyByID(parentID)); if(E.battleWithActorID < 0) stage.beginDuel(stage.getEnemyByID(parentID));
else stage.beginDuel(stage.getEnemyByID(E.battleWithActorID)); else stage.beginDuel(stage.getEnemyByID(E.battleWithActorID));
} }
//Create map object.
//Check for quest flags, local.
//Check for quest flags, global.
} }
} }