Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- AnimalScreen
- AnimationElement
- BitmapElement
- BoxLayoutElement
- BreadcrumbsElement
- ButtonElement
- ButtonOverlay
- ChatWindow
- CheckedOptionElement
- ClearElement
- ColorPickButtonElement
- ConstructionScreen
- ContextActionDisplay
- ControlBarDisplay
- DialogElement
- DynamicFadedBitmapElement
- FillLevelsDisplay
- FlowLayoutElement
- FocusManager
- FrameElement
- FrameReferenceElement
- GameInfoDisplay
- GameInfoDisplayMobile
- GamePausedDisplay
- Gui
- GuiDataSource
- GuiElement
- GuiMixin
- GuiOverlay
- GuiProfile
- GuiSoundPlayer
- GuiTopDownCamera
- GuiTopDownCursor
- GuiUtils
- HUDDisplayElement
- HUDElement
- HUDFrameElement
- HUDPopupMessage
- HUDSliderElement
- HUDTextDisplay
- IndexChangeSubjectMixin
- IndexStateElement
- InfoDisplay
- InfoHUDBox
- InGameIcon
- IngameMap
- IngameMapElement
- InputGlyphElement
- InputGlyphElementUI
- InputHelpDisplay
- KeyValueInfoHUDBox
- ListElement
- ListItemElement
- MapOverlayGenerator
- MixerWagonHUDExtension
- MultiTextOptionElement
- MultiValueTween
- Overlay
- PagingElement
- PictureElement
- PlatformIconElement
- PlayerControlPadDisplay
- PlaySampleMixin
- RenderElement
- RoundStatusBar
- ScreenElement
- ScrollingLayoutElement
- SettingsModel
- SideNotification
- SideNotificationMobile
- SliderElement
- SpeakerDisplay
- SpeedMeterDisplay
- SpeedSliderDisplay
- StatusBar
- SteeringSliderDisplay
- TabbedMenu
- TabbedMenuFrameElement
- TabbedMenuWithDetails
- TableElement
- TableHeaderElement
- TerrainLayerElement
- TextBackdropElement
- TextElement
- TextInputElement
- ThreePartBitmapElement
- TimerElement
- ToggleButtonElement
- TopNotification
- Tween
- TweenSequence
- VariableWorkWidthHUDExten...
- VehicleHUDExtension
- VehicleSchemaDisplay
- VideoElement
- WardrobeScreen
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
Gui
DescriptionGraphical User Interface controller. Builds UI from configurations, provides dialog display and propagates UI input.Functions
- addFrame
- addScreen
- assignPlaySampleCallback
- changeScreen
- closeAllDialogs
- closeDialog
- closeDialogByName
- draw
- enterMenuContext
- getIsDialogVisible
- getIsGuiVisible
- getIsOverlayGuiVisible
- getProfile
- getScreenInstanceByClass
- hasElementInputFocus
- initGuiLibrary
- keyEvent
- leaveMenuContext
- loadGui
- loadGuiRec
- loadMapData
- loadPresets
- loadProfiles
- loadProfileSet
- loadTraits
- makeChangeScreenClosure
- makePlaySampleClosure
- makeToggleCustomInputContextClosure
- mouseEvent
- new
- notifyControls
- onMenuInput
- onReleaseInput
- onReleaseMovement
- registerMenuInput
- resolveFrameReference
- setClient
- setCurrentMission
- setServer
- showAnimalDialog
- showColorPickerDialog
- showConnectionFailedDialog
- showDenyAcceptDialog
- showDialog
- showEditFarmDialog
- showGui
- showInfoDialog
- showLeaseYesNoDialog
- showLicensePlateDialog
- showMessageDialog
- showOptionDialog
- showPasswordDialog
- showPlaceableInfoDialog
- showRefillDialog
- showSellItemDialog
- showServerSettingsDialog
- showSiloDialog
- showSleepDialog
- showTextInputDialog
- showTransferMoneyDialog
- showUnblockDialog
- showVoteDialog
- showYesNoDialog
- toggleCustomInputContext
- touchEvent
- unloadMapData
- update
addFrame
DescriptionAdd the instance of a specific reusable GUI frame.Definition
addFrame()Code
995 | function Gui:addFrame(frameController, frameRootElement) |
996 | -- TODO: switch to class keys like screens |
997 | self.frames[frameController.name] = frameRootElement |
998 | |
999 | frameController:setChangeScreenCallback(self.changeScreenClosure) |
1000 | frameController:setInputContextCallback(self.toggleCustomInputContextClosure) |
1001 | frameController:setPlaySampleCallback(self.playSampleClosure) |
1002 | end |
addScreen
DescriptionAdd the instance of a specific GUI screen.Definition
addScreen()Code
1006 | function Gui:addScreen(screenClass, screenInstance, screenRootElement) |
1007 | self.screens[screenClass] = screenRootElement |
1008 | self.screenControllers[screenClass] = screenInstance |
1009 | |
1010 | -- TODO: use the same pattern for dialog calling from screens |
1011 | screenInstance:setChangeScreenCallback(self.changeScreenClosure) |
1012 | screenInstance:setInputContextCallback(self.toggleCustomInputContextClosure) |
1013 | screenInstance:setPlaySampleCallback(self.playSampleClosure) |
1014 | end |
assignPlaySampleCallback
DescriptionAssign the play sample closure to a GUI element which has the PlaySampleMixin included.Definition
assignPlaySampleCallback(table guiElement)Arguments
table | guiElement | GuiElement instance |
table | The | GuiElement instance given in the guiElement parameter |
964 | function Gui:assignPlaySampleCallback(guiElement) |
965 | if guiElement:hasIncluded(PlaySampleMixin) then |
966 | guiElement:setPlaySampleCallback(self.playSampleClosure) |
967 | end |
968 | |
969 | return guiElement |
970 | end |
changeScreen
DescriptionChange the currently displayed screen.Definition
changeScreen(table source, table screenClass, table returnScreenClass)Arguments
table | source | Source screen instance |
table | screenClass | Class table of the requested screen to change to or nil to close the GUI |
table | returnScreenClass | [optional] Class table of the screen which will be opened on a "back" action in the new screen. |
table | Root | GuiElement instance of target screen |
871 | function Gui:changeScreen(source, screenClass, returnScreenClass) |
872 | local screenController = self.screenControllers[screenClass] |
873 | if screenClass ~= nil and screenController == nil then |
874 | Logging.devWarning("UI '%s' not found", ClassUtil.getClassName(screenClass)) |
875 | return nil |
876 | end |
877 | |
878 | self:closeAllDialogs() |
879 | |
880 | local isMenuOpening = not self:getIsGuiVisible() |
881 | local screenElement = self.screens[screenClass] |
882 | |
883 | if source ~= nil then |
884 | source:onClose() |
885 | end |
886 | |
887 | if source == nil and self.currentGui ~= nil then |
888 | self.currentGui:onClose() |
889 | end |
890 | |
891 | local screenName = screenElement and screenElement.name or "" |
892 | self.currentGui = screenElement |
893 | self.currentGuiName = screenName |
894 | self.currentListener = screenElement |
895 | |
896 | if screenElement ~= nil and isMenuOpening then |
897 | self.messageCenter:publish(MessageType.GUI_BEFORE_OPEN) |
898 | self:enterMenuContext() |
899 | end |
900 | |
901 | FocusManager:setGui(screenName) |
902 | |
903 | screenController = self.screenControllers[screenClass] |
904 | if screenElement ~= nil and screenController ~= nil then |
905 | screenController:setReturnScreenClass(returnScreenClass or screenController.returnScreenClass) -- it's fine if its nil, the value is being checked |
906 | screenElement:onOpen() |
907 | |
908 | if isMenuOpening then |
909 | self.messageCenter:publish(MessageType.GUI_AFTER_OPEN) |
910 | end |
911 | end |
912 | |
913 | if not self:getIsGuiVisible() then |
914 | self.messageCenter:publish(MessageType.GUI_BEFORE_CLOSE) |
915 | -- clear input context if GUI is now completely closed (including dialogs) |
916 | self:leaveMenuContext() |
917 | self.messageCenter:publish(MessageType.GUI_AFTER_CLOSE) |
918 | end |
919 | |
920 | g_adsSystem:setGroupActive(AdsSystem.OCCLUSION_GROUP.UI, self.currentGui ~= nil) |
921 | |
922 | return screenElement -- required by some screens to transfer state to the next view |
923 | end |
closeAllDialogs
DescriptionClose all open dialogs.Definition
closeAllDialogs()Code
578 | function Gui:closeAllDialogs() |
579 | for _,v in ipairs(self.dialogs) do |
580 | self:closeDialog(v) |
581 | end |
582 | end |
closeDialog
DescriptionClose a dialog identified by its root GuiElement. This is always called when a dialog is closed, usually by itself.Definition
closeDialog()Code
531 | function Gui:closeDialog(gui) |
532 | for k,v in ipairs(self.dialogs) do |
533 | if v == gui then |
534 | v:onClose() |
535 | table.remove(self.dialogs, k) |
536 | |
537 | if gui.blurAreaActive then |
538 | g_depthOfFieldManager:popArea() |
539 | gui.blurAreaActive = false |
540 | end |
541 | |
542 | if self.currentListener == gui then |
543 | if #self.dialogs > 0 then |
544 | self.currentListener = self.dialogs[#self.dialogs] |
545 | else |
546 | if self.currentGui == gui then |
547 | self.currentListener = nil |
548 | self.currentGui = nil |
549 | else |
550 | self.currentListener = self.currentGui |
551 | end |
552 | end |
553 | |
554 | if self.currentListener ~= nil then |
555 | FocusManager:setGui(self.currentListener.name) |
556 | if self.focusElements[self.currentListener] ~= nil then |
557 | FocusManager:setFocus(self.focusElements[self.currentListener]) |
558 | self.focusElements[self.currentListener] = nil |
559 | end |
560 | end |
561 | end |
562 | |
563 | -- revert dialog input context |
564 | self.inputManager:revertContext(false) |
565 | |
566 | break |
567 | end |
568 | end |
569 | |
570 | if not self:getIsGuiVisible() then |
571 | -- trigger close screen which dispatches required messages and adjusts input context: |
572 | self:changeScreen(nil) |
573 | end |
574 | end |
closeDialogByName
DescriptionClose a dialog identified by name.Definition
closeDialogByName()Code
521 | function Gui:closeDialogByName(guiName) |
522 | local gui = self.guis[guiName] |
523 | if gui ~= nil then |
524 | self:closeDialog(gui) |
525 | end |
526 | end |
draw
DescriptionDraw the GUI. Propagates draw calls to all active UI elements.Definition
draw()Code
713 | function Gui:draw() |
714 | if self.currentGui ~= nil then |
715 | -- self.currentGui:draw() |
716 | if self.currentGui.target ~= nil then |
717 | if self.currentGui.target.draw ~= nil then |
718 | self.currentGui.target:draw() |
719 | end |
720 | end |
721 | end |
722 | |
723 | for _,v in pairs(self.dialogs) do |
724 | -- v:draw() |
725 | if v.target ~= nil then |
726 | v.target:draw() |
727 | end |
728 | end |
729 | |
730 | if g_uiDebugEnabled then |
731 | local item = FocusManager.currentFocusData.focusElement |
732 | |
733 | local function getName(e) |
734 | if e == nil then |
735 | return "none" |
736 | else |
737 | return e.id or e.profile or e.name |
738 | end |
739 | end |
740 | |
741 | setTextAlignment(RenderText.ALIGN_CENTER) |
742 | renderText(0.5, 0.94, 0.02, "Focused element: " .. getName(item)) |
743 | if item ~= nil then |
744 | renderText(0.5, 0.92, 0.02, "Top element: " .. getName(FocusManager:getNextFocusElement(item, FocusManager.TOP))) |
745 | renderText(0.5, 0.90, 0.02, "Bottom element: " .. getName(FocusManager:getNextFocusElement(item, FocusManager.BOTTOM))) |
746 | renderText(0.5, 0.88, 0.02, "Left element: " .. getName(FocusManager:getNextFocusElement(item, FocusManager.LEFT))) |
747 | renderText(0.5, 0.86, 0.02, "Right element: " .. getName(FocusManager:getNextFocusElement(item, FocusManager.RIGHT))) |
748 | |
749 | local xPixel = 3 / g_screenWidth |
750 | local yPixel = 3 / g_screenHeight |
751 | |
752 | drawFilledRect(item.absPosition[1] - xPixel, item.absPosition[2] - yPixel, item.absSize[1] + 2 * xPixel, yPixel, 1, 0.5, 0, 1) |
753 | drawFilledRect(item.absPosition[1] - xPixel, item.absPosition[2] + item.absSize[2], item.absSize[1] + 2 * xPixel, yPixel, 1, 0.5, 0, 1) |
754 | drawFilledRect(item.absPosition[1] - xPixel, item.absPosition[2], xPixel, item.absSize[2], 1, 0.5, 0, 1) |
755 | drawFilledRect(item.absPosition[1] + item.absSize[1], item.absPosition[2], xPixel, item.absSize[2], 1, 0.5, 0, 1) |
756 | end |
757 | setTextAlignment(RenderText.ALIGN_LEFT) |
758 | end |
759 | end |
enterMenuContext
DescriptionEnter a new menu input context. Menu views which require special input should provide a context name to not collide with the base menu input scheme.Definition
enterMenuContext(string contextName)Arguments
string | contextName | [optional] Custom menu input context name |
976 | function Gui:enterMenuContext(contextName) |
977 | self.inputManager:setContext(contextName or Gui.INPUT_CONTEXT_MENU, true, false) |
978 | self:registerMenuInput() |
979 | self.isInputListening = true |
980 | end |
getIsDialogVisible
DescriptionDetermine if any dialog is visible.Definition
getIsDialogVisible()Code
446 | function Gui:getIsDialogVisible() |
447 | return #self.dialogs > 0 |
448 | end |
getIsGuiVisible
DescriptionDetermine if any menu or dialog is visible.Definition
getIsGuiVisible()Code
440 | function Gui:getIsGuiVisible() |
441 | return self.currentGui ~= nil or self:getIsDialogVisible() |
442 | end |
getIsOverlayGuiVisible
DescriptionDetermine if an overlaid UI view with regular game display is visible, e.g. placement or landscaping.Definition
getIsOverlayGuiVisible()Code
452 | function Gui:getIsOverlayGuiVisible() |
453 | return self.currentGui == self.screens[ConstructionScreen] |
454 | end |
getProfile
DescriptionGet a UI profile by name.Definition
getProfile()Code
396 | function Gui:getProfile(profileName) |
397 | if profileName ~= nil then |
398 | local specialized = false |
399 | |
400 | local defaultProfileName = profileName |
401 | for _, prefix in ipairs(Platform.guiPrefixes) do |
402 | local customProfileName = prefix .. defaultProfileName |
403 | if self.profiles[customProfileName] ~= nil then |
404 | profileName = customProfileName |
405 | specialized = true |
406 | end |
407 | end |
408 | |
409 | if not specialized and Platform.isConsole then |
410 | local consoleProfileName = "console_" .. profileName |
411 | if self.profiles[consoleProfileName] ~= nil then |
412 | profileName = consoleProfileName |
413 | specialized = true |
414 | end |
415 | end |
416 | |
417 | if not specialized and Platform.isMobile then |
418 | local consoleProfileName = "mobile_" .. profileName |
419 | if self.profiles[consoleProfileName] ~= nil then |
420 | profileName = consoleProfileName |
421 | -- specialized = true |
422 | end |
423 | end |
424 | end |
425 | |
426 | if not profileName or not self.profiles[profileName] then |
427 | -- only warn if profile name is wrong, undefined is fine |
428 | if profileName and profileName ~= "" then |
429 | Logging.warning("Could not retrieve GUI profile '%s'. Using base reference profile instead.", tostring(profileName)) |
430 | end |
431 | |
432 | profileName = Gui.GUI_PROFILE_BASE |
433 | end |
434 | |
435 | return self.profiles[profileName] |
436 | end |
getScreenInstanceByClass
DescriptionGet a screen controller instance by class for special cases.Definition
getScreenInstanceByClass(table screenClass)Arguments
table | screenClass | Class table of the requested screen |
table | ScreenElement | descendant instance of the given class or nil if no such instance was registered |
860 | function Gui:getScreenInstanceByClass(screenClass) |
861 | return self.screenControllers[screenClass] |
862 | end |
hasElementInputFocus
DescriptionDetermine if a given GuiElement has input focus.Definition
hasElementInputFocus()Code
848 | function Gui:hasElementInputFocus(element) |
849 | return self.currentListener ~= nil and self.currentListener.target == element |
850 | end |
initGuiLibrary
DescriptionSource in UI modules.Definition
initGuiLibrary(baseDir Base)Arguments
baseDir | Base | scripts directory |
1361 | function Gui.initGuiLibrary(baseDir) |
1362 | source(baseDir .. "/base/GuiProfile.lua") |
1363 | source(baseDir .. "/base/GuiUtils.lua") |
1364 | source(baseDir .. "/base/GuiOverlay.lua") |
1365 | |
1366 | source(baseDir .. "/base/GuiDataSource.lua") |
1367 | |
1368 | source(baseDir .. "/base/GuiMixin.lua") |
1369 | source(baseDir .. "/base/IndexChangeSubjectMixin.lua") |
1370 | source(baseDir .. "/base/PlaySampleMixin.lua") |
1371 | |
1372 | source(baseDir .. "/base/Tween.lua") |
1373 | source(baseDir .. "/base/MultiValueTween.lua") |
1374 | source(baseDir .. "/base/TweenSequence.lua") |
1375 | |
1376 | source(baseDir .. "/elements/GuiElement.lua") |
1377 | source(baseDir .. "/elements/FrameElement.lua") |
1378 | source(baseDir .. "/elements/ScreenElement.lua") |
1379 | source(baseDir .. "/elements/DialogElement.lua") |
1380 | source(baseDir .. "/elements/BitmapElement.lua") |
1381 | source(baseDir .. "/elements/ClearElement.lua") |
1382 | source(baseDir .. "/elements/TextElement.lua") |
1383 | source(baseDir .. "/elements/ButtonElement.lua") |
1384 | source(baseDir .. "/elements/ToggleButtonElement.lua") |
1385 | source(baseDir .. "/elements/ColorPickButtonElement.lua") -- not used anywhere |
1386 | source(baseDir .. "/elements/VideoElement.lua") |
1387 | source(baseDir .. "/elements/SliderElement.lua") |
1388 | source(baseDir .. "/elements/TextInputElement.lua") |
1389 | source(baseDir .. "/elements/ListElement.lua") |
1390 | source(baseDir .. "/elements/MultiTextOptionElement.lua") |
1391 | source(baseDir .. "/elements/CheckedOptionElement.lua") |
1392 | source(baseDir .. "/elements/ListItemElement.lua") |
1393 | source(baseDir .. "/elements/AnimationElement.lua") |
1394 | source(baseDir .. "/elements/TimerElement.lua") -- not used anywhere |
1395 | source(baseDir .. "/elements/BoxLayoutElement.lua") |
1396 | source(baseDir .. "/elements/FlowLayoutElement.lua") |
1397 | source(baseDir .. "/elements/PagingElement.lua") |
1398 | source(baseDir .. "/elements/TableElement.lua") |
1399 | source(baseDir .. "/elements/TableHeaderElement.lua") |
1400 | source(baseDir .. "/elements/IngameMapElement.lua") |
1401 | source(baseDir .. "/elements/IndexStateElement.lua") |
1402 | source(baseDir .. "/elements/FrameReferenceElement.lua") |
1403 | source(baseDir .. "/elements/RenderElement.lua") |
1404 | source(baseDir .. "/elements/BreadcrumbsElement.lua") |
1405 | source(baseDir .. "/elements/ThreePartBitmapElement.lua") |
1406 | source(baseDir .. "/elements/PictureElement.lua") |
1407 | source(baseDir .. "/elements/ScrollingLayoutElement.lua") |
1408 | source(baseDir .. "/elements/MultiOptionElement.lua") |
1409 | source(baseDir .. "/elements/TextBackdropElement.lua") |
1410 | source(baseDir .. "/elements/InputGlyphElementUI.lua") |
1411 | source(baseDir .. "/elements/TerrainLayerElement.lua") |
1412 | source(baseDir .. "/elements/SmoothListElement.lua") |
1413 | source(baseDir .. "/elements/DynamicFadedBitmapElement.lua") |
1414 | source(baseDir .. "/elements/PlatformIconElement.lua") |
1415 | source(baseDir .. "/elements/OptionToggleElement.lua") |
1416 | |
1417 | -- Add new elements here and just above to make them available. |
1418 | local mapping = Gui.CONFIGURATION_CLASS_MAPPING |
1419 | mapping["button"] = ButtonElement |
1420 | mapping["toggleButton"] = ToggleButtonElement |
1421 | mapping["video"] = VideoElement |
1422 | mapping["slider"] = SliderElement |
1423 | mapping["text"] = TextElement |
1424 | mapping["textInput"] = TextInputElement |
1425 | mapping["bitmap"] = BitmapElement |
1426 | mapping["clear"] = ClearElement |
1427 | mapping["list"] = ListElement |
1428 | mapping["multiTextOption"] = MultiTextOptionElement |
1429 | mapping["checkedOption"] = CheckedOptionElement |
1430 | mapping["listItem"] = ListItemElement |
1431 | mapping["animation"] = AnimationElement |
1432 | mapping["timer"] = TimerElement |
1433 | mapping["boxLayout"] = BoxLayoutElement |
1434 | mapping["flowLayout"] = FlowLayoutElement |
1435 | mapping["paging"] = PagingElement |
1436 | mapping["table"] = TableElement |
1437 | mapping["tableHeader"] = TableHeaderElement |
1438 | mapping["ingameMap"] = IngameMapElement |
1439 | mapping["indexState"] = IndexStateElement |
1440 | mapping["frameReference"] = FrameReferenceElement |
1441 | mapping["render"] = RenderElement |
1442 | mapping["breadcrumbs"] = BreadcrumbsElement |
1443 | mapping["threePartBitmap"] = ThreePartBitmapElement |
1444 | mapping["picture"] = PictureElement |
1445 | mapping["scrollingLayout"] = ScrollingLayoutElement |
1446 | mapping["multiOption"] = MultiOptionElement |
1447 | mapping["optionToggle"] = OptionToggleElement |
1448 | mapping["textBackdrop"] = TextBackdropElement |
1449 | mapping["inputGlyph"] = InputGlyphElementUI |
1450 | mapping["colorPickButton"] = ColorPickButtonElement |
1451 | mapping["terrainLayer"] = TerrainLayerElement |
1452 | mapping["smoothList"] = SmoothListElement |
1453 | mapping["dynamicFadedBitmap"] = DynamicFadedBitmapElement |
1454 | mapping["platformIcon"] = PlatformIconElement |
1455 | |
1456 | -- Add element processing function mappings in the same format: |
1457 | local procFuncs = Gui.ELEMENT_PROCESSING_FUNCTIONS |
1458 | procFuncs["frameReference"] = Gui.resolveFrameReference |
1459 | procFuncs["button"] = Gui.assignPlaySampleCallback |
1460 | procFuncs["slider"] = Gui.assignPlaySampleCallback |
1461 | procFuncs["multiTextOption"] = Gui.assignPlaySampleCallback |
1462 | procFuncs["checkedOption"] = Gui.assignPlaySampleCallback |
1463 | procFuncs["smoothList"] = Gui.assignPlaySampleCallback |
1464 | end |
keyEvent
DescriptionGUI key event hook. This is used for GuiElements which need to have direct access to raw key input, such as TextInputElement.Definition
keyEvent()Code
665 | function Gui:keyEvent(unicode, sym, modifier, isDown) |
666 | local eventUsed = false |
667 | if self.currentListener ~= nil then |
668 | eventUsed = self.currentListener:keyEvent(unicode, sym, modifier, isDown) |
669 | end |
670 | |
671 | if self.currentListener ~= nil and self.currentListener.target ~= nil and not eventUsed then |
672 | if self.currentListener.target.keyEvent ~= nil then |
673 | self.currentListener.target:keyEvent(unicode, sym, modifier, isDown, eventUsed) |
674 | end |
675 | end |
676 | end |
leaveMenuContext
DescriptionLeave a menu input context. This wraps the input context setting to check if the menu is actually active and the context should be reverted to the state before entering the menu (or a custom menu input context within the menu).Definition
leaveMenuContext()Code
986 | function Gui:leaveMenuContext() |
987 | if self.isInputListening then |
988 | self.inputManager:revertContext(false) |
989 | self.isInputListening = self:getIsGuiVisible() -- keep listening if still visible |
990 | end |
991 | end |
loadGui
DescriptionLoad a UI screen view's elements from an XML definition.Definition
loadGui(xmlFilename View, name Screen, controller FrameElement, isFrame [optional,)Arguments
xmlFilename | View | definition XML file path, relative to application root. |
name | Screen | name |
controller | FrameElement | instance which serves as the controller for loaded elements |
isFrame | [optional, | default=false] If true, will interpret the loaded view as a frame to be used in multiple places. |
Root | GuiElement | instance of loaded view or nil if the definition XML file could not be loaded. |
247 | function Gui:loadGui(xmlFilename, name, controller, isFrame) |
248 | local xmlFile = loadXMLFile("Temp", xmlFilename) |
249 | |
250 | local gui = nil |
251 | if xmlFile ~= nil and xmlFile ~= 0 then |
252 | FocusManager:setGui(name) |
253 | |
254 | gui = GuiElement.new(controller) |
255 | gui.name = name |
256 | gui.xmlFilename = xmlFilename |
257 | controller.name = name |
258 | controller.xmlFilename = xmlFilename |
259 | |
260 | gui:loadFromXML(xmlFile, "GUI") |
261 | |
262 | if isFrame then |
263 | controller.name = gui.name |
264 | end |
265 | |
266 | self:loadGuiRec(xmlFile, "GUI", gui, controller) |
267 | |
268 | if not isFrame then -- frames must only be scaled as part of screens, do not scale them on loading |
269 | gui:applyScreenAlignment() |
270 | gui:updateAbsolutePosition() |
271 | end |
272 | |
273 | controller:addElement(gui) |
274 | controller:exposeControlsAsFields(name) |
275 | |
276 | controller:onGuiSetupFinished() |
277 | -- call onCreate of configuration root node --> targets onCreate on view |
278 | gui:raiseCallback("onCreateCallback", gui, gui.onCreateArgs) |
279 | |
280 | if isFrame then |
281 | self:addFrame(controller, gui) |
282 | else |
283 | self.guis[name] = gui |
284 | self.nameScreenTypes[name] = controller:class() -- TEMP, until showGui is replaced |
285 | -- store screen by its class for symbolic access |
286 | self:addScreen(controller:class(), controller, gui) |
287 | end |
288 | |
289 | delete(xmlFile) |
290 | else |
291 | Logging.error("Could not open gui-config '%s'!", xmlFilename) |
292 | end |
293 | |
294 | return gui |
295 | end |
loadGuiRec
DescriptionRecursively load and build a UI configuration.Definition
loadGuiRec(xmlFile Opened, xmlNodePath Current, parentGuiElement Current, target Target)Arguments
xmlFile | Opened | GUI configuration XML file |
xmlNodePath | Current | XML node path |
parentGuiElement | Current | parent GuiElement |
target | Target | of newly instantiated elements |
303 | function Gui:loadGuiRec(xmlFile, xmlNodePath, parentGuiElement, target) |
304 | local i = 0 |
305 | while true do |
306 | local currentXmlPath = xmlNodePath .. ".GuiElement(" .. i .. ")" |
307 | local typeName = getXMLString(xmlFile, currentXmlPath .. "#type") |
308 | if typeName == nil then |
309 | break |
310 | end |
311 | |
312 | -- instantiate element and load attribute values |
313 | local newGuiElement |
314 | local elementClass = Gui.CONFIGURATION_CLASS_MAPPING[typeName] |
315 | if elementClass then -- instantiate mapped class |
316 | newGuiElement = elementClass.new(target) |
317 | else -- instantiate base GuiElement as fallback or empty panel |
318 | newGuiElement = GuiElement.new(target) |
319 | end |
320 | newGuiElement.typeName = typeName |
321 | |
322 | newGuiElement:loadFromXML(xmlFile, currentXmlPath) |
323 | parentGuiElement:addElement(newGuiElement) |
324 | |
325 | -- run any processing resolution functions for specific types: |
326 | local processingFunction = Gui.ELEMENT_PROCESSING_FUNCTIONS[typeName] |
327 | if processingFunction then |
328 | newGuiElement = processingFunction(self, newGuiElement) |
329 | end |
330 | |
331 | -- recurse on children |
332 | self:loadGuiRec(xmlFile, currentXmlPath, newGuiElement, target) |
333 | |
334 | -- raise callback after all child nodes have been processed |
335 | newGuiElement:raiseCallback("onCreateCallback", newGuiElement, newGuiElement.onCreateArgs) |
336 | i = i + 1 |
337 | end |
338 | end |
loadMapData
DescriptionLet the GUI (and its components) process map data when it's loaded.Definition
loadMapData(int mapXmlFile)Arguments
int | mapXmlFile | Map configuration XML file handle, do not close, will be handled by caller. |
1029 | function Gui:loadMapData(mapXmlFile, missionInfo, baseDirectory) |
1030 | if not Platform.isMobile then |
1031 | self.screenControllers[ShopConfigScreen]:loadMapData(mapXmlFile, missionInfo, baseDirectory) |
1032 | end |
1033 | |
1034 | if Platform.hasWardrobe then |
1035 | self.screenControllers[WardrobeScreen]:loadMapData(mapXmlFile, missionInfo, baseDirectory) |
1036 | end |
1037 | end |
loadPresets
DescriptionDefinitionloadPresets()Code
112 | function Gui:loadPresets(xmlFile, rootKey) |
113 | local presets = {} |
114 | |
115 | local i = 0 |
116 | while true do |
117 | local key = string.format("%s.Preset(%d)", rootKey, i) |
118 | if not hasXMLProperty(xmlFile, key) then |
119 | break |
120 | end |
121 | |
122 | local name = getXMLString(xmlFile, key .. "#name") |
123 | local value = getXMLString(xmlFile, key .. "#value") |
124 | if name ~= nil and value ~= nil then |
125 | if value:startsWith("$preset_") then |
126 | local preset = string.gsub(value, "$preset_", "") |
127 | if presets[preset] ~= nil then |
128 | value = presets[preset] |
129 | else |
130 | Logging.devWarning("Preset '%s' is not defined in Preset!", preset) |
131 | end |
132 | end |
133 | |
134 | presets[name] = value |
135 | end |
136 | |
137 | i = i + 1 |
138 | end |
139 | |
140 | return presets |
141 | end |
loadProfiles
DescriptionLoad UI profile data from XML.Definition
loadProfiles(xmlFilename UI)Arguments
xmlFilename | UI | profiles definition XML file path, relative to application root. |
207 | function Gui:loadProfiles(xmlFilename) |
208 | local xmlFile = loadXMLFile("Temp", xmlFilename) |
209 | |
210 | if xmlFile ~= nil and xmlFile ~= 0 then |
211 | local presets = self:loadPresets(xmlFile, "GuiProfiles.Presets") |
212 | |
213 | self:loadTraits(xmlFile, "GuiProfiles.Traits", presets) |
214 | self:loadProfileSet(xmlFile, "GuiProfiles", presets) |
215 | |
216 | local i = 0 |
217 | while true do |
218 | local key = string.format("GuiProfiles.Category(%d)", i) |
219 | if not hasXMLProperty(xmlFile, key) then |
220 | break |
221 | end |
222 | |
223 | local categoryName = getXMLString(xmlFile, key .. "#name") |
224 | |
225 | self:loadProfileSet(xmlFile, key, presets, categoryName) |
226 | |
227 | i = i + 1 |
228 | end |
229 | |
230 | delete(xmlFile) |
231 | |
232 | return true |
233 | end |
234 | |
235 | Logging.error("Could not open guiProfile-config '%s'!", xmlFilename) |
236 | |
237 | return false |
238 | end |
loadProfileSet
DescriptionDefinitionloadProfileSet()Code
160 | function Gui:loadProfileSet(xmlFile, rootKey, presets, categoryName) |
161 | local i = 0 |
162 | while true do |
163 | local profile = GuiProfile.new(self.profiles, self.traits) |
164 | if not profile:loadFromXML(xmlFile, rootKey .. ".Profile(" .. i .. ")", presets, false) then |
165 | break |
166 | end |
167 | |
168 | profile.category = categoryName -- for debugging |
169 | |
170 | self.profiles[profile.name] = profile |
171 | |
172 | -- Load variants |
173 | local j = 0 |
174 | while true do |
175 | local k = rootKey .. ".Profile(" .. i .. ").Variant(" .. j .. ")" |
176 | if not hasXMLProperty(xmlFile, k) then |
177 | break |
178 | end |
179 | |
180 | local variantName = getXMLString(xmlFile, k .. "#name") |
181 | if variantName ~= nil then |
182 | local variantProfile = GuiProfile.new(self.profiles, self.traits) |
183 | if not variantProfile:loadFromXML(xmlFile, k, presets, false, true) then |
184 | break |
185 | end |
186 | |
187 | if variantProfile.parent == nil then |
188 | variantProfile.parent = profile.name |
189 | end |
190 | |
191 | variantProfile.category = categoryName |
192 | variantProfile.name = variantName .. "_" .. profile.name |
193 | |
194 | self.profiles[variantProfile.name] = variantProfile |
195 | end |
196 | |
197 | j = j + 1 |
198 | end |
199 | |
200 | i = i + 1 |
201 | end |
202 | end |
loadTraits
DescriptionDefinitionloadTraits()Code
145 | function Gui:loadTraits(xmlFile, rootKey, presets) |
146 | local i = 0 |
147 | while true do |
148 | local trait = GuiProfile.new(self.profiles, self.traits) |
149 | if not trait:loadFromXML(xmlFile, rootKey .. ".Trait(" .. i .. ")", presets, true) then |
150 | break |
151 | end |
152 | |
153 | self.traits[trait.name] = trait |
154 | i = i + 1 |
155 | end |
156 | end |
makeChangeScreenClosure
DescriptionMake a change screen callback function which encloses the Gui self reference. This avoids passing the reference around as a parameter or global reference.Definition
makeChangeScreenClosure()Code
928 | function Gui:makeChangeScreenClosure() |
929 | return function(source, screenClass, returnScreenClass) |
930 | self:changeScreen(source, screenClass, returnScreenClass) |
931 | end |
932 | end |
makePlaySampleClosure
DescriptionMake a play sample function which encloses the Gui self reference.Definition
makePlaySampleClosure()Code
954 | function Gui:makePlaySampleClosure() |
955 | return function(sampleName) |
956 | self.soundPlayer:playSample(sampleName) |
957 | end |
958 | end |
makeToggleCustomInputContextClosure
DescriptionMake a toggle custom input context function which encloses the Gui self reference.Definition
makeToggleCustomInputContextClosure()Code
946 | function Gui:makeToggleCustomInputContextClosure() |
947 | return function(isActive, contextName) |
948 | self:toggleCustomInputContext(isActive, contextName) |
949 | end |
950 | end |
mouseEvent
DescriptionGUI mouse event hook. This is used primarily for mouse location checks, as button inputs are handled by InputBinding.Definition
mouseEvent()Code
631 | function Gui:mouseEvent(posX, posY, isDown, isUp, button) |
632 | local eventUsed = false |
633 | |
634 | if self.currentListener ~= nil then |
635 | eventUsed = self.currentListener:mouseEvent(posX, posY, isDown, isUp, button) |
636 | end |
637 | |
638 | if not eventUsed and self.currentListener ~= nil and self.currentListener.target ~= nil then |
639 | if self.currentListener.target.mouseEvent ~= nil then |
640 | self.currentListener.target:mouseEvent(posX, posY, isDown, isUp, button) |
641 | end |
642 | end |
643 | end |
new
DescriptionDefinitionnew()Code
52 | function Gui.new(messageCenter, languageSuffix, inputManager, guiSoundPlayer) |
53 | local self = setmetatable({}, Gui_mt) |
54 | |
55 | self.messageCenter = messageCenter |
56 | self.languageSuffix = languageSuffix |
57 | -- input manager reference for event registration |
58 | self.inputManager = inputManager |
59 | self.soundPlayer = guiSoundPlayer |
60 | FocusManager:setSoundPlayer(guiSoundPlayer) |
61 | |
62 | self.screens = {} -- screen class -> screen root element |
63 | self.screenControllers = {} -- screen class -> screen instance |
64 | self.dialogs = {} |
65 | self.profiles = {} |
66 | self.traits = {} |
67 | self.focusElements = {} |
68 | self.guis = {} |
69 | self.nameScreenTypes = {} |
70 | self.currentGuiName = "" |
71 | |
72 | -- registered frame elements which can be referenced to be displayed in multiple places / on multiple screen views |
73 | self.frames = {} -- frame name -> frame controller element |
74 | |
75 | -- state flag to check if the GUI input context is active (context can be multiple levels deep) |
76 | self.isInputListening = false |
77 | -- stores event IDs of GUI button/key actions (no movement) |
78 | self.actionEventIds = {} |
79 | -- current frame's input target, all inputs of one frame go to this target |
80 | self.frameInputTarget = nil |
81 | -- flag for handling of current frame's input, avoids reacting to multiple events per frame for double bindings (e.g. ESC on PC) |
82 | self.frameInputHandled = false |
83 | |
84 | self.changeScreenClosure = self:makeChangeScreenClosure() |
85 | self.toggleCustomInputContextClosure =self:makeToggleCustomInputContextClosure() |
86 | self.playSampleClosure = self:makePlaySampleClosure() |
87 | |
88 | g_adsSystem:clearGroupRegion(AdsSystem.OCCLUSION_GROUP.UI) |
89 | g_adsSystem:addGroupRegion(AdsSystem.OCCLUSION_GROUP.UI, 0, 0, 1, 1) |
90 | g_adsSystem:setGroupActive(AdsSystem.OCCLUSION_GROUP.UI, false) |
91 | |
92 | return self |
93 | end |
notifyControls
DescriptionNotify controls of an action input with a value.Definition
notifyControls(action Action, value Action)Arguments
action | Action | name as defined by loaded actions, see also scripts/input/InputAction.lua |
value | Action | value [-1, 1] |
True | if | any control has consumed the action event |
766 | function Gui:notifyControls(action, value) |
767 | local eventUsed = false |
768 | |
769 | -- Ensure that only one component receives input per frame, otherwise we risk some unwanted input handling chains |
770 | -- when GUI current listeners (or similar) change. |
771 | if self.frameInputTarget == nil then |
772 | self.frameInputTarget = self.currentListener |
773 | end |
774 | |
775 | -- check with focus manager if it currently blocks this input |
776 | local locked = FocusManager:isFocusInputLocked(action, value) |
777 | |
778 | if not locked then |
779 | -- try notifying current listener element or its target (usually either of these is a ScreenElement) |
780 | if not eventUsed and self.frameInputTarget ~= nil then |
781 | eventUsed = self.frameInputTarget:inputEvent(action, value) |
782 | end |
783 | |
784 | if not eventUsed and self.frameInputTarget ~= nil and self.frameInputTarget.target ~= nil then |
785 | eventUsed = self.frameInputTarget.target:inputEvent(action, value) |
786 | end |
787 | |
788 | -- send input to the currently focused element if it's active |
789 | local focusedElement = FocusManager:getFocusedElement() |
790 | if not eventUsed and focusedElement ~= nil and focusedElement:getIsActive() then |
791 | eventUsed = focusedElement:inputEvent(action, value) |
792 | end |
793 | |
794 | -- always notify the focus manager, but pass in event usage information |
795 | if not eventUsed then |
796 | eventUsed = FocusManager:inputEvent(action, value, eventUsed) |
797 | end |
798 | end |
799 | |
800 | -- lock down input for the current frame if we have reacted on the current input action |
801 | self.frameInputHandled = eventUsed |
802 | end |
onMenuInput
DescriptionEvent callback for menu input.Definition
onMenuInput()Code
806 | function Gui:onMenuInput(actionName, inputValue) |
807 | if not self.frameInputHandled and self.isInputListening then |
808 | self:notifyControls(actionName, inputValue) |
809 | end |
810 | end |
onReleaseInput
DescriptionEvent callback for released movement menu input.Definition
onReleaseInput()Code
822 | function Gui:onReleaseInput(action) |
823 | if not self.frameInputHandled and self.isInputListening then |
824 | -- check with focus manager if it currently blocks this input |
825 | local locked = FocusManager:isFocusInputLocked(action) |
826 | |
827 | if not locked then |
828 | -- try notifying current listener element or its target (usually either of these is a ScreenElement) |
829 | if self.frameInputTarget ~= nil then |
830 | self.frameInputTarget:inputReleaseEvent(action) |
831 | end |
832 | |
833 | if self.frameInputTarget ~= nil and self.frameInputTarget.target ~= nil then |
834 | self.frameInputTarget.target:inputReleaseEvent(action) |
835 | end |
836 | |
837 | -- send input to the currently focused element if it's active |
838 | local focusedElement = FocusManager:getFocusedElement() |
839 | if focusedElement ~= nil and focusedElement:getIsActive() then |
840 | focusedElement:inputReleaseEvent(action) |
841 | end |
842 | end |
843 | end |
844 | end |
onReleaseMovement
DescriptionEvent callback for released movement menu input.Definition
onReleaseMovement()Code
814 | function Gui:onReleaseMovement(action) |
815 | self:onReleaseInput(action) |
816 | |
817 | FocusManager:releaseMovementFocusInput(action) |
818 | end |
registerMenuInput
DescriptionRegister menu input.Definition
registerMenuInput()Code
586 | function Gui:registerMenuInput() |
587 | self.actionEventIds = {} |
588 | |
589 | -- register the menu input event for all menu navigation actions on button up |
590 | for _, actionName in ipairs(Gui.NAV_ACTIONS) do -- use ipairs to enforce action order |
591 | local _, eventId = self.inputManager:registerActionEvent(actionName, self, self.onMenuInput, false, true, false, true) |
592 | self.inputManager:setActionEventTextVisibility(eventId, false) |
593 | |
594 | if self.actionEventIds[actionName] == nil then |
595 | self.actionEventIds[actionName] = {} |
596 | end |
597 | table.addElement(self.actionEventIds[actionName], eventId) |
598 | |
599 | |
600 | if actionName == InputAction.MENU_PAGE_PREV or actionName == InputAction.MENU_PAGE_NEXT then |
601 | -- react to movement input stops ("up" state), releases locks on focus manager input: |
602 | _, eventId = self.inputManager:registerActionEvent(actionName, self, self.onReleaseInput, true, false, false, true) |
603 | self.inputManager:setActionEventTextVisibility(eventId, false) |
604 | table.addElement(self.actionEventIds[actionName], eventId) |
605 | end |
606 | end |
607 | |
608 | -- register input events for navigation movement actions for each input change |
609 | for _, actionName in pairs(Gui.NAV_AXES) do |
610 | -- react to any axis value changes: |
611 | local _, eventId = self.inputManager:registerActionEvent(actionName, self, self.onMenuInput, false, true, true, true) |
612 | self.inputManager:setActionEventTextVisibility(eventId, false) |
613 | |
614 | if self.actionEventIds[actionName] == nil then |
615 | self.actionEventIds[actionName] = {} |
616 | end |
617 | table.addElement(self.actionEventIds[actionName], eventId) |
618 | |
619 | -- react to movement input stops ("up" state), releases locks on focus manager input: |
620 | _, eventId = self.inputManager:registerActionEvent(actionName, self, self.onReleaseMovement, true, false, false, true) |
621 | self.inputManager:setActionEventTextVisibility(eventId, false) |
622 | table.addElement(self.actionEventIds[actionName], eventId) |
623 | end |
624 | |
625 | self.isInputListening = true |
626 | end |
resolveFrameReference
DescriptionTries resolving a frame reference. If no frame has been loaded with the name given by the reference, then the reference element itself is returned. Otherwise, the registered frame is cloned and returned.Definition
resolveFrameReference(self Gui, frameRefElement FrameReferenceElement)Arguments
self | Gui | instance |
frameRefElement | FrameReferenceElement | instance to resolve |
Cloned | FrameElement | instance or frameRefElement if resolution failed. |
347 | function Gui:resolveFrameReference(frameRefElement) |
348 | local refName = frameRefElement.referencedFrameName or "" |
349 | local frame = self.frames[refName] |
350 | |
351 | if frame ~= nil then |
352 | local frameName = frameRefElement.name or refName |
353 | -- "frame" is the artificial root GuiElement instance holding the frame, |
354 | -- its parent is the controller FrameElement instance which needs to be cloned |
355 | local frameController = frame.parent |
356 | -- clone the controller, including element IDs and suppressing the onCreate callback for all elements |
357 | FocusManager:setGui(frameName) -- set focus data context |
358 | local frameParent = frameRefElement.parent |
359 | local controllerClone = frameController:clone(frameParent, true, true) |
360 | controllerClone.name = frameName |
361 | |
362 | -- re-size and re-orient frame controller and its root to fit the new parent element (required for resolution stability) |
363 | controllerClone.positionOrigin = frameParent.positionOrigin |
364 | controllerClone.screenAlign = frameParent.screenAlign |
365 | controllerClone:setSize(unpack(frameParent.size)) |
366 | local cloneRoot = controllerClone:getRootElement() |
367 | cloneRoot.positionOrigin = frameParent.positionOrigin |
368 | cloneRoot.screenAlign = frameParent.screenAlign |
369 | cloneRoot:setSize(unpack(frameParent.size)) |
370 | |
371 | controllerClone:setTarget(controllerClone, frameController, true) |
372 | |
373 | local frameId = frameRefElement.id |
374 | controllerClone.id = frameId -- swap ID |
375 | |
376 | if frameRefElement.target then |
377 | -- swap frame reference field value for clone frame controller |
378 | frameRefElement.target[frameId] = controllerClone |
379 | end |
380 | |
381 | -- add cloned frame elements to focus system, would not support navigation otherwise |
382 | FocusManager:loadElementFromCustomValues(controllerClone, nil, nil, false, false) |
383 | |
384 | -- safely discard reference element |
385 | frameRefElement:unlinkElement() |
386 | frameRefElement:delete() |
387 | |
388 | return controllerClone |
389 | else |
390 | return frameRefElement |
391 | end |
392 | end |
setClient
DescriptionSet the network client reference for GUI screens.Definition
setClient()Code
1051 | function Gui:setClient(client) |
1052 | for _, controller in pairs(self.screenControllers) do |
1053 | if controller.setClient ~= nil then |
1054 | controller:setClient(client) |
1055 | end |
1056 | end |
1057 | end |
setCurrentMission
DescriptionSet the current mission reference for GUI screens.Definition
setCurrentMission()Code
1018 | function Gui:setCurrentMission(currentMission) |
1019 | for _, controller in pairs(self.screenControllers) do |
1020 | if controller.setCurrentMission ~= nil then |
1021 | controller:setCurrentMission(currentMission) |
1022 | end |
1023 | end |
1024 | end |
setServer
DescriptionSet the network client reference for GUI screens.Definition
setServer()Code
1061 | function Gui:setServer(server) |
1062 | for _, controller in pairs(self.screenControllers) do |
1063 | if controller.setServer ~= nil then |
1064 | controller:setServer(server) |
1065 | end |
1066 | end |
1067 | end |
showAnimalDialog
DescriptionDefinitionshowAnimalDialog()Code
1252 | function Gui:showAnimalDialog(args) |
1253 | local dialog = self:showDialog("AnimalDialog") |
1254 | if dialog ~= nil and args ~= nil then |
1255 | dialog.target:setTitle(args.title) |
1256 | dialog.target:setText(args.text) |
1257 | dialog.target:setHusbandries(args.husbandries) |
1258 | dialog.target:setCallback(args.callback, args.target, args.args) |
1259 | end |
1260 | end |
showColorPickerDialog
DescriptionDefinitionshowColorPickerDialog()Code
1089 | function Gui:showColorPickerDialog(args) |
1090 | local dialog = self:showDialog("ColorPickerDialog") |
1091 | if dialog ~= nil and args ~= nil then |
1092 | dialog.target:setColors(args.colors, args.defaultColor, args.defaultColorMaterial) |
1093 | dialog.target:setCallback(args.callback, args.target, args.args) |
1094 | end |
1095 | end |
showConnectionFailedDialog
DescriptionDefinitionshowConnectionFailedDialog()Code
1208 | function Gui:showConnectionFailedDialog(args) |
1209 | local dialog = self:showDialog("ConnectionFailedDialog", true) |
1210 | if dialog ~= nil and args ~= nil then |
1211 | dialog.target:setDialogType(Utils.getNoNil(args.dialogType, DialogElement.TYPE_WARNING)) |
1212 | dialog.target:setText(args.text) |
1213 | dialog.target:setCallback(args.callback, args.target, args.args) |
1214 | dialog.target:setButtonTexts(args.okText) |
1215 | end |
1216 | end |
showDenyAcceptDialog
DescriptionDefinitionshowDenyAcceptDialog()Code
1220 | function Gui:showDenyAcceptDialog(args) |
1221 | local dialog = self:showDialog("DenyAcceptDialog") |
1222 | if dialog ~= nil and args ~= nil then |
1223 | dialog.target:setCallback(args.callback, args.target) |
1224 | dialog.target:setConnection(args.connection, args.nickname, args.platformId, args.splitShapesWithinLimits) |
1225 | end |
1226 | end |
showDialog
DescriptionDisplay a dialog identified by name.Definition
showDialog()Return Values
Root | GuiElement | of dialog or nil if the name did not match any known dialog. |
471 | function Gui:showDialog(guiName, closeAllOthers) |
472 | local gui = self.guis[guiName] |
473 | if gui ~= nil then |
474 | if closeAllOthers then |
475 | local list = self.dialogs |
476 | for _,v in ipairs(list) do |
477 | if v ~= gui then |
478 | self:closeDialog(v) |
479 | end |
480 | end |
481 | end |
482 | |
483 | local oldListener = self.currentListener |
484 | if self.currentListener == gui then |
485 | return gui |
486 | end |
487 | |
488 | if self.currentListener ~= nil then |
489 | self.focusElements[self.currentListener] = FocusManager:getFocusedElement() |
490 | end |
491 | |
492 | if not self:getIsGuiVisible() then |
493 | self:enterMenuContext() |
494 | end |
495 | |
496 | -- set distinct dialog context which can be reverted on dialog closing if we are in menu already |
497 | self:enterMenuContext(Gui.INPUT_CONTEXT_DIALOG .. "_" .. tostring(guiName)) |
498 | |
499 | FocusManager:setGui(guiName) |
500 | table.insert(self.dialogs, gui) |
501 | gui:onOpen() |
502 | self.currentListener = gui |
503 | |
504 | g_messageCenter:publish(MessageType.GUI_DIALOG_OPENED, guiName, oldListener ~= nil and oldListener ~= gui) |
505 | |
506 | gui.blurAreaActive = false |
507 | if gui.target.getBlurArea ~= nil then |
508 | local x, y, width, height = gui.target:getBlurArea() |
509 | if x ~= nil then |
510 | gui.blurAreaActive = true |
511 | g_depthOfFieldManager:pushArea(x, y, width, height) |
512 | end |
513 | end |
514 | end |
515 | |
516 | return gui |
517 | end |
showEditFarmDialog
DescriptionDefinitionshowEditFarmDialog()Code
1274 | function Gui:showEditFarmDialog(args) |
1275 | local dialog = self:showDialog("EditFarmDialog") |
1276 | if dialog ~= nil and args ~= nil then |
1277 | dialog.target:setExistingFarm(args.farmId) |
1278 | dialog.target:setCallback(args.callback, args.target, args.args) |
1279 | end |
1280 | end |
showGui
DescriptionDisplay and return a screen identified by name.Definition
showGui()Return Values
Root | GuiElement | of screen or nil if the name did not match any known screen. |
459 | function Gui:showGui(guiName) |
460 | -- TODO: replace all calls to this with Gui:changeScreen |
461 | if guiName == nil then |
462 | guiName = "" |
463 | end |
464 | |
465 | return self:changeScreen(self.guis[self.currentGui], self.nameScreenTypes[guiName]) |
466 | end |
showInfoDialog
DescriptionDefinitionshowInfoDialog()Code
1177 | function Gui:showInfoDialog(args) |
1178 | local dialog = self:showDialog("InfoDialog") |
1179 | if dialog ~= nil and args ~= nil then |
1180 | dialog.target:setDialogType(Utils.getNoNil(args.dialogType, DialogElement.TYPE_WARNING)) |
1181 | dialog.target:setText(args.text) |
1182 | dialog.target:setCallback(args.callback, args.target, args.args) |
1183 | dialog.target:setButtonTexts(args.okText) |
1184 | dialog.target:setButtonAction(args.buttonAction) |
1185 | end |
1186 | end |
showLeaseYesNoDialog
DescriptionDefinitionshowLeaseYesNoDialog()Code
1149 | function Gui:showLeaseYesNoDialog(args) |
1150 | local dialog = self:showDialog("LeaseYesNoDialog") |
1151 | if dialog ~= nil and args ~= nil then |
1152 | dialog.target:setText(args.text) |
1153 | dialog.target:setTitle(args.title) |
1154 | dialog.target:setPrices(args.costsBase, args.initialCosts, args.costsPerOperatingHour, args.costsPerDay) |
1155 | dialog.target:setDialogType(Utils.getNoNil(args.dialogType, DialogElement.TYPE_QUESTION)) |
1156 | dialog.target:setCallback(args.callback, args.target, args.args) |
1157 | dialog.target:setButtonTexts(args.yesText, args.noText) |
1158 | dialog.target:setButtonSounds(args.yesSound, args.noSound) |
1159 | end |
1160 | end |
showLicensePlateDialog
DescriptionDefinitionshowLicensePlateDialog()Code
1099 | function Gui:showLicensePlateDialog(args) |
1100 | local dialog = self:showDialog("LicensePlateDialog") |
1101 | if dialog ~= nil and args ~= nil then |
1102 | dialog.target:setLicensePlateData(args.licensePlateData) |
1103 | dialog.target:setCallback(args.callback, args.target, args.args) |
1104 | end |
1105 | end |
showMessageDialog
DescriptionDefinitionshowMessageDialog()Code
1190 | function Gui:showMessageDialog(args) |
1191 | if args ~= nil then |
1192 | if args.visible then |
1193 | local dialog = self.guis["MessageDialog"] |
1194 | dialog.target:setDialogType(Utils.getNoNil(args.dialogType, DialogElement.TYPE_LOADING)) |
1195 | dialog.target:setIsCloseAllowed(Utils.getNoNil(args.isCloseAllowed, true)) |
1196 | dialog.target:setText(args.text) |
1197 | dialog.target:setUpdateCallback(args.updateCallback, args.updateTarget, args.updateArgs) |
1198 | |
1199 | self:showDialog("MessageDialog") |
1200 | else |
1201 | self:closeDialogByName("MessageDialog") |
1202 | end |
1203 | end |
1204 | end |
showOptionDialog
DescriptionDefinitionshowOptionDialog()Code
1164 | function Gui:showOptionDialog(args) |
1165 | local dialog = self:showDialog("OptionDialog") |
1166 | if dialog ~= nil and args ~= nil then |
1167 | dialog.target:setText(args.text) |
1168 | dialog.target:setTitle(args.title) |
1169 | dialog.target:setOptions(args.options) |
1170 | dialog.target:setCallback(args.callback, args.target, args.args) |
1171 | dialog.target:setButtonTexts(args.okText) |
1172 | end |
1173 | end |
showPasswordDialog
DescriptionDefinitionshowPasswordDialog()Code
1122 | function Gui:showPasswordDialog(args) |
1123 | local dialog = self.guis["PasswordDialog"] |
1124 | if dialog ~= nil and args ~= nil then |
1125 | dialog.target:setText(args.text) |
1126 | dialog.target:setCallback(args.callback, args.target, args.defaultPassword, nil, nil, nil, args.args, true) |
1127 | dialog.target:setButtonTexts(args.startText, args.backText) |
1128 | |
1129 | self:showDialog("PasswordDialog") |
1130 | end |
1131 | end |
showPlaceableInfoDialog
DescriptionDefinitionshowPlaceableInfoDialog()Code
1284 | function Gui:showPlaceableInfoDialog(args) |
1285 | local dialog = self:showDialog("PlaceableInfoDialog") |
1286 | if dialog ~= nil and args ~= nil then |
1287 | dialog.target:setPlaceable(args.placeable) |
1288 | dialog.target:setCallback(args.callback, args.target, args.args) |
1289 | end |
1290 | end |
showRefillDialog
DescriptionDefinitionshowRefillDialog()Code
1242 | function Gui:showRefillDialog(args) |
1243 | local dialog = self:showDialog("RefillDialog") |
1244 | if dialog ~= nil and args ~= nil then |
1245 | dialog.target:setData(args.data, args.priceFactor) |
1246 | dialog.target:setCallback(args.callback, args.target, args.args) |
1247 | end |
1248 | end |
showSellItemDialog
DescriptionDefinitionshowSellItemDialog()Code
1264 | function Gui:showSellItemDialog(args) |
1265 | local dialog = self:showDialog("SellItemDialog") |
1266 | if dialog ~= nil and args ~= nil then |
1267 | dialog.target:setItem(args.item, args.price, args.storeItem) |
1268 | dialog.target:setCallback(args.callback, args.target, args.args) |
1269 | end |
1270 | end |
showServerSettingsDialog
DescriptionDefinitionshowServerSettingsDialog()Code
1325 | function Gui:showServerSettingsDialog(args) |
1326 | local dialog = self:showDialog("ServerSettingsDialog") |
1327 | if dialog ~= nil and args ~= nil then |
1328 | dialog.target:setCallback(args.callback, args.target, args.args) |
1329 | end |
1330 | end |
showSiloDialog
DescriptionDefinitionshowSiloDialog()Code
1230 | function Gui:showSiloDialog(args) |
1231 | local dialog = self:showDialog("SiloDialog") |
1232 | if dialog ~= nil and args ~= nil then |
1233 | dialog.target:setTitle(args.title) |
1234 | dialog.target:setText(args.text) |
1235 | dialog.target:setFillLevels(args.fillLevels, args.hasInfiniteCapacity) |
1236 | dialog.target:setCallback(args.callback, args.target, args.args) |
1237 | end |
1238 | end |
showSleepDialog
DescriptionDefinitionshowSleepDialog()Code
1304 | function Gui:showSleepDialog(args) |
1305 | local dialog = self:showDialog("SleepDialog") |
1306 | if dialog ~= nil and args ~= nil then |
1307 | dialog.target:setTitle(g_i18n:getText("ui_inGameSleep")) |
1308 | dialog.target:setText(args.text) |
1309 | dialog.target:setCallback(args.callback, args.target, args.args) |
1310 | end |
1311 | end |
showTextInputDialog
DescriptionDefinitionshowTextInputDialog()Code
1109 | function Gui:showTextInputDialog(args) |
1110 | local dialog = self.guis["TextInputDialog"] |
1111 | if dialog ~= nil and args ~= nil then |
1112 | dialog.target:setText(args.text) |
1113 | dialog.target:setCallback(args.callback, args.target, args.defaultText, args.dialogPrompt, args.imePrompt, args.maxCharacters, args.args, false, args.disableFilter) |
1114 | dialog.target:setButtonTexts(args.confirmText, args.backText, args.activateInputText) |
1115 | |
1116 | self:showDialog("TextInputDialog") |
1117 | end |
1118 | end |
showTransferMoneyDialog
DescriptionDefinitionshowTransferMoneyDialog()Code
1315 | function Gui:showTransferMoneyDialog(args) |
1316 | local dialog = self:showDialog("TransferMoneyDialog") |
1317 | if dialog ~= nil and args ~= nil then |
1318 | dialog.target:setTargetFarm(args.farm) |
1319 | dialog.target:setCallback(args.callback, args.target, args.args) |
1320 | end |
1321 | end |
showUnblockDialog
DescriptionDefinitionshowUnblockDialog()Code
1294 | function Gui:showUnblockDialog(args) |
1295 | local dialog = self:showDialog("UnBanDialog") |
1296 | if dialog ~= nil and args ~= nil then |
1297 | dialog.target:setUseLocalList(args.useLocal or false) |
1298 | dialog.target:setCallback(args.callback, args.target) |
1299 | end |
1300 | end |
showVoteDialog
DescriptionDefinitionshowVoteDialog()Code
1334 | function Gui:showVoteDialog(args) |
1335 | local dialog = self:showDialog("VoteDialog") |
1336 | if dialog ~= nil and args ~= nil then |
1337 | dialog.target:setValue(args.value) |
1338 | dialog.target:setCallback(args.callback, args.target, args.args) |
1339 | end |
1340 | end |
showYesNoDialog
DescriptionDefinitionshowYesNoDialog()Code
1135 | function Gui:showYesNoDialog(args) |
1136 | local dialog = self:showDialog("YesNoDialog") |
1137 | if dialog ~= nil and args ~= nil then |
1138 | dialog.target:setText(args.text) |
1139 | dialog.target:setTitle(args.title) |
1140 | dialog.target:setDialogType(Utils.getNoNil(args.dialogType, DialogElement.TYPE_QUESTION)) |
1141 | dialog.target:setCallback(args.callback, args.target, args.args) |
1142 | dialog.target:setButtonTexts(args.yesText, args.noText) |
1143 | dialog.target:setButtonSounds(args.yesSound, args.noSound) |
1144 | end |
1145 | end |
toggleCustomInputContext
DescriptionToggle a custom menu input context for one of the managed frames or screens.Definition
toggleCustomInputContext()Code
936 | function Gui:toggleCustomInputContext(isActive, contextName) |
937 | if isActive then |
938 | self:enterMenuContext(contextName) |
939 | else |
940 | self:leaveMenuContext() |
941 | end |
942 | end |
touchEvent
DescriptionGUI touch event hook. This is used primarily for touch location checks, as button inputs are handled by InputBinding.Definition
touchEvent()Code
648 | function Gui:touchEvent(posX, posY, isDown, isUp, touchId) |
649 | local eventUsed = false |
650 | |
651 | if self.currentListener ~= nil and self.currentListener.touchEvent ~= nil then |
652 | eventUsed = self.currentListener:touchEvent(posX, posY, isDown, isUp, touchId) |
653 | end |
654 | |
655 | if not eventUsed and self.currentListener ~= nil and self.currentListener.target ~= nil then |
656 | if self.currentListener.target.touchEvent ~= nil then |
657 | self.currentListener.target:touchEvent(posX, posY, isDown, isUp, touchId) |
658 | end |
659 | end |
660 | end |
unloadMapData
DescriptionDefinitionunloadMapData()Code
1041 | function Gui:unloadMapData() |
1042 | self.screenControllers[ShopConfigScreen]:unloadMapData() |
1043 | |
1044 | if Platform.hasWardrobe then |
1045 | self.screenControllers[WardrobeScreen]:unloadMapData() |
1046 | end |
1047 | end |
update
DescriptionUpdate the GUI. Propagates update to all active UI elements.Definition
update()Code
681 | function Gui:update(dt) |
682 | for _,v in pairs(self.dialogs) do |
683 | -- v:update(dt) |
684 | if v.target ~= nil then |
685 | v.target:update(dt) |
686 | end |
687 | end |
688 | |
689 | local currentGui = self.currentGui |
690 | if currentGui ~= nil then |
691 | if currentGui.target ~= nil and currentGui.target.preUpdate ~= nil then |
692 | currentGui.target:preUpdate(dt) |
693 | end |
694 | |
695 | if currentGui == self.currentGui then -- self.currentGui can change during update |
696 | -- currentGui:update(dt) |
697 | if currentGui == self.currentGui then -- self.currentGui can change during update |
698 | if currentGui.target ~= nil and currentGui.target.update ~= nil then |
699 | currentGui.target:update(dt) |
700 | end |
701 | end |
702 | end |
703 | end |
704 | |
705 | -- reset input fields for next frame |
706 | self.frameInputTarget = nil |
707 | self.frameInputHandled = false |
708 | end |