Implemented a generic book interface
Converted all books to new book interface Converted stats command to use the new book interface
This commit is contained in:
@@ -1,197 +0,0 @@
|
||||
package core.game.dialogue.book;
|
||||
|
||||
import core.game.component.Component;
|
||||
import core.game.dialogue.DialoguePlugin;
|
||||
import core.game.dialogue.DialoguePlugin;
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.plugin.PluginManifest;
|
||||
import core.plugin.PluginType;
|
||||
|
||||
/**
|
||||
* Represents a dialogue book.
|
||||
* @author 'Vexia
|
||||
* @date 1/1/14
|
||||
*/
|
||||
@PluginManifest(type = PluginType.DIALOGUE)
|
||||
public abstract class Book extends DialoguePlugin {
|
||||
|
||||
/**
|
||||
* Represents the component interface of the book.
|
||||
*/
|
||||
private static final Component INTERFACE = new Component(49);
|
||||
|
||||
/**
|
||||
* Represents the red string.
|
||||
*/
|
||||
protected static final String RED = "<col=8A0808>";
|
||||
|
||||
/**
|
||||
* Represents the blue string.
|
||||
*/
|
||||
protected static final String BLUE = "<col=08088A>";
|
||||
|
||||
/**
|
||||
* Represents the name of the book.
|
||||
*/
|
||||
protected String name;
|
||||
|
||||
/**
|
||||
* Represents the id of this book.
|
||||
*/
|
||||
protected int id;
|
||||
|
||||
/**
|
||||
* Represents the pages of this book.
|
||||
*/
|
||||
protected PageSet[] sets;
|
||||
|
||||
/**
|
||||
* Represents the index of the page set we're at.
|
||||
*/
|
||||
protected int index = -1;
|
||||
|
||||
/**
|
||||
* Constructs a new {@code Book} {@code Object}.
|
||||
* @param name the name.
|
||||
* @param id the id.
|
||||
*/
|
||||
public Book(final Player player, final String name, final int id, final PageSet... sets) {
|
||||
this.player = player;
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.sets = sets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@code Book} {@code Object}.
|
||||
*/
|
||||
public Book() {
|
||||
/**
|
||||
* empty.
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean open(Object... args) {
|
||||
return open(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(int interfaceId, int buttonId) {
|
||||
switch (buttonId) {
|
||||
case 112:
|
||||
player.getInterfaceManager().close();
|
||||
break;
|
||||
case 66:
|
||||
case 52:
|
||||
next();
|
||||
break;
|
||||
case 64:
|
||||
case 50:
|
||||
previous();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object fireEvent(String identifier, Object... args) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to open a book.
|
||||
* @return <code>True</code> if succesfully opened.
|
||||
*/
|
||||
public boolean open(final Player player) {
|
||||
next();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to write the next dialogue.
|
||||
*/
|
||||
public void next() {
|
||||
player.lock();
|
||||
index++;
|
||||
if (index > sets.length - 1) {
|
||||
player.unlock();
|
||||
player.getInterfaceManager().close();
|
||||
return;
|
||||
}
|
||||
final Page[] set = sets[index].getPages();
|
||||
display(set);
|
||||
player.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to write the previous dialogue.
|
||||
*/
|
||||
public void previous() {
|
||||
player.lock();
|
||||
index--;
|
||||
if (index < 0) {
|
||||
index = 0;
|
||||
}
|
||||
final Page[] set = sets[index].getPages();
|
||||
display(set);
|
||||
player.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to display a set of pages.
|
||||
* @param set the set.
|
||||
*/
|
||||
public void display(Page[] set) {
|
||||
// TODO: It seems like different subclasses instantiate this by
|
||||
// copy-paste, this should probably be made final, and should switch between a few
|
||||
// implementations by component id
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used when the book is finished.
|
||||
*/
|
||||
public void finish() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name.
|
||||
* @return The name.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id.
|
||||
* @return The id.
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the index.
|
||||
* @return The index.
|
||||
*/
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the index.
|
||||
* @param index The index to set.
|
||||
*/
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the interface component.
|
||||
* @return the component.
|
||||
*/
|
||||
public Component getInterface() {
|
||||
return INTERFACE;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package core.game.dialogue.book;
|
||||
|
||||
/**
|
||||
* Represents a book line.
|
||||
* @author 'Vexia
|
||||
* @date 31/12/2013
|
||||
*/
|
||||
public class BookLine {
|
||||
|
||||
/**
|
||||
* Represents the message to display.
|
||||
*/
|
||||
private final String message;
|
||||
|
||||
/**
|
||||
* Represents the child if of the line.
|
||||
*/
|
||||
private final int child;
|
||||
|
||||
/**
|
||||
* Constructs a new {@code Page} {@code Object}.
|
||||
* @param message the message.
|
||||
* @param child the child.
|
||||
*/
|
||||
public BookLine(final String message, final int child) {
|
||||
this.message = message;
|
||||
this.child = child;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message.
|
||||
* @return The message.
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the child.
|
||||
* @return The child.
|
||||
*/
|
||||
public int getChild() {
|
||||
return child;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package core.game.dialogue.book;
|
||||
|
||||
/**
|
||||
* Represents a page on a book.
|
||||
* @author 'Vexia
|
||||
* @date 1/1/14
|
||||
*/
|
||||
public class Page {
|
||||
|
||||
/**
|
||||
* Represents the lines on a page.
|
||||
*/
|
||||
private final BookLine[] lines;
|
||||
|
||||
/**
|
||||
* Constructs a new {@code Page} {@code Object}.
|
||||
* @param lines the lines.
|
||||
*/
|
||||
public Page(BookLine... lines) {
|
||||
this.lines = lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the lines.
|
||||
* @return The lines.
|
||||
*/
|
||||
public BookLine[] getLines() {
|
||||
return lines;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package core.game.dialogue.book;
|
||||
|
||||
/**
|
||||
* Represents a set of pages on a book.
|
||||
* @author 'Vexia
|
||||
*/
|
||||
public class PageSet {
|
||||
|
||||
/**
|
||||
* Represents the set of pages.
|
||||
*/
|
||||
private final Page[] pages;
|
||||
|
||||
/**
|
||||
* Constructs a new {@code PageSet} {@code Object}.
|
||||
* @param pages the pages.
|
||||
*/
|
||||
public PageSet(final Page... pages) {
|
||||
this.pages = pages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the pages.
|
||||
* @return The pages.
|
||||
*/
|
||||
public Page[] getPages() {
|
||||
return pages;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user