Skip to content

Commit

Permalink
Fix leaving to menu with chat form open
Browse files Browse the repository at this point in the history
  • Loading branch information
Web-eWorks committed Dec 22, 2020
1 parent 151fd74 commit 59cfed1
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 7 deletions.
4 changes: 3 additions & 1 deletion data/pigui/libs/chat-form.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ function ChatForm:render ()

self.navButton()

if ui.coloredSelectedButton(l.HANG_UP, self.style.buttonSize, false, colors.buttonBlue, nil, true) then self:Close() end
if ui.coloredSelectedButton(l.HANG_UP, self.style.buttonSize, false, colors.buttonBlue, nil, true) or ui.escapeKeyReleased(true) then
self:Close()
end
end)
end

Expand Down
1 change: 1 addition & 0 deletions data/pigui/libs/forwarded.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ ui.beginPopupModal = pigui.BeginPopupModal
ui.endPopup = pigui.EndPopup
ui.openPopup = pigui.OpenPopup
ui.closeCurrentPopup = pigui.CloseCurrentPopup
ui.isAnyPopupOpen = pigui.IsAnyPopupOpen
ui.shouldShowLabels = pigui.ShouldShowLabels
ui.columns = pigui.Columns
ui.nextColumn = pigui.NextColumn
Expand Down
19 changes: 19 additions & 0 deletions data/pigui/libs/wrappers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,25 @@ function ui.shiftHeld() return pigui.key_shift end
--
function ui.noModifierHeld() return pigui.key_none end

--
-- Function: ui.escapeKeyReleased
--
-- Performs some sanity checks and returns true if the user has pressed escape
-- and the escape key is not currently being consumed.
--
--
-- Parameters:
--
-- ignorePopup - if true, skip checking for open popups.
--
-- Returns:
--
-- boolean - true if the escape key is pressed and not being consumed
--
function ui.escapeKeyReleased(ignorePopup)
return (ignorePopup or not ui.isAnyPopupOpen()) and ui.noModifierHeld() and ui.isKeyReleased(ui.keys.escape)
end

--
-- Function: ui.tabBar
--
Expand Down
2 changes: 1 addition & 1 deletion data/pigui/modules/system-view-ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ local function displaySystemViewUI()
displayOnScreenObjects()
end

if ui.noModifierHeld() and ui.isKeyReleased(ui.keys.escape) then
if ui.escapeKeyReleased() then
Game.SetView("sector")
end
end
Expand Down
2 changes: 1 addition & 1 deletion data/pigui/views/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ ui.registerHandler('game', function(delta_t)
end)
end)

if currentView == "world" and ui.noModifierHeld() and ui.isKeyReleased(ui.keys.escape) then
if currentView == "world" and ui.escapeKeyReleased() then
if not ui.optionsWindow.isOpen then
Game.SetTimeAcceleration("paused")
ui.optionsWindow:open()
Expand Down
2 changes: 1 addition & 1 deletion data/pigui/views/info-view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ infoView.windowPadding = ui.rescaleUI(Vector2(24, 24), Vector2(1920, 1200))

ui.registerModule("game", function()
infoView:renderTabView()
if infoView.isActive and ui.noModifierHeld() and ui.isKeyReleased(ui.keys.escape) then
if infoView.isActive and ui.escapeKeyReleased() then
Game.SetView("world")
end
end)
Expand Down
2 changes: 1 addition & 1 deletion data/pigui/views/map-sector-view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ local function displaySectorViewWindow()
end
end

if ui.noModifierHeld() and ui.isKeyReleased(ui.keys.escape) then
if ui.escapeKeyReleased() then
Game.SetView("world")
end
end
Expand Down
2 changes: 1 addition & 1 deletion data/pigui/views/station-view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ if not stationView then

ui.registerModule("game", function()
stationView:renderTabView()
if stationView.isActive and ui.noModifierHeld() and ui.isKeyReleased(ui.keys.escape) then
if stationView.isActive and ui.escapeKeyReleased() then
Game.SetView("world")
end
end)
Expand Down
2 changes: 1 addition & 1 deletion data/pigui/views/system-info-view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local ui = require 'pigui'

ui.registerModule("game", function()
if Game.CurrentView() == "system_info" then
if ui.noModifierHeld() and ui.isKeyReleased(ui.keys.escape) then
if ui.escapeKeyReleased() then
Game.SetView("sector")
end
end
Expand Down
8 changes: 8 additions & 0 deletions src/lua/LuaPiGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,13 @@ static int l_pigui_close_current_popup(lua_State *l)
return 0;
}

static int l_pigui_is_any_popup_open(lua_State *l)
{
PROFILE_SCOPED()
LuaPush<bool>(l, !ImGui::GetCurrentContext()->OpenPopupStack.empty());
return 1;
}

static int l_pigui_end_popup(lua_State *l)
{
PROFILE_SCOPED()
Expand Down Expand Up @@ -2839,6 +2846,7 @@ void LuaObject<PiGui::Instance>::RegisterClass()
{ "EndPopup", l_pigui_end_popup },
{ "OpenPopup", l_pigui_open_popup },
{ "CloseCurrentPopup", l_pigui_close_current_popup },
{ "IsAnyPopupOpen", l_pigui_is_any_popup_open },
{ "PushID", l_pigui_push_id },
{ "PopID", l_pigui_pop_id },
{ "IsMouseReleased", l_pigui_is_mouse_released },
Expand Down

0 comments on commit 59cfed1

Please sign in to comment.