v0.6.1: even more refactoring and implemented guide UI in journal window
This commit is contained in:
parent
b4835d88e6
commit
6f1d2b17c4
|
@ -466,7 +466,7 @@ public class Badges {
|
|||
public static void validateItemsIdentified() {
|
||||
|
||||
for (Catalog cat : Catalog.values()){
|
||||
if (Catalog.allSeen(cat.items())){
|
||||
if (cat.allSeen()){
|
||||
Badge b = Catalog.catalogBadges.get(cat);
|
||||
if (!global.contains(b)){
|
||||
displayBadge(b);
|
||||
|
|
|
@ -140,6 +140,15 @@ public enum Catalog {
|
|||
return seen.keySet();
|
||||
}
|
||||
|
||||
public boolean allSeen(){
|
||||
for (Class<?extends Item> item : items()){
|
||||
if (!seen.get(item)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static {
|
||||
WEAPONS.seen.put( WornShortsword.class, false);
|
||||
WEAPONS.seen.put( Knuckles.class, false);
|
||||
|
@ -256,15 +265,6 @@ public enum Catalog {
|
|||
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){
|
||||
for (Catalog cat : values()) {
|
||||
if (cat.seen.containsKey(itemClass)) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -51,6 +51,7 @@ public class Journal {
|
|||
}
|
||||
|
||||
Catalog.restore( bundle );
|
||||
Document.restore( bundle );
|
||||
|
||||
loaded = true;
|
||||
}
|
||||
|
@ -66,6 +67,7 @@ public class Journal {
|
|||
Bundle bundle = new Bundle();
|
||||
|
||||
Catalog.store(bundle);
|
||||
Document.store(bundle);
|
||||
|
||||
try {
|
||||
OutputStream output = Game.instance.openFileOutput( JOURNAL_FILE, Game.MODE_PRIVATE );
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.items.rings.Ring;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.journal.Catalog;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.journal.Document;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.journal.Notes;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||
|
@ -64,7 +65,7 @@ public class WndJournal extends WndTabbed {
|
|||
private NotesTab notesTab;
|
||||
private CatalogTab catalogTab;
|
||||
|
||||
public static int last_index = 2;
|
||||
public static int last_index = 0;
|
||||
|
||||
public WndJournal(){
|
||||
|
||||
|
@ -76,6 +77,7 @@ public class WndJournal extends WndTabbed {
|
|||
guideTab = new GuideTab();
|
||||
add(guideTab);
|
||||
guideTab.setRect(0, 0, width, height);
|
||||
guideTab.updateList();
|
||||
|
||||
notesTab = new NotesTab();
|
||||
add(notesTab);
|
||||
|
@ -187,20 +189,92 @@ public class WndJournal extends WndTabbed {
|
|||
|
||||
private static class GuideTab extends Component {
|
||||
|
||||
private RenderedText text;
|
||||
private ScrollPane list;
|
||||
private ArrayList<GuideItem> pages = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected void createChildren() {
|
||||
text = PixelScene.renderText( "Coming Soon...", 9);
|
||||
add( text );
|
||||
list = new ScrollPane( new Component() ){
|
||||
@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
|
||||
protected void layout() {
|
||||
text.x = (width() - text.width())/2f;
|
||||
text.y = 10;
|
||||
PixelScene.align(text);
|
||||
super.layout();
|
||||
list.setRect( 0, 0, width, height);
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -228,6 +302,7 @@ public class WndJournal extends WndTabbed {
|
|||
ArrayList<Notes.KeyRecord> keys = Notes.getRecords(Notes.KeyRecord.class);
|
||||
if (!keys.isEmpty()){
|
||||
RenderedText keyTitle = PixelScene.renderText(Messages.get(this, "keys"), 9);
|
||||
keyTitle.hardlight(TITLE_COLOR);
|
||||
keyTitle.x = (width() - keyTitle.width())/2f;
|
||||
keyTitle.y = pos + (ITEM_HEIGHT - keyTitle.baseLine())/2f;
|
||||
PixelScene.align(keyTitle);
|
||||
|
@ -250,11 +325,12 @@ public class WndJournal extends WndTabbed {
|
|||
//Landmarks
|
||||
ArrayList<Notes.LandmarkRecord> landmarks = Notes.getRecords(Notes.LandmarkRecord.class);
|
||||
if (!landmarks.isEmpty()){
|
||||
RenderedText keyTitle = PixelScene.renderText(Messages.get(this, "landmarks"), 9);
|
||||
keyTitle.x = (width() - keyTitle.width())/2f;
|
||||
keyTitle.y = pos + (ITEM_HEIGHT - keyTitle.baseLine())/2f;
|
||||
PixelScene.align(keyTitle);
|
||||
content.add(keyTitle);
|
||||
RenderedText markTitle = PixelScene.renderText(Messages.get(this, "landmarks"), 9);
|
||||
markTitle.hardlight(TITLE_COLOR);
|
||||
markTitle.x = (width() - markTitle.width())/2f;
|
||||
markTitle.y = pos + (ITEM_HEIGHT - markTitle.baseLine())/2f;
|
||||
PixelScene.align(markTitle);
|
||||
content.add(markTitle);
|
||||
|
||||
ColorBlock line = new ColorBlock( width(), 1, 0xFF222222);
|
||||
line.y = pos;
|
||||
|
@ -271,6 +347,7 @@ public class WndJournal extends WndTabbed {
|
|||
}
|
||||
|
||||
content.setSize( width(), pos );
|
||||
list.setSize( list.width(), list.height() );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public class WndStory extends Window {
|
|||
public WndStory( String text ) {
|
||||
super( 0, 0, Chrome.get( Chrome.Type.SCROLL ) );
|
||||
|
||||
tf = PixelScene.renderMultiline( text, 7 );
|
||||
tf = PixelScene.renderMultiline( text, 6 );
|
||||
tf.maxWidth(ShatteredPixelDungeon.landscape() ?
|
||||
WIDTH_L - MARGIN * 2:
|
||||
WIDTH_P - MARGIN *2);
|
||||
|
|
|
@ -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_awareness=well of awareness
|
||||
journal.notes$landmark.well_of_transmutation=well of transmutation
|
||||
|
|
Loading…
Reference in New Issue
Block a user