Giter Site home page Giter Site logo

godot-tool_button's Introduction

ToolButtonPlugin for Godot - v1.3

Get buttons in the inspector with one line: tool.

ReadMe

Start

  • Enable plugin.
  • Add tool to top of your script.
  • Add func _get_tool_buttons to return names of functions.
  • ๐Ÿ†• Buttons automatically added. _get_tool_buttons not needed, except for fine control.

Simpler Example (v1.3)

tool
extends Node

func my_function():
    print("I was called!")

Simple Example

tool
extends Node

func _get_tool_buttons(): return ["my_function"]

func my_function():
    print("I was called!")

Advanced Example

Using Dictionarys instead of Strings.

call is mandatory. Other's are optional.

key desc default
call Method to call. -
args Array of arguments to pass. -
text Button label. -
tint Button color. Color.white
icon Button icon. -
flat Button is flat style. false
hint Hint text for mouse over. -
print Print output of method call? false
align Button alignment. Button.ALIGN_CENTER
disable Disable button? false
update_filesystem Tells Godot editor to rescan file system. false
var _direction:String = ""
var _score:int = 0

func _get_tool_buttons():
    return [{
        call="go_towards",
        args=["West"]
    },{
        call="go_towards",
        args=["East", true],
        text="Bad Move",
        tint=Color.red,
    }]

func go_towards(direction:String, bad_action:bool=false):
    _direction = direction

    if bad_action:
        _score -= 10

    return _score

More Advanced Example

Showing optional buttons by using Godot's property_list_changed_notify to force update.

tool
extends Node

export(bool) var show_score_button:bool = false setget set_show_score_button
export(int) var score:int = 0

func set_show_score_button(value):
	show_score_button = value
	property_list_changed_notify() # force property list to "redraw"

func _get_tool_buttons():
    var out = []
	if show_score_button:
        # hidden unless show_score_button is enabled
		out.append({call="add_score", args=[10], disable=score>100, tint=Color.aqua})
	return out

func add_score(amount:int):
	self.score += amount
	property_list_changed_notify() # force property list to "redraw"

Resource Example

To get things working on a resource, the _get_tool_buttons needs to be static.

tool
extends Resource
class_name MyResource

# STATIC
static func _get_tool_buttons():
    return ["my_button"]

# LOCAL
export(String) var my_name:String = ""

func my_button():
    print(my_name)

Changes

1.3

  • Automatic. No need for _get_tool_buttons. Just add tool to top of script. Buttons will be at the bottom of the editor inspector.

1.2

  • Works on Resources now.

1.1

  • added tag update_filesystem

godot-tool_button's People

Contributors

teebarjunk avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.