diff --git a/data/pigui/libs/forwarded.lua b/data/pigui/libs/forwarded.lua index a007f01c49a..27842beedf5 100644 --- a/data/pigui/libs/forwarded.lua +++ b/data/pigui/libs/forwarded.lua @@ -45,6 +45,7 @@ ui.selectable = pigui.Selectable ui.progressBar = pigui.ProgressBar ui.plotHistogram = pigui.PlotHistogram ui.setTooltip = pigui.SetTooltip +ui.setItemTooltip = pigui.SetItemTooltip ui.addCircle = pigui.AddCircle ui.addCircleFilled = pigui.AddCircleFilled ui.addRect = pigui.AddRect ---@type fun(a: Vector2, b: Vector2, col: Color, rounding: number, edges: integer, thickness: number) diff --git a/data/pigui/modules/saveloadgame.lua b/data/pigui/modules/saveloadgame.lua index 18dc01e8151..d0e72e75581 100644 --- a/data/pigui/modules/saveloadgame.lua +++ b/data/pigui/modules/saveloadgame.lua @@ -64,8 +64,8 @@ local function getSaveTooltip(name) else ret = ret .. "\n" .. lc.SHIP .. ": " .. lc.UNKNOWN end - - + + if stats.flight_state then ret = ret .. "\n"..lui.FLIGHT_STATE..": " ret = ret .. (rawget(lc, string.upper(stats.flight_state)) or @@ -75,7 +75,7 @@ local function getSaveTooltip(name) if stats.docked_at then ret = ret .. "\n"..lui.DOCKED_AT..": " .. stats.docked_at end if stats.frame then ret = ret .. "\n"..lui.VICINITY_OF..": " .. stats.frame end - + saveFileCache[name].ret = ret return ret end @@ -84,7 +84,7 @@ local function shouldDisplayThisSave(f) if(string.len(searchSave) < minSearchTextLength) then return true end - + return not caseSensitive and string.find(string.lower(f.name), string.lower(searchSave), 1, true) ~= nil or string.find(f.name, searchSave, 1, true) ~= nil end @@ -94,9 +94,9 @@ local function displaySave(f) selectedSave = f.name saveIsValid = pcall(Game.SaveGameStats, f.name) end - if Engine.pigui.IsItemHovered() then - local tooltip = getSaveTooltip(f.name) - Engine.pigui.SetTooltip(tooltip) + + if ui.isItemHovered("ForTooltip") then + ui.setTooltip(getSaveTooltip(f.name)) end ui.nextColumn() @@ -170,24 +170,24 @@ end ui.saveLoadWindow = ModalWindow.New("LoadGame", function() local saving = ui.saveLoadWindow.mode == "SAVE" local searchTextSize = ui.calcTextSize(searchText, pionillium.medium.name, pionillium.medium.size) - + local txt_width = winSize.x - (ui.getWindowPadding().x + optionButtonSize.x + ui.getItemSpacing().x) * 2 - + drawSearchHeader(txt_width) - + ui.separator() - + local saveFilesSearchHeaderHeight = (searchTextSize.y * 2 + ui.getItemSpacing().y * 2 + ui.getWindowPadding().y * 2) local saveFilesChildWindowHeight = (optionButtonSize.y + (saving and searchTextSize.y or 0) + ui.getItemSpacing().y * 2 + ui.getWindowPadding().y * 2) - + local saveFilesChildWindowSize = Vector2(0, (winSize.y - saveFilesChildWindowHeight) - saveFilesSearchHeaderHeight) - + ui.child("savefiles", saveFilesChildWindowSize, function() showSaveFiles() end) ui.separator() - + -- a little padding just before the window border, so that the cancel button will not be cut out txt_width = txt_width / 1.03 if saving then @@ -207,4 +207,4 @@ end) ui.saveLoadWindow.mode = "LOAD" -return {} \ No newline at end of file +return {} diff --git a/src/lua/LuaPiGui.cpp b/src/lua/LuaPiGui.cpp index f08cfd7be1b..c8cf5bddf84 100644 --- a/src/lua/LuaPiGui.cpp +++ b/src/lua/LuaPiGui.cpp @@ -93,9 +93,11 @@ static Type parse_imgui_flags(lua_State *l, int index, LuaFlags &lookupTab theFlags = static_cast(lua_tointeger(l, index)); } else if (lua_istable(l, index)) { theFlags = lookupTable.LookupTable(l, index); + } else if (lua_isstring(l, index)) { + theFlags = lookupTable.LookupEnum(l, index); } else { luaL_traceback(l, l, NULL, 1); - Error("Expected a table or integer, got %s.\n%s\n", luaL_typename(l, index), lua_tostring(l, -1)); + Error("Expected a table, string, or integer, got %s.\n%s\n", luaL_typename(l, index), lua_tostring(l, -1)); } return theFlags; } @@ -383,7 +385,8 @@ static LuaFlags imguiHoveredFlagsTable = { { "AllowWhenBlockedByActiveItem", ImGuiHoveredFlags_AllowWhenBlockedByActiveItem }, { "AllowWhenOverlapped", ImGuiHoveredFlags_AllowWhenOverlapped }, { "AllowWhenDisabled", ImGuiHoveredFlags_AllowWhenDisabled }, - { "RectOnly", ImGuiHoveredFlags_RectOnly } + { "RectOnly", ImGuiHoveredFlags_RectOnly }, + { "ForTooltip", ImGuiHoveredFlags_ForTooltip } }; void pi_lua_generic_pull(lua_State *l, int index, ImGuiHoveredFlags_ &theflags) @@ -1740,7 +1743,8 @@ static int l_pigui_end_child(lua_State *l) static int l_pigui_is_item_hovered(lua_State *l) { PROFILE_SCOPED() - LuaPush(l, ImGui::IsItemHovered()); + int flags = LuaPull(l, 1, ImGuiHoveredFlags_None); + LuaPush(l, ImGui::IsItemHovered(flags)); return 1; } @@ -1861,6 +1865,14 @@ static int l_pigui_set_tooltip(lua_State *l) return 0; } +static int l_pigui_set_item_tooltip(lua_State *l) +{ + PROFILE_SCOPED() + std::string text = LuaPull(l, 1); + ImGui::SetItemTooltip("%s", text.c_str()); + return 0; +} + static int l_pigui_begin_tooltip(lua_State *l) { PROFILE_SCOPED() @@ -3299,6 +3311,7 @@ void LuaObject::RegisterClass() { "PopFont", l_pigui_pop_font }, { "CalcTextSize", l_pigui_calc_text_size }, { "SetTooltip", l_pigui_set_tooltip }, + { "SetItemTooltip", l_pigui_set_item_tooltip }, { "BeginTooltip", l_pigui_begin_tooltip }, { "EndTooltip", l_pigui_end_tooltip }, { "Checkbox", l_pigui_checkbox },