Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- AnimalScreen
- AnimationElement
- BitmapElement
- BoxLayoutElement
- BreadcrumbsElement
- ButtonElement
- ButtonOverlay
- ChatWindow
- CheckedOptionElement
- ClearElement
- ContextActionDisplay
- DialogElement
- FieldInfoDisplay
- FillLevelsDisplay
- FlowLayoutElement
- FocusManager
- FrameElement
- FrameReferenceElement
- GameInfoDisplay
- GamePausedDisplay
- Gui
- GuiDataSource
- GuiElement
- GuiMixin
- GuiOverlay
- GuiProfile
- GuiSoundPlayer
- GuiTopDownCamera
- GuiUtils
- HUDDisplayElement
- HUDElement
- HUDFrameElement
- HUDPopupMessage
- HUDTextDisplay
- IndexChangeSubjectMixin
- IndexStateElement
- InGameIcon
- IngameMap
- IngameMapElement
- InputGlyphElement
- InputHelpDisplay
- ListElement
- ListItemElement
- MapHotspot
- MapOverlayGenerator
- MixerWagonHUDExtension
- MultiTextOptionElement
- MultiValueTween
- Overlay
- PagingElement
- PlaySampleMixin
- RenderElement
- RoundStatusBar
- ScreenElement
- SettingsModel
- SideNotification
- SliderElement
- SpeakerDisplay
- SpeedMeterDisplay
- StableListElement
- StatusBar
- TabbedMenu
- TabbedMenuFrameElement
- TabbedMenuWithDetails
- TableElement
- TableHeaderElement
- TextElement
- TextInputElement
- TimerElement
- ToggleButtonElement
- TopNotification
- Tween
- TweenSequence
- VehicleHUDExtension
- VehicleSchemaDisplay
- VideoElement
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
TabbedMenu
DescriptionNumber of menu buttons which can be modified by pages.Parent
ScreenElementFunctions
- addPage
- addPageTab
- assignMenuButtonInfo
- clearMenuButtonActions
- delete
- exitMenu
- getPageButtonInfo
- goToPage
- makeSelfCallback
- new
- onButtonBack
- onClickActivate
- onClickBack
- onClickCancel
- onClickMenuExtra1
- onClickMenuExtra2
- onClickOk
- onClickPageSelection
- onClose
- onGuiSetupFinished
- onMenuActionClick
- onMenuOpened
- onOpen
- onPageChange
- onPageClicked
- onPageNext
- onPagePrevious
- onPageUpdate
- rebuildTabList
- registerPage
- removePage
- reset
- setPageEnabled
- setPageSelectorTitles
- setPageTabEnabled
- setupMenuButtonInfo
- unregisterPage
- update
- updateButtonsPanel
- updatePageControlVisibility
- updatePages
- updatePageTabDisplay
addPage
DescriptionAdd a page frame to be displayed in the menu at runtime. The page will be part of the in-game menu until restarting the game or removing the page again.Definition
addPage(table pageFrameElement, int position, string tabIconFilename, table tabIconUVs, function enablingPredicateFunction)Arguments
table | pageFrameElement | FrameElement instance which is used as a page. |
int | position | Position index of added page, starting from left at 1 going to right. |
string | tabIconFilename | Path to the texture file which contains the icon for the page tab in the header |
table | tabIconUVs | UV array for the tab icon. Format: {x, y, width, height} in pixels on the texture. |
function | enablingPredicateFunction | [optional] A function which returns the current enabling state of the page at any time. If the function returns true, the page should be enabled. If no argument is given, the page is always enabled. |
712 | function TabbedMenu:addPage(pageFrameElement, position, tabIconFilename, tabIconUVs, enablingPredicateFunction) |
713 | local pageRoot, actualPosition = self:registerPage(pageFrameElement, position, enablingPredicateFunction) |
714 | self:addPageTab(pageFrameElement, tabIconFilename, getNormalizedUVs(tabIconUVs)) |
715 | |
716 | local name = pageRoot.title |
717 | if name == nil then |
718 | name = self.l10n:getText("ui_" .. pageRoot.name) |
719 | end |
720 | |
721 | self.pagingElement:addPage(string.upper(pageRoot.name), pageRoot, name, actualPosition) |
722 | end |
addPageTab
DescriptionAdd a page tab in the menu header. Call this synchronously with TabbedMenu:registerPage() to ensure a correct order of pages and tabs.Definition
addPageTab()Code
213 | function TabbedMenu:addPageTab(frameController, iconFilename, iconUVs) |
214 | local tab = self.pagingTabTemplate:clone() |
215 | tab:fadeIn() |
216 | self.pagingTabList:addElement(tab) |
217 | self.pageTabs[frameController] = tab |
218 | |
219 | local tabButton = tab:getDescendantByName(TabbedMenu.PAGE_TAB_TEMPLATE_BUTTON_NAME) |
220 | tabButton:setImageFilename(nil, iconFilename) |
221 | tabButton:setImageUVs(nil, iconUVs) |
222 | |
223 | tabButton.onClickCallback = function() |
224 | self:onPageClicked(self.activeDetailPage) |
225 | |
226 | local pageId = self.pagingElement:getPageIdByElement(frameController) |
227 | local pageMappingIndex = self.pagingElement:getPageMappingIndex(pageId) |
228 | |
229 | self.pageSelector:setState(pageMappingIndex, true) -- set state with force event |
230 | end |
231 | end |
assignMenuButtonInfo
DescriptionAssign menu button information to the in-game menu buttons.Definition
assignMenuButtonInfo()Code
343 | function TabbedMenu:assignMenuButtonInfo(menuButtonInfo) |
344 | self:clearMenuButtonActions() |
345 | |
346 | for i, button in ipairs(self.menuButton) do |
347 | local info = menuButtonInfo[i] |
348 | local hasInfo = info ~= nil |
349 | button:setVisible(hasInfo) |
350 | |
351 | -- Do not show actions when the game is paused unless specified |
352 | if hasInfo and info.inputAction ~= nil and InputAction[info.inputAction] ~= nil then |
353 | button:setInputAction(info.inputAction) |
354 | |
355 | local buttonText = info.text |
356 | if buttonText == nil and self.defaultMenuButtonInfoByActions[info.inputAction] ~= nil then |
357 | buttonText = self.defaultMenuButtonInfoByActions[info.inputAction].text |
358 | end |
359 | button:setText(buttonText) |
360 | |
361 | local buttonClickCallback = info.callback or self.defaultButtonActionCallbacks[info.inputAction] or NO_CALLBACK |
362 | |
363 | local sound = GuiSoundPlayer.SOUND_SAMPLES.CLICK |
364 | if info.inputAction == InputAction.MENU_BACK then |
365 | sound = GuiSoundPlayer.SOUND_SAMPLES.BACK |
366 | end |
367 | |
368 | if info.clickSound ~= nil and info.clickSound ~= sound then |
369 | sound = info.clickSound |
370 | |
371 | -- We need to activate the sound by hand so that it is also played for gamepad and keyboard input |
372 | -- as those are not triggered by the button |
373 | local oldButtonClickCallback = buttonClickCallback |
374 | buttonClickCallback = function (...) |
375 | self:playSample(sound) |
376 | self:setNextScreenClickSoundMuted() |
377 | |
378 | return oldButtonClickCallback(...) |
379 | end |
380 | |
381 | -- Deactivate sound on button to prevent double-sounds |
382 | button:setClickSound(GuiSoundPlayer.SOUND_SAMPLES.NONE) |
383 | else |
384 | button:setClickSound(sound) |
385 | end |
386 | |
387 | local showForCurrentState = not self.paused or info.showWhenPaused or info.inputAction == InputAction.MENU_BACK |
388 | |
389 | local disabled = info.disabled or not showForCurrentState |
390 | if not disabled then |
391 | if not TabbedMenu.DEFAULT_BUTTON_ACTIONS[info.inputAction] then |
392 | local _, eventId = self.inputManager:registerActionEvent(info.inputAction, InputBinding.NO_EVENT_TARGET, buttonClickCallback, false, true, false, true) |
393 | table.insert(self.customButtonEvents, eventId) -- store event ID to remove again on page change |
394 | else |
395 | self.buttonActionCallbacks[info.inputAction] = buttonClickCallback |
396 | end |
397 | end |
398 | |
399 | button.onClickCallback = buttonClickCallback |
400 | button:setDisabled(disabled) |
401 | end |
402 | end |
403 | |
404 | -- make sure that menu exit is always possible: |
405 | self.buttonActionCallbacks[InputAction.MENU_BACK] = self.clickBackCallback |
406 | |
407 | self.buttonsPanel:invalidateLayout() |
408 | end |
clearMenuButtonActions
DescriptionClear menu button actions, events and callbacks.Definition
clearMenuButtonActions()Code
330 | function TabbedMenu:clearMenuButtonActions() |
331 | for k in pairs(self.buttonActionCallbacks) do |
332 | self.buttonActionCallbacks[k] = nil |
333 | end |
334 | |
335 | for i in ipairs(self.customButtonEvents) do |
336 | self.inputManager:removeActionEvent(self.customButtonEvents[i]) |
337 | self.customButtonEvents[i] = nil |
338 | end |
339 | end |
delete
DescriptionDefinitiondelete()Code
88 | function TabbedMenu:delete() |
89 | self.messageCenter:unsubscribeAll(self) |
90 | self.pagingTabTemplate:delete() -- need to delete the template here because we have unlinked it during setup |
91 | |
92 | TabbedMenu:superClass().delete(self) |
93 | end |
exitMenu
DescriptionDefinitionexitMenu()Code
112 | function TabbedMenu:exitMenu() |
113 | self:changeScreen(nil) |
114 | end |
getPageButtonInfo
DescriptionGet button actions and display information for a given menu page.Definition
getPageButtonInfo()Code
596 | function TabbedMenu:getPageButtonInfo(page) |
597 | local buttonInfo = TabbedMenu.NO_BUTTON_INFO -- makes all buttons invisible |
598 | |
599 | if page:getHasCustomMenuButtons() then |
600 | buttonInfo = page:getMenuButtonInfo() |
601 | else |
602 | buttonInfo = self.defaultMenuButtonInfo |
603 | end |
604 | |
605 | return buttonInfo |
606 | end |
goToPage
DescriptionDefinitiongoToPage()Code
425 | function TabbedMenu:goToPage(page) |
426 | local index = self.pagingElement:getPageIndexByElement(page) |
427 | if index ~= nil then |
428 | self.pageSelector:setState(index, true) |
429 | end |
430 | end |
makeSelfCallback
DescriptionDefinitionmakeSelfCallback()Code
780 | function TabbedMenu:makeSelfCallback(func) |
781 | return function(...) |
782 | return func(self, ...) |
783 | end |
784 | end |
new
DescriptionDefinitionnew()Code
48 | function TabbedMenu:new(target, customMt, messageCenter, l10n, inputManager) |
49 | local self = ScreenElement:new(target, customMt or TabbedMenu_mt) |
50 | |
51 | self:registerControls(TabbedMenu.CONTROLS) |
52 | |
53 | self.messageCenter = messageCenter |
54 | self.l10n = l10n |
55 | self.inputManager = inputManager |
56 | |
57 | self.pageFrames = {} -- FrameElement instances array in order of display |
58 | self.pageTabs = {} -- Page tabs in the header, {FrameElement -> ListItemElement} |
59 | self.pageTypeControllers = {} -- Mapping of page FrameElement sub-classes to the controller instances |
60 | self.pageRoots = {} -- Mapping of page controller instances to their original root GuiElements |
61 | self.pageEnablingPredicates = {} -- Mapping of page controller instances to enabling predicate functions (if return true -> enable) |
62 | self.disabledPages = {} -- hash of disabled paging controllers to avoid re-activation in updatePages() |
63 | |
64 | self.currentPageId = 1 |
65 | self.currentPageName = "" -- currently active page name for focus context setting |
66 | self.currentPage = nil -- current page controller reference |
67 | |
68 | self.restorePageIndex = 1 -- memorized menu page mapping index (initialize on index 1 for the map overview) |
69 | |
70 | self.buttonActionCallbacks = {} -- InputAction name -> function |
71 | self.defaultButtonActionCallbacks = {} -- InputAction name -> function |
72 | self.defaultMenuButtonInfoByActions = {} |
73 | self.customButtonEvents = {} -- array of event IDs from InputBinding |
74 | |
75 | self.clickBackCallback = NO_CALLBACK |
76 | |
77 | self.frameClosePageNextCallback = self:makeSelfCallback(self.onPageNext) |
78 | self.frameClosePagePreviousCallback = self:makeSelfCallback(self.onPagePrevious) |
79 | |
80 | -- Subclass configuration |
81 | self.performBackgroundBlur = false |
82 | |
83 | return self |
84 | end |
onButtonBack
DescriptionDefinitiononButtonBack()Code
615 | function TabbedMenu:onButtonBack() |
616 | self:exitMenu() |
617 | end |
onClickActivate
DescriptionHandle menu activate input event. Bound to save the game.Definition
onClickActivate()Code
486 | function TabbedMenu:onClickActivate() |
487 | local eventUnused = TabbedMenu:superClass().onClickActivate(self) |
488 | if eventUnused then |
489 | eventUnused = self:onMenuActionClick(InputAction.MENU_ACTIVATE) |
490 | end |
491 | |
492 | return eventUnused |
493 | end |
onClickBack
DescriptionHandle menu back input event.Definition
onClickBack()Code
458 | function TabbedMenu:onClickBack() |
459 | local eventUnused = true |
460 | |
461 | if self.currentPage:requestClose(self.clickBackCallback) then |
462 | eventUnused = TabbedMenu:superClass().onClickBack(self) |
463 | if eventUnused then |
464 | eventUnused = self:onMenuActionClick(InputAction.MENU_BACK) |
465 | end |
466 | end |
467 | |
468 | return eventUnused |
469 | end |
onClickCancel
DescriptionHandle menu cancel input event. Bound to quite the game to the main menu.Definition
onClickCancel()Code
474 | function TabbedMenu:onClickCancel() |
475 | local eventUnused = TabbedMenu:superClass().onClickCancel(self) |
476 | if eventUnused then |
477 | eventUnused = self:onMenuActionClick(InputAction.MENU_CANCEL) |
478 | end |
479 | |
480 | return eventUnused |
481 | end |
onClickMenuExtra1
DescriptionHandle menu extra 1 input event. Used for various functions when convenient buttons run out.Definition
onClickMenuExtra1()Code
498 | function TabbedMenu:onClickMenuExtra1() |
499 | local eventUnused = TabbedMenu:superClass().onClickMenuExtra1(self) |
500 | if eventUnused then |
501 | eventUnused = self:onMenuActionClick(InputAction.MENU_EXTRA_1) |
502 | end |
503 | |
504 | return eventUnused |
505 | end |
onClickMenuExtra2
DescriptionHandle menu extra 2 input event. Used for various functions when convenient buttons run out.Definition
onClickMenuExtra2()Code
510 | function TabbedMenu:onClickMenuExtra2() |
511 | local eventUnused = TabbedMenu:superClass().onClickMenuExtra2(self) |
512 | if eventUnused then |
513 | eventUnused = self:onMenuActionClick(InputAction.MENU_EXTRA_2) |
514 | end |
515 | |
516 | return eventUnused |
517 | end |
onClickOk
DescriptionHandle menu confirmation input event.Definition
onClickOk()Code
450 | function TabbedMenu:onClickOk() |
451 | -- do not call the super class event here so we can always handle this event any way we need |
452 | local eventUnused = self:onMenuActionClick(InputAction.MENU_ACCEPT) |
453 | return eventUnused |
454 | end |
onClickPageSelection
DescriptionHandle activation of page selection.Definition
onClickPageSelection()Code
521 | function TabbedMenu:onClickPageSelection(state) |
522 | if self.pagingElement:setPage(state) then |
523 | self:playSample(GuiSoundPlayer.SOUND_SAMPLES.PAGING) |
524 | end |
525 | end |
onClose
DescriptionHandle in-game menu closing event.Definition
onClose()Code
162 | function TabbedMenu:onClose(element) |
163 | if self.currentPage ~= nil then |
164 | self.currentPage:onFrameClose() -- the current page gets its specific close event first |
165 | end |
166 | |
167 | TabbedMenu:superClass().onClose(self) |
168 | |
169 | if self.performBackgroundBlur then |
170 | g_depthOfFieldManager:setBlurState(false) |
171 | end |
172 | |
173 | self.inputManager:storeEventBindings() -- reset any disabled bindings for page custom input in menu context |
174 | self:clearMenuButtonActions() |
175 | |
176 | self.restorePageIndex = self.pageSelector:getState() |
177 | |
178 | if self.gameState ~= nil then |
179 | g_currentMission:resetGameState() |
180 | end |
181 | end |
onGuiSetupFinished
DescriptionDefinitiononGuiSetupFinished()Code
97 | function TabbedMenu:onGuiSetupFinished() |
98 | TabbedMenu:superClass().onGuiSetupFinished(self) |
99 | |
100 | self.clickBackCallback = self:makeSelfCallback(self.onButtonBack) |
101 | |
102 | -- take the tab template out of the element hierarchy, later we clone it as needed (and delete it separately) |
103 | self.pagingTabTemplate:unlinkElement() |
104 | |
105 | self:setupMenuButtonInfo() |
106 | |
107 | self.header.parent:addElement(self.header) -- re-add (will remove first, does not copy) header as last child to draw on top |
108 | end |
onMenuActionClick
DescriptionHandle a menu action click by calling one of the menu button callbacks.Definition
onMenuActionClick()Return Values
bool | True | if no callback was present and no action was taken, false otherwise |
439 | function TabbedMenu:onMenuActionClick(menuActionName) |
440 | local buttonCallback = self.buttonActionCallbacks[menuActionName] |
441 | if buttonCallback ~= nil and buttonCallback ~= NO_CALLBACK then |
442 | return buttonCallback() or false |
443 | end |
444 | |
445 | return true |
446 | end |
onMenuOpened
DescriptionCalled when opening the menu, after changing the pageDefinition
onMenuOpened()Code
621 | function TabbedMenu:onMenuOpened() |
622 | end |
onOpen
DescriptionHandle in-game menu opening event.Definition
onOpen()Code
130 | function TabbedMenu:onOpen(element) |
131 | TabbedMenu:superClass().onOpen(self) |
132 | |
133 | if self.performBackgroundBlur then |
134 | g_depthOfFieldManager:setBlurState(true) |
135 | end |
136 | |
137 | self:playSample(GuiSoundPlayer.SOUND_SAMPLES.PAGING) |
138 | |
139 | if self.gameState ~= nil then |
140 | g_gameStateManager:setGameState(self.gameState) |
141 | end |
142 | |
143 | -- Disable all focus sounds. We play our own for opening the menu |
144 | self:setSoundSuppressed(true) |
145 | |
146 | -- setup menus |
147 | self:updatePages() |
148 | |
149 | -- restore last selected page |
150 | local restorePageMappingIndex = 1 |
151 | if self.restorePageIndex ~= nil then |
152 | self.pageSelector:setState(self.restorePageIndex, true) |
153 | end |
154 | |
155 | self:setSoundSuppressed(false) |
156 | |
157 | self:onMenuOpened() |
158 | end |
onPageChange
DescriptionHandle changing to another menu page.Definition
onPageChange()Code
545 | function TabbedMenu:onPageChange(pageIndex, pageMappingIndex, element, skipTabVisualUpdate) |
546 | -- ask the paging element for the current page which is safer than the currentPage reference (may not be initialized) |
547 | local prevPage = self.pagingElement:getPageElementByIndex(self.currentPageId) |
548 | prevPage:onFrameClose() |
549 | prevPage:setVisible(false) |
550 | |
551 | self.inputManager:storeEventBindings() -- reset any disabled bindings for page custom input in menu context |
552 | |
553 | local page = self.pagingElement:getPageElementByIndex(pageIndex) |
554 | self.currentPage = page |
555 | self.currentPageName = page.name -- store page name for FocusManager GUI context override in update() |
556 | |
557 | if not skipTabVisualUpdate then |
558 | self.currentPageId = pageIndex |
559 | |
560 | -- clear profiles on tabs |
561 | for _, element in pairs(self.pagingTabList.listItems) do |
562 | element:applyProfile(TabbedMenu.PROFILE.PAGE_TAB) |
563 | end |
564 | |
565 | local activeTab = self.pageTabs[page] |
566 | if activeTab ~= nil then |
567 | activeTab:applyProfile(TabbedMenu.PROFILE.PAGE_TAB_ACTIVE) |
568 | end |
569 | self:updatePageTabDisplay() |
570 | end |
571 | |
572 | page:setVisible(true) |
573 | page:setSoundSuppressed(true) |
574 | FocusManager:setGui(page.name) |
575 | page:setSoundSuppressed(false) |
576 | page:onFrameOpen() |
577 | |
578 | self:updateButtonsPanel(page) |
579 | end |
onPageClicked
DescriptionDefinitiononPageClicked()Code
235 | function TabbedMenu:onPageClicked(oldPage) |
236 | end |
onPageNext
DescriptionHandle next page event.Definition
onPageNext()Code
537 | function TabbedMenu:onPageNext() |
538 | if self.currentPage:requestClose(self.frameClosePageNextCallback) then |
539 | TabbedMenu:superClass().onPageNext(self) |
540 | end |
541 | end |
onPagePrevious
DescriptionHandle previous page event.Definition
onPagePrevious()Code
529 | function TabbedMenu:onPagePrevious() |
530 | if self.currentPage:requestClose(self.frameClosePagePreviousCallback) then |
531 | TabbedMenu:superClass().onPagePrevious(self) |
532 | end |
533 | end |
onPageUpdate
DescriptionHandle a page being disabled.Definition
onPageUpdate()Code
610 | function TabbedMenu:onPageUpdate() |
611 | end |
rebuildTabList
DescriptionRebuild page tab list in order.Definition
rebuildTabList()Code
248 | function TabbedMenu:rebuildTabList() |
249 | for i = #self.pagingTabList.listItems, 1, -1 do |
250 | local tab = self.pagingTabList.listItems[i] |
251 | self.pagingTabList:removeElement(tab) |
252 | end |
253 | |
254 | for _, page in ipairs(self.pageFrames) do |
255 | local tab = self.pageTabs[page] |
256 | if tab:getIsVisible() then |
257 | self.pagingTabList:addElement(tab) |
258 | end |
259 | end |
260 | |
261 | self.pagingTabList.firstVisibleItem = 1 |
262 | end |
registerPage
DescriptionRegister a page frame element in the menu. This does not add the page to the paging component of the menu.Definition
registerPage(table pageFrameElement, int position, function enablingPredicateFunction)Arguments
table | pageFrameElement | Page FrameElement instance |
int | position | [optional] Page position index in menu |
function | enablingPredicateFunction | [optional] A function which returns the current enabling state of the page at any time. If the function returns true, the page should be enabled. If no argument is given, the page is always enabled. |
636 | function TabbedMenu:registerPage(pageFrameElement, position, enablingPredicateFunction) |
637 | if position == nil then |
638 | position = #self.pageFrames + 1 |
639 | else |
640 | position = math.max(1, math.min(#self.pageFrames + 1, position)) |
641 | end |
642 | |
643 | table.insert(self.pageFrames, position, pageFrameElement) |
644 | self.pageTypeControllers[pageFrameElement:class()] = pageFrameElement |
645 | local pageRoot = pageFrameElement:getFirstDescendant() |
646 | self.pageRoots[pageFrameElement] = pageRoot |
647 | self.pageEnablingPredicates[pageFrameElement] = enablingPredicateFunction |
648 | |
649 | pageFrameElement:setVisible(false) -- set invisible at the start to allow visibility-based behavior for pages |
650 | |
651 | return pageRoot, position |
652 | end |
removePage
DescriptionRemove a page from the menu at runtime by its class type. The removed page is also deleted, including all of its children. Note that this method removes the page for an entire game run, because the UI is loaded on game start. If you only need to disable a page, use TabbedMenu:setPageEnabled() instead. The method will not remove game default pages, but only disable them.Definition
removePage(table pageFrameClass)Arguments
table | pageFrameClass | Class table of a FrameElement sub-class |
736 | function TabbedMenu:removePage(pageFrameClass) |
737 | local defaultPage = self.pageTypeControllers[pageFrameClass] |
738 | if self.defaultPageElementIDs[defaultPage] ~= nil then |
739 | self:setPageEnabled(pageFrameClass, false) |
740 | else |
741 | local needDelete, pageController, pageRoot, pageTab = self:unregisterPage(pageFrameClass) |
742 | if needDelete then |
743 | self.pagingElement:removeElement(pageRoot) |
744 | pageRoot:delete() |
745 | pageController:delete() |
746 | |
747 | self.pagingTabList:removeElement(pageTab) |
748 | pageTab:delete() |
749 | end |
750 | end |
751 | end |
reset
DescriptionDefinitionreset()Code
118 | function TabbedMenu:reset() |
119 | TabbedMenu:superClass().reset(self) |
120 | |
121 | self.currentPageId = 1 |
122 | self.currentPageName = "" |
123 | self.currentPage = nil |
124 | |
125 | self.restorePageIndex = 1 |
126 | end |
setPageEnabled
DescriptionSet the enabled state of a page identified by its controller class type. This will also set the controller's state, so it can react to being enabled/disabled. The setting will persist through calls to TabbedMenu:reset() and must be reverted manually, if necessary.Definition
setPageEnabled(table pageFrameClass, bool isEnabled)Arguments
table | pageFrameClass | Class table of a FrameElement sub-class |
bool | isEnabled | True for enabled, false for disabled |
759 | function TabbedMenu:setPageEnabled(pageFrameClass, isEnabled) |
760 | local pageController = self.pageTypeControllers[pageFrameClass] |
761 | if pageController ~= nil then |
762 | local pageId = self.pagingElement:getPageIdByElement(pageController) |
763 | self.pagingElement:setPageIdDisabled(pageId, not isEnabled) |
764 | |
765 | pageController:setDisabled(not isEnabled) |
766 | |
767 | if not isEnabled then |
768 | self.disabledPages[pageController] = pageController |
769 | else |
770 | self.disabledPages[pageController] = nil |
771 | end |
772 | |
773 | self:setPageTabEnabled(pageController, isEnabled) |
774 | self.pagingTabList:updateItemPositions() |
775 | end |
776 | end |
setPageSelectorTitles
DescriptionGet page titles from currently visible pages and apply to the selector element.Definition
setPageSelectorTitles()Code
412 | function TabbedMenu:setPageSelectorTitles() |
413 | local texts = self.pagingElement:getPageTitles() |
414 | |
415 | self.pageSelector:setTexts(texts) |
416 | self.pageSelector:setDisabled(#texts == 1) |
417 | |
418 | -- Update state without triggering any events |
419 | local id = self.pagingElement:getCurrentPageId() |
420 | self.pageSelector.state = self.pagingElement:getPageMappingIndex(id) |
421 | end |
setPageTabEnabled
DescriptionSet enabled state of a page tab in the header.Definition
setPageTabEnabled()Code
240 | function TabbedMenu:setPageTabEnabled(pageController, isEnabled) |
241 | local tab = self.pageTabs[pageController] |
242 | tab:setDisabled(not isEnabled) |
243 | tab:setVisible(isEnabled) |
244 | end |
setupMenuButtonInfo
DescriptionSetup the menu buttons. Override to initializeDefinition
setupMenuButtonInfo()Code
207 | function TabbedMenu:setupMenuButtonInfo() |
208 | end |
unregisterPage
DescriptionUnregister a page frame element identified by class from the menu. This does not remove the page from the paging component of the menu or the corresponding page tab from the header.Definition
unregisterPage(table pageFrameClass)Arguments
table | pageFrameClass | FrameElement descendant class of a page which was previously registered |
bool | True | if there was a page of the given class and it was unregistered |
table | Unregistered | page controller instance or nil |
table | Unregistered | page root GuiElement instance or nil |
table | Unregistered | page tab ListElement instance of nil |
663 | function TabbedMenu:unregisterPage(pageFrameClass) |
664 | local pageController = self.pageTypeControllers[pageFrameClass] |
665 | local pageTab = nil |
666 | local pageRoot = nil |
667 | if pageController ~= nil then |
668 | local pageRemoveIndex = -1 |
669 | for i, page in ipairs(self.pageFrames) do |
670 | if page == pageController then |
671 | pageRemoveIndex = i |
672 | break |
673 | end |
674 | end |
675 | |
676 | table.remove(self.pageFrames, pageRemoveIndex) |
677 | |
678 | local pageRoot = self.pageRoots[pageController] |
679 | self.pageRoots[pageController] = nil |
680 | self.pageTypeControllers[pageFrameClass] = nil |
681 | self.pageEnablingPredicates[pageController] = nil |
682 | |
683 | self.pageTabs[pageController] = nil |
684 | end |
685 | |
686 | return pageController ~= nil, pageController, pageRoot, pageTab |
687 | end |
update
DescriptionUpdate the menu state each frame. This uses a state machine approach for the game saving process.Definition
update()Code
186 | function TabbedMenu:update(dt) |
187 | TabbedMenu:superClass().update(self, dt) |
188 | |
189 | -- Enforce the current page as the focus context. This is required because dialogs on dialogs (e.g. during saving) |
190 | -- can break reverting to a valid focus state in this menu. |
191 | if FocusManager.currentGui ~= self.currentPageName and not g_gui:getIsDialogVisible() then |
192 | FocusManager:setGui(self.currentPageName) |
193 | end |
194 | |
195 | if self.currentPage ~= nil and self.currentPage:isMenuButtonInfoDirty() then |
196 | self:assignMenuButtonInfo(self.currentPage:getMenuButtonInfo()) |
197 | self.currentPage:clearMenuButtonInfoDirty() |
198 | end |
199 | end |
updateButtonsPanel
DescriptionUpdate the buttons panel when a given page is visible.Definition
updateButtonsPanel()Code
583 | function TabbedMenu:updateButtonsPanel(page) |
584 | -- assign button info anyway to make at least MENU_BACK work in all cases: |
585 | local buttonInfo = self:getPageButtonInfo(page) |
586 | self:assignMenuButtonInfo(buttonInfo) |
587 | |
588 | local pageSize = page:getMainElementSize() |
589 | local pagePos = page:getMainElementPosition() |
590 | self.buttonsPanel:setSize(pageSize[1], nil) -- only set width |
591 | self.buttonsPanel:setAbsolutePosition(pagePos[1], pagePos[2] - self.buttonsPanel.size[2]) |
592 | end |
updatePageControlVisibility
DescriptionDefinitionupdatePageControlVisibility()Code
321 | function TabbedMenu:updatePageControlVisibility() |
322 | local showButtons = #self.pagingTabList.listItems ~= 1 |
323 | |
324 | self.pagingButtonLeft:setVisible(showButtons) |
325 | self.pagingButtonRight:setVisible(showButtons) |
326 | end |
updatePages
DescriptionUpdate page enabled states.Definition
updatePages()Code
266 | function TabbedMenu:updatePages() |
267 | for pageElement, predicate in pairs(self.pageEnablingPredicates) do |
268 | local pageId = self.pagingElement:getPageIdByElement(pageElement) |
269 | local enable = self.disabledPages[pageElement] == nil and predicate() |
270 | |
271 | self.pagingElement:setPageIdDisabled(pageId, not enable) |
272 | self:setPageTabEnabled(pageElement, enable) |
273 | end |
274 | |
275 | self:rebuildTabList() |
276 | self:updatePageTabDisplay() |
277 | self:setPageSelectorTitles() |
278 | self:updatePageControlVisibility() |
279 | end |
updatePageTabDisplay
DescriptionUpdate page tabs display after any page changes.Definition
updatePageTabDisplay()Code
283 | function TabbedMenu:updatePageTabDisplay() |
284 | -- center page tabs manually: |
285 | local width = 0 |
286 | for i = 1, #self.pagingTabList.listItems do |
287 | width = width + self.pagingTabList.listItemWidth + self.pagingTabList.listItemPadding |
288 | end |
289 | |
290 | self.pagingTabList.listItemStartXOffset = (self.pagingTabList.size[1] - width) * 0.5 |
291 | self.pagingTabList:updateItemPositions() |
292 | |
293 | -- remove frame borders on tabs to avoid visual overlaps, but first reset visibility |
294 | for i, listItem in ipairs(self.pagingTabList.listItems) do |
295 | listItem:toggleFrameSide(GuiElement.FRAME_LEFT, true) |
296 | listItem:toggleFrameSide(GuiElement.FRAME_TOP, true) |
297 | listItem:toggleFrameSide(GuiElement.FRAME_RIGHT, true) |
298 | listItem:toggleFrameSide(GuiElement.FRAME_BOTTOM, true) |
299 | end |
300 | |
301 | for i, listItem in ipairs(self.pagingTabList.listItems) do |
302 | local prevItem = self.pagingTabList.listItems[i - 1] |
303 | local nextItem = self.pagingTabList.listItems[i + 1] |
304 | |
305 | if listItem.profile == TabbedMenu.PROFILE.PAGE_TAB_ACTIVE then |
306 | if prevItem ~= nil then |
307 | prevItem:toggleFrameSide(GuiElement.FRAME_RIGHT, false) |
308 | end |
309 | |
310 | if nextItem ~= nil then |
311 | nextItem:toggleFrameSide(GuiElement.FRAME_LEFT, false) |
312 | end |
313 | elseif i > 1 then |
314 | listItem:toggleFrameSide(GuiElement.FRAME_LEFT, false) |
315 | end |
316 | end |
317 | end |