v0.9.4: document pages now open directly from the flashing prompt

This commit is contained in:
Evan Debenham 2021-08-07 11:20:04 -04:00
parent 15862f98e8
commit 8c9012e085
5 changed files with 90 additions and 57 deletions

View File

@ -52,9 +52,10 @@ public abstract class DocumentPage extends Item {
@Override
public final boolean doPickUp(Hero hero) {
GameScene.pickUpJournal(this, hero.pos);
GameScene.flashJournal();
GameScene.flashForDocument(page());
if (document() == Document.ALCHEMY_GUIDE){
WndJournal.last_index = 1;
WndJournal.AlchemyTab.currentPageIdx = document().pageIdx(page());
} else {
WndJournal.last_index = 0;
}

View File

@ -52,6 +52,18 @@ public enum Document {
return false;
}
public boolean findPage( int pageIdx ) {
return findPage( pagesStates.keySet().toArray(new String[0])[pageIdx] );
}
public boolean pageFound( String page ){
return pagesStates.containsKey(page) && pagesStates.get(page) > NOT_FOUND;
}
public boolean pageFound( int pageIdx ){
return pageFound( pagesStates.keySet().toArray(new String[0])[pageIdx] );
}
public boolean readPage( String page ) {
if (pagesStates.containsKey(page) && pagesStates.get(page) == FOUND){
pagesStates.put(page, READ);
@ -60,13 +72,9 @@ public enum Document {
}
return false;
}
public boolean pageFound( String page ){
return pagesStates.containsKey(page) && pagesStates.get(page) > NOT_FOUND;
}
public boolean pageFound( int pageIdx ){
return pageFound( pagesStates.keySet().toArray(new String[0])[pageIdx] );
public boolean readPage( int pageIdx ) {
return readPage( pagesStates.keySet().toArray(new String[0])[pageIdx] );
}
public boolean pageRead( String page ){
@ -77,14 +85,21 @@ public enum Document {
return pageRead( pagesStates.keySet().toArray(new String[0])[pageIdx] );
}
public void setPageState( String page, int state ){
if (pagesStates.containsKey(page)) pagesStates.put(page, state);
}
public Collection<String> pageNames(){
return pagesStates.keySet();
}
public int pageIdx(String name){
int i = 0;
for( String page : pagesStates.keySet()){
if (page.equals(name)){
return i;
}
i++;
}
return -1;
}
private int pageSprite;
public int pageSprite(){
return pageSprite;

View File

@ -917,9 +917,10 @@ public class GameScene extends PixelScene {
public static void pickUpJournal( Item item, int pos ) {
if (scene != null) scene.pane.pickup( item, pos );
}
public static void flashJournal(){
if (scene != null) scene.pane.flash();
//TODO currently only works with guidebooks
public static void flashForDocument( String page ){
if (scene != null) scene.pane.flashForPage( page );
}
public static void updateKeyDisplay(){

View File

@ -27,12 +27,14 @@ import com.shatteredpixel.shatteredpixeldungeon.SPDAction;
import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.journal.Document;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndGame;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndHero;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndJournal;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndStory;
import com.watabou.input.GameAction;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Camera;
@ -264,9 +266,9 @@ public class StatusPane extends Component {
btnJournal.journalIcon.x + btnJournal.journalIcon.width()/2f,
btnJournal.journalIcon.y + btnJournal.journalIcon.height()/2f);
}
public void flash(){
btnJournal.flashing = true;
public void flashForPage( String page ){
btnJournal.flashingPage = page;
}
public void updateKeys(){
@ -279,7 +281,7 @@ public class StatusPane extends Component {
private Image journalIcon;
private KeyDisplay keyIcon;
private boolean flashing;
private String flashingPage = Document.GUIDE_INTRO_PAGE;
public JournalButton() {
super();
@ -327,15 +329,16 @@ public class StatusPane extends Component {
}
private float time;
private static final float FLASH_RATE = (float)(Math.PI*1.5f); //1.5 blinks per second
@Override
public void update() {
super.update();
if (flashing){
journalIcon.am = (float)Math.abs(Math.cos( 3 * (time += Game.elapsed) ));
if (flashingPage != null){
journalIcon.am = (float)Math.abs(Math.cos( FLASH_RATE * (time += Game.elapsed) ));
keyIcon.am = journalIcon.am;
if (time >= 0.333f*Math.PI) {
if (time >= Math.PI/FLASH_RATE) {
time = 0;
}
}
@ -369,10 +372,20 @@ public class StatusPane extends Component {
@Override
protected void onClick() {
flashing = false;
time = 0;
keyIcon.am = journalIcon.am = 1;
GameScene.show( new WndJournal() );
if (flashingPage != null){
if (Document.ADVENTURERS_GUIDE.pageNames().contains(flashingPage)){
GameScene.show( new WndStory( WndJournal.GuideTab.iconForPage(flashingPage),
Document.ADVENTURERS_GUIDE.pageTitle(flashingPage),
Document.ADVENTURERS_GUIDE.pageBody(flashingPage) ));
} else {
GameScene.show( new WndJournal() );
}
flashingPage = null;
} else {
GameScene.show( new WndJournal() );
}
}
}

View File

@ -200,7 +200,7 @@ public class WndJournal extends WndTabbed {
}
}
private static class GuideTab extends Component {
public static class GuideTab extends Component {
private ScrollPane list;
private ArrayList<GuideItem> pages = new ArrayList<>();
@ -283,43 +283,44 @@ public class WndJournal extends WndTabbed {
GameScene.show( new WndStory( iconForPage(page),
Document.ADVENTURERS_GUIDE.pageTitle(page),
Document.ADVENTURERS_GUIDE.pageBody(page) ));
Document.ALCHEMY_GUIDE.readPage(page);
return true;
} else {
return false;
}
}
//TODO might just want this to be part of the Document class
private static Image iconForPage( String page ){
if (!Document.ADVENTURERS_GUIDE.pageFound(page)){
return new ItemSprite( ItemSpriteSheet.GUIDE_PAGE );
}
switch (page){
case Document.GUIDE_INTRO_PAGE: default:
return new ItemSprite(ItemSpriteSheet.MASTERY);
case "Identifying":
return new ItemSprite( ItemSpriteSheet.SCROLL_ISAZ );
case Document.GUIDE_SEARCH_PAGE:
return new ItemSprite( ItemSpriteSheet.LOCKED_CHEST );
case "Strength":
return new ItemSprite( ItemSpriteSheet.ARMOR_SCALE );
case "Food":
return new ItemSprite( ItemSpriteSheet.PASTY );
case "Levelling":
return new ItemSprite( ItemSpriteSheet.POTION_MAGENTA );
case "Surprise_Attacks":
return new ItemSprite( ItemSpriteSheet.ASSASSINS_BLADE );
case "Dieing":
return new ItemSprite( ItemSpriteSheet.ANKH );
case "Looting":
return new ItemSprite( ItemSpriteSheet.CRYSTAL_KEY );
case "Magic":
return new ItemSprite( ItemSpriteSheet.WAND_LIGHTNING );
}
}
}
//TODO might just want this to be part of the Document class
public static Image iconForPage( String page ){
if (!Document.ADVENTURERS_GUIDE.pageFound(page)){
return new ItemSprite( ItemSpriteSheet.GUIDE_PAGE );
}
switch (page){
case Document.GUIDE_INTRO_PAGE: default:
return new ItemSprite(ItemSpriteSheet.MASTERY);
case "Identifying":
return new ItemSprite( ItemSpriteSheet.SCROLL_ISAZ );
case Document.GUIDE_SEARCH_PAGE:
return new ItemSprite( ItemSpriteSheet.LOCKED_CHEST );
case "Strength":
return new ItemSprite( ItemSpriteSheet.ARMOR_SCALE );
case "Food":
return new ItemSprite( ItemSpriteSheet.PASTY );
case "Levelling":
return new ItemSprite( ItemSpriteSheet.POTION_MAGENTA );
case "Surprise_Attacks":
return new ItemSprite( ItemSpriteSheet.ASSASSINS_BLADE );
case "Dieing":
return new ItemSprite( ItemSpriteSheet.ANKH );
case "Looting":
return new ItemSprite( ItemSpriteSheet.CRYSTAL_KEY );
case "Magic":
return new ItemSprite( ItemSpriteSheet.WAND_LIGHTNING );
}
}
}
public static class AlchemyTab extends Component {
@ -329,7 +330,7 @@ public class WndJournal extends WndTabbed {
private static final int[] spriteIndexes = {10, 12, 7, 8, 3, 9, 11, 13, 14, 15};
private static int currentPageIdx = -1;
public static int currentPageIdx = -1;
private IconTitle title;
private RenderedTextBlock body;
@ -436,6 +437,8 @@ public class WndJournal extends WndTabbed {
body.text(Document.ALCHEMY_GUIDE.pageBody(currentPageIdx));
body.setPos(0, title.bottom());
content.add(body);
Document.ALCHEMY_GUIDE.readPage(currentPageIdx);
ArrayList<QuickRecipe> toAdd = QuickRecipe.getRecipes(currentPageIdx);