latest code update
- app icon - starting with map view - code cleanup Signed-off-by: Peter Siegmund <mars3142@noreply.mars3142.dev>
This commit is contained in:
@@ -1,14 +1,19 @@
|
||||
#include "lua/wherigo.h"
|
||||
#include "app.h"
|
||||
#include "lua/game_engine.h"
|
||||
#include "lua/zobject.h"
|
||||
#include "lua/ztimer.h"
|
||||
#include "ui/wherigo_dialog.h"
|
||||
|
||||
extern "C" {
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include <lua.h>
|
||||
}
|
||||
|
||||
#include <wx/dir.h>
|
||||
#include <wx/filename.h>
|
||||
#include <wx/log.h>
|
||||
#include <wx/stdpaths.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
@@ -17,6 +22,63 @@ extern "C" {
|
||||
|
||||
namespace wherigo {
|
||||
|
||||
std::string getCompletionCode(lua_State *L) {
|
||||
lua_getglobal(L, "Player");
|
||||
if (!lua_istable(L, -1)) {
|
||||
lua_pop(L, 1);
|
||||
return "";
|
||||
}
|
||||
|
||||
lua_getfield(L, -1, "CompletionCode");
|
||||
std::string completionCode;
|
||||
if (lua_isstring(L, -1)) {
|
||||
completionCode = lua_tostring(L, -1);
|
||||
if (completionCode.length() > 15) {
|
||||
completionCode = completionCode.substr(0, 15);
|
||||
}
|
||||
}
|
||||
lua_pop(L, 2);
|
||||
|
||||
return completionCode;
|
||||
}
|
||||
|
||||
// Wherigo.RequestSync()
|
||||
static int wherigo_RequestSync(lua_State *L) {
|
||||
// RequestSync shows the completion code from the cartridge in a MessageBox
|
||||
wxLogDebug(
|
||||
"Wherigo.RequestSync() called - showing completion code from cartridge");
|
||||
|
||||
auto completionCode = getCompletionCode(L);
|
||||
if (completionCode.empty()) {
|
||||
wxApp *app = wxTheApp;
|
||||
if (!app) {
|
||||
wxLogWarning("Cannot sync: no app instance");
|
||||
return 0;
|
||||
}
|
||||
|
||||
cApp *wherigApp = dynamic_cast<cApp *>(app);
|
||||
if (!wherigApp || !wherigApp->isCartridgeLoaded()) {
|
||||
wxLogWarning("Cannot sync: no cartridge loaded");
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto cartridge = wherigApp->getCartridge();
|
||||
|
||||
completionCode = cartridge->completionCode().substr(0, 15);
|
||||
}
|
||||
|
||||
wxString message =
|
||||
wxString::Format("Completion Code:\n\n%s\n\nEnter this code on "
|
||||
"wherigo.com to verify your completion.",
|
||||
completionCode.c_str());
|
||||
|
||||
std::vector<wxString> buttons = {"OK"};
|
||||
wherigo::WherigoMessageDialog dlg(nullptr, message, "Wherigo Completion",
|
||||
buttons);
|
||||
dlg.ShowModal();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Wherigo.ZonePoint(lat, lng, alt)
|
||||
static int wherigo_ZonePoint(lua_State *L) {
|
||||
@@ -131,7 +193,6 @@ static int wherigo_ZTask(lua_State *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// Wherigo.ZTimer(cartridge)
|
||||
static int wherigo_ZTimer(lua_State *L) {
|
||||
lua_newtable(L);
|
||||
@@ -190,9 +251,7 @@ static int wherigo_ZMedia(lua_State *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void resetMediaCounter() {
|
||||
s_mediaCounter = 0;
|
||||
}
|
||||
void resetMediaCounter() { s_mediaCounter = 0; }
|
||||
|
||||
// Wherigo.ZCartridge()
|
||||
static int wherigo_ZCartridge(lua_State *L) {
|
||||
@@ -204,6 +263,9 @@ static int wherigo_ZCartridge(lua_State *L) {
|
||||
lua_newtable(L);
|
||||
lua_setfield(L, -2, "AllZObjects");
|
||||
|
||||
lua_pushcfunction(L, wherigo_RequestSync);
|
||||
lua_setfield(L, -2, "RequestSync");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -238,7 +300,8 @@ static int wherigo_Player(lua_State *L) {
|
||||
|
||||
// Wherigo.MessageBox(table)
|
||||
static int wherigo_MessageBox(lua_State *L) {
|
||||
if (!lua_istable(L, 1)) return 0;
|
||||
if (!lua_istable(L, 1))
|
||||
return 0;
|
||||
|
||||
// Get Text
|
||||
lua_getfield(L, 1, "Text");
|
||||
@@ -273,7 +336,8 @@ static int wherigo_MessageBox(lua_State *L) {
|
||||
wxLogDebug("MessageBox: %s", text);
|
||||
|
||||
// Show dialog
|
||||
WherigoMessageDialog dlg(nullptr, wxString::FromUTF8(text), "Wherigo", buttons);
|
||||
WherigoMessageDialog dlg(nullptr, wxString::FromUTF8(text), "Wherigo",
|
||||
buttons);
|
||||
dlg.ShowModal();
|
||||
int selected = dlg.getSelectedButton();
|
||||
|
||||
@@ -294,12 +358,17 @@ static int wherigo_MessageBox(lua_State *L) {
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, callbackRef);
|
||||
}
|
||||
|
||||
// Notify game state change after MessageBox
|
||||
// This ensures UI updates if state was modified during the MessageBox
|
||||
GameEngine::getInstance().notifyStateChanged();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Wherigo.Dialog(table)
|
||||
static int wherigo_Dialog(lua_State *L) {
|
||||
if (!lua_istable(L, 1)) return 0;
|
||||
if (!lua_istable(L, 1))
|
||||
return 0;
|
||||
|
||||
std::vector<DialogEntry> entries;
|
||||
int n = lua_objlen(L, 1);
|
||||
@@ -341,7 +410,7 @@ static int wherigo_Dialog(lua_State *L) {
|
||||
}
|
||||
|
||||
wxLogDebug("Dialog with %zu entries", entries.size());
|
||||
for (const auto& entry : entries) {
|
||||
for (const auto &entry : entries) {
|
||||
wxLogDebug(" Text: %s, Media: %s", entry.text.c_str(),
|
||||
entry.mediaName.empty() ? "(none)" : entry.mediaName.c_str());
|
||||
}
|
||||
@@ -378,6 +447,45 @@ static int wherigo_PlayAudio(lua_State *L) {
|
||||
static int wherigo_ShowScreen(lua_State *L) {
|
||||
int screen = luaL_optinteger(L, 1, 0);
|
||||
wxLogDebug("ShowScreen: %d", screen);
|
||||
|
||||
// Show details dialog for DETAILSCREEN
|
||||
if (screen == 5 && lua_gettop(L) >= 2 && lua_istable(L, 2)) {
|
||||
// Get Name
|
||||
lua_getfield(L, 2, "Name");
|
||||
std::string name = lua_isstring(L, -1) ? lua_tostring(L, -1) : "Details";
|
||||
lua_pop(L, 1);
|
||||
// Get Description
|
||||
lua_getfield(L, 2, "Description");
|
||||
std::string desc = lua_isstring(L, -1) ? lua_tostring(L, -1) : "";
|
||||
lua_pop(L, 1);
|
||||
// Get Media name (prefer Media, fallback to Icon)
|
||||
std::string mediaName;
|
||||
lua_getfield(L, 2, "Media");
|
||||
if (lua_istable(L, -1)) {
|
||||
lua_getfield(L, -1, "Name");
|
||||
if (lua_isstring(L, -1)) {
|
||||
mediaName = lua_tostring(L, -1);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
if (mediaName.empty()) {
|
||||
lua_getfield(L, 2, "Icon");
|
||||
if (lua_istable(L, -1)) {
|
||||
lua_getfield(L, -1, "Name");
|
||||
if (lua_isstring(L, -1)) {
|
||||
mediaName = lua_tostring(L, -1);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
// Show dialog with media if available
|
||||
std::vector<wxString> buttons = {"OK"};
|
||||
wherigo::WherigoMessageDialog dlg(nullptr, wxString::FromUTF8(desc.c_str()), wxString::FromUTF8(name.c_str()), buttons, wxString::FromUTF8(mediaName.c_str()));
|
||||
dlg.ShowModal();
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -443,30 +551,30 @@ static int wherigo_VectorToSegment(lua_State *L) {
|
||||
}
|
||||
|
||||
static const luaL_Reg wherigo_funcs[] = {
|
||||
{"ZonePoint", wherigo_ZonePoint},
|
||||
{"Distance", wherigo_Distance},
|
||||
{"Zone", wherigo_Zone},
|
||||
{"ZCharacter", wherigo_ZCharacter},
|
||||
{"ZItem", wherigo_ZItem},
|
||||
{"ZTask", wherigo_ZTask},
|
||||
{"ZTimer", wherigo_ZTimer},
|
||||
{"ZInput", wherigo_ZInput},
|
||||
{"ZMedia", wherigo_ZMedia},
|
||||
{"ZCartridge", wherigo_ZCartridge},
|
||||
{"ZCommand", wherigo_ZCommand},
|
||||
{"MessageBox", wherigo_MessageBox},
|
||||
{"Dialog", wherigo_Dialog},
|
||||
{"GetInput", wherigo_GetInput},
|
||||
{"PlayAudio", wherigo_PlayAudio},
|
||||
{"ShowScreen", wherigo_ShowScreen},
|
||||
{"LogMessage", wherigo_LogMessage},
|
||||
{"NoCaseEquals", wherigo_NoCaseEquals},
|
||||
{"TranslatePoint", wherigo_TranslatePoint},
|
||||
{"VectorToZone", wherigo_VectorToZone},
|
||||
{"VectorToPoint", wherigo_VectorToPoint},
|
||||
{"VectorToSegment", wherigo_VectorToSegment},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
{"ZonePoint", wherigo_ZonePoint},
|
||||
{"Distance", wherigo_Distance},
|
||||
{"Zone", wherigo_Zone},
|
||||
{"ZCharacter", wherigo_ZCharacter},
|
||||
{"ZItem", wherigo_ZItem},
|
||||
{"ZTask", wherigo_ZTask},
|
||||
{"ZTimer", wherigo_ZTimer},
|
||||
{"ZInput", wherigo_ZInput},
|
||||
{"ZMedia", wherigo_ZMedia},
|
||||
{"ZCartridge", wherigo_ZCartridge},
|
||||
{"ZCommand", wherigo_ZCommand},
|
||||
{"MessageBox", wherigo_MessageBox},
|
||||
{"Dialog", wherigo_Dialog},
|
||||
{"GetInput", wherigo_GetInput},
|
||||
{"PlayAudio", wherigo_PlayAudio},
|
||||
{"ShowScreen", wherigo_ShowScreen},
|
||||
{"LogMessage", wherigo_LogMessage},
|
||||
{"NoCaseEquals", wherigo_NoCaseEquals},
|
||||
{"TranslatePoint", wherigo_TranslatePoint},
|
||||
{"VectorToZone", wherigo_VectorToZone},
|
||||
{"VectorToPoint", wherigo_VectorToPoint},
|
||||
{"VectorToSegment", wherigo_VectorToSegment},
|
||||
{"RequestSync", wherigo_RequestSync},
|
||||
{nullptr, nullptr}};
|
||||
|
||||
int luaopen_Wherigo(lua_State *L) {
|
||||
luaL_register(L, "Wherigo", wherigo_funcs);
|
||||
@@ -509,4 +617,3 @@ int luaopen_Wherigo(lua_State *L) {
|
||||
}
|
||||
|
||||
} // namespace wherigo
|
||||
|
||||
|
||||
Reference in New Issue
Block a user