From 6f1d2b17c42e6015476847beb0231a9878941bb4 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Thu, 13 Jul 2017 03:55:45 -0400 Subject: [PATCH] v0.6.1: even more refactoring and implemented guide UI in journal window --- .../shatteredpixeldungeon/Badges.java | 2 +- .../journal/Catalog.java | 20 +-- .../journal/Document.java | 115 ++++++++++++++++++ .../journal/Journal.java | 2 + .../windows/WndJournal.java | 101 +++++++++++++-- .../windows/WndStory.java | 2 +- .../messages/journal/journal.properties | 4 + 7 files changed, 222 insertions(+), 24 deletions(-) create mode 100644 core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/journal/Document.java diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Badges.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Badges.java index 74dd7bbbf..cd92e0be5 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Badges.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Badges.java @@ -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); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/journal/Catalog.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/journal/Catalog.java index 86cf1e605..f6f9699df 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/journal/Catalog.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/journal/Catalog.java @@ -140,6 +140,15 @@ public enum Catalog { return seen.keySet(); } + public boolean allSeen(){ + for (Class item : items()){ + if (!seen.get(item)){ + return false; + } + } + return true; + } + static { WEAPONS.seen.put( WornShortsword.class, false); WEAPONS.seen.put( Knuckles.class, false); @@ -216,7 +225,7 @@ public enum Catalog { ARTIFACTS.seen.put( SandalsOfNature.class, false); ARTIFACTS.seen.put( TalismanOfForesight.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( PotionOfStrength.class, false); @@ -256,15 +265,6 @@ public enum Catalog { catalogBadges.put(SCROLLS, Badges.Badge.ALL_SCROLLS_IDENTIFIED); } - public static boolean allSeen( Collection> items){ - for (Class item : items){ - if (!isSeen(item)){ - return false; - } - } - return true; - } - public static boolean isSeen(Class itemClass){ for (Catalog cat : values()) { if (cat.seen.containsKey(itemClass)) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/journal/Document.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/journal/Document.java new file mode 100644 index 000000000..53913b58d --- /dev/null +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/journal/Document.java @@ -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 + */ + +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 pages = new LinkedHashMap<>(); + + public Collection 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 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 pages = Arrays.asList(docBundle.getStringArray(doc.name())); + for (String page : pages){ + if (doc.pages.containsKey(page)) { + doc.pages.put(page, true); + } + } + } + } + } + +} diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/journal/Journal.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/journal/Journal.java index 22088c41b..77cd05005 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/journal/Journal.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/journal/Journal.java @@ -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 ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndJournal.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndJournal.java index e1dbf31f3..7f25fe53a 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndJournal.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndJournal.java @@ -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 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 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 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() ); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndStory.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndStory.java index ecb802cd0..c39cc712b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndStory.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndStory.java @@ -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); diff --git a/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/journal/journal.properties b/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/journal/journal.properties index b8898065c..853944035 100644 --- a/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/journal/journal.properties +++ b/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/journal/journal.properties @@ -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