From 89e4c8345acad119cae7106768dffcc0ab2d8516 Mon Sep 17 00:00:00 2001 From: Ada Date: Sat, 4 Nov 2023 20:21:42 +0100 Subject: [PATCH 1/3] Coloured prompt for user out of money --- src/kasse.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/kasse.c b/src/kasse.c index eec44c3..939d42f 100644 --- a/src/kasse.c +++ b/src/kasse.c @@ -213,9 +213,10 @@ static signed int buy(char *name, int32_t price) { credit->credit); exit(1); } - cprintf("\r\n%s hat nicht genug Geld (%s). e) einzahlen a) abbruch t) " - "trotzdem\r\n", - nickname, rest); + cprintf("\r\n%s hat nicht genug Geld (%s)", nickname, rest); + MENU_KEY(" e", "einzahlen"); + MENU_KEY(" a", "abbruch"); + MENU_KEY(" t", "trotzdem"); c = cgetc(); if (c == 'e') { deposit_credit(nickname); From 68d716a322cd81813bc9e2a9026166543a6b62fb Mon Sep 17 00:00:00 2001 From: Ada Date: Sat, 4 Nov 2023 23:55:07 +0100 Subject: [PATCH 2/3] Introduce more coloured prompt with macros GOOD and ERROR Fixes https://github.com/nnev/c128-kasse/issues/52 Fixes https://github.com/nnev/c128-kasse/issues/51 --- include/general.h | 18 +++++++++++++++--- src/credit_manager.c | 16 +++++++++------- src/itemz.c | 8 ++++---- src/kasse.c | 35 +++++++++++++++++++---------------- 4 files changed, 47 insertions(+), 30 deletions(-) diff --git a/include/general.h b/include/general.h index e3d14f4..d8ad1d7 100644 --- a/include/general.h +++ b/include/general.h @@ -26,11 +26,23 @@ extern BYTE _oserror; #define KASSE_AUTHORS "phil_fry, sECuRE, sur5r, mxf, ada" #define MENU_KEY(key, label) \ + textcolor(TC_YELLOW); \ + cprintf(key); \ + textcolor(TC_LIGHT_GRAY); \ + cprintf(") " label); + +#define ERROR(message) \ + do { \ + textcolor(TC_RED); \ + cprintf(message); \ + textcolor(TC_LIGHT_GRAY); \ + } while (0) + +#define GOOD(message) \ do { \ - textcolor(TC_YELLOW); \ - cprintf(key); \ + textcolor(TC_GREEN); \ + cprintf(message); \ textcolor(TC_LIGHT_GRAY); \ - cprintf(") " label); \ } while (0) /* C128 color codes, see PDF page 127 of diff --git a/src/credit_manager.c b/src/credit_manager.c index 847953e..f425159 100644 --- a/src/credit_manager.c +++ b/src/credit_manager.c @@ -168,7 +168,8 @@ static void deposit_credit_idx(int8_t i) { credit->credit += (signed int)deposit; print_the_buffer(); - cprintf("\r\nEinzahlung durchgef" uUML "hrt, dr" uUML "cke RETURN...\r\n"); + cprintf("\r\n\r\nEinzahlung durchgef" uUML "hrt"); + GOOD("\r\nDr" uUML "cke RETURN...\r\n"); cget_return(); } @@ -188,8 +189,8 @@ static void new_credit(void) { int credit; if (credits.num_items == MAX_CREDIT_ITEMS) { - cprintf("\rEs ist bereits die maximale Anzahl an Eintr" aUML - "gen erreicht, dr" uUML "cke RETURN...\r\n"); + ERROR("\rEs ist bereits die maximale Anzahl an Eintr" aUML + "gen erreicht, dr" uUML "cke RETURN...\r\n"); cget_return(); return; } @@ -200,7 +201,7 @@ static void new_credit(void) { return; if (find_credit_idx(name) >= 0) { - cprintf("\rNickname existiert bereits, dr" uUML "cke RETURN...\r\n"); + ERROR("\r\nNickname existiert bereits, dr" uUML "cke RETURN...\r\n"); cget_return(); return; } @@ -209,6 +210,7 @@ static void new_credit(void) { credit = cget_number(0); if (credit < 0) { cprintf("\r\nLege mit 0 an und verkaufe Waren oder Freitext\r\n"); + GOOD("\r\nDr" uUML "cke RETURN...\r\n"); cget_return(); return; } @@ -275,7 +277,7 @@ void credit_manager(void) { break; case 's': save_credits(); - cprintf("\r\nDr" uUML "cke RETURN...\r\n"); + GOOD("\r\nDr" uUML "cke RETURN...\r\n"); cget_return(); break; case 'f': @@ -306,11 +308,11 @@ void credit_manager(void) { break; case 'z': save_credits(); - cprintf("\r\nDr" uUML "cke RETURN...\r\n"); + GOOD("\r\nDr" uUML "cke RETURN...\r\n"); cget_return(); return; default: - cprintf("Unbekannter Befehl, dr" uUML "cke RETURN...\r\n"); + ERROR("\r\nUnbekannter Befehl, dr" uUML "cke RETURN...\r\n"); cget_return(); } } diff --git a/src/itemz.c b/src/itemz.c index 5989021..80e1f7e 100644 --- a/src/itemz.c +++ b/src/itemz.c @@ -43,8 +43,8 @@ static void new_item(void) { int price, times_sold; if (status.num_items == MAX_ITEMS) { - cprintf("\rEs ist bereits die maximale Anzahl an Eintr" aUML - "gen erreicht, dr" uUML "cke RETURN...\r\n"); + ERROR("\rEs ist bereits die maximale Anzahl an Eintr" aUML + "gen erreicht, dr" uUML "cke RETURN...\r\n"); cget_return(); return; } @@ -142,11 +142,11 @@ void itemz_manager() { break; case 'z': save_items(); - cprintf("\r\nDr" uUML "cke RETURN...\r\n"); + GOOD("\r\nDr" uUML "cke RETURN...\r\n"); cget_return(); return; default: - cprintf("Unbekannter Befehl, dr" uUML "cke RETURN...\r\n"); + ERROR("\r\nUnbekannter Befehl, dr" uUML "cke RETURN...\r\n"); cget_return(); } } diff --git a/src/kasse.c b/src/kasse.c index 939d42f..26a6d5e 100644 --- a/src/kasse.c +++ b/src/kasse.c @@ -191,8 +191,8 @@ static signed int buy(char *name, int32_t price) { einheiten = cget_number(1); if (einheiten > 100 || einheiten < -100 || einheiten == 0) { - cprintf("\r\nEinheit nicht in [-100, 100] oder 0, Abbruch, dr" uUML "cke " - "RETURN...\r\n"); + ERROR("\r\n\r\nEinheit nicht in [-100, 100] oder 0, Abbruch"); + GOOD("\r\nDr" uUML "cke RETURN...\r\n"); cget_return(); return 1; } @@ -213,7 +213,7 @@ static signed int buy(char *name, int32_t price) { credit->credit); exit(1); } - cprintf("\r\n%s hat nicht genug Geld (%s)", nickname, rest); + cprintf("\r\n%s hat nicht genug Guthaben (%s)", nickname, rest); MENU_KEY(" e", "einzahlen"); MENU_KEY(" a", "abbruch"); MENU_KEY(" t", "trotzdem"); @@ -234,18 +234,15 @@ static signed int buy(char *name, int32_t price) { exit(1); } - textcolor(TC_LIGHT_GREEN); - cprintf("\r\nVerbleibendes Guthaben f" uUML "r %s: %s. Dr" uUML - "cke RETURN...\r\n", - nickname, rest); - textcolor(TC_LIGHT_GRAY); + cprintf("\r\n\r\nVerbleibendes Guthaben f" uUML "r %s: %s.", nickname, + rest); + GOOD("\r\nDr" uUML "cke RETURN...\r\n"); cget_return(); matches++; } else { - textcolor(TC_LIGHT_RED); - cprintf("\r\nNickname nicht gefunden in der Guthabenverwaltung! Abbruch, " - "dr" uUML "cke RETURN...\r\n"); - textcolor(TC_LIGHT_GRAY); + ERROR("\r\n\r\nNickname nicht gefunden in der Guthabenverwaltung! " + "Abbruch!"); + GOOD("\r\nDr" uUML "cke RETURN...\r\n"); cget_return(); return 0; } @@ -261,7 +258,8 @@ static signed int buy(char *name, int32_t price) { void buy_stock(BYTE n) { if (n >= status.num_items || status.status[n].item_name == NULL) { - cprintf("FEHLER: Diese Einheit existiert nicht.\r\n"); + ERROR("\r\nDiese Einheit existiert nicht."); + GOOD("\r\nDr" uUML "cke RETURN\r\n"); cget_return(); return; } @@ -284,7 +282,8 @@ void buy_custom(void) { price = cget_number(0); if (price == 0) { - cprintf("Kauf abgebrochen, dr" uUML "cke RETURN...\r\n"); + ERROR("\r\nKauf abgebrochen"); + GOOD("\r\nDr" uUML "cke RETURN\r\n"); cget_return(); return; } @@ -393,7 +392,8 @@ int main(void) { save_items(); save_credits(); log_flush(); - cprintf("\r\nDr" uUML "cke RETURN...\r\n"); + GOOD("\r\nDr" uUML "cke RETURN...\r\n"); + cget_return(); } else if (*c == 'g') { credit_manager(); } else if (*c == 'i') { @@ -405,9 +405,12 @@ int main(void) { save_items(); save_credits(); log_flush(); - cprintf("\r\nDr" uUML "cke RETURN...\r\n"); + GOOD("\r\nDr" uUML "cke RETURN...\r\n"); cget_return(); break; + } else { + ERROR("\r\nUnbekannter Befehl, dr" uUML "cke RETURN...\r\n"); + cget_return(); } } clrscr(); From c73616e486a0803fa069d451d651ff65d4d2eaf6 Mon Sep 17 00:00:00 2001 From: Ada Date: Sun, 5 Nov 2023 00:42:03 +0100 Subject: [PATCH 3/3] Colour users red if they have a negative balance --- credits | Bin 978 -> 978 bytes src/credit_manager.c | 13 +++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/credits b/credits index 212f43d40ac23d0f2a4885425a2bf8b178d3722d..6dc01be14958412a04f4ab661fad56573f3359c8 100644 GIT binary patch delta 12 Ucmcb_eu;g;YR3N?*QhZA043=KbN~PV delta 12 Tcmcb_eu;g;YDR{QYt)zlAnpWp diff --git a/src/credit_manager.c b/src/credit_manager.c index f425159..1a1060a 100644 --- a/src/credit_manager.c +++ b/src/credit_manager.c @@ -40,8 +40,17 @@ static void print_item(BYTE i) { cprintf("%2d", i); textcolor(TC_LIGHT_GRAY); // TODO: switch to MAX_CREDIT_NAME_LENGTH once that is increased - cprintf(" %-" xstr(MAX_ITEM_NAME_LENGTH) "s \xDD%3s ", - credits.credits[i].nickname, buffer); + if (credit < 0) { + textcolor(TC_LIGHT_RED); + } + cprintf(" %-" xstr(MAX_ITEM_NAME_LENGTH) "s ", credits.credits[i].nickname); + textcolor(TC_LIGHT_GRAY); + cprintf("\xDD"); + if (credit < 0) { + textcolor(TC_LIGHT_RED); + } + cprintf("%3s ", buffer); + textcolor(TC_LIGHT_GRAY); } static void print_line(BYTE i) {