diff --git a/game/engines/default/engine/HotkeysIconsDisplay.lua b/game/engines/default/engine/HotkeysIconsDisplay.lua index 26e6dc0716a54167a1a2c0168624d30fdf1daca6..36096e8eac841ea4316d16fefcd1d5d510a08d31 100644 --- a/game/engines/default/engine/HotkeysIconsDisplay.lua +++ b/game/engines/default/engine/HotkeysIconsDisplay.lua @@ -258,13 +258,8 @@ function _M:onMouse(button, mx, my, click, on_over, on_click) else if a.hotkey[i][1] == "talent" then local t = self.actor:getTalentFromId(a.hotkey[i][2]) --- local s = t.display_entity:getEntityFinalSurface(nil, 64, 64) --- game.mouse:startDrag(mx, my, s, {kind=a.hotkey[i][1], id=a.hotkey[i][2], source_hotkey_slot=i}, function(drag, used) if not used then self.actor.hotkey[i] = nil self.actor.changed = true end end) - local e = t.display_entity - local tex = game.level.map.tiles:get(e.display, e.color_r, e.color_g, e.color_b, e.color_br, e.color_bg, e.color_bb, e.image, e._noalpha and 255, e.ascii_outline, true) - local s = tex:toSurface() + local s = t.display_entity:getEntityFinalSurface(nil, 64, 64) game.mouse:startDrag(mx, my, s, {kind=a.hotkey[i][1], id=a.hotkey[i][2], source_hotkey_slot=i}, function(drag, used) if not used then self.actor.hotkey[i] = nil self.actor.changed = true end end) - elseif a.hotkey[i][1] == "inventory" then local o = a:findInAllInventories(a.hotkey[i][2], {no_add_name=true, force_id=true, no_count=true}) local s = nil diff --git a/game/engines/default/engine/Mouse.lua b/game/engines/default/engine/Mouse.lua index e109ed85d8aa1d5b36b2f2af92e616e284c0c66e..d03e1fa73924e3917bcfbc415db2e835b02e7174 100644 --- a/game/engines/default/engine/Mouse.lua +++ b/game/engines/default/engine/Mouse.lua @@ -110,7 +110,11 @@ function _M:startDrag(x, y, cursor, payload, on_done) if _M.drag then if _M.drag.prestart and math.max(math.abs(_M.drag.start_x - x), math.abs(_M.drag.start_y - y)) > 6 then _M.drag.prestart = nil - if _M.drag.cursor then game:setMouseCursor(_M.drag.cursor, nil, 0, 0) end + if _M.drag.cursor then + local w, h = _M.drag.cursor:getSize() + _M.drag.cursor = _M.drag.cursor:glTexture() + core.display.setMouseDrag(_M.drag.cursor, w, h) + end print("[MOUSE] enabling drag from predrag") end return @@ -123,7 +127,7 @@ end function _M:endDrag(x, y) local drag = _M.drag print("[MOUSE] ending drag'n'drop") - game:defaultMouseCursor() + core.display.setMouseDrag(nil, 0, 0) _M.drag = nil _M.dragged = drag _M.current:receiveMouse("drag-end", x, y, true, nil, {drag=drag}) diff --git a/game/modules/tome/data/gfx/lore/farportal_entering.png b/game/modules/tome/data/gfx/lore/farportal_entering.png index b023b6ca99ccc88406d29cdefa3ea9e0e7784f6d..cec97eecab7c8f20914beda03bc285bc680a735a 100644 Binary files a/game/modules/tome/data/gfx/lore/farportal_entering.png and b/game/modules/tome/data/gfx/lore/farportal_entering.png differ diff --git a/game/modules/tome/dialogs/Birther.lua b/game/modules/tome/dialogs/Birther.lua index 907ba1edb188824dfda07fa71fb6d48e8a26469a..d2b152a56d58a4e8398c5cc524956ccd62bf0c0f 100644 --- a/game/modules/tome/dialogs/Birther.lua +++ b/game/modules/tome/dialogs/Birther.lua @@ -300,7 +300,7 @@ function _M:randomBirth() -- Random subclass if class then local subclass, subclass_id = nil - repeat subclass, subclass_id = rng.table(self.all_classes[class_id].nodes) + repeat subclass, subclass_id = rng.table(self.all_classes[class_id].nodes) print("====", subclass, subclass_id, class_id) until not subclass.locked self:classUse(subclass) end diff --git a/src/core_lua.c b/src/core_lua.c index d25014a60ff74f3078aca4ae60903cfcfe787775..d67bc0f6c75079e49373975f44c5d9db7548df17 100644 --- a/src/core_lua.c +++ b/src/core_lua.c @@ -1673,8 +1673,8 @@ static int sdl_redraw_screen(lua_State *L) return 0; } -extern int mouse_cursor_tex, mouse_cursor_tex_ref; -extern int mouse_cursor_down_tex, mouse_cursor_down_tex_ref; +int mouse_cursor_s_ref = LUA_NOREF; +int mouse_cursor_down_s_ref = LUA_NOREF; SDL_Surface *mouse_cursor_s = NULL; SDL_Surface *mouse_cursor_down_s = NULL; SDL_Cursor *mouse_cursor = NULL; @@ -1686,21 +1686,17 @@ static int sdl_set_mouse_cursor(lua_State *L) mouse_cursor_oy = luaL_checknumber(L, 2); /* Down */ - if (mouse_cursor_down_tex_ref != LUA_NOREF) + if (mouse_cursor_down_s_ref != LUA_NOREF) { - luaL_unref(L, LUA_REGISTRYINDEX, mouse_cursor_down_tex_ref); - mouse_cursor_down_tex_ref = LUA_NOREF; + luaL_unref(L, LUA_REGISTRYINDEX, mouse_cursor_down_s_ref); + mouse_cursor_down_s_ref = LUA_NOREF; } - if (lua_isnil(L, 4)) - { - mouse_cursor_down_tex = 0; - } - else + if (!lua_isnil(L, 4)) { SDL_Surface **s = (SDL_Surface**)auxiliar_checkclass(L, "sdl{surface}", 4); mouse_cursor_down_s = *s; - mouse_cursor_down_tex_ref = luaL_ref(L, LUA_REGISTRYINDEX); + mouse_cursor_down_s_ref = luaL_ref(L, LUA_REGISTRYINDEX); if (mouse_cursor_down) { SDL_FreeCursor(mouse_cursor_down); mouse_cursor_down = NULL; } mouse_cursor_down = SDL_CreateColorCursor(mouse_cursor_down_s, -mouse_cursor_ox, -mouse_cursor_oy); @@ -1708,22 +1704,17 @@ static int sdl_set_mouse_cursor(lua_State *L) } /* Default */ - if (mouse_cursor_tex_ref != LUA_NOREF) + if (mouse_cursor_s_ref != LUA_NOREF) { - luaL_unref(L, LUA_REGISTRYINDEX, mouse_cursor_tex_ref); - mouse_cursor_tex_ref = LUA_NOREF; + luaL_unref(L, LUA_REGISTRYINDEX, mouse_cursor_s_ref); + mouse_cursor_s_ref = LUA_NOREF; } - if (lua_isnil(L, 3)) - { -// mouse_cursor_tex = 0; -// SDL_ShowCursor(SDL_ENABLE); - } - else + if (!lua_isnil(L, 3)) { SDL_Surface **s = (SDL_Surface**)auxiliar_checkclass(L, "sdl{surface}", 3); mouse_cursor_s = *s; - mouse_cursor_tex_ref = luaL_ref(L, LUA_REGISTRYINDEX); + mouse_cursor_s_ref = luaL_ref(L, LUA_REGISTRYINDEX); if (mouse_cursor) { SDL_FreeCursor(mouse_cursor); mouse_cursor = NULL; } mouse_cursor = SDL_CreateColorCursor(mouse_cursor_s, -mouse_cursor_ox, -mouse_cursor_oy); @@ -1732,6 +1723,34 @@ static int sdl_set_mouse_cursor(lua_State *L) return 0; } +extern int mouse_drag_tex, mouse_drag_tex_ref; +extern int mouse_drag_w, mouse_drag_h; +static int sdl_set_mouse_cursor_drag(lua_State *L) +{ + mouse_drag_w = luaL_checknumber(L, 2); + mouse_drag_h = luaL_checknumber(L, 3); + + /* Default */ + if (mouse_drag_tex_ref != LUA_NOREF) + { + luaL_unref(L, LUA_REGISTRYINDEX, mouse_drag_tex_ref); + mouse_drag_tex_ref = LUA_NOREF; + } + + if (lua_isnil(L, 1)) + { + mouse_drag_tex = 0; + } + else + { + GLuint *t = (GLuint*)auxiliar_checkclass(L, "gl{texture}", 1); + mouse_drag_tex = *t; + mouse_drag_tex_ref = luaL_ref(L, LUA_REGISTRYINDEX); + } + return 0; +} + + /************************************************************** * Quadratic Objects **************************************************************/ @@ -2152,6 +2171,7 @@ static const struct luaL_reg displaylib[] = {"setWindowPos", sdl_set_window_pos}, {"getModesList", sdl_get_modes_list}, {"setMouseCursor", sdl_set_mouse_cursor}, + {"setMouseDrag", sdl_set_mouse_cursor_drag}, {"setGamma", sdl_set_gamma}, {"glTranslate", gl_translate}, {"glScale", gl_scale}, diff --git a/src/main.c b/src/main.c index 70184c18b3eb041c6e21b3e519c726ac9747eccb..8ba8f6c9af5ca3cf5bca7c80dddec4a3c1e0b7a8 100644 --- a/src/main.c +++ b/src/main.c @@ -63,9 +63,9 @@ bool exit_engine = FALSE; bool no_sound = FALSE; bool isActive = TRUE; bool tickPaused = FALSE; -int mouse_cursor_tex = 0, mouse_cursor_tex_ref = LUA_NOREF; -int mouse_cursor_down_tex = 0, mouse_cursor_down_tex_ref = LUA_NOREF; -int mouse_cursor_ox = 0, mouse_cursor_oy = 0; +int mouse_cursor_ox, mouse_cursor_oy; +int mouse_drag_w = 32, mouse_drag_h = 32; +int mouse_drag_tex = 0, mouse_drag_tex_ref = LUA_NOREF; int mousex = 0, mousey = 0; float gamma_correction = 1; int requested_fps = 30; @@ -419,7 +419,7 @@ void call_draw(int nb_keyframes) } /* Mouse pointer */ - if (mouse_cursor_tex && mouse_cursor_down_tex) + if (mouse_drag_tex) { GLfloat texcoords[2*4] = { 0, 0, @@ -437,16 +437,17 @@ void call_draw(int nb_keyframes) glTexCoordPointer(2, GL_FLOAT, 0, texcoords); glColorPointer(4, GL_FLOAT, 0, colors); - int x = mousex + mouse_cursor_ox; - int y = mousey + mouse_cursor_oy; - int down = SDL_GetMouseState(NULL, NULL); - tglBindTexture(GL_TEXTURE_2D, down ? mouse_cursor_down_tex : mouse_cursor_tex); + int x = mousex; + int y = mousey; + int w = mouse_drag_w / 2; + int h = mouse_drag_h / 2; + tglBindTexture(GL_TEXTURE_2D, mouse_drag_tex); GLfloat vertices[2*4] = { - x, y, - x, y + 32, - x + 32, y + 32, - x + 32, y, + x - w, y - h, + x - w, y + h, + x + w, y + h, + x + w, y - h, }; glVertexPointer(2, GL_FLOAT, 0, vertices); glDrawArrays(GL_QUADS, 0, 4);