Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic shops v2 Electric Boogaloo #425

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4d2c1ec
adding pagination to shop to allow for more items
TheDanDLion Aug 13, 2023
646f160
applying relic discounts, only setting isPurchased when it's not a st…
TheDanDLion Aug 14, 2023
79a3bab
setting y position for store relic/potion so they can be in either ro…
TheDanDLion Aug 14, 2023
098ae04
Merge branch 'daviscook477:master' into dynamic-shops
TheDanDLion Jan 18, 2024
bc4a03b
cleaning up shop pagination
TheDanDLion Jan 19, 2024
a466a17
maybe fixed it, also added custom pages
TheDanDLion Jan 19, 2024
244005a
bruh
TheDanDLion Jan 19, 2024
11eeacb
finally fixed spacing, now gotta do alignment
TheDanDLion Jan 19, 2024
667afdf
fleshed out commands, fixed alignment
TheDanDLion Jan 20, 2024
d8ff4de
added commands and some other stuff
TheDanDLion Jan 20, 2024
a0e724c
add debug box, add special case to use normal Y position when row = 2
TheDanDLion Jan 20, 2024
1e0fd4a
fix some things, mainly the page stuff
TheDanDLion Jan 20, 2024
385f67f
fix default spacing issue
TheDanDLion Jan 20, 2024
13a86bd
whelp
TheDanDLion Jan 20, 2024
1face0d
fixing bugs in commands and patches
TheDanDLion Jan 21, 2024
a6d0bb3
making more resilient
TheDanDLion Jan 21, 2024
99c3497
modify text and gold rendering so it looks better
TheDanDLion Jan 21, 2024
4b42625
add price tag when grid is dense, fixed pricing
TheDanDLion Jan 22, 2024
c0dd53b
fix up commands, disable patches for incompatible potions/relics
TheDanDLion Jan 22, 2024
bb47f35
fix compatiblity issue, fix page removal issue
TheDanDLion Jan 22, 2024
8b894da
fix weird edge case
TheDanDLion Jan 22, 2024
4ab7954
polishing up custom shop item, nav button
TheDanDLion Feb 3, 2024
ee6b678
dont set potion & storePotion to null
TheDanDLion Feb 9, 2024
12e6246
tweaks to make it compatible with SpicyShops
TheDanDLion Feb 9, 2024
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
Prev Previous commit
Next Next commit
fleshed out commands, fixed alignment
  • Loading branch information
TheDanDLion committed Jan 20, 2024
commit 667afdf39a5cb7dc519fc272e439c65d6a6d2dec
59 changes: 58 additions & 1 deletion mod/src/main/java/basemod/ShopGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
import com.megacrit.cardcrawl.helpers.ImageMaster;
import com.megacrit.cardcrawl.helpers.controller.CInputActionSet;
import com.megacrit.cardcrawl.helpers.input.InputHelper;
import com.megacrit.cardcrawl.shop.ShopScreen;
import com.megacrit.cardcrawl.shop.StorePotion;
import com.megacrit.cardcrawl.shop.StoreRelic;

import basemod.abstracts.CustomShopItem;

public class ShopGrid {
Expand Down Expand Up @@ -44,13 +48,23 @@ public class ShopGrid {

public static NavButton rightArrow;

private static Hitbox hb;

private static float pageY;

public static void initialize() {
pages.clear();
currentPage = addDefaultPage();
rightArrow = new NavButton(true);
leftArrow = new NavButton(false);
hb = new Hitbox(gridWidth(), gridHeight());
hb.move(leftEdge, bottomEdge);
}

public static Page addEmptyPage() {
Page page = new Page();
pages.addLast(page);
return page;
}

public static Page addDefaultPage() {
Expand All @@ -68,6 +82,28 @@ public static Page addCustomPage(String modId, int ... rowSizes) {
return page;
}

public static boolean removePage(Page page) {
if (pages.contains(page)) {
if (page == currentPage)
currentPage = page.getNextPage();
pages.remove(page);
return true;
} else if (customPages.contains(page)) {
if (page == currentPage)
currentPage = page.getNextPage();
customPages.remove(page);
return true;
}
return false;
}

public static boolean removePage(String modId) {
for (Page page : customPages)
if (page.id.equals(modId))
return removePage(page);
return false;
}

public static boolean tryAddItem(CustomShopItem item) {
for (Page page : pages)
if (page.tryAddItem(item))
Expand All @@ -86,7 +122,7 @@ public static boolean tryAddItemToCustomPage(String id, CustomShopItem item) {
}

public static float gridWidth() {
return leftEdge - rightEdge;
return rightEdge - leftEdge;
}

public static float gridHeight() {
Expand Down Expand Up @@ -139,6 +175,7 @@ public void hide() {
public void update(float rugY) {
for (Row row : rows)
row.update(rugY);
hb.update();
leftArrow.update(rugY);
rightArrow.update(rugY);
pageY = rugY + 500.0F * Settings.yScale;
Expand All @@ -150,6 +187,7 @@ public void render(SpriteBatch sb) {
row.render(sb);
leftArrow.render(sb);
rightArrow.render(sb);
hb.render(sb);
if (pages.size() > 1) {
FontHelper.renderFontCentered(
sb,
Expand All @@ -172,6 +210,16 @@ public boolean tryAddItem(CustomShopItem item) {
return false;
}

public Row addRow() {
return addRow(defaultPageCols);
}

public Row addRow(int size) {
Row row = new Row(this, rows.size(), size);
rows.add(row);
return row;
}

public boolean isFull() {
for (Row row : rows)
if (!row.isFull())
Expand Down Expand Up @@ -254,11 +302,20 @@ public float getY(int row, float rugY) {
return rugY + bottomEdge + (row + 1F) / (owner.rows.size() + 1F) * gridHeight();
}

@SuppressWarnings("unchecked")
public boolean tryAddItem(CustomShopItem item) {
if (items.size() < maxColumns) {
item.row = rowNumber;
item.col = items.size();
items.add(item);
if (item.storePotion != null) {
ArrayList<StoreRelic> relics = (ArrayList<StoreRelic>)ReflectionHacks.getPrivate(AbstractDungeon.shopScreen, ShopScreen.class, "relics");
relics.add(item.storeRelic);
}
if (item.storePotion != null) {
ArrayList<StorePotion> potions = (ArrayList<StorePotion>)ReflectionHacks.getPrivate(AbstractDungeon.shopScreen, ShopScreen.class, "potions");
potions.add(item.storePotion);
}
return true;
}
return false;
Expand Down
9 changes: 0 additions & 9 deletions mod/src/main/java/basemod/abstracts/CustomShopItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import basemod.ReflectionHacks;
import basemod.ShopGrid;
import java.util.ArrayList;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
Expand Down Expand Up @@ -50,8 +49,6 @@ public class CustomShopItem {
private static final float PRICE_OFFSET_X = ReflectionHacks.getPrivateStatic(StoreRelic.class, "RELIC_PRICE_OFFSET_X");
private static final float PRICE_OFFSET_Y = ReflectionHacks.getPrivateStatic(StoreRelic.class, "RELIC_PRICE_OFFSET_Y");

public CustomShopItem() { /* not recommended */ }

public CustomShopItem(AbstractRelic relic) {
this(new StoreRelic(relic, 0, AbstractDungeon.shopScreen));
}
Expand All @@ -60,18 +57,12 @@ public CustomShopItem(AbstractPotion potion) {
this(new StorePotion(potion, 0, AbstractDungeon.shopScreen));
}

@SuppressWarnings("unchecked")
public CustomShopItem(StoreRelic storeRelic) {
this.storeRelic = storeRelic;
ArrayList<StoreRelic> relics = (ArrayList<StoreRelic>)ReflectionHacks.getPrivate(AbstractDungeon.shopScreen, ShopScreen.class, "relics");
relics.add(this.storeRelic);
}

@SuppressWarnings("unchecked")
public CustomShopItem(StorePotion storePotion) {
this.storePotion = storePotion;
ArrayList<StorePotion> potions = (ArrayList<StorePotion>)ReflectionHacks.getPrivate(AbstractDungeon.shopScreen, ShopScreen.class, "potions");
potions.add(this.storePotion);
}

public CustomShopItem(Texture img, int price, String tipTitle, String tipBody) {
Expand Down
8 changes: 6 additions & 2 deletions mod/src/main/java/basemod/devcommands/shop/Shop.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ public void errorMsg() {
public static void cmdShopHelp() {
DevConsole.couldNotParse();
DevConsole.log("options are:");
DevConsole.log("* remove [row] [col]");
DevConsole.log("* add [relic/potion] [id]");
DevConsole.log("* add page [row size] [row size] ...");
DevConsole.log("* add potion [id]");
DevConsole.log("* add relic [id]");
DevConsole.log("* add row [id] [id] ...");
DevConsole.log("* remove item [row] [col]");
DevConsole.log("* remove page");
}
}
129 changes: 114 additions & 15 deletions mod/src/main/java/basemod/devcommands/shop/ShopAdd.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package basemod.devcommands.shop;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.helpers.PotionHelper;
import com.megacrit.cardcrawl.helpers.RelicLibrary;
import com.megacrit.cardcrawl.potions.AbstractPotion;
import com.megacrit.cardcrawl.relics.AbstractRelic;

import basemod.DevConsole;
import basemod.ShopGrid;
import basemod.abstracts.CustomShopItem;
import basemod.devcommands.ConsoleCommand;
Expand All @@ -19,28 +24,122 @@ public ShopAdd() {
simpleCheck = true;
}

private static ArrayList<String> allPotions() {
ArrayList<String> results = new ArrayList<>();
List<String> allPotions = PotionHelper.getPotions(AbstractPlayer.PlayerClass.IRONCLAD, true);
for (String key : allPotions) {
results.add(key.replace(' ', '_'));
}
return results;
}

private static CustomShopItem randomItem() {
if (AbstractDungeon.miscRng.randomBoolean())
return new CustomShopItem(AbstractDungeon.returnRandomRelic(AbstractDungeon.returnRandomRelicTier()));
else
return new CustomShopItem(AbstractDungeon.returnRandomPotion());
}

private static CustomShopItem itemFromId(String id) {
Object obj = RelicLibrary.getRelic(id);
CustomShopItem item = null;
if (obj != null)
item = new CustomShopItem((AbstractRelic)obj);
else if ((obj = PotionHelper.getPotion(id)) != null)
item = new CustomShopItem((AbstractPotion)obj);
return item;
}

@Override
public ArrayList<String> extraOptions(String[] tokens, int depth) {
String item = tokens[1];
if (item.equals("relic"))
return ConsoleCommand.getRelicOptions();
if (tokens.length == 2) {
ArrayList<String> choices = new ArrayList<>();
choices.add("page");
choices.add("potion");
choices.add("relic");
choices.add("row");
return choices;
}

ArrayList<String> result = new ArrayList<>();
List<String> allPotions = PotionHelper.getPotions(AbstractPlayer.PlayerClass.IRONCLAD, true);
for (String key : allPotions) {
result.add(key.replace(' ', '_'));
ArrayList<String> results = new ArrayList<>();
switch(tokens[2]) {
case "page":
results.add("3 3 3 ...");
return results;
case "potion":
if (tokens.length > 3)
return results;
return allPotions();
case "relic":
if (tokens.length > 3)
return results;
return ConsoleCommand.getRelicOptions();
case "row":
results.addAll(allPotions());
results.addAll(ConsoleCommand.getRelicOptions());
results.sort(Comparator.comparing(String::toString));
return results;
default:
return new ArrayList<>();
}
return result;
}

@Override
protected void execute(String[] tokens, int depth) {
String item = tokens[1];
String id = tokens[2];

if (item.equals("relic"))
ShopGrid.tryAddItem(new CustomShopItem(RelicLibrary.getRelic(id)));
else if (item.equals("potion"))
ShopGrid.tryAddItem(new CustomShopItem(PotionHelper.getPotion(id)));
switch(tokens[2]) {
case "page":
if (tokens.length == 3) {
ShopGrid.Page page = ShopGrid.addDefaultPage();
while (page.tryAddItem(randomItem()));
ShopGrid.currentPage = page;
} else {
ShopGrid.Page page = ShopGrid.addEmptyPage();
for (int i = 3; i < tokens.length; i++)
page.addRow(Integer.parseInt(tokens[i]));
while (page.tryAddItem(randomItem()));
ShopGrid.currentPage = page;
}
case "row":
if (tokens.length == 3) {
ShopGrid.Row row = ShopGrid.currentPage.addRow();
while (row.tryAddItem(randomItem()));
} else {
ArrayList<CustomShopItem> items = new ArrayList<CustomShopItem>();
for (int i = 3; i < tokens.length; i++)
items.add(itemFromId(tokens[i]));
ShopGrid.Row row = ShopGrid.currentPage.addRow(items.size());
for (CustomShopItem item : items)
row.tryAddItem(item);
}
break;
case "relic":
if (tokens.length > 4) {
errorMsg();
return;
}
AbstractRelic relic;
if (tokens.length < 4)
relic = AbstractDungeon.returnRandomRelic(AbstractDungeon.returnRandomRelicTier());
else
relic = RelicLibrary.getRelic(tokens[3]);
if (!ShopGrid.tryAddItem(new CustomShopItem(relic)))
DevConsole.log("could not add " + relic.relicId + " to shop grid");
break;
case "potion":
if (tokens.length > 4) {
errorMsg();
return;
}
AbstractPotion potion;
if (tokens.length < 4)
potion = AbstractDungeon.returnRandomPotion();
else
potion = PotionHelper.getPotion(tokens[3]);
if (!ShopGrid.tryAddItem(new CustomShopItem(potion)))
DevConsole.log("could not add " + potion.ID + " to shop grid");
break;
default:
errorMsg();
}
}
}
47 changes: 44 additions & 3 deletions mod/src/main/java/basemod/devcommands/shop/ShopRemove.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,61 @@
package basemod.devcommands.shop;

import java.util.ArrayList;
import java.util.Iterator;

import basemod.ShopGrid;
import basemod.abstracts.CustomShopItem;
import basemod.devcommands.ConsoleCommand;

public class ShopRemove extends ConsoleCommand {

public ShopRemove() {
requiresPlayer = true;
minExtraTokens = 2;
maxExtraTokens = 2;
simpleCheck = true;
}

@Override
public ArrayList<String> extraOptions(String[] tokens, int depth) {
if (tokens.length == 2) {
ArrayList<String> choices = new ArrayList<>();
choices.add("item");
choices.add("page");
}

ArrayList<String> results = new ArrayList<>();
switch(tokens[2]) {
case "item":
if (tokens.length < 5)
results.add("col");
if (tokens.length < 4)
results.add("row");
return results;
}
return results;
}

@Override
public void execute(String[] tokens, int depth) {
int row = Integer.parseInt(tokens[0]);
int col = Integer.parseInt(tokens[1]);
ShopGrid.currentPage.rows.get(row).items.remove(col);
switch(tokens[2]) {
case "item":
int row = Integer.parseInt(tokens[3]);
if (tokens.length == 4) {
Iterator<CustomShopItem> it = ShopGrid.currentPage.rows.get(row).items.iterator();
while (it.hasNext()) {
it.remove();
}
} else if (tokens.length == 5) {
int col = Integer.parseInt(tokens[5]);
ShopGrid.currentPage.rows.get(row).items.remove(col);
} else {
errorMsg();
}
break;
case "page":
ShopGrid.removePage(ShopGrid.currentPage);
break;
}
}
}
Loading