-
Notifications
You must be signed in to change notification settings - Fork 1
NPC Dialog Code Structure
NPC dialog interaction is mainly implemented in NpcInteractionDisplay.java and DialogWithSelection.java. In NpcInteractionDisplay.java, a dialog box is set, and dialog texts will be placed in the dialog box according to different chapter scripts.
// set dialog box
dialogBox = new Image(ServiceLocator.getResourceService().getAsset(
"images/npc_interaction/dialog_box.png", Texture.class));
dialogBox.setPosition((float) (stage.getWidth() * 0.05), 0);
dialogBox.setSize((float) (stage.getWidth() * 0.9), (float) (stage.getHeight() * 0.2));
stage.addActor(dialogBox);
setDialog() will read dialogs in different chapters according to the chapterNum.
private void setDialog() {
step = 0;
dialog = new Label("Chapter " + chapterNum, skin);
dialog.setPosition((float) (stage.getWidth() * 0.1), (float) (stage.getHeight() * 0.1));
dialog.setWrap(true);
dialog.setWidth((float) (stage.getWidth() * 0.8));
stage.addActor(dialog);
try {
if (chapterNum == 1 || chapterNum == 4) {// chapter without selections
ArrayList<String> texts = NpcInteraction.readNpcFiles(chapterNum);
Iterator<String> it = texts.iterator();
switch (chapterNum) {
case 1 -> clickListener = new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
chapter1Listener(it);
}
};
case 4 -> clickListener = new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
chapter4Listener(it);
}
};
}
} else {
switch (chapterNum) {
case 2 -> {
root = DialogWithSelection.getChapter2Dialog();
clickListener = new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
chapter2Listener();
}
};
}
case 3 -> {
root = DialogWithSelection.getChapter3Dialog();
clickListener = new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
chapter3Listener();
}
};
}
case 5 -> {
root = DialogWithSelection.getChapter5Dialog();
clickListener = new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
chapter5Listener();
}
};
}
}
}
dialogBox.addListener(clickListener);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Chapter 1 and 4 do not have selection points, so their dialogs are implemented in an array list, and the dialogs are advanced through the iterator.
The other chapters have selection points, so their dialogs are implemented through a tree data structure (DialogWithSelection) in DialogWithSelection.java.
public class DialogWithSelection {
private String dialog;
private DialogWithSelection next;
private DialogWithSelection option1;
private DialogWithSelection option2;
A DialogWithSelection has four properties:
- dialog: One line sentence in the dialog script
- next: The next dialog.
- option1: The first option of a selection point.
- option2: The second option of a selection point.
If a dialog is a selection point, it will be set as the selection point through setSelectionPoint function, which will set a DialogWithSelection without dialog as its next DialogWithSelection, and set options on the new DialogWithSelection, and then set follow-up dialogs for the two options.
public void setSelectionPoint(String option1Text, String option2Text,
int chapterNum, int selectionNum) {
// set selection point for root
DialogWithSelection selectionPoint = new DialogWithSelection(null);
DialogWithSelection option1 = new DialogWithSelection(option1Text);
DialogWithSelection option2 = new DialogWithSelection(option2Text);
this.setNext(selectionPoint);
selectionPoint.setOption1(option1);
selectionPoint.setOption2(option2);
// set follow-up dialogs for the two options
try {
for (String dialog : readOptionDialogs(chapterNum, selectionNum, 1)) {
option1.setNext(new DialogWithSelection(dialog));
option1 = option1.getNext();
}
for (String dialog : readOptionDialogs(chapterNum, selectionNum, 2)) {
option2.setNext(new DialogWithSelection(dialog));
option2 = option2.getNext();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
After setting all dialogs of chapter X, the root (the first sentence of a chapter) DialogWithSelection will be returned through the getChapterXDialog function, and the dialog can be advanced through getNext, getOption1, getOption2 functions.
- Uniform Pixel Grid Resolution
- Storyline
- Instruction
- NPC info
- NPC Communication Script
- Inventory-System-and-Consumables
- Storyline User Test
- Traitor Clues
- Game Characters
- Player Profile User Test
- Player Eviction Menu Sprint1: User survey (Team 7)
- Player Eviction Menu Sprint2: User survey (Team 7)
- Sprint3 - Win/lose Condition: User survey (Team 7)
- Sprint4 - Polishing-tasks: User survey (Team 7)
- Transition Animation/Special Effects/Sound Effects: Feature Overviews
- Transition Animation and Effects: Design Process & Guideline
- Sprint 4 User Testing
- Transition Animation & Effect: Code Guideline-Sprint4
- Sound effect when players complete npc tasks and hover over npc cards
- Fixing the clue bug
- Music Test
- Player Eviction Menu: Design Process & Guideline
- Player Eviction Menu (Feature Overviews)
- Player Eviction Menu: Code Guideline - Sprint1
- Sprint 1 User Testing
- Detailed Eviction Card: Design Process & Guideline
- Detailed Eviction Card: Feature Overviews
- Sprint 2 User Testing
- Player Eviction Menu: Code Guideline - Sprint2
- Sprint 2 Inventory System and Consumables Items User Testing
- Sprint 2 Inventory System and Consumables Items Functionality
- NPC interaction testing plan sprint3
- NPC interaction testing results sprint3
- NPC Dialogue Scripts
- Code Guideline
- Win/lose Condition: Design Process & Guideline
- Win/lose Condition: Feature Overviews
- Sprint 3 User Testing
- Win/lose condition: Code Guideline - Sprint3
- Enemy List
- User Testing 1: Enemy Image Filter
- User Testing 2: Enemy Animation and AI
- User Testing 3: Basic Attack