v1.2.0: fixed scroll panes working incorrectly with offset windows

This commit is contained in:
Evan Debenham 2022-02-02 18:09:39 -05:00
parent 8b4b3686cd
commit 15e4ff15e6
8 changed files with 61 additions and 17 deletions

View File

@ -100,6 +100,8 @@ public class ScrollOfMetamorphosis extends ExoticScroll {
public static WndMetamorphChoose INSTANCE; public static WndMetamorphChoose INSTANCE;
TalentsPane pane;
public WndMetamorphChoose(){ public WndMetamorphChoose(){
super(); super();
@ -130,12 +132,12 @@ public class ScrollOfMetamorphosis extends ExoticScroll {
} }
} }
TalentsPane p = new TalentsPane(TalentButton.Mode.METAMORPH_CHOOSE, talents); pane = new TalentsPane(TalentButton.Mode.METAMORPH_CHOOSE, talents);
add(p); add(pane);
p.setPos(0, top); pane.setPos(0, top);
p.setSize(120, p.content().height()); pane.setSize(120, pane.content().height());
resize((int)p.width(), (int)p.bottom()); resize((int)pane.width(), (int)pane.bottom());
p.setPos(0, top); pane.setPos(0, top);
} }
@Override @Override
@ -154,6 +156,12 @@ public class ScrollOfMetamorphosis extends ExoticScroll {
curItem.collect(); curItem.collect();
} }
} }
@Override
public void offset(int xOffset, int yOffset) {
super.offset(xOffset, yOffset);
pane.setPos(pane.left(), pane.top()); //triggers layout
}
} }
public static class WndMetamorphReplace extends Window { public static class WndMetamorphReplace extends Window {

View File

@ -117,12 +117,13 @@ public class TalentButton extends Button {
protected void onClick() { protected void onClick() {
super.onClick(); super.onClick();
Window toAdd;
if (mode == Mode.UPGRADE if (mode == Mode.UPGRADE
&& Dungeon.hero != null && Dungeon.hero != null
&& Dungeon.hero.isAlive() && Dungeon.hero.isAlive()
&& Dungeon.hero.talentPointsAvailable(tier) > 0 && Dungeon.hero.talentPointsAvailable(tier) > 0
&& Dungeon.hero.pointsInTalent(talent) < talent.maxPoints()){ && Dungeon.hero.pointsInTalent(talent) < talent.maxPoints()){
ShatteredPixelDungeon.scene().addToFront(new WndInfoTalent(talent, pointsInTalent, new WndInfoTalent.TalentButtonCallback() { toAdd = new WndInfoTalent(talent, pointsInTalent, new WndInfoTalent.TalentButtonCallback() {
@Override @Override
public String prompt() { public String prompt() {
@ -133,9 +134,9 @@ public class TalentButton extends Button {
public void call() { public void call() {
upgradeTalent(); upgradeTalent();
} }
})); });
} else if (mode == Mode.METAMORPH_CHOOSE && Dungeon.hero != null && Dungeon.hero.isAlive()) { } else if (mode == Mode.METAMORPH_CHOOSE && Dungeon.hero != null && Dungeon.hero.isAlive()) {
ShatteredPixelDungeon.scene().addToFront(new WndInfoTalent(talent, pointsInTalent, new WndInfoTalent.TalentButtonCallback() { toAdd = new WndInfoTalent(talent, pointsInTalent, new WndInfoTalent.TalentButtonCallback() {
@Override @Override
public String prompt() { public String prompt() {
@ -149,9 +150,9 @@ public class TalentButton extends Button {
} }
GameScene.show(new ScrollOfMetamorphosis.WndMetamorphReplace(talent, tier)); GameScene.show(new ScrollOfMetamorphosis.WndMetamorphReplace(talent, tier));
} }
})); });
} else if (mode == Mode.METAMORPH_REPLACE && Dungeon.hero != null && Dungeon.hero.isAlive()) { } else if (mode == Mode.METAMORPH_REPLACE && Dungeon.hero != null && Dungeon.hero.isAlive()) {
ShatteredPixelDungeon.scene().addToFront(new WndInfoTalent(talent, pointsInTalent, new WndInfoTalent.TalentButtonCallback() { toAdd = new WndInfoTalent(talent, pointsInTalent, new WndInfoTalent.TalentButtonCallback() {
@Override @Override
public String prompt() { public String prompt() {
@ -204,9 +205,15 @@ public class TalentButton extends Button {
} }
} }
})); });
} else { } else {
ShatteredPixelDungeon.scene().addToFront(new WndInfoTalent(talent, pointsInTalent, null)); toAdd = new WndInfoTalent(talent, pointsInTalent, null);
}
if (ShatteredPixelDungeon.scene() instanceof GameScene){
GameScene.show(toAdd);
} else {
ShatteredPixelDungeon.scene().addToFront(toAdd);
} }
} }

View File

@ -131,6 +131,7 @@ public class Window extends Group implements Signal.Listener<KeyEvent> {
shadow.boxRect( camera.x / camera.zoom, camera.y / camera.zoom, chrome.width(), chrome.height ); shadow.boxRect( camera.x / camera.zoom, camera.y / camera.zoom, chrome.width(), chrome.height );
} }
//windows with scroll panes will likely need to override this and refresh them when offset changes
public void offset( int xOffset, int yOffset ){ public void offset( int xOffset, int yOffset ){
camera.x -= this.xOffset * camera.zoom; camera.x -= this.xOffset * camera.zoom;
this.xOffset = xOffset; this.xOffset = xOffset;

View File

@ -112,6 +112,13 @@ public class WndHero extends WndTabbed {
select( lastIdx ); select( lastIdx );
} }
@Override
public void offset(int xOffset, int yOffset) {
super.offset(xOffset, yOffset);
talents.layout();
buffs.layout();
}
private class StatsTab extends Group { private class StatsTab extends Group {
private static final int GAP = 6; private static final int GAP = 6;
@ -136,8 +143,12 @@ public class WndHero extends WndTabbed {
@Override @Override
protected void onClick() { protected void onClick() {
super.onClick(); super.onClick();
if (ShatteredPixelDungeon.scene() instanceof GameScene){
GameScene.show(new WndHeroInfo(hero.heroClass));
} else {
ShatteredPixelDungeon.scene().addToFront(new WndHeroInfo(hero.heroClass)); ShatteredPixelDungeon.scene().addToFront(new WndHeroInfo(hero.heroClass));
} }
}
}; };
infoButton.setRect(title.right(), 0, 16, 16); infoButton.setRect(title.right(), 0, 16, 16);
add(infoButton); add(infoButton);

View File

@ -135,6 +135,15 @@ public class WndJournal extends WndTabbed {
select(last_index); select(last_index);
} }
@Override
public void offset(int xOffset, int yOffset) {
super.offset(xOffset, yOffset);
guideTab.layout();
alchemyTab.layout();
catalogTab.layout();
notesTab.layout();
}
private static class ListItem extends Component { private static class ListItem extends Component {
protected RenderedTextBlock label; protected RenderedTextBlock label;

View File

@ -156,6 +156,12 @@ public class WndKeyBindings extends Window {
} }
@Override
public void offset(int xOffset, int yOffset) {
super.offset(xOffset, yOffset);
bindingsList.setPos(bindingsList.left(), bindingsList.top()); //calls layout
}
@Override @Override
public void onBackPressed() { public void onBackPressed() {
//do nothing, avoids accidental back presses which would lose progress. //do nothing, avoids accidental back presses which would lose progress.

View File

@ -30,6 +30,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor; import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.FetidRatSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.FetidRatSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.GnollTricksterSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.GnollTricksterSprite;
@ -143,7 +144,7 @@ public class WndSadGhost extends Window {
} }
@Override @Override
protected void onClick() { protected void onClick() {
ShatteredPixelDungeon.scene().addToFront(new RewardWindow(item)); GameScene.show(new RewardWindow(item));
} }
}; };
add(slot); add(slot);

View File

@ -31,6 +31,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.quest.CorpseDust;
import com.shatteredpixel.shatteredpixeldungeon.items.quest.Embers; import com.shatteredpixel.shatteredpixeldungeon.items.quest.Embers;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.plants.Rotberry; import com.shatteredpixel.shatteredpixeldungeon.plants.Rotberry;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot; import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot;
@ -137,7 +138,7 @@ public class WndWandmaker extends Window {
@Override @Override
protected void onClick() { protected void onClick() {
if (Dungeon.hero.belongings.contains(questItem)) { if (Dungeon.hero.belongings.contains(questItem)) {
ShatteredPixelDungeon.scene().addToFront(new RewardWindow(item)); GameScene.show(new RewardWindow(item));
} else { } else {
hide(); hide();
} }