Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/java/spireQuests/questStats/QuestStatsScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ private void updateButtons() {
public void render(SpriteBatch sb) {
sb.setColor(Color.WHITE);
renderBG(sb);
if (!questDropdown.isOpen) {
questDropdown.render(sb, LEFT_ALIGN, DROPDOWN_Y);
}
if (selectedQuest == null){
renderTrophyHelp(sb);
renderSummary(sb);
Expand All @@ -243,7 +246,9 @@ public void render(SpriteBatch sb) {
renderTrophyTooltip(sb);
renderCheckbox(sb);
}
questDropdown.render(sb, LEFT_ALIGN, DROPDOWN_Y);
if (questDropdown.isOpen) {
questDropdown.render(sb, LEFT_ALIGN, DROPDOWN_Y);
}
cancelButton.render(sb);
}

Expand Down
51 changes: 45 additions & 6 deletions src/main/java/spireQuests/questStats/StatRewardBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static spireQuests.Anniv8Mod.makeUIPath;

import java.lang.reflect.Field;
import java.util.ArrayList;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
Expand All @@ -23,10 +24,12 @@
import basemod.IUIElement;
import spireQuests.quests.AbstractQuest;
import spireQuests.quests.QuestReward;
import spireQuests.quests.QuestReward.CardChoiceReward;
import spireQuests.quests.QuestReward.CardReward;
import spireQuests.quests.QuestReward.GoldReward;
import spireQuests.quests.QuestReward.MaxHPReward;
import spireQuests.quests.QuestReward.PotionReward;
import spireQuests.quests.QuestReward.QuestRewardType;
import spireQuests.quests.QuestReward.RandomRelicReward;
import spireQuests.quests.QuestReward.RelicReward;
import spireQuests.util.ImageHelper;
Expand All @@ -43,6 +46,7 @@ public class StatRewardBox implements IUIElement {
private static final Texture GOLD_TEX = TexLoader.getTexture(makeUIPath("stats/gold.png"));
private static final Texture HEALTH_TEX = TexLoader.getTexture(makeUIPath("stats/heart.png"));
private static final Texture RANDOM_REWARD_TEX = TexLoader.getTexture(makeUIPath("stats/random_item.png"));
private static final Texture CARD_CHOICE_TEX = TexLoader.getTexture(makeUIPath("stats/card_choice.png"));

private static final String ID = makeID(StatRewardBox.class.getSimpleName());
private UIStrings uiStrings = CardCrawlGame.languagePack.getUIString(ID);
Expand All @@ -58,8 +62,10 @@ public class StatRewardBox implements IUIElement {
private float xPos;
private float yPos;
private AbstractCard card = null;
private ArrayList<AbstractCard> cards = null;
private AbstractPotion potion = null;
private AbstractRelic relic = null;
private QuestRewardType type = QuestRewardType.OTHER;

public StatRewardBox(QuestReward reward, float xPos, float yPos) {
this(xPos, yPos);
Expand All @@ -71,26 +77,42 @@ public StatRewardBox(QuestReward reward, float xPos, float yPos) {
this.relic = ((RelicReward)reward).getRelic().makeCopy();
this.header = relic.name;
this.body = relic.description;
this.type = QuestRewardType.RELIC;
}
if (reward instanceof CardReward) {
this.card = ((CardReward)reward).getCard().makeStatEquivalentCopy();
this.type = QuestRewardType.CARD;
}
if (reward instanceof CardChoiceReward) {
this.cards = ((CardChoiceReward)reward).getCards();
if (((CardChoiceReward)reward).isColorless) {
this.header = uiStrings.TEXT[7];
} else {
this.header = uiStrings.TEXT[6];
}
this.img = new TextureRegion(CARD_CHOICE_TEX);
this.type = QuestRewardType.CARD_CHOICE;
}
if (reward instanceof PotionReward) {
this.potion = ((PotionReward)reward).getPotion().makeCopy();
this.header = potion.name;
this.body = potion.description;
this.type = QuestRewardType.POTION;
}
if (reward instanceof RandomRelicReward) {
this.header = uiStrings.TEXT[0];
this.img = new TextureRegion(RANDOM_RELIC_TEX);
this.type = QuestRewardType.RANDOM_RELIC;
}
if (reward instanceof GoldReward) {
this.header = uiStrings.TEXT[1];
this.img = new TextureRegion(GOLD_TEX);
this.type = QuestRewardType.GOLD;
}
if (reward instanceof MaxHPReward) {
this.header = uiStrings.TEXT[3];
this.img = new TextureRegion(HEALTH_TEX);
this.type = QuestRewardType.MAX_HP;
}

}
Expand Down Expand Up @@ -135,7 +157,7 @@ public void render(SpriteBatch sb) {
sb.draw(FRAME, xPos, yPos, FRAME_X, FRAME_Y);
}

if (this.card != null) {
if (this.type.equals(QuestRewardType.CARD)) {
Color cardBGColor;
switch (this.card.color) {
case RED:
Expand All @@ -160,7 +182,7 @@ public void render(SpriteBatch sb) {
sb.setColor(Color.WHITE);
this.img = new TextureRegion(CARD_FG_TEX);
sb.draw(this.img, xPos + (FRAME_X - WIDTH) / 2, yPos + (FRAME_Y - HEIGHT) / 2, WIDTH, HEIGHT);
} else if (this.potion != null) {
} else if (this.type.equals(QuestRewardType.POTION)) {
try {
renderPotion(sb);
} catch (Exception e) {
Expand All @@ -172,13 +194,30 @@ public void render(SpriteBatch sb) {
}

if (this.hb.hovered) {
if (card != null) {
if (this.type.equals(QuestRewardType.CARD)) {
card.current_x = InputHelper.mX + (AbstractCard.RAW_W * card.drawScale) * Settings.scale;
card.current_y = InputHelper.mY;
card.renderHoverShadow(sb);
card.render(sb);
} else if (this.type.equals(QuestRewardType.CARD_CHOICE)){
if (this.cards != null && !this.cards.isEmpty()) {
float gap = 25.0F * Settings.scale;
float cardWidth = AbstractCard.RAW_W * this.cards.get(0).drawScale * Settings.scale;
float totalWidth = (this.cards.size() * cardWidth) + ((this.cards.size() - 1) * gap);
float startX = InputHelper.mX - totalWidth / 2.0F;
float aboveY = (this.yPos + HEIGHT) + ((AbstractCard.RAW_W * this.cards.get(0).drawScale) * Settings.scale);
for (int i = 0; i < this.cards.size(); i++) {
AbstractCard c = this.cards.get(i);
c.current_x = startX + cardWidth * 0.5F + i * (cardWidth + gap);
c.current_y = aboveY;
c.renderHoverShadow(sb);
c.render(sb);
}
} else {
ImageHelper.tipBoxAtMousePos(this.header, this.body);
}
} else {
ImageHelper.tipBoxAtMousePos(this.header, this.body);
ImageHelper.tipBoxAtMousePos(this.header, this.body);
}
}
this.hb.render(sb);
Expand Down Expand Up @@ -230,9 +269,9 @@ public void update() {
CardCrawlGame.sound.play("UI_HOVER");
}
if (this.hb.hovered && InputHelper.justClickedRight) {
if (card != null) {
if (type.equals(QuestRewardType.CARD)) {
CardCrawlGame.cardPopup.open(card);
} else if (relic != null) {
} else if (type.equals(QuestRewardType.RELIC)) {
CardCrawlGame.relicPopup.open(relic);
}
}
Expand Down
109 changes: 108 additions & 1 deletion src/main/java/spireQuests/quests/QuestReward.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.AbstractCard.CardColor;
import com.megacrit.cardcrawl.cards.CardSave;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
Expand All @@ -29,12 +30,14 @@
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import static spireQuests.Anniv8Mod.makeID;
import static spireQuests.Anniv8Mod.makeUIPath;
import static spireQuests.util.LanguageUtils.formatLanguage;

public abstract class QuestReward {

private static final String[] TEXT = CardCrawlGame.languagePack.getUIString(makeID("QuestReward")).TEXT;
private static final Map<String, RewardLoader> rewardLoaders = new HashMap<>();
protected final Hitbox hb;
Expand All @@ -45,9 +48,14 @@ public abstract class QuestReward {
addRewardSaver(new RewardLoader(RandomRelicReward.class, (save) -> new RandomRelicReward(RelicLibrary.getRelic(save.param).makeCopy())));
addRewardSaver(new RewardLoader(PotionReward.class, (save) -> new PotionReward(PotionHelper.getPotion(save.param))));
addRewardSaver(new RewardLoader(CardReward.class, CardReward::fromSave));
addRewardSaver(new RewardLoader(CardChoiceReward.class, CardChoiceReward::fromSave));
addRewardSaver(new RewardLoader(MaxHPReward.class, (save) -> new MaxHPReward(Integer.parseInt(save.param))));
}

public enum QuestRewardType {
OTHER, GOLD, RELIC, RANDOM_RELIC, POTION, CARD, CARD_CHOICE, MAX_HP
}

private static void addRewardSaver(RewardLoader loader) {
rewardLoaders.put(loader.key, loader);
}
Expand Down Expand Up @@ -342,6 +350,95 @@ public AbstractCard getCard() {
}
}

public static class CardChoiceReward extends QuestReward {

private static final TextureRegion IMG = TexLoader.getTextureAsAtlasRegion(makeUIPath("card_reward.png"));
private ArrayList<AbstractCard> rewardCards;
public boolean isColorless = false;

public CardChoiceReward() {
super(TEXT[7]);
this.rewardCards = new ArrayList<>();
}

public CardChoiceReward(boolean isColorless) {
super(TEXT[9]);
this.isColorless = true;
this.rewardCards = new ArrayList<>();
}

public CardChoiceReward(ArrayList<AbstractCard> rewardCards) {
super(String.format(TEXT[8], String.join(", ", rewardCards.stream().map(c -> c.name).collect(Collectors.toList()))));
this.rewardCards = rewardCards;
}

@Override
public TextureRegion icon() {
return IMG;
}

@Override
protected String saveParam() {
return String.join(";", rewardCards.stream().map(c-> c.cardID).collect(Collectors.toList()));
}

@Override
public QuestRewardSave getSave() {
ArrayList<CardSave> cardSaves = new ArrayList<>();
for (AbstractCard c : rewardCards) {
cardSaves.add(new CardSave(c.cardID, c.timesUpgraded, c.misc));
}
return new QuestRewardSave(getClass().getSimpleName(), saveParam(), cardSaves);
}

public static CardChoiceReward fromSave(QuestRewardSave save) {
ArrayList<CardSave> cardSaves = save.cards;
ArrayList<AbstractCard> loadedCards = new ArrayList<>();
for (CardSave s: cardSaves) {
AbstractCard loaded = CardLibrary.getCopy(s.id, s.upgrades, s.misc);
loadedCards.add(loaded);
}
return new CardChoiceReward(loadedCards);
}


@Override
public void obtainRewardItem() {
RewardItem reward = getRewardItem();
AbstractDungeon.combatRewardScreen.rewards.add(0, reward);
AbstractDungeon.combatRewardScreen.positionRewards();
}

private RewardItem getRewardItem() {
RewardItem ret;
if (this.isColorless) {
ret = new RewardItem(CardColor.COLORLESS);
} else {
ret = new RewardItem();
}
if (rewardCards != null && !rewardCards.isEmpty()) {
ret.cards = rewardCards;
for (AbstractCard c : ret.cards) {
for (AbstractRelic r : Wiz.p().relics)
r.onPreviewObtainCard(c);
}
}
return ret;
}

@Override
public void obtainInstant() {
RewardItem reward = getRewardItem();
AbstractDungeon.previousScreen = AbstractDungeon.screen;
AbstractDungeon.cardRewardScreen.open(reward.cards, reward, "TEXT[TODO]");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to update this text.

}

public ArrayList<AbstractCard> getCards() {
return rewardCards;
}

}

public static class MaxHPReward extends QuestReward {
private static final TextureRegion img = new TextureRegion(ImageMaster.TP_HP, 8, 0, 48, 48);
private final int amount;
Expand Down Expand Up @@ -428,19 +525,29 @@ public static class QuestRewardSave {
public String type;
public String param;
public CardSave card;
public ArrayList<CardSave> cards;

public QuestRewardSave() {

}

public QuestRewardSave(String type, String param) {
this(type, param, null);
this(type, param, null, null);
}

public QuestRewardSave(String type, String param, CardSave card) {
this(type, param, card, null);
}

public QuestRewardSave(String type, String param, ArrayList<CardSave> cards) {
this(type, param, null, cards);
}

public QuestRewardSave(String type, String param, CardSave card, ArrayList<CardSave> cards) {
this.type = type;
this.param = param;
this.card = card;
this.cards = cards;
}
}

Expand Down
Loading