Fix bulls_cows.yab UI layout/scrolling and index engmenu items 1 to 7

This commit is contained in:
Luxferre committed 2026-11-03 10:05:34 +02:00
1 parent 6d31efd796
commit ebdb0f8ee2
4 files changed
+90 -94

No files matched your search

@@ -10,9 +10,9 @@
// Controls:
// 0-9 keys : Append a digit to your guess (duplicates rejected)
// OK (Enter): Submit your guess / confirm a dialog choice
// Space / Right Softkey (F2): Delete last digit, or Quit if guess is empty
// Space / * / Right Softkey (F2): Delete last digit, or Quit if empty
// Left Softkey (F1): Open the Action Menu (New Game / About / Quit)
// Up / Down: Scroll the guess history
// Up / Down: Scroll the guess history up (older) or down (newer)
//
// Note: this build of yabasic has no function returns and no RNG seeding,
// so randomness uses a small LCG seeded from the wall clock (time$).
@@ -30,6 +30,7 @@ fi
// ----------------------------------------------------------------------------
MAX_GUESSES = 10
CODE_LEN = 4
VISIBLE_HISTORY = 4
secret$ = ""
guess_count = 0
@@ -190,6 +191,7 @@ sub submit_guess()
history_result$(guess_count) = result$
guess_count = guess_count + 1
current_guess$ = ""
history_scroll = 0
if ev_bulls = CODE_LEN then
won = 1
@@ -207,7 +209,7 @@ sub submit_guess()
end sub
// ----------------------------------------------------------------------------
// Rendering
// Rendering (240x296 window: header 0..34, content 36..266, softbar 270..296)
// ----------------------------------------------------------------------------
sub render_header()
local badge$
@@ -220,71 +222,82 @@ sub render_header()
end sub
sub render_secret_area()
local y, i, mask$
y = 40
local y, i, mask$, col
y = 36
if game_over then
if won then
col = neoui.TEXT_GREEN
else
col = neoui.TEXT_RED
fi
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_MUTED, 8, y, 14, "Secret code:", 224)
neoui_draw_text(neoui.FONT_LARGE, neoui.TEXT_GREEN, 8, y + 16, 22, secret$, 224)
neoui_draw_text(neoui.FONT_LARGE, col, 8, y + 14, 20, secret$, 224)
else
mask$ = ""
for i = 1 to CODE_LEN
mask$ = mask$ + "?"
next i
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_MUTED, 8, y, 14, "Secret code:", 224)
neoui_draw_text(neoui.FONT_LARGE, neoui.TEXT_LIGHT, 8, y + 16, 22, mask$, 224)
neoui_draw_text(neoui.FONT_LARGE, neoui.TEXT_LIGHT, 8, y + 14, 20, mask$, 224)
fi
end sub
sub render_input_area()
local y, prompt$
y = 84
local y, prompt$, focused
y = 74
focused = 0
if game_over then
prompt$ = "Game finished"
else
prompt$ = "Your guess (4 unique digits)"
if modal_mode = 0 and len(current_guess$) > 0 then
focused = 1
fi
fi
neoui_draw_input_box(8, y, 224, 40, 0, prompt$, current_guess$, "0-9 keys to type", 0)
neoui_draw_input_box(8, y, 224, 38, focused, prompt$, current_guess$, "0-9 keys to type", 0)
end sub
sub render_history()
local y, i, start_idx, end_idx, visible, result$
y = 136
local y, i, start_idx, end_idx, max_off, result$
y = 118
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_YELLOW, 8, y, 14, "Guess history:", 224)
y = y + 20
visible = 4
if guess_count <= visible then
y = 136
if guess_count <= VISIBLE_HISTORY then
start_idx = 0
else
start_idx = guess_count - visible + history_scroll
max_off = guess_count - VISIBLE_HISTORY
start_idx = max_off + history_scroll
if start_idx < 0 then start_idx = 0 fi
if start_idx > guess_count - visible then start_idx = guess_count - visible fi
if start_idx > max_off then start_idx = max_off fi
fi
end_idx = start_idx + visible - 1
end_idx = start_idx + VISIBLE_HISTORY - 1
if end_idx > guess_count - 1 then end_idx = guess_count - 1 fi
for i = start_idx to end_idx
if i >= 0 and i < guess_count then
result$ = history_result$(i)
neoui_draw_list_row(i - start_idx, y, 26, 0, neoui_icon$("list"), neoui.TEXT_BLUE, "#" + str$(i + 1) + " " + history_guess$(i), result$, "")
neoui_draw_list_row(i - start_idx, y, 26, 0, neoui_icon$("list"), neoui.TEXT_BLUE, "#" + str$(i + 1) + " " + history_guess$(i) + " " + result$, "", "")
y = y + 26
fi
next i
if guess_count > visible then
neoui_draw_scrollbar(234, 156, 104, guess_count, visible, -history_scroll)
if guess_count > VISIBLE_HISTORY then
neoui_draw_scrollbar(234, 136, 104, guess_count, VISIBLE_HISTORY, start_idx)
fi
end sub
sub render_hint()
local y
y = 248
if game_over then
if won then
neoui_draw_text_centered(neoui.FONT_SMALL, neoui.TEXT_GREEN, 8, 264, 224, 16, "Solved in " + str$(guess_count) + " tries! OK = New game")
neoui_draw_text_centered(neoui.FONT_SMALL, neoui.TEXT_GREEN, 8, y, 224, 16, "Solved in " + str$(guess_count) + " tries! OK = New game")
else
neoui_draw_text_centered(neoui.FONT_SMALL, neoui.TEXT_RED, 8, 264, 224, 16, "Out of tries! Code was " + secret$ + " - OK = New game")
neoui_draw_text_centered(neoui.FONT_SMALL, neoui.TEXT_RED, 8, y, 224, 16, "Out of tries! OK = New game")
fi
else
neoui_draw_text_centered(neoui.FONT_SMALL, neoui.TEXT_MUTED, 8, 264, 224, 16, "0-9 type OK go Up/Dn scroll")
neoui_draw_text_centered(neoui.FONT_SMALL, neoui.TEXT_MUTED, 8, y, 224, 16, "0-9 type OK go Up/Dn scroll")
fi
end sub
@@ -302,16 +315,20 @@ sub render_all()
neoui_draw_softkeys("Close", "Select", "Back")
elsif modal_mode = 2 then
neoui_draw_confirm_dialog("Start New Game?", "Abandon the current", "round and guess a new code?", "Cancel", "New Game", confirm_new)
neoui_draw_softkeys("Cancel", "Confirm", "Back")
neoui_draw_softkeys("New Game", "Confirm", "Cancel")
elsif modal_mode = 3 then
if won then
neoui_draw_confirm_dialog("You Win!", "Cracked the code in", str$(guess_count) + " tries!", "Quit", "Play Again", confirm_new)
else
neoui_draw_confirm_dialog("Game Over", "The code was " + secret$, "Better luck next time!", "Quit", "Play Again", confirm_new)
fi
neoui_draw_softkeys("Quit", "Confirm", "Back")
neoui_draw_softkeys("Again", "Confirm", "Close")
else
neoui_draw_softkeys("Menu", "Submit", "Del/Quit")
if game_over then
neoui_draw_softkeys("Menu", "New Game", "Quit")
else
neoui_draw_softkeys("Menu", "Submit", "Del/Quit")
fi
fi
neoui_end_frame()
@@ -337,6 +354,9 @@ while running
if modal_mode = 0 then
modal_mode = 1
menu_sel = 0
elsif modal_mode = 2 or modal_mode = 3 then
reset_game()
neoui_show_toast("New game started!", 1500)
else
modal_mode = 0
fi
@@ -377,7 +397,11 @@ while running
render_all()
elsif modal_mode = 2 then
if k = neoui.KEY_LEFT or k = neoui.KEY_RIGHT or k = neoui.KEY_UP or k = neoui.KEY_DOWN then
if k = neoui.KEY_LEFT then
confirm_new = 0
elsif k = neoui.KEY_RIGHT then
confirm_new = 1
elsif k = neoui.KEY_UP or k = neoui.KEY_DOWN then
confirm_new = 1 - confirm_new
elsif k = neoui.KEY_BACK then
modal_mode = 0
@@ -391,7 +415,11 @@ while running
render_all()
elsif modal_mode = 3 then
if k = neoui.KEY_LEFT or k = neoui.KEY_RIGHT or k = neoui.KEY_UP or k = neoui.KEY_DOWN then
if k = neoui.KEY_LEFT then
confirm_new = 0
elsif k = neoui.KEY_RIGHT then
confirm_new = 1
elsif k = neoui.KEY_UP or k = neoui.KEY_DOWN then
confirm_new = 1 - confirm_new
elsif k = neoui.KEY_BACK then
modal_mode = 0
@@ -408,18 +436,23 @@ while running
else
if k = neoui.KEY_OK then
submit_guess()
if game_over then
reset_game()
neoui_show_toast("New game started!", 1500)
else
submit_guess()
fi
elsif k = neoui.KEY_BACK then
running = 0
elsif k = neoui.KEY_UP then
if guess_count > VISIBLE_HISTORY and history_scroll > -(guess_count - VISIBLE_HISTORY) then
history_scroll = history_scroll - 1
fi
elsif k = neoui.KEY_DOWN then
if history_scroll < 0 then
history_scroll = history_scroll + 1
fi
elsif k = neoui.KEY_DOWN then
if guess_count > 5 and history_scroll > -(guess_count - 5) then
history_scroll = history_scroll - 1
fi
elsif k = neoui.KEY_SPACE then
elsif k = neoui.KEY_SPACE or k = neoui.KEY_STAR then
backspace_guess()
elsif k = neoui.KEY_0 then
append_digit(0)
Binary file not shown.
Binary file not shown.
+22 -59
View File
@@ -365,44 +365,44 @@ int engmenu_run_main(int argc, char** argv) {
bool isRfnv = (status.nvMethod == "rfnv");
// 1. [4] Override TTL (qualcommonly)
// 1. [1] Override TTL (qualcommonly)
std::string ttlSub = (status.ttlOverride > 0)
? ("Fixed at TTL " + std::to_string(status.ttlOverride) + " until reboot")
: ("Default TTL " + std::to_string(status.ttlCurrent) + " (tether & wwan0)");
std::string ttlBadge = (status.ttlOverride > 0)
? ("TTL " + std::to_string(status.ttlOverride))
: "Def 64";
rows.push_back({"4", "4: Override TTL", ttlSub, ttlBadge,
rows.push_back({"1", "1: Override TTL", ttlSub, ttlBadge,
status.ttlOverride > 0 ? 1 : 0});
// 2. [5] Edit IMEI1 (imeionly danger)
// 2. [2] Edit IMEI1 (imeionly danger)
std::string im1Sub = "SIM 1: " + (status.imei1.empty() ? std::string("--") : status.imei1);
rows.push_back({"5", "5: Edit IMEI 1", im1Sub,
rows.push_back({"2", "2: Edit IMEI 1", im1Sub,
isRfnv ? "rf_nv" : "NV 550", 3});
// 3. [6] Edit IMEI2 (imeionly sim2only danger)
// 3. [3] Edit IMEI2 (imeionly sim2only danger)
std::string im2Sub = "SIM 2: " + (status.imei2.empty() ? std::string("--") : status.imei2);
rows.push_back({"6", "6: Edit IMEI 2", im2Sub,
rows.push_back({"3", "3: Edit IMEI 2", im2Sub,
isRfnv ? "rf_nv" : "Ctx 1", 3});
// 4. [*] Run overclock script (qualcommonly)
// 4. [4] Run overclock script (qualcommonly)
std::string ocSub = status.cpuGov + " @ " +
std::to_string(status.cpuCurMhz) + "/" +
std::to_string(status.cpuMaxMhz) + " MHz";
rows.push_back({"*", "*: Run Overclock Script", ocSub,
rows.push_back({"4", "4: Run Overclock Script", ocSub,
status.overclockActive ? "ON" : "OFF",
status.overclockActive ? 1 : 0});
// 5. [0] Toggle DIAG port (qualcommonly)
// 5. [5] Toggle DIAG port (qualcommonly)
std::string diagSub = "USB " + status.usbPid +
(status.diagActive ? " (DIAG+AT+NCM)" : " (USB Net)");
rows.push_back({"0", "0: Toggle DIAG Port", diagSub,
rows.push_back({"5", "5: Toggle DIAG Port", diagSub,
status.diagActive ? "ON" : "OFF",
status.diagActive ? 1 : 0});
// 6. [Call] Edit Wi-Fi MAC (imeionly)
// 6. [6] Edit Wi-Fi MAC (imeionly)
std::string wmacSub = "wlan0: " + status.wifiMac;
rows.push_back({"Call", "Call: Edit Wi-Fi MAC", wmacSub,
rows.push_back({"6", "6: Edit Wi-Fi MAC", wmacSub,
isRfnv ? "persist" : "NV 4678", 2});
// 7. [7] Edit Bluetooth MAC (imeionly)
@@ -443,33 +443,33 @@ int engmenu_run_main(int argc, char** argv) {
auto triggerRowAction = [&](int idx) {
if (idx == 0) {
// 4: Override TTL
// 1: Override TTL
editBuf = (status.ttlOverride > 0) ? std::to_string(status.ttlOverride) : "64";
modal = EngModal::EditTtl;
} else if (idx == 1) {
// 5: Edit IMEI 1
// 2: Edit IMEI 1
modal = EngModal::ConfirmImei1;
} else if (idx == 2) {
// 6: Edit IMEI 2
// 3: Edit IMEI 2
if (!status.dsdsSupported) {
showToast("Error: single-SIM configuration");
return;
}
modal = EngModal::ConfirmImei2;
} else if (idx == 3) {
// *: Run Overclock Script
// 4: Run Overclock Script
std::string res = runEngCtlCapture({"overclock", "toggle"});
refreshStatus();
showToast(status.overclockActive ? "Overclocking until reboot"
: "Overclock disabled (schedutil)");
} else if (idx == 4) {
// 0: Toggle DIAG Port
// 5: Toggle DIAG Port
std::string res = runEngCtlCapture({"diag", "toggle"});
refreshStatus();
showToast(status.diagActive ? "Diagnostics port enabled"
: "Diagnostics port disabled");
} else if (idx == 5) {
// Call: Edit Wi-Fi MAC
// 6: Edit Wi-Fi MAC
editBuf = generateRandomMac();
lastHexKey = -1;
modal = EngModal::EditWifiMac;
@@ -1019,47 +1019,10 @@ int engmenu_run_main(int argc, char** argv) {
continue;
}
// Direct Wallace Toolbox hotkeys (4, 5, 6, *, 0, Call, 7/#)
if (sym == XF86XK_Phone || sym == XF86XK_PickupPhone ||
sym == XF86XK_Send) {
selIdx = 5;
triggerRowAction(5);
render();
continue;
}
if (dch == '4') {
selIdx = 0;
triggerRowAction(0);
render();
continue;
}
if (dch == '5') {
selIdx = 1;
triggerRowAction(1);
render();
continue;
}
if (dch == '6') {
selIdx = 2;
triggerRowAction(2);
render();
continue;
}
if (dch == '*') {
selIdx = 3;
triggerRowAction(3);
render();
continue;
}
if (dch == '0') {
selIdx = 4;
triggerRowAction(4);
render();
continue;
}
if (dch == '7' || dch == '#') {
selIdx = 6;
triggerRowAction(6);
// Direct hotkeys 1..7
if (dch >= '1' && dch <= '7') {
selIdx = dch - '1';
triggerRowAction(selIdx);
render();
continue;
}