Skip to content

Commit

Permalink
add hooks to register callbacks when a wiki page is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
notnotmelon committed Nov 30, 2023
1 parent 30caa70 commit 4bd7f4f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Date: ?
Changes:
- Fixed a crash when configuring AMFM beacons (https://github.com/pyanodon/pybugreports/issues/349)
- Removed burner assembling machine wiki page. It's info was outdated after previous patch which removed the ingredient limit.
- Fixed a crash when viewing a wiki page that doesn't exist
---------------------------------------------------------------------------------------------------
Version: 2.1.8
Date: 2023-11-21
Expand Down
21 changes: 19 additions & 2 deletions scripts/wiki/wiki.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,15 @@ end

function Wiki.close_wiki(player)
local main_frame = Wiki.get_wiki_gui(player)
if main_frame then main_frame.destroy() end
if not main_frame then return end

local pages = Wiki.get_pages(player)
local page_data = pages.tags.contents[pages.selected_index]
if page_data and page_data.on_closed then
local on_closed = page_data.on_closed
remote.call(on_closed[1], on_closed[2], contents, player)
end
main_frame.destroy()
end

Gui.on_click('py_open_wiki', function(event)
Expand Down Expand Up @@ -137,10 +145,19 @@ function Wiki.open_page(player, index)
local page_data = pages.tags.contents[index]

if page_data.is_section then
Wiki.open_page(player, global.currently_opened_wiki_page[player.index] or 1)
local previous_index = global.currently_opened_wiki_page[player.index] or 1
if previous_index ~= index then Wiki.open_page(player, previous_index) end
return
end

if global.currently_opened_wiki_page[player.index] then
local previous_page_data = pages.tags.contents[global.currently_opened_wiki_page[player.index]]
if previous_page_data and previous_page_data.on_closed then
local on_closed = previous_page_data.on_closed
remote.call(on_closed[1], on_closed[2], contents, player)
end
end

title.clear()
local localised_title = {'pywiki-sections.' .. (page_data.title or page_data.name)}
title.add{type = 'label', style = 'subheader_label', name = 'page_title', caption = {'', '[font=default-semibold][color=255,230,192]', localised_title, '[/color][/font]'}}
Expand Down

0 comments on commit 4bd7f4f

Please sign in to comment.