patch from Erich Hoover: Menu support(partialy), Text fixes
This commit is contained in:
parent
f51215c370
commit
57c52d7498
6 changed files with 430 additions and 92 deletions
55
engine.cpp
55
engine.cpp
|
@ -76,6 +76,38 @@ Engine::Engine() :
|
||||||
printLineDefaults.justify = 2;
|
printLineDefaults.justify = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Engine::handleButton(int operation, int key) {
|
||||||
|
lua_beginblock();
|
||||||
|
lua_Object menu = getEventHandler("menuHandler");
|
||||||
|
if (menu != LUA_NOOBJECT && !lua_isnil(menu)) {
|
||||||
|
lua_Object system_table = lua_getglobal("system");
|
||||||
|
lua_pushobject(system_table);
|
||||||
|
lua_pushstring(const_cast<char *>("userPaintHandler"));
|
||||||
|
lua_pushobject(lua_gettable());
|
||||||
|
lua_pushnumber(key);
|
||||||
|
if (operation == SDL_KEYDOWN)
|
||||||
|
lua_pushnil();
|
||||||
|
else
|
||||||
|
lua_pushnumber(1);
|
||||||
|
lua_pushnil();
|
||||||
|
lua_callfunction(menu);
|
||||||
|
}
|
||||||
|
lua_endblock();
|
||||||
|
|
||||||
|
lua_beginblock();
|
||||||
|
lua_Object handler = getEventHandler("buttonHandler");
|
||||||
|
if (handler != LUA_NOOBJECT) {
|
||||||
|
lua_pushnumber(key);
|
||||||
|
if (operation == SDL_KEYDOWN)
|
||||||
|
lua_pushnumber(1);
|
||||||
|
else
|
||||||
|
lua_pushnil();
|
||||||
|
lua_pushnil();
|
||||||
|
lua_callfunction(handler);
|
||||||
|
}
|
||||||
|
lua_endblock();
|
||||||
|
}
|
||||||
|
|
||||||
void Engine::mainLoop() {
|
void Engine::mainLoop() {
|
||||||
_movieTime = 0;
|
_movieTime = 0;
|
||||||
_frameTime = 0;
|
_frameTime = 0;
|
||||||
|
@ -92,17 +124,8 @@ void Engine::mainLoop() {
|
||||||
// Process events
|
// Process events
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
if (event.type == SDL_KEYDOWN && _controlsEnabled[event.key.keysym.sym]) {
|
if (event.type == SDL_KEYDOWN && _controlsEnabled[event.key.keysym.sym])
|
||||||
lua_beginblock();
|
handleButton(SDL_KEYDOWN, event.key.keysym.sym);
|
||||||
lua_Object handler = getEventHandler("buttonHandler");
|
|
||||||
if (handler != LUA_NOOBJECT) {
|
|
||||||
lua_pushnumber(event.key.keysym.sym);
|
|
||||||
lua_pushnumber(1);
|
|
||||||
lua_pushnil();
|
|
||||||
lua_callfunction(handler);
|
|
||||||
}
|
|
||||||
lua_endblock();
|
|
||||||
}
|
|
||||||
if (event.type == SDL_KEYUP && _controlsEnabled[event.key.keysym.sym]) {
|
if (event.type == SDL_KEYUP && _controlsEnabled[event.key.keysym.sym]) {
|
||||||
// temporary hack for save/load request until game menu will work
|
// temporary hack for save/load request until game menu will work
|
||||||
if (event.key.keysym.sym == SDLK_F7) {
|
if (event.key.keysym.sym == SDLK_F7) {
|
||||||
|
@ -113,15 +136,7 @@ void Engine::mainLoop() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_beginblock();
|
handleButton(SDL_KEYUP, event.key.keysym.sym);
|
||||||
lua_Object handler = getEventHandler("buttonHandler");
|
|
||||||
if (handler != LUA_NOOBJECT) {
|
|
||||||
lua_pushnumber(event.key.keysym.sym);
|
|
||||||
lua_pushnil();
|
|
||||||
lua_pushnil();
|
|
||||||
lua_callfunction(handler);
|
|
||||||
}
|
|
||||||
lua_endblock();
|
|
||||||
}
|
}
|
||||||
if (event.type == SDL_QUIT) {
|
if (event.type == SDL_QUIT) {
|
||||||
lua_beginblock();
|
lua_beginblock();
|
||||||
|
|
8
engine.h
8
engine.h
|
@ -102,6 +102,9 @@ public:
|
||||||
|
|
||||||
float perSecond(float rate) const { return rate * _frameTime / 1000; }
|
float perSecond(float rate) const { return rate * _frameTime / 1000; }
|
||||||
|
|
||||||
|
void setMenuMode(int mode) { _menuMode = mode; }
|
||||||
|
int getMenuMode() { return _menuMode; }
|
||||||
|
|
||||||
void enableControl(int num) { _controlsEnabled[num] = true; }
|
void enableControl(int num) { _controlsEnabled[num] = true; }
|
||||||
void disableControl(int num) { _controlsEnabled[num] = false; }
|
void disableControl(int num) { _controlsEnabled[num] = false; }
|
||||||
|
|
||||||
|
@ -122,6 +125,7 @@ public:
|
||||||
void setSelectedActor(Actor *a) { _selectedActor = a; }
|
void setSelectedActor(Actor *a) { _selectedActor = a; }
|
||||||
Actor *selectedActor() { return _selectedActor; }
|
Actor *selectedActor() { return _selectedActor; }
|
||||||
|
|
||||||
|
// Text Object Registration
|
||||||
typedef std::list<TextObject *> TextListType;
|
typedef std::list<TextObject *> TextListType;
|
||||||
TextListType::const_iterator textsBegin() const {
|
TextListType::const_iterator textsBegin() const {
|
||||||
return _textObjects.begin();
|
return _textObjects.begin();
|
||||||
|
@ -156,8 +160,10 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void handleButton(int operation, int key);
|
||||||
|
|
||||||
Scene *_currScene;
|
Scene *_currScene;
|
||||||
int _mode;
|
int _mode, _menuMode;
|
||||||
int _speechMode;
|
int _speechMode;
|
||||||
|
|
||||||
unsigned _frameStart, _frameTime, _movieTime;
|
unsigned _frameStart, _frameTime, _movieTime;
|
||||||
|
|
389
lua.cpp
389
lua.cpp
|
@ -39,6 +39,10 @@
|
||||||
|
|
||||||
extern Imuse *g_imuse;
|
extern Imuse *g_imuse;
|
||||||
|
|
||||||
|
#define strmatch(src, dst) (strlen(src) == strlen(dst) && strcmp(src, dst) == 0)
|
||||||
|
|
||||||
|
static void stubWarning(char *funcName);
|
||||||
|
|
||||||
static inline bool isObject(int num) {
|
static inline bool isObject(int num) {
|
||||||
lua_Object param = lua_getparam(num);
|
lua_Object param = lua_getparam(num);
|
||||||
if (lua_isuserdata(param) && lua_tag(param) == MKID('STAT'))
|
if (lua_isuserdata(param) && lua_tag(param) == MKID('STAT'))
|
||||||
|
@ -108,6 +112,14 @@ static inline TextObject *check_textobject(int num) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline Bitmap *check_bitmapobject(int num) {
|
||||||
|
lua_Object param = lua_getparam(num);
|
||||||
|
if (lua_isuserdata(param) && lua_tag(param) == MKID('IMAG'))
|
||||||
|
return static_cast<Bitmap *>(lua_getuserdata(param));
|
||||||
|
luaL_argerror(num, "image object expected");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static inline int check_int(int num) {
|
static inline int check_int(int num) {
|
||||||
double val = luaL_check_number(num);
|
double val = luaL_check_number(num);
|
||||||
|
|
||||||
|
@ -290,7 +302,7 @@ static void SetSayLineDefaults() {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
key_text = lua_getstring(key);
|
key_text = lua_getstring(key);
|
||||||
if (strstr(key_text, "font"))
|
if (strmatch(key_text, "font"))
|
||||||
sayLineDefaults.font = check_font(2);
|
sayLineDefaults.font = check_font(2);
|
||||||
else
|
else
|
||||||
error("Unknown SetSayLineDefaults key %s\n", key_text);
|
error("Unknown SetSayLineDefaults key %s\n", key_text);
|
||||||
|
@ -795,6 +807,8 @@ static void SayLine() {
|
||||||
static void InputDialog() {
|
static void InputDialog() {
|
||||||
int c, i = 0;
|
int c, i = 0;
|
||||||
char buf[512];
|
char buf[512];
|
||||||
|
|
||||||
|
stubWarning("InputDialog");
|
||||||
fprintf(stderr, "%s %s: ", luaL_check_string(1), luaL_check_string(2));
|
fprintf(stderr, "%s %s: ", luaL_check_string(1), luaL_check_string(2));
|
||||||
while (i < 512 && (c = fgetc(stdin)) != EOF && c != '\n')
|
while (i < 512 && (c = fgetc(stdin)) != EOF && c != '\n')
|
||||||
buf[i++] = c;
|
buf[i++] = c;
|
||||||
|
@ -844,7 +858,7 @@ static void IsActorInSector(void) {
|
||||||
for (i = 0; i < numSectors; i++) {
|
for (i = 0; i < numSectors; i++) {
|
||||||
Sector *sector = g_engine->currScene()->getSectorBase(i);
|
Sector *sector = g_engine->currScene()->getSectorBase(i);
|
||||||
|
|
||||||
if (sector->visible() && strstr(sector->name(), name)) {
|
if (sector->visible() && strmatch(sector->name(), name)) {
|
||||||
if (sector->isPointInSector(act->pos())) {
|
if (sector->isPointInSector(act->pos())) {
|
||||||
lua_pushnumber(sector->id());
|
lua_pushnumber(sector->id());
|
||||||
lua_pushstring((char *)sector->name());
|
lua_pushstring((char *)sector->name());
|
||||||
|
@ -874,7 +888,7 @@ static void MakeSectorActive(void) {
|
||||||
|
|
||||||
for (i = 0; i < numSectors; i++) {
|
for (i = 0; i < numSectors; i++) {
|
||||||
Sector *sector = g_engine->currScene()->getSectorBase(i);
|
Sector *sector = g_engine->currScene()->getSectorBase(i);
|
||||||
if (strstr(sector->name(), name)) {
|
if (strmatch(sector->name(), name)) {
|
||||||
sector->setVisible(visible);
|
sector->setVisible(visible);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1144,11 +1158,13 @@ void PerSecond() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnableControl() {
|
void EnableControl() {
|
||||||
|
stubWarning("EnableControl");
|
||||||
int num = check_control(1);
|
int num = check_control(1);
|
||||||
g_engine->enableControl(num);
|
g_engine->enableControl(num);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisableControl() {
|
void DisableControl() {
|
||||||
|
stubWarning("DisableControl");
|
||||||
int num = check_control(1);
|
int num = check_control(1);
|
||||||
g_engine->disableControl(num);
|
g_engine->disableControl(num);
|
||||||
}
|
}
|
||||||
|
@ -1181,56 +1197,188 @@ void getTextObjectParams(TextObject *textObject, lua_Object table_obj) {
|
||||||
if (lua_isnil(key))
|
if (lua_isnil(key))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// printf("debug param: %s %s\n", lua_getstring(key), lua_getstring(lua_getresult(2)));
|
||||||
|
|
||||||
key_text = lua_getstring(key);
|
key_text = lua_getstring(key);
|
||||||
if (strstr(key_text, "x"))
|
if (strmatch(key_text, "x"))
|
||||||
textObject->setX(atoi(lua_getstring(lua_getresult(2))));
|
textObject->setX(atoi(lua_getstring(lua_getresult(2))));
|
||||||
else if (strstr(key_text, "y"))
|
else if (strmatch(key_text, "y"))
|
||||||
textObject->setY(atoi(lua_getstring(lua_getresult(2))));
|
textObject->setY(atoi(lua_getstring(lua_getresult(2))));
|
||||||
else if (strstr(key_text, "width"))
|
else if (strmatch(key_text, "width"))
|
||||||
textObject->setWidth(atoi(lua_getstring(lua_getresult(2))));
|
textObject->setWidth(atoi(lua_getstring(lua_getresult(2))));
|
||||||
else if (strstr(key_text, "height"))
|
else if (strmatch(key_text, "height"))
|
||||||
textObject->setHeight(atoi(lua_getstring(lua_getresult(2))));
|
textObject->setHeight(atoi(lua_getstring(lua_getresult(2))));
|
||||||
else if (strstr(key_text, "font"))
|
else if (strmatch(key_text, "font"))
|
||||||
textObject->setFont(check_font(2));
|
textObject->setFont(check_font(2));
|
||||||
else if (strstr(key_text, "fgcolor"))
|
else if (strmatch(key_text, "fgcolor"))
|
||||||
textObject->setFGColor(check_color(2));
|
textObject->setFGColor(check_color(2));
|
||||||
else if (strstr(key_text, "center"))
|
else if (strmatch(key_text, "disabled"))
|
||||||
|
textObject->setDisabled(atoi(lua_getstring(lua_getresult(2))) != 0);
|
||||||
|
else if (strmatch(key_text, "center"))
|
||||||
textObject->setJustify(1);
|
textObject->setJustify(1);
|
||||||
else if (strstr(key_text, "ljustify"))
|
else if (strmatch(key_text, "ljustify"))
|
||||||
textObject->setJustify(2);
|
textObject->setJustify(2);
|
||||||
else if (strstr(key_text, "disabled"))
|
else if (strmatch(key_text, "rjustify"))
|
||||||
warning("getTextObjectParams: key %s\n not implemented yet", key_text);
|
textObject->setJustify(3);
|
||||||
else
|
else
|
||||||
error("Unknown getTextObjectParams key %s\n", key_text);
|
error("Unknown getTextObjectParams key '%s'\n", key_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MakeTextObject() {
|
/* Clean the buffer of text objects
|
||||||
int x = 0, y = 0, height = 0, width = 0;
|
* this is known to be used when changing between menus
|
||||||
bool center = false, ljustify = false;
|
*/
|
||||||
Color *fgColor = NULL;
|
static void CleanBuffer() {
|
||||||
Font *font = NULL;
|
g_engine->killTextObjects();
|
||||||
|
|
||||||
char *line = lua_getstring(lua_getparam(1));
|
|
||||||
lua_Object tableObj = lua_getparam(2);
|
|
||||||
|
|
||||||
TextObject *textObject = new TextObject();
|
|
||||||
textObject->setDefaults(&textObjectDefaults);
|
|
||||||
|
|
||||||
if (lua_istable(tableObj))
|
|
||||||
getTextObjectParams(textObject, tableObj);
|
|
||||||
|
|
||||||
textObject->setText(line);
|
|
||||||
textObject->createBitmap();
|
|
||||||
g_engine->registerTextObject(textObject);
|
|
||||||
|
|
||||||
lua_pushusertag(textObject, MKID('TEXT'));
|
|
||||||
lua_pushnumber(textObject->getBitmapWidth());
|
|
||||||
lua_pushnumber(textObject->getBitmapHeight());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void mainMenuHandler() {
|
||||||
|
lua_Object menuTable = lua_getparam(1);
|
||||||
|
lua_Object keycode = lua_getparam(2);
|
||||||
|
lua_Object pushcode = lua_getparam(3);
|
||||||
|
lua_Object itemTable;
|
||||||
|
int key, operation;
|
||||||
|
int _menuItem = 1, _menuItems = 1;
|
||||||
|
|
||||||
|
stubWarning("mainMenuHandler");
|
||||||
|
if (!lua_isnumber(keycode) || !lua_istable(menuTable))
|
||||||
|
return;
|
||||||
|
if (lua_isnil(pushcode))
|
||||||
|
operation = 0;
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
|
||||||
|
// get the item list
|
||||||
|
itemTable = getTableValue(menuTable, "menu");
|
||||||
|
if (!lua_istable(itemTable))
|
||||||
|
return;
|
||||||
|
|
||||||
|
key = atoi(lua_getstring(keycode));
|
||||||
|
|
||||||
|
// get the current item
|
||||||
|
_menuItem = atoi(lua_getstring(getTableValue(itemTable, "cur_item")));
|
||||||
|
_menuItems = atoi(lua_getstring(getTableValue(itemTable, "num_items")));
|
||||||
|
|
||||||
|
/* if we're running the menu then we need to manually handle
|
||||||
|
* a lot of the operations necessary to use the menu
|
||||||
|
*/
|
||||||
|
bool menuChanged = false;
|
||||||
|
if (key == SDLK_RETURN) {
|
||||||
|
switch(_menuItem) {
|
||||||
|
case 10:
|
||||||
|
key = SDLK_r;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
key = SDLK_RETURN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(key) {
|
||||||
|
case SDLK_r:
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
{
|
||||||
|
lua_Object close = getTableFunction(menuTable, "cancel");
|
||||||
|
lua_Object destroy = getTableFunction(menuTable, "destroy");
|
||||||
|
|
||||||
|
lua_beginblock();
|
||||||
|
lua_pushobject(menuTable);
|
||||||
|
lua_callfunction(destroy);
|
||||||
|
lua_endblock();
|
||||||
|
|
||||||
|
lua_beginblock();
|
||||||
|
lua_Object is_active = lua_createtable();
|
||||||
|
lua_pushobject(is_active);
|
||||||
|
lua_pushstring("is_active");
|
||||||
|
lua_pushnumber(1);
|
||||||
|
lua_settable();
|
||||||
|
lua_pushobject(is_active);
|
||||||
|
lua_callfunction(close);
|
||||||
|
lua_endblock();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SDLK_RETURN:
|
||||||
|
{
|
||||||
|
lua_Object choose = getTableFunction(menuTable, "choose_item");
|
||||||
|
lua_beginblock();
|
||||||
|
lua_pushnumber(_menuItem);
|
||||||
|
lua_callfunction(choose);
|
||||||
|
lua_endblock();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SDLK_DOWN:
|
||||||
|
menuChanged = true;
|
||||||
|
_menuItem++;
|
||||||
|
break;
|
||||||
|
case SDLK_UP:
|
||||||
|
menuChanged = true;
|
||||||
|
_menuItem--;
|
||||||
|
break;
|
||||||
|
case SDLK_h:
|
||||||
|
menuChanged = true;
|
||||||
|
_menuItem = 1; // help
|
||||||
|
break;
|
||||||
|
case SDLK_o:
|
||||||
|
menuChanged = true;
|
||||||
|
_menuItem = 2; // options
|
||||||
|
break;
|
||||||
|
case SDLK_s:
|
||||||
|
menuChanged = true;
|
||||||
|
_menuItem = 3; // load game
|
||||||
|
break;
|
||||||
|
case SDLK_l:
|
||||||
|
menuChanged = true;
|
||||||
|
_menuItem = 4; // load game
|
||||||
|
break;
|
||||||
|
case SDLK_d:
|
||||||
|
menuChanged = true;
|
||||||
|
_menuItem = 6; // dialog transcripts
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (menuChanged) {
|
||||||
|
if (_menuItem < 1)
|
||||||
|
_menuItem = 1;
|
||||||
|
if (_menuItem > _menuItems)
|
||||||
|
_menuItem = _menuItems;
|
||||||
|
|
||||||
|
setTableValue(itemTable, "cur_item", _menuItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clean the requested menu
|
||||||
|
*/
|
||||||
|
static void CloseMenu() {
|
||||||
|
stubWarning("CloseMenu");
|
||||||
|
CleanBuffer();
|
||||||
|
lua_Object system_table = lua_getglobal("system");
|
||||||
|
setTableValue(system_table, "menuHandler", (lua_Object) 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check for an existing object by a certain name
|
||||||
|
* this function is used by several functions that look
|
||||||
|
* for text objects to see if they need to be created/modified/destroyed.
|
||||||
|
*/
|
||||||
|
TextObject *TextObjectExists(char *name) {
|
||||||
|
TextObject *modifyObject = NULL;
|
||||||
|
|
||||||
|
for (Engine::TextListType::const_iterator i = g_engine->textsBegin(); i != g_engine->textsEnd(); i++) {
|
||||||
|
TextObject *textO = *i;
|
||||||
|
if (strlen(name) == strlen(textO->name()) && strcmp(textO->name(), name) == 0) {
|
||||||
|
modifyObject = textO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return modifyObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Destroy a text object since we don't need it anymore
|
||||||
|
* note that the menu creates more objects than it needs,
|
||||||
|
* so it deletes some objects right after creating them
|
||||||
|
*/
|
||||||
static void KillTextObject() {
|
static void KillTextObject() {
|
||||||
TextObject *textObjectParm;
|
TextObject *textObjectParm, *delText;
|
||||||
|
|
||||||
if (lua_isnil(lua_getparam(1))) {
|
if (lua_isnil(lua_getparam(1))) {
|
||||||
error("KillTextObject(NULL)");
|
error("KillTextObject(NULL)");
|
||||||
|
@ -1239,21 +1387,23 @@ static void KillTextObject() {
|
||||||
|
|
||||||
textObjectParm = check_textobject(1);
|
textObjectParm = check_textobject(1);
|
||||||
|
|
||||||
for (Engine::TextListType::const_iterator i = g_engine->textsBegin(); i != g_engine->textsEnd(); i++) {
|
delText = TextObjectExists((char *) textObjectParm->name());
|
||||||
TextObject *textO = *i;
|
if (delText != NULL)
|
||||||
|
g_engine->killTextObject(delText);
|
||||||
|
}
|
||||||
|
|
||||||
if (strstr(textO->name(), textObjectParm->name())) {
|
/* Make changes to a text object based on the parameters passed
|
||||||
g_engine->killTextObject(textO);
|
* in the table in the LUA parameter 2.
|
||||||
delete textO;
|
*/
|
||||||
|
static void ChangeTextObject() {
|
||||||
|
TextObject *modifyObject, *textObject = check_textobject(1);
|
||||||
|
lua_Object tableObj = lua_getparam(2);
|
||||||
|
|
||||||
|
modifyObject = TextObjectExists((char *)textObject->name());
|
||||||
|
if (modifyObject == NULL) {
|
||||||
|
warning("ChangeTextObject(): Cannot find active text object");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ChangeTextObject() {
|
|
||||||
TextObject *textObject = check_textobject(1);
|
|
||||||
lua_Object tableObj = lua_getparam(2);
|
|
||||||
TextObject *modifyObject = NULL;
|
|
||||||
|
|
||||||
for (Engine::TextListType::const_iterator i = g_engine->textsBegin(); i != g_engine->textsEnd(); i++) {
|
for (Engine::TextListType::const_iterator i = g_engine->textsBegin(); i != g_engine->textsEnd(); i++) {
|
||||||
TextObject *textO = *i;
|
TextObject *textO = *i;
|
||||||
|
@ -1266,18 +1416,51 @@ static void ChangeTextObject() {
|
||||||
if (!modifyObject)
|
if (!modifyObject)
|
||||||
error("ChangeTextObject(): Cannot find active text object");
|
error("ChangeTextObject(): Cannot find active text object");
|
||||||
|
|
||||||
modifyObject->destroyBitmap();
|
|
||||||
|
|
||||||
// textObject->setDefaults(&textObjectDefaults);
|
|
||||||
if (lua_istable(tableObj))
|
if (lua_istable(tableObj))
|
||||||
getTextObjectParams(modifyObject, tableObj);
|
getTextObjectParams(modifyObject, tableObj);
|
||||||
|
else
|
||||||
|
warning("Expecting table parameter!");
|
||||||
|
|
||||||
|
// to modify current bitmap it need recreate it
|
||||||
|
modifyObject->destroyBitmap();
|
||||||
modifyObject->createBitmap();
|
modifyObject->createBitmap();
|
||||||
|
|
||||||
lua_pushnumber(modifyObject->getBitmapWidth());
|
lua_pushnumber(modifyObject->getBitmapWidth());
|
||||||
lua_pushnumber(modifyObject->getBitmapHeight());
|
lua_pushnumber(modifyObject->getBitmapHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Make a text object, known to be used by the menu
|
||||||
|
* please note that if the same text is issued we will
|
||||||
|
* add an additional space (TEXT_NULL) until the text
|
||||||
|
* becomes unique
|
||||||
|
* (otherwise we'll get identically named menu objects)
|
||||||
|
*/
|
||||||
|
static void MakeTextObject() {
|
||||||
|
TextObject *textObject;
|
||||||
|
char *line = lua_getstring(lua_getparam(1));
|
||||||
|
std::string text = line;
|
||||||
|
lua_Object tableObj = lua_getparam(2);
|
||||||
|
|
||||||
|
textObject = new TextObject();
|
||||||
|
textObject->setDefaults(&textObjectDefaults);
|
||||||
|
|
||||||
|
if (lua_istable(tableObj))
|
||||||
|
getTextObjectParams(textObject, tableObj);
|
||||||
|
|
||||||
|
while (TextObjectExists((char *)text.c_str()) != NULL)
|
||||||
|
text += TEXT_NULL;
|
||||||
|
|
||||||
|
//printf("Make: %s\n", (char *)text.c_str());
|
||||||
|
|
||||||
|
textObject->setText((char *)text.c_str());
|
||||||
|
textObject->createBitmap();
|
||||||
|
g_engine->registerTextObject(textObject);
|
||||||
|
|
||||||
|
lua_pushusertag(textObject, MKID('TEXT'));
|
||||||
|
lua_pushnumber(textObject->getBitmapWidth());
|
||||||
|
lua_pushnumber(textObject->getBitmapHeight());
|
||||||
|
}
|
||||||
|
|
||||||
static void GetTextObjectDimensions() {
|
static void GetTextObjectDimensions() {
|
||||||
TextObject *textObjectParam = check_textobject(1);
|
TextObject *textObjectParam = check_textobject(1);
|
||||||
lua_pushnumber(textObjectParam->getBitmapWidth());
|
lua_pushnumber(textObjectParam->getBitmapWidth());
|
||||||
|
@ -1304,6 +1487,11 @@ static void BlastText() {
|
||||||
MakeTextObject();
|
MakeTextObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void SetOffscreenTextPos() {
|
||||||
|
// this sets where we shouldn't put dialog maybe?
|
||||||
|
stubWarning("SetOffscreenTextPos");
|
||||||
|
}
|
||||||
|
|
||||||
static void SetSpeechMode() {
|
static void SetSpeechMode() {
|
||||||
int mode = check_int(1);
|
int mode = check_int(1);
|
||||||
if ((mode >= 1) && (mode <= 3))
|
if ((mode >= 1) && (mode <= 3))
|
||||||
|
@ -1459,6 +1647,42 @@ static void SetAmbientLight() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void RenderModeUser() {
|
||||||
|
stubWarning("RenderModeUser");
|
||||||
|
// it enable/disable updating display
|
||||||
|
lua_Object param1 = lua_getparam(1);
|
||||||
|
bool mode;
|
||||||
|
if (lua_isnumber(param1)) {
|
||||||
|
mode = check_int(1) != 0;
|
||||||
|
} else if (lua_isnil(param1)) {
|
||||||
|
mode = false;
|
||||||
|
} else {
|
||||||
|
error("RenderModeUser() Unknown type of param");
|
||||||
|
}
|
||||||
|
g_engine->setMenuMode(mode);
|
||||||
|
if (mode)
|
||||||
|
printf("RenderModeUser() Enable\n");
|
||||||
|
else
|
||||||
|
printf("RenderModeUser() Disable\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Display() {
|
||||||
|
stubWarning("Display");
|
||||||
|
lua_Object system_table = lua_getglobal("system");
|
||||||
|
// Install Menu Close Handler
|
||||||
|
lua_pushobject(system_table);
|
||||||
|
lua_pushstring(const_cast<char *>("userPaintHandler"));
|
||||||
|
lua_pushobject(lua_gettable());
|
||||||
|
lua_pushstring(const_cast<char *>("destroy"));
|
||||||
|
lua_pushcfunction(CloseMenu);
|
||||||
|
lua_settable();
|
||||||
|
// Install Menu Key Handler
|
||||||
|
lua_pushobject(system_table);
|
||||||
|
lua_pushstring(const_cast<char *>("menuHandler"));
|
||||||
|
lua_pushcfunction(mainMenuHandler);
|
||||||
|
lua_settable();
|
||||||
|
}
|
||||||
|
|
||||||
static void EngineDisplay() {
|
static void EngineDisplay() {
|
||||||
// it enable/disable updating display
|
// it enable/disable updating display
|
||||||
lua_Object param1 = lua_getparam(1);
|
lua_Object param1 = lua_getparam(1);
|
||||||
|
@ -1470,6 +1694,7 @@ static void EngineDisplay() {
|
||||||
} else {
|
} else {
|
||||||
error("EngineDisplay() Unknown type of param");
|
error("EngineDisplay() Unknown type of param");
|
||||||
}
|
}
|
||||||
|
g_engine->setMenuMode(!mode);
|
||||||
if (mode)
|
if (mode)
|
||||||
printf("EngineDisplay() Enable\n");
|
printf("EngineDisplay() Enable\n");
|
||||||
else
|
else
|
||||||
|
@ -1556,12 +1781,9 @@ STUB_FUNC(SetActorShadowPoint)
|
||||||
STUB_FUNC(SetActorShadowPlane)
|
STUB_FUNC(SetActorShadowPlane)
|
||||||
STUB_FUNC(ActivateActorShadow)
|
STUB_FUNC(ActivateActorShadow)
|
||||||
STUB_FUNC(SetShadowColor)
|
STUB_FUNC(SetShadowColor)
|
||||||
STUB_FUNC(Display)
|
|
||||||
STUB_FUNC(CleanBuffer)
|
|
||||||
STUB_FUNC(DimRegion)
|
STUB_FUNC(DimRegion)
|
||||||
STUB_FUNC(DimScreen)
|
STUB_FUNC(DimScreen)
|
||||||
STUB_FUNC(ForceRefresh)
|
STUB_FUNC(ForceRefresh)
|
||||||
STUB_FUNC(RenderModeUser)
|
|
||||||
STUB_FUNC(SetGamma)
|
STUB_FUNC(SetGamma)
|
||||||
STUB_FUNC(LightMgrStartup)
|
STUB_FUNC(LightMgrStartup)
|
||||||
STUB_FUNC(SetLightIntensity)
|
STUB_FUNC(SetLightIntensity)
|
||||||
|
@ -1604,7 +1826,6 @@ STUB_FUNC(SetActorTimeScale)
|
||||||
STUB_FUNC(GetActorTimeScale)
|
STUB_FUNC(GetActorTimeScale)
|
||||||
STUB_FUNC(SetActorScale)
|
STUB_FUNC(SetActorScale)
|
||||||
STUB_FUNC(SetActorColormap)
|
STUB_FUNC(SetActorColormap)
|
||||||
STUB_FUNC(SetOffscreenTextPos)
|
|
||||||
STUB_FUNC(SetEmergencyFont)
|
STUB_FUNC(SetEmergencyFont)
|
||||||
STUB_FUNC(GetTranslationMode)
|
STUB_FUNC(GetTranslationMode)
|
||||||
STUB_FUNC(SetTranslationMode)
|
STUB_FUNC(SetTranslationMode)
|
||||||
|
@ -2334,9 +2555,8 @@ int bundle_dofile(const char *filename) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_Object getEventHandler(const char *name) {
|
lua_Object getTableFunction(lua_Object table, char *name) {
|
||||||
lua_Object system_table = lua_getglobal("system");
|
lua_pushobject(table);
|
||||||
lua_pushobject(system_table);
|
|
||||||
lua_pushstring(const_cast<char *>(name));
|
lua_pushstring(const_cast<char *>(name));
|
||||||
lua_Object handler = lua_gettable();
|
lua_Object handler = lua_gettable();
|
||||||
|
|
||||||
|
@ -2359,3 +2579,54 @@ lua_Object getEventHandler(const char *name) {
|
||||||
|
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lua_Object getTableValue(lua_Object table, char *name) {
|
||||||
|
char *key_text = NULL;
|
||||||
|
lua_Object key;
|
||||||
|
|
||||||
|
if (!lua_istable(table)) {
|
||||||
|
error("getTableValue(): Parameter not a table!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
lua_pushobject(table);
|
||||||
|
if (key_text)
|
||||||
|
lua_pushobject(key);
|
||||||
|
else
|
||||||
|
lua_pushnil();
|
||||||
|
|
||||||
|
lua_call("next");
|
||||||
|
key = lua_getresult(1);
|
||||||
|
if (lua_isnil(key))
|
||||||
|
break;
|
||||||
|
|
||||||
|
key_text = lua_getstring(key);
|
||||||
|
if (strmatch(key_text, name))
|
||||||
|
return lua_getresult(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTableValue(lua_Object table, char *name, int newvalue) {
|
||||||
|
lua_pushobject(table);
|
||||||
|
lua_pushstring(name);
|
||||||
|
lua_pushnumber(newvalue);
|
||||||
|
lua_settable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTableValue(lua_Object table, char *name, lua_Object newvalue) {
|
||||||
|
lua_pushobject(table);
|
||||||
|
lua_pushstring(name);
|
||||||
|
if (newvalue == 0)
|
||||||
|
lua_pushnil();
|
||||||
|
else
|
||||||
|
lua_pushobject(newvalue);
|
||||||
|
lua_settable();
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_Object getEventHandler(const char *name) {
|
||||||
|
lua_Object system_table = lua_getglobal("system");
|
||||||
|
return getTableFunction(system_table, (char *)name);
|
||||||
|
}
|
||||||
|
|
10
lua.h
10
lua.h
|
@ -39,4 +39,14 @@ void setMovieTime(float movieTime);
|
||||||
// object if appropriate
|
// object if appropriate
|
||||||
lua_Object getEventHandler(const char *name);
|
lua_Object getEventHandler(const char *name);
|
||||||
|
|
||||||
|
// set the value for a table item
|
||||||
|
void setTableValue(lua_Object table, char *name, int newvalue);
|
||||||
|
void setTableValue(lua_Object table, char *name, lua_Object newvalue);
|
||||||
|
|
||||||
|
// get the value of a table item
|
||||||
|
lua_Object getTableValue(lua_Object table, char *name);
|
||||||
|
|
||||||
|
// get a function stored in a table
|
||||||
|
lua_Object getTableFunction(lua_Object table, char *name);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -28,15 +28,27 @@ TextObjectDefaults printLineDefaults;
|
||||||
TextObjectDefaults textObjectDefaults;
|
TextObjectDefaults textObjectDefaults;
|
||||||
|
|
||||||
TextObject::TextObject() :
|
TextObject::TextObject() :
|
||||||
_created(false), _dim(false), _x(0), _y(0), _width(0), _height(0), _justify(0),
|
_created(false), _x(0), _y(0), _width(0), _height(0), _justify(0),
|
||||||
_font(NULL), _textBitmap(NULL), _bitmapWidth(0),
|
_font(NULL), _textBitmap(NULL), _bitmapWidth(0),
|
||||||
_bitmapHeight(0), _textObjectHandle(NULL) {
|
_bitmapHeight(0), _textObjectHandle(NULL), _disabled(0) {
|
||||||
memset(_textID, 0, sizeof(_textID));
|
memset(_textID, 0, sizeof(_textID));
|
||||||
_fgColor._vals[0] = 0;
|
_fgColor._vals[0] = 0;
|
||||||
_fgColor._vals[1] = 0;
|
_fgColor._vals[1] = 0;
|
||||||
_fgColor._vals[2] = 0;
|
_fgColor._vals[2] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextObject::setText(char *text) {
|
||||||
|
if (strlen(text) < sizeof(_textID))
|
||||||
|
strcpy(_textID, text);
|
||||||
|
else {
|
||||||
|
error("Text ID exceeded maximum length (%d): %s\n", sizeof(_textID), text);
|
||||||
|
// this should be good enough to still be unique
|
||||||
|
// but for debug purposes lets make this crash the program so we know about it
|
||||||
|
strncpy(_textID, text, sizeof(_textID));
|
||||||
|
_textID[sizeof(_textID)] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TextObject::~TextObject() {
|
TextObject::~TextObject() {
|
||||||
destroyBitmap();
|
destroyBitmap();
|
||||||
}
|
}
|
||||||
|
@ -49,6 +61,7 @@ void TextObject::setDefaults(TextObjectDefaults *defaults) {
|
||||||
_font = defaults->font;
|
_font = defaults->font;
|
||||||
_fgColor = defaults->fgColor;
|
_fgColor = defaults->fgColor;
|
||||||
_justify = defaults->justify;
|
_justify = defaults->justify;
|
||||||
|
_disabled = defaults->disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TextObject::getTextCharPosition(int pos) {
|
int TextObject::getTextCharPosition(int pos) {
|
||||||
|
@ -66,10 +79,17 @@ void TextObject::createBitmap() {
|
||||||
destroyBitmap();
|
destroyBitmap();
|
||||||
|
|
||||||
std::string msg = parseMsgText(_textID, NULL);
|
std::string msg = parseMsgText(_textID, NULL);
|
||||||
|
char *c = (char *)msg.c_str();
|
||||||
|
|
||||||
_bitmapWidth = 0;
|
_bitmapWidth = 0;
|
||||||
_bitmapHeight = 0;
|
_bitmapHeight = 0;
|
||||||
|
|
||||||
|
// remove spaces (NULL_TEXT) from the end of the string,
|
||||||
|
// while this helps make the string unique it screws up
|
||||||
|
// text justification
|
||||||
|
for(int i = (int) msg.length() - 1; c[i] == TEXT_NULL; i--)
|
||||||
|
msg.erase(msg.length() - 1, msg.length());
|
||||||
|
|
||||||
for (int i = 0; msg[i] != '\0'; ++i) {
|
for (int i = 0; msg[i] != '\0'; ++i) {
|
||||||
_bitmapWidth += _font->getCharLogicalWidth(msg[i]) + _font->getCharStartingCol(msg[i]);
|
_bitmapWidth += _font->getCharLogicalWidth(msg[i]) + _font->getCharStartingCol(msg[i]);
|
||||||
|
|
||||||
|
@ -108,20 +128,32 @@ void TextObject::createBitmap() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextObject::destroyBitmap() {
|
void TextObject::destroyBitmap() {
|
||||||
|
_created = false;
|
||||||
if (_textObjectHandle) {
|
if (_textObjectHandle) {
|
||||||
g_driver->destroyTextBitmap(_textObjectHandle);
|
g_driver->destroyTextBitmap(_textObjectHandle);
|
||||||
delete _textObjectHandle;
|
delete _textObjectHandle;
|
||||||
_textObjectHandle = NULL;
|
_textObjectHandle = NULL;
|
||||||
}
|
}
|
||||||
_created = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextObject::draw() {
|
void TextObject::draw() {
|
||||||
int x = _x;
|
if (!_created)
|
||||||
|
return;
|
||||||
|
|
||||||
if (_justify == 1) {
|
if (_justify == LJUSTIFY || _justify == NONE)
|
||||||
x = 320 - (_bitmapWidth / 2);
|
g_driver->drawTextBitmap(_x, _y, _textObjectHandle);
|
||||||
}
|
else if (_justify == CENTER) {
|
||||||
|
int x = _x - (1 / 2.0) * _bitmapWidth;
|
||||||
|
if (x < 0)
|
||||||
|
x = 0;
|
||||||
|
|
||||||
g_driver->drawTextBitmap(x, _y, _textObjectHandle);
|
g_driver->drawTextBitmap(x, _y, _textObjectHandle);
|
||||||
|
} else if (_justify == RJUSTIFY) {
|
||||||
|
int x = _x - _bitmapWidth;
|
||||||
|
if (x < 0)
|
||||||
|
x = 0;
|
||||||
|
|
||||||
|
g_driver->drawTextBitmap(x, _y, _textObjectHandle);
|
||||||
|
} else
|
||||||
|
warning("TextObject::draw: Unknown justification code (%d)!", _justify);
|
||||||
}
|
}
|
||||||
|
|
12
textobject.h
12
textobject.h
|
@ -31,9 +31,12 @@ struct TextObjectDefaults {
|
||||||
int x, y;
|
int x, y;
|
||||||
int width, height;
|
int width, height;
|
||||||
int justify;
|
int justify;
|
||||||
|
bool disabled;
|
||||||
Font *font;
|
Font *font;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define TEXT_NULL ' '
|
||||||
|
|
||||||
extern TextObjectDefaults sayLineDefaults;
|
extern TextObjectDefaults sayLineDefaults;
|
||||||
extern TextObjectDefaults printLineDefaults;
|
extern TextObjectDefaults printLineDefaults;
|
||||||
extern TextObjectDefaults textObjectDefaults;
|
extern TextObjectDefaults textObjectDefaults;
|
||||||
|
@ -45,7 +48,7 @@ public:
|
||||||
void createBitmap();
|
void createBitmap();
|
||||||
void destroyBitmap();
|
void destroyBitmap();
|
||||||
void setDefaults(TextObjectDefaults *defaults);
|
void setDefaults(TextObjectDefaults *defaults);
|
||||||
void setText(char *text) { strcpy(_textID, text); }
|
void setText(char *text);
|
||||||
void setX(int x) { _x = x; }
|
void setX(int x) { _x = x; }
|
||||||
void setY(int y) { _y = y; }
|
void setY(int y) { _y = y; }
|
||||||
void setWidth(int width) { _width = width; }
|
void setWidth(int width) { _width = width; }
|
||||||
|
@ -53,7 +56,7 @@ public:
|
||||||
void setFGColor(Color *fgColor) { _fgColor = fgColor; }
|
void setFGColor(Color *fgColor) { _fgColor = fgColor; }
|
||||||
void setFont(Font *font) { _font = font; }
|
void setFont(Font *font) { _font = font; }
|
||||||
void setJustify(int justify) { _justify = justify; }
|
void setJustify(int justify) { _justify = justify; }
|
||||||
void setDim() { _dim = true; }
|
void setDisabled(bool disabled) { _disabled = disabled; }
|
||||||
int getBitmapWidth() { return _bitmapWidth; }
|
int getBitmapWidth() { return _bitmapWidth; }
|
||||||
int getBitmapHeight() { return _bitmapHeight; }
|
int getBitmapHeight() { return _bitmapHeight; }
|
||||||
int getTextCharPosition(int pos);
|
int getTextCharPosition(int pos);
|
||||||
|
@ -64,16 +67,17 @@ public:
|
||||||
enum Justify {
|
enum Justify {
|
||||||
NONE,
|
NONE,
|
||||||
CENTER,
|
CENTER,
|
||||||
LJUSTIFY
|
LJUSTIFY,
|
||||||
|
RJUSTIFY
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool _created;
|
bool _created;
|
||||||
bool _dim;
|
|
||||||
Color _fgColor;
|
Color _fgColor;
|
||||||
int _x, _y;
|
int _x, _y;
|
||||||
uint _width, _height;
|
uint _width, _height;
|
||||||
int _justify;
|
int _justify;
|
||||||
|
bool _disabled;
|
||||||
Font *_font;
|
Font *_font;
|
||||||
char _textID[32];
|
char _textID[32];
|
||||||
uint8 *_textBitmap;
|
uint8 *_textBitmap;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue