-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ExportHelper v1.0 - Categories and Buttons
- Loading branch information
1 parent
428b767
commit 4d2fef9
Showing
10 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Allison Ghost | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
# ToolButtonPlugin for Godot 3.5 - by Allison Ghost | ||
|
||
Export categories, and clickable buttons that run script functions. | ||
Serves as a replacement to mathewcst's [godot-export-categories](https://github.com/mathewcst/godot-export-categories) | ||
|
||
![cover](./img/Preview.png "Preview") | ||
|
||
## Usage | ||
|
||
- Install and enable the plugin. | ||
- Use the `_c_` prefix on a variable to export a category: | ||
|
||
Example: ```export var _c_category_name:int``` | ||
|
||
![cover](./img/category.png "Preview") | ||
|
||
- Use the `_btn_` prefix on a variable to export a button | ||
- Create a function that the button will call, with a name matches the variable name but without the leading `_` | ||
|
||
NOTE: | ||
- Exporting an `int` or a `bool` type variable will export a standalone button. | ||
- Exporting a `String` or other data type will export the button with an argument field that is passed to the function when clicked. | ||
|
||
Examples: | ||
``` | ||
export (String) var _btn_button_arg = "test" | ||
export (bool) var _btn_button | ||
func btn_button_arg(entry): | ||
pass | ||
func btn_button(): | ||
pass | ||
``` | ||
![cover](./img/buttons.png "Preview") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
class_name InspectorFunctionButton | ||
extends HBoxContainer | ||
|
||
var args = LineEdit.new() | ||
var spacer = Control.new() | ||
var spacer2 = Control.new() | ||
var button = Button.new() | ||
var object:Object | ||
var info:Dictionary | ||
var method:String | ||
var type | ||
|
||
func _init(obj:Object, i): | ||
object = obj | ||
info = i | ||
method = info["method"] | ||
|
||
alignment = BoxContainer.ALIGN_CENTER | ||
size_flags_horizontal = SIZE_EXPAND_FILL | ||
|
||
add_child(spacer) | ||
spacer.size_flags_horizontal = SIZE_EXPAND_FILL | ||
spacer.size_flags_stretch_ratio = 0.33 | ||
|
||
add_child(button) | ||
button.size_flags_horizontal = SIZE_EXPAND_FILL | ||
button.align = Button.ALIGN_CENTER | ||
button.modulate = info.get("tint", Color(1.5, 1.3, 0.8)) | ||
button.size_flags_stretch_ratio = 0.5 | ||
# Label and Tooltip | ||
button.text = method.capitalize().trim_prefix("Btn").trim_prefix(" ") | ||
button.hint_tooltip = "Click to call "+method | ||
# | ||
button.connect("pressed", self, "_on_button_pressed") | ||
button.disabled = false | ||
|
||
if info.get("use_arg", false): | ||
add_child(args) | ||
args.size_flags_stretch_ratio = 0.33 | ||
args.size_flags_horizontal = SIZE_EXPAND_FILL | ||
args.modulate = info.get("tint", Color(1.1,1.1,1.1)) | ||
args.placeholder_text = "[ Argument ]" | ||
args.placeholder_alpha = 0.3 | ||
args.align = 1 | ||
else: | ||
add_child(spacer2) | ||
spacer2.size_flags_horizontal = SIZE_EXPAND_FILL | ||
spacer2.size_flags_stretch_ratio = 0.33 | ||
|
||
func infer_string_datatype(value): | ||
if value == "true": return true | ||
elif value == "false": return false | ||
elif float(value) > 0 || float(value) < 0 || value == "0" || value == "0.0" || value == "0.00": | ||
value = float(value) | ||
if float(value) == int(value): | ||
value = int(value) | ||
return value | ||
|
||
func _on_button_pressed(): | ||
if info.get("use_arg", false): | ||
object.call(method,infer_string_datatype(args.text)) | ||
args.text = "" | ||
else: | ||
object.call(method) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class_name InspectorCategory | ||
extends Button | ||
|
||
var txt = RichTextLabel.new() | ||
|
||
func _init(info:Dictionary): | ||
align = 0 | ||
size_flags_horizontal = SIZE_EXPAND_FILL | ||
text = get_label(info.get("name", "Category")) | ||
hint_tooltip = "" | ||
focus_mode = 0 | ||
disabled = true | ||
modulate = info.get("tint", Color(1.5, 1.5, 1.5, 0.5)) | ||
add_color_override("font_color_disabled", Color(1.7, 1.7, 1.7)) | ||
|
||
func get_label(name): | ||
return " ■ "+name.capitalize()+" " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
extends EditorInspectorPlugin | ||
|
||
var plugin | ||
|
||
func can_handle(object): | ||
return true | ||
|
||
func parse_property(object: Object, type: int, path: String, hint: int, hint_text: String, usage: int) -> bool: | ||
if "_btn_" in path: | ||
# Hide argument field if exporting as bool or int. | ||
# Show field if exporting as String or other. | ||
# String is type 4, bool is type 1, int is type 2 | ||
var usearg = false if type == 1 || type == 2 else true | ||
add_custom_control(InspectorFunctionButton.new(object, { | ||
method=path.trim_prefix("_"), | ||
use_arg=usearg, | ||
type=type, | ||
update_filesystem=true | ||
})) | ||
return true | ||
elif "_c_" in path: | ||
add_custom_control(InspectorCategory.new({ | ||
name=path.trim_prefix("_c_"), | ||
})) | ||
return true | ||
return false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
tool | ||
extends EditorPlugin | ||
|
||
var plugin | ||
|
||
func _enter_tree(): | ||
plugin = preload("./FuncButton_InspectorPlugin.gd").new() | ||
add_inspector_plugin(plugin) | ||
|
||
func _exit_tree(): | ||
remove_inspector_plugin(plugin) | ||
|
||
func rescan_filesystem(): | ||
var filesys = get_editor_interface().get_resource_filesystem() | ||
filesys.update_script_classes() | ||
filesys.scan_sources() | ||
filesys.scan() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[plugin] | ||
|
||
name="Export Helper" | ||
description="Export clickable buttons that run script functions." | ||
author="Allison Ghost" | ||
version="1.0" | ||
script="FuncButton_Plugin.gd" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.