Building editing update
This commit is contained in:
@@ -18,6 +18,8 @@ WorldEditor::WorldEditor()
|
||||
, current_camera_mode(-1)
|
||||
, motion(Vector2())
|
||||
, old_mouse_pos(Vector2(-1, -1))
|
||||
, dragging(false)
|
||||
, drag_delay(0.2f)
|
||||
{
|
||||
if (!InputMap::get_singleton()->has_action("left"))
|
||||
InputMap::get_singleton()->add_action("left");
|
||||
@@ -31,6 +33,14 @@ WorldEditor::WorldEditor()
|
||||
InputMap::get_singleton()->add_action("action");
|
||||
if (!InputMap::get_singleton()->has_action("action2"))
|
||||
InputMap::get_singleton()->add_action("action2");
|
||||
if (!InputMap::get_singleton()->has_action("editor_cam1"))
|
||||
InputMap::get_singleton()->add_action("editor_cam1");
|
||||
if (!InputMap::get_singleton()->has_action("editor_cam2"))
|
||||
InputMap::get_singleton()->add_action("editor_cam2");
|
||||
if (!InputMap::get_singleton()->has_action("editor_cam3"))
|
||||
InputMap::get_singleton()->add_action("editor_cam3");
|
||||
if (!InputMap::get_singleton()->has_action("mouse1"))
|
||||
InputMap::get_singleton()->add_action("mouse1");
|
||||
}
|
||||
|
||||
WorldEditor::~WorldEditor()
|
||||
@@ -245,8 +255,10 @@ void WorldEditor::_notification(int which)
|
||||
}
|
||||
}
|
||||
set_process_unhandled_input(true);
|
||||
set_physics_process(true);
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE:
|
||||
set_physics_process(false);
|
||||
set_process_unhandled_input(false);
|
||||
break;
|
||||
case NOTIFICATION_PHYSICS_PROCESS: {
|
||||
@@ -256,6 +268,29 @@ void WorldEditor::_notification(int which)
|
||||
if (!cam)
|
||||
return;
|
||||
float delta = get_physics_process_delta_time();
|
||||
if (Input::get_singleton()->is_action_just_pressed(
|
||||
"editor_cam1"))
|
||||
set_camera_mode(1);
|
||||
if (Input::get_singleton()->is_action_just_pressed(
|
||||
"editor_cam2"))
|
||||
set_camera_mode(2);
|
||||
if (Input::get_singleton()->is_action_just_pressed(
|
||||
"editor_cam3"))
|
||||
set_camera_mode(3);
|
||||
if (dragging) {
|
||||
if (!Input::get_singleton()->is_action_pressed(
|
||||
"mouse1")) {
|
||||
dragging = false;
|
||||
drag_delay = 0.2f;
|
||||
Array args;
|
||||
Vector2 position =
|
||||
get_viewport()->get_mouse_position();
|
||||
args.push_back(position);
|
||||
emit_signal("editor_event", "mouse_drag_off",
|
||||
args);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
Transform cam_xform = cam->get_global_transform();
|
||||
if (current_camera_mode == 1) {
|
||||
Vector2 mouse_pos =
|
||||
@@ -288,14 +323,50 @@ void WorldEditor::_notification(int which)
|
||||
cam_xform.origin.y += 10.0f * hh * delta;
|
||||
moved = true;
|
||||
}
|
||||
if (moved) {
|
||||
cam->set_global_transform(cam_xform);
|
||||
Array move_args;
|
||||
move_args.push_back(cam_xform);
|
||||
emit_signal("editor_event",
|
||||
"editor_camera_moved", move_args);
|
||||
}
|
||||
}
|
||||
if (!dragging && drag_delay >= 0.0f)
|
||||
drag_delay -= delta;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void WorldEditor::_unhandled_input(const Ref<InputEvent> &event)
|
||||
{
|
||||
print_line("unhandled_input: " + event->as_text());
|
||||
if (current_camera_mode != 1) {
|
||||
Ref<InputEventMouseMotion> motionevt = event;
|
||||
if (motionevt.is_valid())
|
||||
motion = motionevt->get_relative();
|
||||
}
|
||||
if (Input::get_singleton()->is_action_just_pressed("mouse1")) {
|
||||
Array args;
|
||||
Vector2 position = get_viewport()->get_mouse_position();
|
||||
args.push_back(position);
|
||||
emit_signal("editor_event", "mouse_press", args);
|
||||
} else if (Input::get_singleton()->is_action_pressed("mouse1")) {
|
||||
if (dragging) {
|
||||
Array args;
|
||||
Vector2 position = get_viewport()->get_mouse_position();
|
||||
args.push_back(position);
|
||||
emit_signal("editor_event", "mouse_drag", args);
|
||||
} else {
|
||||
if (drag_delay < 0.0f && !dragging) {
|
||||
dragging = true;
|
||||
Array args;
|
||||
Vector2 position =
|
||||
get_viewport()->get_mouse_position();
|
||||
args.push_back(position);
|
||||
emit_signal("editor_event", "mouse_drag_on",
|
||||
args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WorldEditor::world_exited()
|
||||
|
||||
@@ -30,6 +30,8 @@ private:
|
||||
int current_camera_mode;
|
||||
Vector2 motion;
|
||||
Vector2 old_mouse_pos;
|
||||
bool dragging;
|
||||
float drag_delay;
|
||||
|
||||
public:
|
||||
WorldEditor();
|
||||
|
||||
Reference in New Issue
Block a user