summaryrefslogtreecommitdiff
path: root/modules/visual_script
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-09-01 18:58:52 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-09-01 18:59:46 -0300
commit5b96c3a5527c1b2989dbfbe625f1c763b8887334 (patch)
tree6fbd6ed3703a3f8514e0e45eb590aeac7bc1284d /modules/visual_script
parent3759d378da7ceab382b31b86d69bb90b9eeaba90 (diff)
-Modified Input and added is_action_just_pressed() as well as is_action_just_released()
Diffstat (limited to 'modules/visual_script')
-rw-r--r--modules/visual_script/visual_script_nodes.cpp57
-rw-r--r--modules/visual_script/visual_script_nodes.h13
2 files changed, 67 insertions, 3 deletions
diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp
index f5c5159af7..c0efa8b4ba 100644
--- a/modules/visual_script/visual_script_nodes.cpp
+++ b/modules/visual_script/visual_script_nodes.cpp
@@ -3247,13 +3247,29 @@ PropertyInfo VisualScriptInputAction::get_output_value_port_info(int p_idx) cons
String VisualScriptInputAction::get_caption() const {
+
return "Action";
}
String VisualScriptInputAction::get_text() const {
- return name;
+ switch(mode) {
+ case MODE_PRESSED: {
+ return name;
+ } break;
+ case MODE_RELEASED: {
+ return "not "+name;
+ } break;
+ case MODE_JUST_PRESSED: {
+ return String(name)+" "+TTR("just pressed");
+ } break;
+ case MODE_JUST_RELEASED: {
+ return String(name)+" "+TTR("just released");
+ } break;
+ }
+
+ return String();
}
@@ -3278,19 +3294,50 @@ StringName VisualScriptInputAction::get_action_name() const {
return name;
}
+void VisualScriptInputAction::set_action_mode(Mode p_mode) {
+
+ if (mode==p_mode)
+ return;
+
+ mode=p_mode;
+ ports_changed_notify();
+
+}
+VisualScriptInputAction::Mode VisualScriptInputAction::get_action_mode() const {
+
+ return mode;
+}
+
class VisualScriptNodeInstanceInputAction : public VisualScriptNodeInstance {
public:
VisualScriptInstance* instance;
StringName action;
+ VisualScriptInputAction::Mode mode;
virtual int get_working_memory_size() const { return 1; }
virtual int step(const Variant** p_inputs,Variant** p_outputs,StartMode p_start_mode,Variant* p_working_mem,Variant::CallError& r_error,String& r_error_str) {
- *p_outputs[0]=Input::get_singleton()->is_action_pressed(action);
+ switch(mode) {
+ case VisualScriptInputAction::MODE_PRESSED: {
+ *p_outputs[0]=Input::get_singleton()->is_action_pressed(action);
+ } break;
+ case VisualScriptInputAction::MODE_RELEASED: {
+ *p_outputs[0]=!Input::get_singleton()->is_action_pressed(action);
+ } break;
+ case VisualScriptInputAction::MODE_JUST_PRESSED: {
+ *p_outputs[0]=Input::get_singleton()->is_action_just_pressed(action);
+ } break;
+ case VisualScriptInputAction:: MODE_JUST_RELEASED: {
+ *p_outputs[0]=Input::get_singleton()->is_action_just_released(action);
+ } break;
+
+ }
+
+
return 0;
}
@@ -3302,6 +3349,7 @@ VisualScriptNodeInstance* VisualScriptInputAction::instance(VisualScriptInstance
VisualScriptNodeInstanceInputAction * instance = memnew(VisualScriptNodeInstanceInputAction );
instance->instance=p_instance;
instance->action=name;
+ instance->mode=mode;
return instance;
}
@@ -3348,13 +3396,18 @@ void VisualScriptInputAction::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_action_name","name"),&VisualScriptInputAction::set_action_name);
ObjectTypeDB::bind_method(_MD("get_action_name"),&VisualScriptInputAction::get_action_name);
+ ObjectTypeDB::bind_method(_MD("set_action_mode","mode"),&VisualScriptInputAction::set_action_mode);
+ ObjectTypeDB::bind_method(_MD("get_action_mode"),&VisualScriptInputAction::get_action_mode);
+
ADD_PROPERTY( PropertyInfo(Variant::STRING,"action"),_SCS("set_action_name"),_SCS("get_action_name"));
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Pressed,Released,JustPressed,JustReleased"),_SCS("set_action_mode"),_SCS("get_action_mode"));
}
VisualScriptInputAction::VisualScriptInputAction() {
name="";
+ mode=MODE_PRESSED;
}
diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h
index c0ffb17e15..eeb2f3328d 100644
--- a/modules/visual_script/visual_script_nodes.h
+++ b/modules/visual_script/visual_script_nodes.h
@@ -906,8 +906,16 @@ public:
class VisualScriptInputAction: public VisualScriptNode {
OBJ_TYPE(VisualScriptInputAction,VisualScriptNode)
+public:
+ enum Mode {
+ MODE_PRESSED,
+ MODE_RELEASED,
+ MODE_JUST_PRESSED,
+ MODE_JUST_RELEASED,
+ };
StringName name;
+ Mode mode;
protected:
@@ -936,12 +944,15 @@ public:
void set_action_name(const StringName& p_name);
StringName get_action_name() const;
+ void set_action_mode(Mode p_mode);
+ Mode get_action_mode() const;
+
virtual VisualScriptNodeInstance* instance(VisualScriptInstance* p_instance);
VisualScriptInputAction();
};
-
+VARIANT_ENUM_CAST( VisualScriptInputAction::Mode )
class VisualScriptDeconstruct: public VisualScriptNode {