Skip to content
项目

murikistudio/simple-gui-transitions

在 GitHub 查看

关于

Godot plugin to swap GUI menus elegantly.

设计与媒体

这些数字如何统计

实测星标增长

24小时
0
7天
0
15天
0
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

Simple GUI Transitions

Godot's Simple GUI Transitions

"Simple GUI transitions to swap menus elegantly."

This plugin gives access to the GuiTransition node which allows to transition multiple GUI layouts easily. Designed for Godot 4.x (3.x version available here). See the example scene on addons/simple-gui-transitions/example to see this plugin in action.

Download it on Godot Asset Library

Index

Installation

  • Install the plugin through the AssetLib or copy the plugin addons folder to your project's directory
  • Enable the plugin on Project > Project Settings > Plugins
  • Reload your current project

Basic Usage

Node Configuration

After installing the plugin, enabling it on Project > Project Settings > Plugins and reloading your project, you can instance the node GuiTransition in your scene. See the properties in the next section to learn how to configure it properly, but pay attention to the properties:

  • Layout: The main layout node. It will be hidden and shown accordingly. Should be the topmost node of the current GUI layout, usually the scene root. If you don't set the Layout ID property, this node's name will be assumed as the layout ID. Always required!
  • Controls: An array of nodes that will be animated in sequence.

⚠️ Note: If you don't set Controls, the Layout itself will be animated.

Triggering Transitions

After setting up its properties, the layout should at least be shown with a transition at startup. After that you can use code to trigger the transitions through the singleton. For example:

func _on_button_pressed() -> void:
    GuiTransitions.hide("Hud")

This will hide the layout with the layout ID Hud. Keep in mind that you can have multiple layouts with the same ID, so you can add different transitions to specific parts of the interface, for example, the health and mana bars in the top of the screen would slide upwards and the equipment list in the bottom would slide downwards. In that example, you would have two GuiTransition nodes in the scene with the same Layout ID (Hud) and different Controls and Animation Enter/Animation Leave properties. This way, you can have different transitions for each part of the interface and trigger all parts with a single command.

You can change to another layout with the go_to method. For example, you may want to hide the HUD and show the pause menu. To achieve this, the HUD must be visible and the pause menu must be hidden. The following code will hide the HUD and show the pause menu.

func _on_button_pause_pressed() -> void:
    GuiTransitions.go_to("Pause")

You can even pass a Callable as the second argument of the go_to method if you want to execute a function in between the transitions. However, if you like a more explicit code, other common operation is waiting for the layout to finish its transition and triggering the next layout afterwards. This can be easily done with the following code:

func _on_button_pause_pressed() -> void:
    prints("Hud will now hide")
    GuiTransitions.hide("Hud")
    await GuiTransitions.hide_completed
    prints("Hud hidden, will now show Pause")
    GuiTransitions.show("Pause")

Simple GUI Transitions is exactly that: simple to set up and use. Check the detailed documentation below to learn more.

Global Settings

The default transition settings can be set on Project > Project Settings > GUI Transitions > Config (you may need to enable Advanced Settings to see this section). Those settings will be applied on top of any Default property on the node GuiTransition. This is useful to increase or decrease the speed of transitions on the whole project, for example. See each property description below.

Node GuiTransition

The node GuiTransition is responsible for transitioning a specific layout. Most properties can be changed at runtime, useful if your layout contains dynamic Controls (or if you want to add a special touch by making the animations random every time a layout is triggered 😝).

Properties

Auto Start

If the current layout will trigger its transition at startup automatically. Enabled by default. Invisible layouts won't trigger its transitions.

Fade Layout

If enabled, will fade the whole layout along with the selected animation of individual controls. The fade duration is based on the Duration property. Enabled by default.

Animation Enter

The animation type of the controls when entering the screen. The available animations are:

  • Fade
  • Slide left, right, up and down
  • Scale vertical, horizontal and both
  • Rotate zoom in, rotate zoom out

Animation Leave

The animation type of the controls when leaving the screen. The available animations are:

  • Fade
  • Slide left, right, up and down
  • Scale vertical, horizontal and both
  • Rotate zoom in, rotate zoom out

Duration

The total animation duration in seconds. A negative value such as the default -0.01 will make the transition use the default value set in Project Settings.

Delay

Delay ratio between transitions for each node contained in Controls. The default value is 0.5.

  • A negative value such as the default -0.01 will make the transition use the default value set in Project Settings.
  • A delay of 0.0 means no delay, that is, all controls will start and finish their animations at the same time.
  • A delay of 1.0 will make each control wait for the previous one to finish its animation to start its own.
  • A delay between 0.0 and 1.0 will make controls intertwine animations, giving a smoother effect.

⚠️ Note: See addons/simple-gui-transitions/example/layout_3.tscn for an interactive and visual representation of different delay ratios.

Layout ID

Optional ID of layout to identify this layout to the singleton GuiTransitions. If empty, will be assumed as the Layout node name.

For example, if you call GuiTransitions.go_to("SomeLayout"), the layout node must be named SomeLayout or you should set Layout ID to SomeLayout for it to be affected by the call.

This property can be useful if you want to trigger more than one layout at the same time with the same ID (a HUD with different animations, for example).

Layout

Required! The main layout node. It will be hidden and shown accordingly. Should be the topmost node of the current layout. If your don't set Controls, the Layout itself will be animated.

Controls

Array of individual nodes to be animated. The order will be taken in consideration to apply the animation Delay. You can add or remove items from this array at runtime in case your layout is dynamic.

Center Pivot

When Animation Enter or Animation Leave is one of the scale or rotate animations, it will center the control's offset_transform_pivot_ratio property.

Transition Enter

Transition curve of enter animations. Same as Tween.TransitionType.

Transition Leave

Transition curve of leave animations. Same as Tween.TransitionType.

Ease Enter

Ease curve of enter animations. Same as Tween.EaseType.

Ease Leave

Ease curve of leave animations. Same as Tween.EaseType.

Singleton GuiTransitions

The singleton GuiTransitions allows to trigger the transitions globally and swap GUI layouts.

Signals

show_started(layout_name: StringName)

Emitted when a layout is about to be shown.

show_completed(layout_name: StringName)

Emitted after a layout has been shown.

hide_started(layout_name: StringName)

Emited when a layout is about to be hidden.

hide_completed(layout_name: StringName)

Emitted after a layout has been hidden.

transition_started(layout_name: StringName)

Emmited when a layout is about to be shown or hidden.

transition_completed(layout_name: StringName)

Emited after a layout has been shown or hidden.

Public Methods

⚠️ Note: Optional arguments in the methods below are suffixed with ? (e.g. function?).

go_to(id: StringName, function?: Callable)

The method go_to hides the current layout and shows the layout with the given id. If function (optional) is passed in, the function will be executed halfway through. Both signals hide_completed and show_completed are emitted accordingly.

update(function?: Callable)

The method update hides and shows the current layout. If function (optional) is passed in, the function will be executed halfway through. Both signals hide_completed and show_completed are emited accordingly.

show(id?: StringName)

The method show shows the layout with the given id, or all hidden layouts if no id is passed in. Emits the signal show_completed on completion.

hide(id?: StringName, function?: Callable)

The method hide hides the layout with the given id, or all visible layouts if no id is passed in. Emits the signal hide_completed on completion.

is_shown(id: StringName)

The method is_shown returns if the layout with the given id is currently visible.

is_hidden(id: StringName)

The method is_hidden returns if the layout with the given id is currently hidden.

in_transition(id?: StringName)

The method in_transition returns if any layout or one with the given id is currently transitioning.

探索相关项目

加载中…