v0.9.4: adjusted document functionality, now supports page states.
This commit is contained in:
@@ -414,8 +414,8 @@ public class Heap implements Bundlable {
|
|||||||
//remove any document pages that either don't exist anymore or that the player already has
|
//remove any document pages that either don't exist anymore or that the player already has
|
||||||
for (Item item : items.toArray(new Item[0])){
|
for (Item item : items.toArray(new Item[0])){
|
||||||
if (item instanceof DocumentPage
|
if (item instanceof DocumentPage
|
||||||
&& ( !((DocumentPage) item).document().pages().contains(((DocumentPage) item).page())
|
&& ( !((DocumentPage) item).document().pageNames().contains(((DocumentPage) item).page())
|
||||||
|| ((DocumentPage) item).document().hasPage(((DocumentPage) item).page()))){
|
|| ((DocumentPage) item).document().pageFound(((DocumentPage) item).page()))){
|
||||||
items.remove(item);
|
items.remove(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -58,7 +58,7 @@ public abstract class DocumentPage extends Item {
|
|||||||
} else {
|
} else {
|
||||||
WndJournal.last_index = 0;
|
WndJournal.last_index = 0;
|
||||||
}
|
}
|
||||||
document().addPage(page);
|
document().findPage(page);
|
||||||
Sample.INSTANCE.play( Assets.Sounds.ITEM );
|
Sample.INSTANCE.play( Assets.Sounds.ITEM );
|
||||||
hero.spendAndNext( TIME_TO_PICK_UP );
|
hero.spendAndNext( TIME_TO_PICK_UP );
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -26,11 +26,8 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
|
|||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
import com.watabou.utils.DeviceCompat;
|
import com.watabou.utils.DeviceCompat;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public enum Document {
|
public enum Document {
|
||||||
|
|
||||||
@@ -40,37 +37,52 @@ public enum Document {
|
|||||||
Document( int sprite ){
|
Document( int sprite ){
|
||||||
pageSprite = sprite;
|
pageSprite = sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final int NOT_FOUND = 0;
|
||||||
|
private static final int FOUND = 1;
|
||||||
|
private static final int READ = 2;
|
||||||
|
private LinkedHashMap<String, Integer> pagesStates = new LinkedHashMap<>();
|
||||||
|
|
||||||
private LinkedHashMap<String, Boolean> pages = new LinkedHashMap<>();
|
public boolean findPage(String page ) {
|
||||||
|
if (pagesStates.containsKey(page) && pagesStates.get(page) == NOT_FOUND){
|
||||||
public Collection<String> pages(){
|
pagesStates.put(page, FOUND);
|
||||||
return pages.keySet();
|
Journal.saveNeeded = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addPage( String page ) {
|
public boolean readPage( String page ) {
|
||||||
if (pages.containsKey(page) && !pages.get(page)){
|
if (pagesStates.containsKey(page) && pagesStates.get(page) == FOUND){
|
||||||
pages.put(page, true);
|
pagesStates.put(page, READ);
|
||||||
Journal.saveNeeded = true;
|
Journal.saveNeeded = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPage( String page ){
|
public boolean pageFound( String page ){
|
||||||
return pages.containsKey(page) && pages.get(page);
|
return pagesStates.containsKey(page) && pagesStates.get(page) > NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPage( int pageIdx ){
|
public boolean pageFound( int pageIdx ){
|
||||||
return hasPage( pages.keySet().toArray(new String[0])[pageIdx] );
|
return pageFound( pagesStates.keySet().toArray(new String[0])[pageIdx] );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAnyPages(){
|
public boolean pageRead( String page ){
|
||||||
for (String p : pages.keySet()){
|
return pagesStates.containsKey(page) && pagesStates.get(page) == READ;
|
||||||
if (pages.get(p)) {
|
}
|
||||||
return true;
|
|
||||||
}
|
public boolean pageRead( int pageIdx ){
|
||||||
}
|
return pageRead( pagesStates.keySet().toArray(new String[0])[pageIdx] );
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
public void setPageState( String page, int state ){
|
||||||
|
if (pagesStates.containsKey(page)) pagesStates.put(page, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<String> pageNames(){
|
||||||
|
return pagesStates.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int pageSprite;
|
private int pageSprite;
|
||||||
@@ -87,7 +99,7 @@ public enum Document {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String pageTitle( int pageIdx ){
|
public String pageTitle( int pageIdx ){
|
||||||
return pageTitle( pages.keySet().toArray(new String[0])[pageIdx] );
|
return pageTitle( pagesStates.keySet().toArray(new String[0])[pageIdx] );
|
||||||
}
|
}
|
||||||
|
|
||||||
public String pageBody( String page ){
|
public String pageBody( String page ){
|
||||||
@@ -95,58 +107,60 @@ public enum Document {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String pageBody( int pageIdx ){
|
public String pageBody( int pageIdx ){
|
||||||
return pageBody( pages.keySet().toArray(new String[0])[pageIdx] );
|
return pageBody( pagesStates.keySet().toArray(new String[0])[pageIdx] );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String GUIDE_INTRO_PAGE = "Intro";
|
public static final String GUIDE_INTRO_PAGE = "Intro";
|
||||||
public static final String GUIDE_SEARCH_PAGE = "Examining_and_Searching";
|
public static final String GUIDE_SEARCH_PAGE = "Examining_and_Searching";
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ADVENTURERS_GUIDE.pages.put(GUIDE_INTRO_PAGE, DeviceCompat.isDebug());
|
ADVENTURERS_GUIDE.pagesStates.put(GUIDE_INTRO_PAGE, DeviceCompat.isDebug() ? 2 : 0);
|
||||||
ADVENTURERS_GUIDE.pages.put("Identifying", DeviceCompat.isDebug());
|
ADVENTURERS_GUIDE.pagesStates.put("Identifying", DeviceCompat.isDebug() ? 2 : 0);
|
||||||
ADVENTURERS_GUIDE.pages.put(GUIDE_SEARCH_PAGE, DeviceCompat.isDebug());
|
ADVENTURERS_GUIDE.pagesStates.put(GUIDE_SEARCH_PAGE, DeviceCompat.isDebug() ? 2 : 0);
|
||||||
ADVENTURERS_GUIDE.pages.put("Strength", DeviceCompat.isDebug());
|
ADVENTURERS_GUIDE.pagesStates.put("Strength", DeviceCompat.isDebug() ? 2 : 0);
|
||||||
ADVENTURERS_GUIDE.pages.put("Food", DeviceCompat.isDebug());
|
ADVENTURERS_GUIDE.pagesStates.put("Food", DeviceCompat.isDebug() ? 2 : 0);
|
||||||
ADVENTURERS_GUIDE.pages.put("Levelling", DeviceCompat.isDebug());
|
ADVENTURERS_GUIDE.pagesStates.put("Levelling", DeviceCompat.isDebug() ? 2 : 0);
|
||||||
ADVENTURERS_GUIDE.pages.put("Surprise_Attacks", DeviceCompat.isDebug());
|
ADVENTURERS_GUIDE.pagesStates.put("Surprise_Attacks", DeviceCompat.isDebug() ? 2 : 0);
|
||||||
ADVENTURERS_GUIDE.pages.put("Dieing", DeviceCompat.isDebug());
|
ADVENTURERS_GUIDE.pagesStates.put("Dieing", DeviceCompat.isDebug() ? 2 : 0);
|
||||||
ADVENTURERS_GUIDE.pages.put("Looting", DeviceCompat.isDebug());
|
ADVENTURERS_GUIDE.pagesStates.put("Looting", DeviceCompat.isDebug() ? 2 : 0);
|
||||||
ADVENTURERS_GUIDE.pages.put("Magic", DeviceCompat.isDebug());
|
ADVENTURERS_GUIDE.pagesStates.put("Magic", DeviceCompat.isDebug() ? 2 : 0);
|
||||||
|
|
||||||
//sewers
|
//sewers
|
||||||
ALCHEMY_GUIDE.pages.put("Potions", DeviceCompat.isDebug());
|
ALCHEMY_GUIDE.pagesStates.put("Potions", DeviceCompat.isDebug() ? 2 : 0);
|
||||||
ALCHEMY_GUIDE.pages.put("Stones", DeviceCompat.isDebug());
|
ALCHEMY_GUIDE.pagesStates.put("Stones", DeviceCompat.isDebug() ? 2 : 0);
|
||||||
ALCHEMY_GUIDE.pages.put("Energy_Food", DeviceCompat.isDebug());
|
ALCHEMY_GUIDE.pagesStates.put("Energy_Food", DeviceCompat.isDebug() ? 2 : 0);
|
||||||
ALCHEMY_GUIDE.pages.put("Bombs", DeviceCompat.isDebug());
|
ALCHEMY_GUIDE.pagesStates.put("Bombs", DeviceCompat.isDebug() ? 2 : 0);
|
||||||
ALCHEMY_GUIDE.pages.put("Weapons", DeviceCompat.isDebug());
|
ALCHEMY_GUIDE.pagesStates.put("Weapons", DeviceCompat.isDebug() ? 2 : 0);
|
||||||
|
|
||||||
//prison
|
//prison
|
||||||
ALCHEMY_GUIDE.pages.put("Exotic_Potions", DeviceCompat.isDebug());
|
ALCHEMY_GUIDE.pagesStates.put("Exotic_Potions", DeviceCompat.isDebug() ? 2 : 0);
|
||||||
ALCHEMY_GUIDE.pages.put("Exotic_Scrolls", DeviceCompat.isDebug());
|
ALCHEMY_GUIDE.pagesStates.put("Exotic_Scrolls", DeviceCompat.isDebug() ? 2 : 0);
|
||||||
ALCHEMY_GUIDE.pages.put("Catalysts", DeviceCompat.isDebug());
|
ALCHEMY_GUIDE.pagesStates.put("Catalysts", DeviceCompat.isDebug() ? 2 : 0);
|
||||||
ALCHEMY_GUIDE.pages.put("Brews_Elixirs", DeviceCompat.isDebug());
|
ALCHEMY_GUIDE.pagesStates.put("Brews_Elixirs", DeviceCompat.isDebug() ? 2 : 0);
|
||||||
ALCHEMY_GUIDE.pages.put("Spells", DeviceCompat.isDebug());
|
ALCHEMY_GUIDE.pagesStates.put("Spells", DeviceCompat.isDebug() ? 2 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String DOCUMENTS = "documents";
|
private static final String DOCUMENTS = "documents";
|
||||||
|
|
||||||
public static void store( Bundle bundle ){
|
public static void store( Bundle bundle ){
|
||||||
|
|
||||||
Bundle docBundle = new Bundle();
|
Bundle docsBundle = new Bundle();
|
||||||
|
|
||||||
for ( Document doc : values()){
|
for ( Document doc : values()){
|
||||||
ArrayList<String> pages = new ArrayList<>();
|
Bundle pagesBundle = new Bundle();
|
||||||
for (String page : doc.pages()){
|
boolean empty = true;
|
||||||
if (doc.pages.get(page)){
|
for (String page : doc.pageNames()){
|
||||||
pages.add(page);
|
if (doc.pagesStates.get(page) != NOT_FOUND){
|
||||||
|
pagesBundle.put(page, doc.pagesStates.get(page));
|
||||||
|
empty = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!pages.isEmpty()) {
|
if (!empty){
|
||||||
docBundle.put(doc.name(), pages.toArray(new String[0]));
|
docsBundle.put(doc.name(), pagesBundle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bundle.put( DOCUMENTS, docBundle );
|
bundle.put( DOCUMENTS, docsBundle );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,14 +170,25 @@ public enum Document {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bundle docBundle = bundle.getBundle( DOCUMENTS );
|
Bundle docsBundle = bundle.getBundle( DOCUMENTS );
|
||||||
|
|
||||||
for ( Document doc : values()){
|
for ( Document doc : values()){
|
||||||
if (docBundle.contains(doc.name())){
|
if (docsBundle.contains(doc.name())){
|
||||||
List<String> pages = Arrays.asList(docBundle.getStringArray(doc.name()));
|
Bundle pagesBundle = docsBundle.getBundle(doc.name());
|
||||||
for (String page : pages){
|
|
||||||
if (doc.pages.containsKey(page)) {
|
//compatibility with pre-0.9.4 saves
|
||||||
doc.pages.put(page, true);
|
if (pagesBundle.isNull()) {
|
||||||
|
for (String page : docsBundle.getStringArray(doc.name())){
|
||||||
|
if (doc.pagesStates.containsKey(page)) {
|
||||||
|
doc.pagesStates.put(page, READ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
for (String page : doc.pageNames()) {
|
||||||
|
if (pagesBundle.contains(page)) {
|
||||||
|
doc.pagesStates.put(page, pagesBundle.getInt(page));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -436,10 +436,10 @@ public abstract class RegularLevel extends Level {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//guide pages
|
//guide pages
|
||||||
Collection<String> allPages = Document.ADVENTURERS_GUIDE.pages();
|
Collection<String> allPages = Document.ADVENTURERS_GUIDE.pageNames();
|
||||||
ArrayList<String> missingPages = new ArrayList<>();
|
ArrayList<String> missingPages = new ArrayList<>();
|
||||||
for ( String page : allPages){
|
for ( String page : allPages){
|
||||||
if (!Document.ADVENTURERS_GUIDE.hasPage(page)){
|
if (!Document.ADVENTURERS_GUIDE.pageFound(page)){
|
||||||
missingPages.add(page);
|
missingPages.add(page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -216,7 +216,7 @@ public abstract class RegularPainter extends Painter {
|
|||||||
|
|
||||||
//entrance doors on floor 2 are hidden if the player hasn't picked up 2nd guidebook page
|
//entrance doors on floor 2 are hidden if the player hasn't picked up 2nd guidebook page
|
||||||
if (Dungeon.depth == 2
|
if (Dungeon.depth == 2
|
||||||
&& !Document.ADVENTURERS_GUIDE.hasPage(Document.GUIDE_SEARCH_PAGE)
|
&& !Document.ADVENTURERS_GUIDE.pageFound(Document.GUIDE_SEARCH_PAGE)
|
||||||
&& r instanceof EntranceRoom){
|
&& r instanceof EntranceRoom){
|
||||||
d.type = Room.Door.Type.HIDDEN;
|
d.type = Room.Door.Type.HIDDEN;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -76,10 +76,10 @@ public class LaboratoryRoom extends SpecialRoom {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//guide pages
|
//guide pages
|
||||||
Collection<String> allPages = Document.ALCHEMY_GUIDE.pages();
|
Collection<String> allPages = Document.ALCHEMY_GUIDE.pageNames();
|
||||||
ArrayList<String> missingPages = new ArrayList<>();
|
ArrayList<String> missingPages = new ArrayList<>();
|
||||||
for ( String page : allPages){
|
for ( String page : allPages){
|
||||||
if (!Document.ALCHEMY_GUIDE.hasPage(page)){
|
if (!Document.ALCHEMY_GUIDE.pageFound(page)){
|
||||||
missingPages.add(page);
|
missingPages.add(page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -66,7 +66,7 @@ public class EntranceRoom extends StandardRoom {
|
|||||||
Random.pushGenerator();
|
Random.pushGenerator();
|
||||||
|
|
||||||
//places the first guidebook page on floor 1
|
//places the first guidebook page on floor 1
|
||||||
if (Dungeon.depth == 1 && !Document.ADVENTURERS_GUIDE.hasPage(Document.GUIDE_INTRO_PAGE)){
|
if (Dungeon.depth == 1 && !Document.ADVENTURERS_GUIDE.pageFound(Document.GUIDE_INTRO_PAGE)){
|
||||||
int pos;
|
int pos;
|
||||||
do {
|
do {
|
||||||
//can't be on bottom row of tiles
|
//can't be on bottom row of tiles
|
||||||
@@ -79,7 +79,7 @@ public class EntranceRoom extends StandardRoom {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//places the third guidebook page on floor 2
|
//places the third guidebook page on floor 2
|
||||||
if (Dungeon.depth == 2 && !Document.ADVENTURERS_GUIDE.hasPage(Document.GUIDE_SEARCH_PAGE)){
|
if (Dungeon.depth == 2 && !Document.ADVENTURERS_GUIDE.pageFound(Document.GUIDE_SEARCH_PAGE)){
|
||||||
int pos;
|
int pos;
|
||||||
do {
|
do {
|
||||||
//can't be on bottom row of tiles
|
//can't be on bottom row of tiles
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ public class WndJournal extends WndTabbed {
|
|||||||
|
|
||||||
pos += Math.max(ITEM_HEIGHT, title.height());
|
pos += Math.max(ITEM_HEIGHT, title.height());
|
||||||
|
|
||||||
for (String page : Document.ADVENTURERS_GUIDE.pages()){
|
for (String page : Document.ADVENTURERS_GUIDE.pageNames()){
|
||||||
GuideItem item = new GuideItem( page );
|
GuideItem item = new GuideItem( page );
|
||||||
|
|
||||||
item.setRect( 0, pos, width(), ITEM_HEIGHT );
|
item.setRect( 0, pos, width(), ITEM_HEIGHT );
|
||||||
@@ -268,7 +268,7 @@ public class WndJournal extends WndTabbed {
|
|||||||
super( iconForPage(page), Messages.titleCase(Document.ADVENTURERS_GUIDE.pageTitle(page)));
|
super( iconForPage(page), Messages.titleCase(Document.ADVENTURERS_GUIDE.pageTitle(page)));
|
||||||
|
|
||||||
this.page = page;
|
this.page = page;
|
||||||
found = Document.ADVENTURERS_GUIDE.hasPage(page);
|
found = Document.ADVENTURERS_GUIDE.pageFound(page);
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
icon.hardlight( 0.5f, 0.5f, 0.5f);
|
icon.hardlight( 0.5f, 0.5f, 0.5f);
|
||||||
@@ -291,7 +291,7 @@ public class WndJournal extends WndTabbed {
|
|||||||
|
|
||||||
//TODO might just want this to be part of the Document class
|
//TODO might just want this to be part of the Document class
|
||||||
private static Image iconForPage( String page ){
|
private static Image iconForPage( String page ){
|
||||||
if (!Document.ADVENTURERS_GUIDE.hasPage(page)){
|
if (!Document.ADVENTURERS_GUIDE.pageFound(page)){
|
||||||
return new ItemSprite( ItemSpriteSheet.GUIDE_PAGE );
|
return new ItemSprite( ItemSpriteSheet.GUIDE_PAGE );
|
||||||
}
|
}
|
||||||
switch (page){
|
switch (page){
|
||||||
@@ -349,7 +349,7 @@ public class WndJournal extends WndTabbed {
|
|||||||
updateList();
|
updateList();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (Document.ALCHEMY_GUIDE.hasPage(i)) {
|
if (Document.ALCHEMY_GUIDE.pageFound(i)) {
|
||||||
pageButtons[i].icon(new ItemSprite(ItemSpriteSheet.SOMETHING + spriteIndexes[i], null));
|
pageButtons[i].icon(new ItemSprite(ItemSpriteSheet.SOMETHING + spriteIndexes[i], null));
|
||||||
} else {
|
} else {
|
||||||
pageButtons[i].icon(new ItemSprite(ItemSpriteSheet.SOMETHING, null));
|
pageButtons[i].icon(new ItemSprite(ItemSpriteSheet.SOMETHING, null));
|
||||||
|
|||||||
Reference in New Issue
Block a user