diff --git a/game/engines/default/engine/Entity.lua b/game/engines/default/engine/Entity.lua index ca0bf1223be89b7c1bc49bed23216ce5884e2218..ba31e8feeae434459d0ec2aa3cf91b384c557be1 100644 --- a/game/engines/default/engine/Entity.lua +++ b/game/engines/default/engine/Entity.lua @@ -411,7 +411,8 @@ end -- @param y where to display -- @param w the width -- @param h the height -function _M:toScreen(tiles, x, y, w, h) +-- @param a the alpha setting, defaults to 1 +function _M:toScreen(tiles, x, y, w, h, a) local Map = require "engine.Map" tiles = tiles or Map.tiles @@ -421,7 +422,7 @@ function _M:toScreen(tiles, x, y, w, h) for i = 1, Map.zdepth do if mos[i] then list[#list+1] = mos[i] end end - core.map.mapObjectsToScreen(x, y, w, h, unpack(list)) + core.map.mapObjectsToScreen(x, y, w, h, a, unpack(list)) end --- Resolves an entity diff --git a/game/engines/default/engine/LogDisplay.lua b/game/engines/default/engine/LogDisplay.lua index acfd4f4444a6b12f39e692eea149c8824443fa42..a5e187cdc41e245cd831aa4f8ba5063339705ddc 100644 --- a/game/engines/default/engine/LogDisplay.lua +++ b/game/engines/default/engine/LogDisplay.lua @@ -150,7 +150,7 @@ function _M:display() if self.cache[tstr] then gen = self.cache[tstr] else - gen = self.font:draw(tstr, self.w, 255, 255, 255) + gen = self.font:draw(tstr, self.w, 255, 255, 255, false, true) self.cache[tstr] = gen end for i = #gen, 1, -1 do @@ -185,6 +185,7 @@ function _M:toScreen() if self.shadow then item._tex:toScreenFull(self.display_x+2, h+2, item.w, item.h, item._tex_w, item._tex_h, 0,0,0, self.shadow * fade) end item._tex:toScreenFull(self.display_x, h, item.w, item.h, item._tex_w, item._tex_h, 1, 1, 1, fade) + for di = 1, #item._dduids do item._dduids[di].e:toScreen(nil, self.display_x + item._dduids[di].x, h, item._dduids[di].w, item._dduids[di].w, fade) end h = h - self.fh end diff --git a/game/engines/default/engine/utils.lua b/game/engines/default/engine/utils.lua index 7f4b09e88af4fb5f3a8bdd7b442bb0c873b079a7..0009a7dbe986f5224ea35390542c5afbabfc853d 100644 --- a/game/engines/default/engine/utils.lua +++ b/game/engines/default/engine/utils.lua @@ -361,6 +361,15 @@ function __get_uid_surface(uid, w, h) return nil end +function __get_uid_entity(uid) + uid = tonumber(uid) + local e = uid and __uids[uid] + if e and game.level then + return e + end + return nil +end + local tmps = core.display.newSurface(1, 1) getmetatable(tmps).__index.drawColorString = function(s, font, str, x, y, r, g, b, alpha_from_texture, limit_w) local list = str:split("#" * (Puid + Pcolorcodefull + Pcolorname + Pfontstyle + Pextra) * "#", true) diff --git a/game/modules/tome/class/uiset/Minimalist.lua b/game/modules/tome/class/uiset/Minimalist.lua index 2bb79b7e9c9ebdd03a0e04165ff7fc022d530334..18cddeb3168dd7250f8570c0011ffe8508a70fa3 100644 --- a/game/modules/tome/class/uiset/Minimalist.lua +++ b/game/modules/tome/class/uiset/Minimalist.lua @@ -1542,9 +1542,9 @@ function _M:display(nb_keyframes) d.glTranslate(-self.places.gamelog.x, -self.places.gamelog.y, -0) -- Chat log - d.glTranslate(self.places.chatlog.x, self.places.chatlog.y, 0) - self:displayChatLog(1, self.places.chatlog.x, self.places.chatlog.y) - d.glTranslate(-self.places.chatlog.x, -self.places.chatlog.y, -0) +-- d.glTranslate(self.places.chatlog.x, self.places.chatlog.y, 0) +-- self:displayChatLog(1, self.places.chatlog.x, self.places.chatlog.y) +-- d.glTranslate(-self.places.chatlog.x, -self.places.chatlog.y, -0) -- Toolbar if game.show_npc_list then self.npcs_display:toScreen() else self.hotkeys_display:toScreen() end diff --git a/src/core_lua.c b/src/core_lua.c index 6fcd08f5f2ce5bc04cad5fdc2cdbd258777f4f42..05a47fdbd7bac17a15a1411b8db5ea1a6a72af08 100644 --- a/src/core_lua.c +++ b/src/core_lua.c @@ -543,9 +543,20 @@ static int sdl_surface_drawstring_newsurface_aa(lua_State *L) return 1; } -static font_make_texture_line(lua_State *L, SDL_Surface *s, int id, bool is_separator, int id_real_line, char *line_data, int line_data_size) +static font_make_texture_line(lua_State *L, SDL_Surface *s, int id, bool is_separator, int id_real_line, char *line_data, int line_data_size, bool direct_uid_draw) { - lua_createtable(L, 0, 5); + lua_createtable(L, 0, 9); + + if (direct_uid_draw) + { + lua_pushliteral(L, "_dduids"); + lua_pushvalue(L, -4); + lua_rawset(L, -3); + + // Replace dduids by a new one + lua_newtable(L); + lua_replace(L, -4); + } lua_pushliteral(L, "_tex"); GLuint *t = (GLuint*)lua_newuserdata(L, sizeof(GLuint)); @@ -603,6 +614,7 @@ static int sdl_font_draw(lua_State *L) int g = luaL_checknumber(L, 5); int b = luaL_checknumber(L, 6); bool no_linefeed = lua_toboolean(L, 7); + bool direct_uid_draw = lua_toboolean(L, 8); int h = TTF_FontLineSkip(*f); SDL_Color color = {r,g,b}; @@ -619,6 +631,12 @@ static int sdl_font_draw(lua_State *L) SDL_Surface *s = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, max_width, h, 32, rmask, gmask, bmask, amask); SDL_FillRect(s, NULL, SDL_MapRGBA(s->format, 0, 0, 0, 0)); + int id_dduid = 1; + if (direct_uid_draw) + { + lua_newtable(L); + } + lua_newtable(L); int nb_lines = 1; @@ -656,7 +674,7 @@ static int sdl_font_draw(lua_State *L) if (!no_linefeed && (force_nl || (txt && (size + txt->w > max_width)))) { // Push it & reset the surface - font_make_texture_line(L, s, nb_lines, is_separator, id_real_line, line_data, line_data_size); + font_make_texture_line(L, s, nb_lines, is_separator, id_real_line, line_data, line_data_size, direct_uid_draw); is_separator = FALSE; SDL_FillRect(s, NULL, SDL_MapRGBA(s->format, 0, 0, 0, 0)); // printf("Ending previous line at size %d\n", size); @@ -702,21 +720,54 @@ static int sdl_font_draw(lua_State *L) } // Entity UID else if ((codestop - (next+1) > 4) && (*(next+1) == 'U') && (*(next+2) == 'I') && (*(next+3) == 'D') && (*(next+4) == ':')) { - lua_getglobal(L, "__get_uid_surface"); - char *colon = next + 5; - while (*colon && *colon != ':') colon++; - lua_pushlstring(L, next+5, colon - (next+5)); -// printf("Drawing UID %s\n", lua_tostring(L,-1)); - lua_pushnumber(L, h); - lua_pushnumber(L, h); - lua_call(L, 3, 1); - if (lua_isuserdata(L, -1)) + if (!direct_uid_draw) { - SDL_Surface **img = (SDL_Surface**)auxiliar_checkclass(L, "sdl{surface}", -1); - sdlDrawImage(s, *img, size, 0); - size += (*img)->w; + lua_getglobal(L, "__get_uid_surface"); + char *colon = next + 5; + while (*colon && *colon != ':') colon++; + lua_pushlstring(L, next+5, colon - (next+5)); +// printf("Drawing UID %s\n", lua_tostring(L,-1)); + lua_pushnumber(L, h); + lua_pushnumber(L, h); + lua_call(L, 3, 1); + if (lua_isuserdata(L, -1)) + { + SDL_Surface **img = (SDL_Surface**)auxiliar_checkclass(L, "sdl{surface}", -1); + sdlDrawImage(s, *img, size, 0); + size += (*img)->w; + } + lua_pop(L, 1); + } + else + { + lua_getglobal(L, "__get_uid_entity"); + char *colon = next + 5; + while (*colon && *colon != ':') colon++; + lua_pushlstring(L, next+5, colon - (next+5)); + lua_call(L, 1, 1); + if (lua_istable(L, -1)) + { +// printf("DirectDrawUID in font:draw %d : %d\n", size, h); + lua_createtable(L, 0, 4); + + lua_pushliteral(L, "e"); + lua_pushvalue(L, -3); + lua_rawset(L, -3); + + lua_pushliteral(L, "x"); + lua_pushnumber(L, size); + lua_rawset(L, -3); + + lua_pushliteral(L, "w"); + lua_pushnumber(L, h); + lua_rawset(L, -3); + + lua_rawseti(L, -4, id_dduid++); // __dduids + + size += h; + } + lua_pop(L, 1); } - lua_pop(L, 1); } // Extra data else if ((*(next+1) == '&')) { @@ -801,7 +852,7 @@ static int sdl_font_draw(lua_State *L) next++; } - font_make_texture_line(L, s, nb_lines, is_separator, id_real_line, line_data, line_data_size); + font_make_texture_line(L, s, nb_lines, is_separator, id_real_line, line_data, line_data_size, direct_uid_draw); if (size > max_size) max_size = size; if (txt) SDL_FreeSurface(txt); @@ -810,6 +861,8 @@ static int sdl_font_draw(lua_State *L) lua_pushnumber(L, nb_lines); lua_pushnumber(L, max_size); + if (direct_uid_draw) lua_remove(L, -4); + return 3; } diff --git a/src/map.c b/src/map.c index 69ed2b6d9c466780d77a17b4b1f0d1ba08b8b8ef..173e12f650332c3c23c5241b340ea17c1b7e6cf3 100644 --- a/src/map.c +++ b/src/map.c @@ -357,6 +357,7 @@ static int map_objects_toscreen(lua_State *L) int y = luaL_checknumber(L, 2); int w = luaL_checknumber(L, 3); int h = luaL_checknumber(L, 4); + float a = (lua_isnumber(L, 5) ? lua_tonumber(L, 5) : 1); GLfloat vertices[3*4]; GLfloat texcoords[2*4] = { @@ -366,10 +367,10 @@ static int map_objects_toscreen(lua_State *L) 0, 1, }; GLfloat colors[4*4] = { - 1, 1, 1, 1, - 1, 1, 1, 1, - 1, 1, 1, 1, - 1, 1, 1, 1, + 1, 1, 1, a, + 1, 1, 1, a, + 1, 1, 1, a, + 1, 1, 1, a, }; glTexCoordPointer(2, GL_FLOAT, 0, texcoords); @@ -379,7 +380,7 @@ static int map_objects_toscreen(lua_State *L) /*************************************************** * Render ***************************************************/ - int moid = 5; + int moid = 6; while (lua_isuserdata(L, moid)) { map_object *m = (map_object*)auxiliar_checkclass(L, "core{mapobj}", moid);