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
PagingElement
DescriptionPaging control element. Organizes grouped elements into pages to be displayed one at a time. To set it up, one defines several same-sized container elements (e.g. bare GuiElement) as children of the PagingElement to hold the pages' contents. The pages should be given #name properties which are resolved to a localization text with a prepended "ui_" prefix. On loading, any named child element of this PagingElement will be added as a page.Parent
GuiElementXML Configuration Parameters
GuiElement#onPageChange | callback [optional] onPageChangeCallback(pageIndex, pageMappingIndex, element) Called when the page changes. Receives the current index in all pages, the current index in all enabled pages and this element. |
GuiElement#onPageUpdate | callback [optional] onPageUpdateCallback(pageInfo) Called when a page is disabled. Receives the page information {id=[index], mappingIndex=[mappingIndex], idName=[elementId], element=[element], title=[title], disabled=[true/false]} |
Functions
- addElement
- copyAttributes
- getCurrentPageId
- getIsPageDisabled
- getPageById
- getPageMappingIndex
- loadFromXML
- new
- onGuiSetupFinished
- removeElement
- setPageDisabled
- updatePageMapping
addElement
DescriptionDefinitionaddElement()Code
97 | function PagingElement:addElement(element) |
98 | PagingElement:superClass().addElement(self, element) |
99 | if element.name ~= nil and g_i18n:hasText("ui_"..element.name) then |
100 | self:addPage(string.upper(element.name), element, g_i18n:getText("ui_"..element.name)) |
101 | else |
102 | self:addPage(tostring(element), element, "") |
103 | end |
104 | end |
copyAttributes
DescriptionDefinitioncopyAttributes()Code
54 | function PagingElement:copyAttributes(src) |
55 | PagingElement:superClass().copyAttributes(self, src) |
56 | self.onPageChangeCallback = src.onPageChangeCallback |
57 | self.onPageUpdateCallback = src.onPageUpdateCallback |
58 | |
59 | GuiMixin.cloneMixin(IndexChangeSubjectMixin, src, self) |
60 | end |
getCurrentPageId
DescriptionGet the page ID of the currently displayed page.Definition
getCurrentPageId()Code
229 | function PagingElement:getCurrentPageId() |
230 | return self.pages[self.currentPageIndex].id |
231 | end |
getIsPageDisabled
DescriptionDetermine if a page, identified by page ID, is disabled.Definition
getIsPageDisabled()Code
241 | function PagingElement:getIsPageDisabled(pageId) |
242 | return self.idPageHash[pageId].disabled |
243 | end |
getPageById
DescriptionGet a page by ID.Definition
getPageById()Code
247 | function PagingElement:getPageById(pageId) |
248 | return self.idPageHash[pageId] |
249 | end |
getPageMappingIndex
DescriptionGet the index of a page in the page mappings (only visible pages) by page ID.Definition
getPageMappingIndex()Code
235 | function PagingElement:getPageMappingIndex(pageId) |
236 | return self.idPageHash[pageId].mappingIndex |
237 | end |
loadFromXML
DescriptionDefinitionloadFromXML()Code
45 | function PagingElement:loadFromXML(xmlFile, key) |
46 | PagingElement:superClass().loadFromXML(self, xmlFile, key) |
47 | |
48 | self:addCallback(xmlFile, key .. "#onPageChange", "onPageChangeCallback") |
49 | self:addCallback(xmlFile, key .. "#onPageUpdate", "onPageUpdateCallback") |
50 | end |
new
DescriptionDefinitionnew()Code
23 | function PagingElement:new(target, custom_mt) |
24 | if custom_mt == nil then |
25 | custom_mt = PagingElement_mt |
26 | end |
27 | |
28 | local self = GuiElement:new(target, custom_mt) |
29 | self:include(IndexChangeSubjectMixin)-- add index change subject mixin for paging observers |
30 | |
31 | self.pageIdCount = 1 |
32 | |
33 | self.pages = {} -- list of pages |
34 | self.idPageHash = {} -- hash of page ID to actual page |
35 | self.pageMapping = {} -- map of visible page indices to all page indices |
36 | |
37 | self.currentPageIndex = 1 |
38 | self.currentPageMappingIndex = 1 |
39 | |
40 | return self |
41 | end |
onGuiSetupFinished
DescriptionDefinitiononGuiSetupFinished()Code
64 | function PagingElement:onGuiSetupFinished() |
65 | PagingElement:superClass().onGuiSetupFinished(self) |
66 | self:updatePageMapping() |
67 | end |
removeElement
DescriptionDefinitionremoveElement()Code
222 | function PagingElement:removeElement(element) |
223 | PagingElement:superClass().removeElement(self, element) |
224 | self:removePageByElement(element) -- also remove any page using that element as its root node |
225 | end |
setPageDisabled
DescriptionDefinitionsetPageDisabled()Code
253 | function PagingElement:setPageDisabled(page, disabled) |
254 | if page ~= nil then |
255 | page.disabled = disabled |
256 | self:updatePageMapping() |
257 | self:raiseCallback("onPageUpdateCallback", page, self) |
258 | end |
259 | end |
updatePageMapping
DescriptionDefinitionupdatePageMapping()Code
272 | function PagingElement:updatePageMapping() |
273 | self.pageMapping = {} |
274 | self.pageTitles = {} |
275 | local currentPage = self.pages[self.currentPageIndex] |
276 | |
277 | for i, page in ipairs(self.pages) do |
278 | if not page.disabled then |
279 | table.insert(self.pageMapping, i) |
280 | table.insert(self.pageTitles, page.title) |
281 | page.mappingIndex = #self.pageMapping |
282 | else |
283 | if page == currentPage then |
284 | -- force page resetting |
285 | currentPage = nil |
286 | end |
287 | page.mappingIndex = 1 |
288 | end |
289 | end |
290 | |
291 | if currentPage == nil then |
292 | self.currentPageMappingIndex = MathUtil.clamp(self.currentPageMappingIndex, 1, #self.pageMapping) |
293 | if self.currentPageMappingIndex > 0 then |
294 | self:setPage(self.currentPageMappingIndex) |
295 | end |
296 | else |
297 | self:notifyIndexChange(self.currentPageMappingIndex, #self.pageMapping) -- notify change in number of pages |
298 | end |
299 | end |