v0.6.1: even more refactoring and implemented guide UI in journal window

This commit is contained in:
Evan Debenham 2017-07-13 03:55:45 -04:00
parent b4835d88e6
commit 6f1d2b17c4
7 changed files with 222 additions and 24 deletions

View File

@ -466,7 +466,7 @@ public class Badges {
public static void validateItemsIdentified() { public static void validateItemsIdentified() {
for (Catalog cat : Catalog.values()){ for (Catalog cat : Catalog.values()){
if (Catalog.allSeen(cat.items())){ if (cat.allSeen()){
Badge b = Catalog.catalogBadges.get(cat); Badge b = Catalog.catalogBadges.get(cat);
if (!global.contains(b)){ if (!global.contains(b)){
displayBadge(b); displayBadge(b);

View File

@ -140,6 +140,15 @@ public enum Catalog {
return seen.keySet(); return seen.keySet();
} }
public boolean allSeen(){
for (Class<?extends Item> item : items()){
if (!seen.get(item)){
return false;
}
}
return true;
}
static { static {
WEAPONS.seen.put( WornShortsword.class, false); WEAPONS.seen.put( WornShortsword.class, false);
WEAPONS.seen.put( Knuckles.class, false); WEAPONS.seen.put( Knuckles.class, false);
@ -216,7 +225,7 @@ public enum Catalog {
ARTIFACTS.seen.put( SandalsOfNature.class, false); ARTIFACTS.seen.put( SandalsOfNature.class, false);
ARTIFACTS.seen.put( TalismanOfForesight.class, false); ARTIFACTS.seen.put( TalismanOfForesight.class, false);
ARTIFACTS.seen.put( TimekeepersHourglass.class, false); ARTIFACTS.seen.put( TimekeepersHourglass.class, false);
ARTIFACTS.seen.put(UnstableSpellbook.class, false); ARTIFACTS.seen.put( UnstableSpellbook.class, false);
POTIONS.seen.put( PotionOfHealing.class, false); POTIONS.seen.put( PotionOfHealing.class, false);
POTIONS.seen.put( PotionOfStrength.class, false); POTIONS.seen.put( PotionOfStrength.class, false);
@ -256,15 +265,6 @@ public enum Catalog {
catalogBadges.put(SCROLLS, Badges.Badge.ALL_SCROLLS_IDENTIFIED); catalogBadges.put(SCROLLS, Badges.Badge.ALL_SCROLLS_IDENTIFIED);
} }
public static boolean allSeen( Collection<Class<?extends Item>> items){
for (Class<?extends Item> item : items){
if (!isSeen(item)){
return false;
}
}
return true;
}
public static boolean isSeen(Class<? extends Item> itemClass){ public static boolean isSeen(Class<? extends Item> itemClass){
for (Catalog cat : values()) { for (Catalog cat : values()) {
if (cat.seen.containsKey(itemClass)) { if (cat.seen.containsKey(itemClass)) {

View File

@ -0,0 +1,115 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2017 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.journal;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.watabou.utils.Bundle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
public enum Document {
ADVENTURERS_GUIDE;
private LinkedHashMap<String, Boolean> pages = new LinkedHashMap<>();
public Collection<String> pages(){
return pages.keySet();
}
public boolean hasPage( String page ){
return pages.containsKey(page) && pages.get(page);
}
public String title(){
return Messages.get( this, name() + ".title");
}
public String pageTitle( String page ){
return Messages.get( this, name() + "." + page + ".title");
}
public String pageBody( String page ){
return Messages.get( this, name() + "." + page + ".body");
}
static {
ADVENTURERS_GUIDE.pages.put("0", false);
ADVENTURERS_GUIDE.pages.put("1", false);
ADVENTURERS_GUIDE.pages.put("2", false);
ADVENTURERS_GUIDE.pages.put("3", false);
ADVENTURERS_GUIDE.pages.put("4", false);
ADVENTURERS_GUIDE.pages.put("5", false);
ADVENTURERS_GUIDE.pages.put("6", false);
ADVENTURERS_GUIDE.pages.put("7", false);
ADVENTURERS_GUIDE.pages.put("8", false);
ADVENTURERS_GUIDE.pages.put("9", false);
}
private static final String DOCUMENTS = "documents";
public static void store( Bundle bundle ){
Bundle docBundle = new Bundle();
for ( Document doc : values()){
ArrayList<String> pages = new ArrayList<>();
for (String page : doc.pages()){
if (doc.pages.get(page)){
pages.add(page);
}
}
if (!pages.isEmpty()) {
docBundle.put(doc.name(), pages.toArray(new String[0]));
}
}
bundle.put( DOCUMENTS, docBundle );
}
public static void restore( Bundle bundle ){
if (!bundle.contains( DOCUMENTS )){
return;
}
Bundle docBundle = bundle.getBundle( DOCUMENTS );
for ( Document doc : values()){
if (docBundle.contains(doc.name())){
List<String> pages = Arrays.asList(docBundle.getStringArray(doc.name()));
for (String page : pages){
if (doc.pages.containsKey(page)) {
doc.pages.put(page, true);
}
}
}
}
}
}

View File

@ -51,6 +51,7 @@ public class Journal {
} }
Catalog.restore( bundle ); Catalog.restore( bundle );
Document.restore( bundle );
loaded = true; loaded = true;
} }
@ -66,6 +67,7 @@ public class Journal {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
Catalog.store(bundle); Catalog.store(bundle);
Document.store(bundle);
try { try {
OutputStream output = Game.instance.openFileOutput( JOURNAL_FILE, Game.MODE_PRIVATE ); OutputStream output = Game.instance.openFileOutput( JOURNAL_FILE, Game.MODE_PRIVATE );

View File

@ -28,6 +28,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
import com.shatteredpixel.shatteredpixeldungeon.items.rings.Ring; import com.shatteredpixel.shatteredpixeldungeon.items.rings.Ring;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll;
import com.shatteredpixel.shatteredpixeldungeon.journal.Catalog; import com.shatteredpixel.shatteredpixeldungeon.journal.Catalog;
import com.shatteredpixel.shatteredpixeldungeon.journal.Document;
import com.shatteredpixel.shatteredpixeldungeon.journal.Notes; import com.shatteredpixel.shatteredpixeldungeon.journal.Notes;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
@ -64,7 +65,7 @@ public class WndJournal extends WndTabbed {
private NotesTab notesTab; private NotesTab notesTab;
private CatalogTab catalogTab; private CatalogTab catalogTab;
public static int last_index = 2; public static int last_index = 0;
public WndJournal(){ public WndJournal(){
@ -76,6 +77,7 @@ public class WndJournal extends WndTabbed {
guideTab = new GuideTab(); guideTab = new GuideTab();
add(guideTab); add(guideTab);
guideTab.setRect(0, 0, width, height); guideTab.setRect(0, 0, width, height);
guideTab.updateList();
notesTab = new NotesTab(); notesTab = new NotesTab();
add(notesTab); add(notesTab);
@ -187,20 +189,92 @@ public class WndJournal extends WndTabbed {
private static class GuideTab extends Component { private static class GuideTab extends Component {
private RenderedText text; private ScrollPane list;
private ArrayList<GuideItem> pages = new ArrayList<>();
@Override @Override
protected void createChildren() { protected void createChildren() {
text = PixelScene.renderText( "Coming Soon...", 9); list = new ScrollPane( new Component() ){
add( text ); @Override
public void onClick( float x, float y ) {
int size = pages.size();
for (int i=0; i < size; i++) {
if (pages.get( i ).onClick( x, y )) {
break;
}
}
}
};
add( list );
} }
@Override @Override
protected void layout() { protected void layout() {
text.x = (width() - text.width())/2f; super.layout();
text.y = 10; list.setRect( 0, 0, width, height);
PixelScene.align(text);
} }
private void updateList(){
Component content = list.content();
float pos = 0;
RenderedText title = PixelScene.renderText(Document.ADVENTURERS_GUIDE.title(), 9);
title.hardlight(TITLE_COLOR);
title.x = (width() - title.width())/2f;
title.y = pos + (ITEM_HEIGHT - title.baseLine())/2f;
PixelScene.align(title);
content.add(title);
ColorBlock line = new ColorBlock( width(), 1, 0xFF222222);
line.y = pos;
content.add(line);
pos += ITEM_HEIGHT;
for (String page : Document.ADVENTURERS_GUIDE.pages()){
GuideItem item = new GuideItem( page );
item.setRect( 0, pos, width(), ITEM_HEIGHT );
content.add( item );
pos += item.height();
pages.add(item);
}
content.setSize( width(), pos );
list.setSize( list.width(), list.height() );
}
private static class GuideItem extends ListItem {
private boolean found = false;
private String page;
public GuideItem( String page ){
super( Icons.get(Icons.MASTERY), Messages.titleCase(Document.ADVENTURERS_GUIDE.pageTitle(page)), -1);
this.page = page;
found = Document.ADVENTURERS_GUIDE.hasPage(page);
if (!found) {
icon.hardlight( 0.5f, 0.5f, 0.5f);
label.text("???");
label.hardlight( 0x999999 );
}
}
public boolean onClick( float x, float y ) {
if (inside( x, y ) && found) {
GameScene.show( new WndStory( Document.ADVENTURERS_GUIDE.pageBody(page) ));
return true;
} else {
return false;
}
}
}
} }
private static class NotesTab extends Component { private static class NotesTab extends Component {
@ -228,6 +302,7 @@ public class WndJournal extends WndTabbed {
ArrayList<Notes.KeyRecord> keys = Notes.getRecords(Notes.KeyRecord.class); ArrayList<Notes.KeyRecord> keys = Notes.getRecords(Notes.KeyRecord.class);
if (!keys.isEmpty()){ if (!keys.isEmpty()){
RenderedText keyTitle = PixelScene.renderText(Messages.get(this, "keys"), 9); RenderedText keyTitle = PixelScene.renderText(Messages.get(this, "keys"), 9);
keyTitle.hardlight(TITLE_COLOR);
keyTitle.x = (width() - keyTitle.width())/2f; keyTitle.x = (width() - keyTitle.width())/2f;
keyTitle.y = pos + (ITEM_HEIGHT - keyTitle.baseLine())/2f; keyTitle.y = pos + (ITEM_HEIGHT - keyTitle.baseLine())/2f;
PixelScene.align(keyTitle); PixelScene.align(keyTitle);
@ -250,11 +325,12 @@ public class WndJournal extends WndTabbed {
//Landmarks //Landmarks
ArrayList<Notes.LandmarkRecord> landmarks = Notes.getRecords(Notes.LandmarkRecord.class); ArrayList<Notes.LandmarkRecord> landmarks = Notes.getRecords(Notes.LandmarkRecord.class);
if (!landmarks.isEmpty()){ if (!landmarks.isEmpty()){
RenderedText keyTitle = PixelScene.renderText(Messages.get(this, "landmarks"), 9); RenderedText markTitle = PixelScene.renderText(Messages.get(this, "landmarks"), 9);
keyTitle.x = (width() - keyTitle.width())/2f; markTitle.hardlight(TITLE_COLOR);
keyTitle.y = pos + (ITEM_HEIGHT - keyTitle.baseLine())/2f; markTitle.x = (width() - markTitle.width())/2f;
PixelScene.align(keyTitle); markTitle.y = pos + (ITEM_HEIGHT - markTitle.baseLine())/2f;
content.add(keyTitle); PixelScene.align(markTitle);
content.add(markTitle);
ColorBlock line = new ColorBlock( width(), 1, 0xFF222222); ColorBlock line = new ColorBlock( width(), 1, 0xFF222222);
line.y = pos; line.y = pos;
@ -271,6 +347,7 @@ public class WndJournal extends WndTabbed {
} }
content.setSize( width(), pos ); content.setSize( width(), pos );
list.setSize( list.width(), list.height() );
} }
} }

View File

@ -66,7 +66,7 @@ public class WndStory extends Window {
public WndStory( String text ) { public WndStory( String text ) {
super( 0, 0, Chrome.get( Chrome.Type.SCROLL ) ); super( 0, 0, Chrome.get( Chrome.Type.SCROLL ) );
tf = PixelScene.renderMultiline( text, 7 ); tf = PixelScene.renderMultiline( text, 6 );
tf.maxWidth(ShatteredPixelDungeon.landscape() ? tf.maxWidth(ShatteredPixelDungeon.landscape() ?
WIDTH_L - MARGIN * 2: WIDTH_L - MARGIN * 2:
WIDTH_P - MARGIN *2); WIDTH_P - MARGIN *2);

View File

@ -1,3 +1,7 @@
journal.document.adventurers_guide.title=Adventurer's Guide
journal.document.adventurers_guide.0.title=Coming soon...
journal.document.adventurers_guide.0.body=Welcome to the Adventurer's Guide to Dungeoneering!\n\nThe most important thing to remember: DON'T PANIC!
journal.notes$landmark.well_of_health=well of health journal.notes$landmark.well_of_health=well of health
journal.notes$landmark.well_of_awareness=well of awareness journal.notes$landmark.well_of_awareness=well of awareness
journal.notes$landmark.well_of_transmutation=well of transmutation journal.notes$landmark.well_of_transmutation=well of transmutation