-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPropsScript.js
More file actions
177 lines (162 loc) · 5.67 KB
/
Copy pathPropsScript.js
File metadata and controls
177 lines (162 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// !_ref: http://source.com/mywidget.ui
engine.ImportExtension("qt.core");
var data_ =
{
widget : null
};
var clicker =
{
highlightName : "MySpecialHighlight",
handleClick : function(ent, button, raycast)
{
//print("Entity clicked: " + ent);
this.toggleHover(ent);
},
toggleHover : function(ent)
{
var h = ent.GetComponent("EC_Highlight", this.highlightName);
if (h == null && ent.dynamiccomponent)
{
print("- Enabling selection");
h = ent.CreateComponent("EC_Highlight", this.highlightName, 2, false);
h.SetTemporary(true);
h.visible = true;
}
else
{
print("- Disabling selection");
ent.RemoveComponent("EC_Highlight", this.highlightName);
//Tänne remove inputs
}
},
removeHighlights : function(ents)
{
for(var i=0; i<ents.length; ++i)
if (ents[i].GetComponent("EC_Highlight", this.highlightName) != null)
this.toggleHover(ents[i]);
},
getSelectedEntities : function()
{
scene.GetEntitiesWithComponent("EC_Highlight", this.highlightName);
},
//Handling keypresses in Tundra
/*
Props will be distinguished from background entities with an EC_Dynamiccomponent called Prop
*/
HandleKeyPressed : function(e)
{
//First, movement to xyz coordinates.(Arrows, space and ctrl)
if(e.keyCode == Qt.Key_Up){
var ents = scene.GetEntitiesWithComponent('EC_Highlight', this.highlightName);
for(var i=0; i<ents.length; i++){
var tm = ents[i].placeable.transform;
tm.pos.x = tm.pos.x + 0.5;
ents[i].placeable.transform = tm;
}
}else if(e.keyCode == Qt.Key_Down){
var ents = scene.GetEntitiesWithComponent('EC_Highlight', this.highlightName);
for(var i=0; i<ents.length; i++){
var tm = ents[i].placeable.transform;
tm.pos.x = tm.pos.x - 0.5;
ents[i].placeable.transform = tm;
}
}else if(e.keyCode == Qt.Key_Right){
var ents = scene.GetEntitiesWithComponent('EC_Highlight', this.highlightName);
for(var i=0; i<ents.length; i++){
var tm = ents[i].placeable.transform;
tm.pos.z = tm.pos.z + 0.5;
ents[i].placeable.transform = tm;
}
}else if(e.keyCode == Qt.Key_Left){
var ents = scene.GetEntitiesWithComponent('EC_Highlight', this.highlightName);
for(var i=0; i<ents.length; i++){
var tm = ents[i].placeable.transform;
tm.pos.z = tm.pos.z - 0.5;
ents[i].placeable.transform = tm;
}
}else if(e.keyCode == Qt.Key_Space){
var ents = scene.GetEntitiesWithComponent('EC_Highlight', this.highlightName);
for(var i=0; i<ents.length; i++){
var tm = ents[i].placeable.transform;
tm.pos.y = tm.pos.y + 0.5;
ents[i].placeable.transform = tm;
}
}else if(e.keyCode == Qt.Key_Control){
var ents = scene.GetEntitiesWithComponent('EC_Highlight', this.highlightName);
for(var i=0; i<ents.length; i++){
var tm = ents[i].placeable.transform;
tm.pos.y = tm.pos.y - 0.5;
ents[i].placeable.transform = tm;
}
//Add rotation.(Tab + CapsLock)
}else if(e.keyCode == Qt.Key_CapsLock){
var ents = scene.GetEntitiesWithComponent('EC_Highlight', this.highlightName);
for(var i=0; i<ents.length; i++){
var tm = ents[i].placeable.transform;
tm.rot.y = tm.rot.y + 0.5;
ents[i].placeable.transform = tm;
}
}else if(e.keyCode == Qt.Key_Tab){
var ents = scene.GetEntitiesWithComponent('EC_Highlight', this.highlightName);
for(var i=0; i<ents.length; i++){
var tm = ents[i].placeable.transform;
tm.rot.y = tm.rot.y - 0.5;
ents[i].placeable.transform = tm;
}
}else if(e.keyCode == Qt.Key_Delete){
var ents = scene.GetEntitiesWithComponent('EC_Highlight', this.highlightName);
for(var i=0; i<ents.length; i++){
//Maybe some prompt 'Are you sure you want to remove entity? etc here'
//scene.RemoveEntity(ents[i].Id());
}
}
},
checkInputs : function(ent)
{
if(!inputMapper){
var inputMapper = input.RegisterInputContextRaw('RendererSettings', 90);
inputMapper.KeyPressed.connect(this, this.HandleKeyPressed);
inputMapper.KeyDown.connect(this, this.HandleKeyPressed);
}
},
init: function(ent)
{
print("Initialized");
sceneinteract.EntityClicked.connect(this, this.handleClick);
this.checkInputs(ent);
}
};
function Start(ent)
{
clicker.init(ent);
/*
data_.widget = ui.LoadFromFile("http://source.com/mywidget.ui", false);
data_.widget.myButton.clicked.connect(ButtonOrSomethingPressed);
data_.widget.visible = true;
*/
}
function ButtonOrSomethingPressed()
{
var selected = clicker.getSelectedEntities();
if (selected.length == 0)
{
console.LogWarning("No selected entities");
return;
}
for (i in selected){
print (selected[i]);
}
clicker.removeHighlights(selected);
}
if (server.IsRunning())
Start();
else
Start();
function OnScriptDestroyed(){
if(clicker != null ){
//clicker.removeHighlights(clicker.getSelectedEntities());
input.UnregisterInputContextRaw("RendererSettings");
data_ = null;
clicker = null;
}
}