A window is a special extension of a component. There is no concept of a window in the editor, because a window can set any component as its display content. Window = content component + window management API.

Design window

The window content component needs to be edited in the editor. Usually the window will include a title bar for dragging, a close button, etc. FairyGUI uses convention names to associate some common window functions with our defined components. First of all, a name needs to be placed in the window content component asframeThis component will be the background of the window or the frame. Extensions for this component are usually chosen as “tags”.

The production method of this frame component is:

Note that the above conventions are optional. Whether the component frame or the component frame contains the agreed functional components will not affect the normal display and close of the window.

Use window

After the content components are created, the runtime can create and use windows in the following ways:

Window win = new Window ();
    win.contentPane = UIPackage.CreateObject ("package name", "content component name"). asCom;
    win.Show ();

In addition, FairyGUI also provides a set of mechanisms for dynamic window creation. Dynamic creation refers to specifying only the resources that the window needs to use initially, and actually starting to build the content of the window when the window needs to be displayed. First need to be called in the window’s constructorAddUISource。 This method requires aIUISourceType parameters, and IUISource is an interface, and users need to implement the logic of loading related UI packages by themselves. When the window is displayed for the first time, the loading method of IUISource will be called, and wait for the loading to complete before returning to execution.OnInitAnd then the window will be displayed.

transferShowProcess of displaying window:

If you need to play the animation effect when the window is displayed, then overrideDoShowAnimationWrite your animation code and call onShown after the animation ends.
coverOnShownWrite other business logic that needs to be handled when the window is displayed.

transferHideProcess of hiding window:

If you need to play the animation effect when the window is hidden, then overrideDoHideAnimationWrite your animation code and call it at the end of the animationHideImmediatelyNote that onHide is not called directly!).
coverone hydrochlorideWrite other business logic that needs to be handled when the window is hidden.


Window management

GRoot provides some common APIs for window management.

Adding components directly to GRoot, what is the difference between using Windows?

GRoot is the root container for 2D UI. After we create the top-level UI interface through UIPackage.CreateObject, add it to GRoot. For example, the game’s login interface, main interface, etc. This type of interface is characterized by the bottom layer of the game and is relatively fixed.

The essence of Window is also the top-level UI interface dynamically created through UIPackage.CreateObject, but it provides commonly used window features, such as automatic sorting, show / hide processes, modal windows, etc. Dialog interface for games, such as character status, backpack, mall, etc. This type of interface is characterized by being on top of the game and switching frequently.

Automatic window sorting

By default, Window has a click auto-sort function, that is, if you click a window, the system will automatically bring the window to the front of all windows, which is also the specification of all window systems. But you can turn off this feature:

UIConfig.bringWindowToFrontOnClick = false;