Skip to content

Commit

Permalink
UI fixes and randomized runs button
Browse files Browse the repository at this point in the history
  • Loading branch information
daviscook477 committed Mar 15, 2018
1 parent 9000ec6 commit 75b2fea
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 33 deletions.
136 changes: 103 additions & 33 deletions src/main/java/customclimb/CustomClimb.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ private static Texture makeTexture(String path, float scale) {
public static final float CHAR_SELECT_X_DELTA = 100.0f;
public static final float SEED_X = 1450.0f;
public static final float SEED_Y = 680.0f;
public static final float CHAOTIC_RANDOM_X = 1400.0f;
public static final float CHAOTIC_RANDOM_X = 1350.0f;
public static final float CHAOTIC_RANDOM_Y = 680.0f;
public static final float BALANCED_RANDOM_X = 1350.0f;
public static final float BALANCED_RANDOM_X = 1250.0f;
public static final float BALANCED_RANDOM_Y = 680.0f;
public static final String CONFIRM_BUTTON_TEXT = "Embark";
public static final String HEADER_TEXT = "Custom Climb";
Expand All @@ -131,6 +131,7 @@ private static Texture makeTexture(String path, float scale) {
public static final float APPLIED_MODS_LIST_X_BUTTON = 870.0f;
public static final float MOD_LIST_LINE_WIDTH = 400.0f;
public static final float MOD_LIST_LINE_SPACING = 30.0f;
public static final float MOD_LIST_MIN_DELTA_Y = 80.0f;

public static final float POSSIBLE_MODS_LEFT_ARROW_X = 1000.0f;
public static final float POSSIBLE_MODS_LEFT_ARROW_Y = 190.0f;
Expand Down Expand Up @@ -229,10 +230,7 @@ private void setupHitboxes() {
builder.append(": ");
builder.append(mod.description);

y += FontHelper.getSmartHeight(FontHelper.charDescFont, builder.toString(),
MOD_LIST_LINE_WIDTH * Settings.scale,
MOD_LIST_LINE_SPACING * Settings.scale) -
POSSIBLE_MODS_LIST_Y_DELTA * Settings.scale;
y += calcSpacing(builder.toString());
}

y = APPLIED_MODS_LIST_Y * Settings.scale;
Expand Down Expand Up @@ -260,10 +258,59 @@ private void setupHitboxes() {
builder.append(": ");
builder.append(mod.description);

y += FontHelper.getSmartHeight(FontHelper.charDescFont, builder.toString(),
MOD_LIST_LINE_WIDTH * Settings.scale,
MOD_LIST_LINE_SPACING * Settings.scale) -
APPLIED_MODS_LIST_Y_DELTA * Settings.scale;
y += calcSpacing(builder.toString());
}
}

private void recalcHitboxes() {
float y = POSSIBLE_MODS_LIST_Y * Settings.scale;

for (int i = 0; i < POSSIBLE_PER_PAGE; i++) {
if (!hasPossibleModAtPageIndex(i)) {
continue;
}

possibleHB.get(i).y = y - 94.0f * Settings.scale + (HB_SHRINK * Settings.scale);

AbstractDailyMod mod = getPossibleModAtPageIndex(i);

StringBuilder builder = new StringBuilder();

if (mod.positive) {
builder.append(FontHelper.colorString(mod.name, "g"));
} else {
builder.append(FontHelper.colorString(mod.name, "r"));
}

builder.append(": ");
builder.append(mod.description);

y += calcSpacing(builder.toString());
}

y = APPLIED_MODS_LIST_Y * Settings.scale;

for (int i = 0; i < APPLIED_PER_PAGE; i++) {
if (!hasAppliedModAtPageIndex(i)) {
continue;
}

appliedHB.get(i).y = y - 94.0f * Settings.scale + (HB_SHRINK * Settings.scale);

AbstractDailyMod mod = getAppliedModAtPageIndex(i);

StringBuilder builder = new StringBuilder();

if (mod.positive) {
builder.append(FontHelper.colorString(mod.name, "g"));
} else {
builder.append(FontHelper.colorString(mod.name, "r"));
}

builder.append(": ");
builder.append(mod.description);

y += calcSpacing(builder.toString());
}
}

Expand Down Expand Up @@ -303,7 +350,6 @@ private void setupModLists() {
appliedMods.add(possibleMods.remove(0));
appliedMods.add(possibleMods.remove(0));
appliedMods.add(possibleMods.remove(0));

calcPageMax();
}

Expand All @@ -314,10 +360,16 @@ private void doSelect(int selected) {
}

private String buildPossiblePageText() {
if (maxPossiblePage == 0) {
return PAGE_TEXT + ": " + "0/0";
}
return PAGE_TEXT + ": " + (possiblePage + 1) + "/" + maxPossiblePage;
}

private String buildAppliedPageText() {
if (maxAppliedPage == 0) {
return PAGE_TEXT + ": " + "0/0";
}
return PAGE_TEXT + ": " + (appliedPage + 1) + "/" + maxAppliedPage;
}

Expand Down Expand Up @@ -501,7 +553,7 @@ public void update() {
CHAOTIC_RANDOM_X, CHAOTIC_RANDOM_Y,
new Texture(makePath(CHAOTIC_RANDOM_IMG)), climbPanel,
(me) -> {
BaseMod.openTextPanel(climbPanel, "How many modifiers?", Integer.toString(modAmount), Integer.toString(DEFAULT_MOD_AMOUNT), "How many modifiers?", (panel) -> {
BaseMod.openTextPanel(climbPanel, "Chaos!\n How many modifiers?", Integer.toString(modAmount), Integer.toString(DEFAULT_MOD_AMOUNT), "Chaos!\n How many modifiers?", (panel) -> {
// do nothing - was cancelled
}, (panel) -> {
this.modAmount = Integer.parseInt(ModTextPanel.textField);
Expand All @@ -515,7 +567,7 @@ public void update() {
BALANCED_RANDOM_X, BALANCED_RANDOM_Y,
new Texture(makePath(BALANCED_RANDOM_IMG)), climbPanel,
(me) -> {
BaseMod.openTextPanel(climbPanel, "How many modifiers?", Integer.toString(modAmount), Integer.toString(DEFAULT_MOD_AMOUNT), "How many modifiers?", (panel) -> {
BaseMod.openTextPanel(climbPanel, "Balance!\n How many modifiers?", Integer.toString(modAmount), Integer.toString(DEFAULT_MOD_AMOUNT), "Balance!\n How many modifiers?", (panel) -> {
// do nothing - was cancelled
}, (panel) -> {
this.modAmount = Integer.parseInt(ModTextPanel.textField);
Expand All @@ -540,10 +592,12 @@ private void fixPages() {
}
possiblePageLabel.text = buildPossiblePageText();
appliedPageLabel.text = buildAppliedPageText();
recalcHitboxes();
}

private void updateHitboxes() {
int index = 0;
boolean changed = false;
for (Hitbox hb : possibleHB) {
if (index >= (possibleMods.size() - possiblePage * POSSIBLE_PER_PAGE )) continue;

Expand All @@ -561,7 +615,7 @@ private void updateHitboxes() {
logger.info("possible mods " + index + " clicked");
hb.clicked = false;
appliedMods.add(possibleMods.remove(getPossiblePageIndex(index)));
fixPages();
changed = true;
}
index++;
}
Expand All @@ -583,10 +637,13 @@ private void updateHitboxes() {
logger.info("applied mods " + index + " clicked");
hb.clicked = false;
possibleMods.add(appliedMods.remove(getAppliedPageIndex(index)));
fixPages();
changed = true;
}
index++;
}
if (changed) {
fixPages();
}
}

public static final int DEFAULT_MOD_AMOUNT = 4;
Expand Down Expand Up @@ -618,8 +675,10 @@ private void randomizeMods(int amount, boolean balanced) {
}
if (!balanced) {
for (int i = 0; i < amount; i++) {
int listPos = random.nextInt(possibleMods.size());
appliedMods.add(0, possibleMods.remove(listPos));
if (possibleMods.size() > 0) {
int listPos = random.nextInt(possibleMods.size());
appliedMods.add(0, possibleMods.remove(listPos));
}
}
} else {
int positiveAmount = (int) (BALANCED_POSITIVE * amount);
Expand All @@ -629,18 +688,34 @@ private void randomizeMods(int amount, boolean balanced) {
int negativeAmount = amount - positiveAmount;
setPositivesAndNegatives();
for (int i = 0; i < positiveAmount; i++) {
int listPos = random.nextInt(positives.size());
AbstractDailyMod positiveMod = positives.get(listPos);
appliedMods.add(positiveMod);
possibleMods.remove(positiveMod);
if (positives.size() > 0) {
int listPos = random.nextInt(positives.size());
AbstractDailyMod positiveMod = positives.remove(listPos);
appliedMods.add(positiveMod);
possibleMods.remove(positiveMod);
}
}
for (int i = 0; i < negativeAmount; i++) {
int listPos = random.nextInt(negatives.size());
AbstractDailyMod negativeMod = negatives.get(listPos);
appliedMods.add(negativeMod);
possibleMods.remove(negativeMod);
if (negatives.size() > 0) {
int listPos = random.nextInt(negatives.size());
AbstractDailyMod negativeMod = negatives.remove(listPos);
appliedMods.add(negativeMod);
possibleMods.remove(negativeMod);
}
}
}
fixPages();
}

private float calcSpacing(String desc) {
float deltaY = FontHelper.getSmartHeight(FontHelper.charDescFont, desc,
MOD_LIST_LINE_WIDTH * Settings.scale,
MOD_LIST_LINE_SPACING * Settings.scale) -
APPLIED_MODS_LIST_Y_DELTA * Settings.scale;
if (deltaY > -1.0f * MOD_LIST_MIN_DELTA_Y * Settings.scale) {
deltaY = -1.0f * MOD_LIST_MIN_DELTA_Y * Settings.scale;
}
return deltaY;
}

private void renderMods(SpriteBatch sb) {
Expand Down Expand Up @@ -673,10 +748,7 @@ private void renderMods(SpriteBatch sb) {
sb.draw(plusTexture, POSSIBLE_MODS_LIST_X_BUTTON * Settings.scale, y - 94.0f * Settings.scale,
plusTexture.getWidth() * Settings.scale, plusTexture.getHeight() * Settings.scale);

y += FontHelper.getSmartHeight(FontHelper.charDescFont, builder.toString(),
MOD_LIST_LINE_WIDTH * Settings.scale,
MOD_LIST_LINE_SPACING * Settings.scale) -
POSSIBLE_MODS_LIST_Y_DELTA * Settings.scale;
y += calcSpacing(builder.toString());
}

y = APPLIED_MODS_LIST_Y * Settings.scale;
Expand Down Expand Up @@ -708,10 +780,8 @@ private void renderMods(SpriteBatch sb) {
sb.draw(minusTexture, APPLIED_MODS_LIST_X_BUTTON * Settings.scale, y - 94.0f * Settings.scale,
minusTexture.getWidth() * Settings.scale, minusTexture.getHeight() * Settings.scale);

y += FontHelper.getSmartHeight(FontHelper.charDescFont, builder.toString(),
MOD_LIST_LINE_WIDTH * Settings.scale,
MOD_LIST_LINE_SPACING * Settings.scale) -
APPLIED_MODS_LIST_Y_DELTA * Settings.scale;

y += calcSpacing(builder.toString());
}
}

Expand Down
Binary file added src/main/resources/img/balanced_random.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/img/balanced_random.xcf
Binary file not shown.
Binary file added src/main/resources/img/chaotic_random.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/img/chaotic_random.xcf
Binary file not shown.

0 comments on commit 75b2fea

Please sign in to comment.