Skip to content

Commit 3cb0a2b

Browse files
committed
New action map logic
1 parent f603824 commit 3cb0a2b

File tree

9 files changed

+93
-26
lines changed

9 files changed

+93
-26
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
extends Control
2+
3+
class_name OpenXRActionSetsEditor
4+
5+
var edit_action_sets : OpenXRActionSets = null
6+
7+
func set_edit_action_sets(action_sets : OpenXRActionSets):
8+
edit_action_sets = action_sets
9+
if edit_action_sets:
10+
# setup our interface
11+
pass
12+
13+
# Called when the node enters the scene tree for the first time.
14+
func _ready():
15+
pass # Replace with function body.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://dq5euwagt54y1"]
2+
3+
[ext_resource type="Script" path="res://addons/godot-openxr/editor/OpenXRActionSetsEditor.gd" id="1_oxgn0"]
4+
5+
[node name="OpenXRActionSetsEditor" type="Control"]
6+
script = ExtResource( "1_oxgn0" )
7+
__meta__ = {
8+
"_edit_use_anchors_": false
9+
}

demo/addons/godot-openxr/editor/OpenXRRunSelect.gd

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
@tool
12
extends OptionButton
23

3-
# @tool
4-
54
var available_runtimes : Array = Array()
6-
onready var platform = OS.get_name()
5+
@onready var platform = OS.get_name()
76

87
var home_folder = ''
98

10-
func _parse_path(p_path):
9+
func _parse_path(p_path) -> String:
1110
# we might want to add more stuff here at some point
1211
p_path = p_path.replace("~", home_folder)
1312
return p_path
@@ -31,8 +30,10 @@ func _ready():
3130
# read our json file, may have entries for multiple platforms, we'll filter them later
3231
var f = File.new()
3332
if (f.open("res://addons/godot-openxr/runtimes.json", File.READ)) == OK:
34-
var json = JSON.parse(f.get_as_text())
35-
available_runtimes = json.result as Array
33+
var json = JSON.new()
34+
var err : int = json.parse(f.get_as_text())
35+
if err == OK:
36+
available_runtimes = json.get_data()
3637
f.close()
3738

3839
# check what our current value is
@@ -44,8 +45,8 @@ func _ready():
4445
add_item("Default", -1)
4546

4647
# check which runtimes are actually available
47-
var dir = Directory.new()
48-
var index = 0
48+
var dir : Directory = Directory.new()
49+
var index : int = 0
4950
for i in available_runtimes.size():
5051
var runtime = available_runtimes[i]
5152
var path = _parse_path(runtime["path"])
@@ -63,8 +64,7 @@ func _ready():
6364
# I guess nothing supported on this platform
6465
visible = false
6566

66-
func _on_OpenXRRunSelect_item_selected(index):
67-
# this need latest 3.2.4
67+
func _on_OpenXRRunSelect_item_selected(index : int):
6868
if index == 0:
6969
print("Returning to default")
7070
OS.set_environment("XR_RUNTIME_JSON", "")

demo/addons/godot-openxr/editor/OpenXRRunSelect.tscn

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
[gd_scene load_steps=2 format=2]
1+
[gd_scene load_steps=2 format=3 uid="uid://7eqmk3bil2rq"]
22

3-
[ext_resource path="res://addons/godot-openxr/editor/OpenXRRunSelect.gd" type="Script" id=1]
3+
[ext_resource type="Script" path="res://addons/godot-openxr/editor/OpenXRRunSelect.gd" id="1"]
44

55
[node name="OpenXRRunSelect" type="OptionButton"]
6+
theme_override_font_sizes/font_size = 16
67
text = "Default"
7-
items = [ "Default", null, false, 0, null, "SteamVR", null, false, 2, null, "Oculus", null, false, 3, null, "Microsoft MR", null, false, 4, null ]
8+
items = ["Default", null, false, 0, null, "SteamVR", null, false, 2, null, "Oculus", null, false, 3, null, "Microsoft MR", null, false, 4, null]
89
selected = 0
9-
script = ExtResource( 1 )
10+
script = ExtResource( "1" )
1011
__meta__ = {
1112
"_edit_use_anchors_": false
1213
}

demo/addons/godot-openxr/plugin.gd

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,49 @@
1-
tool
1+
@tool
22
extends EditorPlugin
33

44
var openxr_run_select = null
5+
var action_set_editor : OpenXRActionSetsEditor = null
6+
var action_set_button = null
57

68
func _enter_tree():
7-
openxr_run_select = preload("res://addons/godot-openxr/editor/OpenXRRunSelect.tscn").instance()
9+
openxr_run_select = preload("res://addons/godot-openxr/editor/OpenXRRunSelect.tscn").instantiate()
810
add_control_to_container(CONTAINER_TOOLBAR, openxr_run_select)
11+
12+
action_set_editor = preload("res://addons/godot-openxr/editor/OpenXRActionSetsEditor.tscn").instantiate()
13+
if action_set_editor:
14+
action_set_button = add_control_to_bottom_panel(action_set_editor, "Action Sets")
15+
action_set_button.hide()
916

1017
func _exit_tree():
18+
if action_set_editor:
19+
remove_control_from_bottom_panel(action_set_editor)
20+
action_set_editor.queue_free()
21+
action_set_editor = null
22+
action_set_button = null
23+
1124
if openxr_run_select:
1225
remove_control_from_container(EditorPlugin.CONTAINER_TOOLBAR, openxr_run_select)
1326
openxr_run_select.queue_free()
1427
openxr_run_select = null
28+
29+
func _handles(object) -> bool:
30+
if action_set_editor and object.is_class("OpenXRActionSets"):
31+
return true
32+
33+
return false
34+
35+
func _edit(object):
36+
if action_set_editor and object.is_class("OpenXRActionSets"):
37+
action_set_editor.set_edit_action_sets(object)
38+
39+
func _make_visible(visible):
40+
if visible:
41+
action_set_button.show()
42+
make_bottom_panel_item_visible(action_set_editor)
43+
action_set_editor.set_process_input(true)
44+
else:
45+
if action_set_editor.is_visible_in_tree():
46+
hide_bottom_panel()
47+
action_set_button.hide()
48+
action_set_editor.set_process_input(false)
49+

demo/project.godot

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88

99
config_version=4
1010

11+
_global_script_classes=[{
12+
"base": "Control",
13+
"class": &"OpenXRActionSetsEditor",
14+
"language": &"GDScript",
15+
"path": "res://addons/godot-openxr/editor/OpenXRActionSetsEditor.gd"
16+
}]
17+
_global_script_class_icons={
18+
"OpenXRActionSetsEditor": ""
19+
}
20+
1121
[application]
1222

1323
config/name="Godot OpenXR demo"
@@ -20,7 +30,7 @@ window/vsync/use_vsync=false
2030

2131
[editor_plugins]
2232

23-
enabled=PackedStringArray()
33+
enabled=PackedStringArray("res://addons/godot-openxr/plugin.cfg")
2434

2535
[gdnative]
2636

src/gdclasses/actions/OpenXRActionSets.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ Ref<OpenXRInteractionProfile> OpenXRActionSets::get_interaction_profile(int p_in
103103
}
104104
}
105105

106-
/* this needs https://github.com/godotengine/godot-cpp/pull/656
107106
Array OpenXRActionSets::_get_property_list() {
108107
// We are returning hidden entries for our action sets and interaction profiles so they get saved into our resource file
109108
// These are not for direct use.
@@ -117,7 +116,7 @@ Array OpenXRActionSets::_get_property_list() {
117116
Dictionary property;
118117

119118
String name = "action_sets/";
120-
name += String::num((double) i, 0);
119+
name = name + String::num((double) i, 0);
121120

122121
property["name"] = name;
123122
property["type"] = Variant::OBJECT;
@@ -133,13 +132,14 @@ Array OpenXRActionSets::_get_property_list() {
133132
Dictionary property;
134133

135134
String name = "interaction_profile/";
136-
name += String::num((double) i, 0);
135+
name = name + String::num((double) i, 0);
137136

138137
property["name"] = name;
139138
property["type"] = Variant::OBJECT;
140139
property["hint"] = PROPERTY_HINT_RESOURCE_TYPE;
141140
property["hint_string"] = "OpenXRInteractionProfile";
142-
property["usage"] = PROPERTY_USAGE_NO_EDITOR; // don't show in editor, only load from/save to tscn
141+
// property["usage"] = PROPERTY_USAGE_NO_EDITOR; // don't show in editor, only load from/save to tscn
142+
property["usage"] = 0;
143143

144144
arr.push_back(property);
145145
}
@@ -193,7 +193,7 @@ bool OpenXRActionSets::_set(const String p_name, Variant p_value) {
193193
} else if (p_name.begins_with(str_interaction_profiles)) {
194194
Ref<OpenXRInteractionProfile> interaction_profile = p_value;
195195

196-
if (interaction_profiles.is_valid()) {
196+
if (interaction_profile.is_valid()) {
197197
String index = p_name.split("/")[1];
198198
int id = index.to_int();
199199

@@ -211,7 +211,6 @@ bool OpenXRActionSets::_set(const String p_name, Variant p_value) {
211211
// Must be a property of our superclass, returning false will handle it further
212212
return false;
213213
}
214-
*/
215214

216215
OpenXRActionSets::OpenXRActionSets() {
217216
// nothing to do here yet...

src/gdclasses/actions/OpenXRActionSets.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ class OpenXRActionSets : public Resource {
3535
int number_of_interaction_profiles() const;
3636
Ref<OpenXRInteractionProfile> get_interaction_profile(int p_index) const;
3737

38-
/* this needs https://github.com/godotengine/godot-cpp/pull/656
3938
Array _get_property_list();
4039
Variant _get(const String p_name) const;
4140
bool _set(const String p_name, Variant p_value);
42-
*/
4341

4442
OpenXRActionSets();
4543
~OpenXRActionSets();

0 commit comments

Comments
 (0)