2022-06-17 16:38:40 -05:00
|
|
|
/*
|
|
|
|
Slangin'
|
|
|
|
Menu Helpers
|
|
|
|
Author: Rudis Muiznieks
|
|
|
|
License: WTFPL
|
|
|
|
*/
|
|
|
|
|
|
|
|
const uint8_t PROGMEM spriteMenuCursor[] = {
|
|
|
|
3, 5,
|
|
|
|
0x1f, 0x0e, 0x04,
|
|
|
|
};
|
|
|
|
|
2022-06-19 10:37:16 -05:00
|
|
|
String lookupLocation(GameLocation loc) {
|
|
|
|
switch (loc) {
|
|
|
|
case LOC_BRONX:
|
|
|
|
return F("Bronx");
|
|
|
|
case LOC_GHETTO:
|
|
|
|
return F("Ghetto");
|
|
|
|
case LOC_CENTRAL_PARK:
|
|
|
|
return F("Central Park");
|
|
|
|
case LOC_MANHATTEN:
|
|
|
|
return F("Manhatten");
|
|
|
|
case LOC_CONEY_ISLAND:
|
|
|
|
return F("Coney Island");
|
|
|
|
case LOC_BROOKLYN:
|
|
|
|
return F("Brooklyn");
|
|
|
|
default:
|
|
|
|
return F("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String lookupDrug(Drug drug) {
|
|
|
|
switch (drug) {
|
|
|
|
case DRUG_COCAINE:
|
|
|
|
return F("Cocaine");
|
|
|
|
case DRUG_HEROINE:
|
|
|
|
return F("Heroine");
|
|
|
|
case DRUG_ACID:
|
|
|
|
return F("Acid");
|
|
|
|
case DRUG_WEED:
|
|
|
|
return F("Weed");
|
|
|
|
case DRUG_SPEED:
|
|
|
|
return F("Speed");
|
|
|
|
case DRUG_LUDES:
|
|
|
|
return F("Ludes");
|
|
|
|
default:
|
|
|
|
return F("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-17 16:38:40 -05:00
|
|
|
void computeMenuSizes(const bool small, const bool cols,
|
|
|
|
const int itemCount, const String items[],
|
|
|
|
int& x1, int& x2, int& y) {
|
|
|
|
const int charWidth = small ? 4 : 5;
|
|
|
|
const int charHeight = small ? 8 : 9;
|
|
|
|
|
|
|
|
if (cols) { // two colums
|
|
|
|
int col1Count = round(itemCount / 2.0);
|
|
|
|
int col2Count = itemCount - col1Count;
|
|
|
|
int col1Width = 0;
|
|
|
|
int col2Width = 0;
|
|
|
|
for (int i = 0; i < col1Count; i++) {
|
|
|
|
const int newLen = items[i].length();
|
|
|
|
if (newLen > col1Width) col1Width = newLen;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < col2Count; i++) {
|
|
|
|
const int newLen = items[i + col1Count].length();
|
|
|
|
if (newLen > col2Width) col2Width = newLen;
|
|
|
|
}
|
2022-06-18 00:05:30 -05:00
|
|
|
x1 = 66 - round((col1Width + col2Width + 1.75) * (charWidth / 2.0));
|
|
|
|
x2 = x1 + round((col1Width + 1.75) * charWidth);
|
|
|
|
y = 42 - round(col1Count * (charHeight / 2.0));
|
2022-06-17 16:38:40 -05:00
|
|
|
} else { // one column
|
|
|
|
int colWidth = 0;
|
|
|
|
for (int i = 0; i < itemCount; i++) {
|
|
|
|
const int newLen = items[i].length();
|
|
|
|
if (newLen > colWidth) colWidth = newLen;
|
|
|
|
}
|
|
|
|
x1 = 66 - round(colWidth * (charWidth / 2.0));
|
|
|
|
x2 = -1;
|
2022-06-18 00:05:30 -05:00
|
|
|
y = 42 - round(itemCount * (charHeight / 2.0));
|
2022-06-17 16:38:40 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawMenu(const bool small, const bool cols,
|
|
|
|
const int itemCount, const String items[]) {
|
|
|
|
const int charWidth = small ? 4 : 5;
|
|
|
|
const int charHeight = small ? 8 : 9;
|
|
|
|
int x1, x2, y;
|
|
|
|
computeMenuSizes(small, cols, itemCount, items, x1, x2, y);
|
|
|
|
const int col1Count = round(itemCount / 2.0);
|
|
|
|
for (int i = 0; i < itemCount; i++) {
|
|
|
|
int cx, cy;
|
|
|
|
if (cols) { // two columns
|
|
|
|
const bool col1 = i < col1Count;
|
|
|
|
cx = col1 ? x1 : x2;
|
|
|
|
cy = col1
|
|
|
|
? i * charHeight + y
|
|
|
|
: (i - col1Count) * charHeight + y;
|
|
|
|
} else { // one column
|
|
|
|
cx = x1;
|
|
|
|
cy = i * charHeight + y;
|
|
|
|
}
|
|
|
|
if (small) {
|
|
|
|
font3x5.setCursor(cx, cy);
|
|
|
|
font3x5.print(items[i]);
|
|
|
|
} else {
|
|
|
|
font4x6.setCursor(cx, cy);
|
|
|
|
font4x6.print(items[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawMenuIndicator(const int menuSelected, const bool small,
|
2022-06-17 18:55:36 -05:00
|
|
|
const bool cols, const int itemCount, const String items[],
|
|
|
|
const bool clear) {
|
2022-06-17 16:38:40 -05:00
|
|
|
const int charWidth = small ? 4 : 5;
|
|
|
|
const int charHeight = small ? 8 : 9;
|
|
|
|
int x1, x2, y;
|
|
|
|
computeMenuSizes(small, cols, itemCount, items, x1, x2, y);
|
|
|
|
int cx, cy;
|
|
|
|
if (cols) { // two columns
|
|
|
|
const int col1Count = round(itemCount / 2.0);
|
|
|
|
const bool col1 = menuSelected < col1Count;
|
|
|
|
cx = col1 ? x1 : x2;
|
|
|
|
cy = col1
|
|
|
|
? menuSelected * charHeight + y
|
|
|
|
: (menuSelected - col1Count) * charHeight + y;
|
|
|
|
} else { // one column
|
|
|
|
cx = x1;
|
|
|
|
cy = menuSelected * charHeight + y;
|
|
|
|
}
|
2022-06-17 18:55:36 -05:00
|
|
|
if (clear) {
|
|
|
|
arduboy.fillRect(cx - 4, cy + (small ? 1 : 2), 3, 5, BLACK);
|
|
|
|
} else {
|
|
|
|
Sprites::drawOverwrite(cx - 4, cy + (small ? 1 : 2), spriteMenuCursor, 0);
|
|
|
|
}
|
2022-06-17 16:38:40 -05:00
|
|
|
}
|
2022-06-19 10:37:16 -05:00
|
|
|
|
|
|
|
void buildDrugMenu(const long extra[6]) {
|
|
|
|
int lengths[6];
|
|
|
|
int col1Max = 0;
|
|
|
|
int col2Max = 0;
|
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
int extraLen = String(extra[i]).length();
|
|
|
|
lengths[i] = lookupDrug(i).length() + 1 + extraLen;
|
|
|
|
if (i < 3 && lengths[i] > col1Max) col1Max = lengths[i];
|
|
|
|
if (i >= 3 && lengths[i] > col2Max) col2Max = lengths[i];
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
const int colMax = i < 3 ? col1Max : col2Max;
|
|
|
|
menu[i] = lookupDrug(i);
|
|
|
|
menu[i] += F(" ");
|
|
|
|
for (int s = 0; s < colMax - lengths[i]; s++) {
|
|
|
|
menu[i] += F(" ");
|
|
|
|
}
|
|
|
|
menu[i] += String(extra[i]);
|
|
|
|
}
|
|
|
|
menuLength = 6;
|
|
|
|
menuCols = true;
|
|
|
|
menuSmall = col1Max + col2Max > 22;
|
|
|
|
}
|
2022-06-21 10:50:50 -05:00
|
|
|
|
|
|
|
int getMenuBackOut() {
|
|
|
|
// this whole thing could have been done so much better :(
|
|
|
|
// i suck at C++
|
|
|
|
switch (sGameState) {
|
|
|
|
case STATE_SELL_MENU:
|
|
|
|
case STATE_BORROW_INPUT:
|
|
|
|
case STATE_WITHDRAW_INPUT:
|
|
|
|
return 1;
|
|
|
|
case STATE_INVENTORY:
|
2022-06-21 21:36:50 -05:00
|
|
|
case STATE_HIGH_SCORES:
|
2022-06-21 10:50:50 -05:00
|
|
|
return 2;
|
|
|
|
case STATE_JET_MENU:
|
|
|
|
return 3;
|
|
|
|
case STATE_SHARK_MENU:
|
|
|
|
return 4;
|
|
|
|
case STATE_BANK_MENU:
|
|
|
|
return 5;
|
|
|
|
case STATE_BUY_QTY_INPUT:
|
|
|
|
case STATE_SELL_QTY_INPUT:
|
|
|
|
return sCurrentDrug;
|
|
|
|
case STATE_INFO_DIALOG:
|
|
|
|
switch (sPreviousGameState) {
|
|
|
|
case STATE_BUY_MENU:
|
|
|
|
case STATE_SELL_MENU:
|
|
|
|
return sCurrentDrug;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|