Using lines cursor
This commit is contained in:
@@ -28,6 +28,7 @@ func _ready():
|
|||||||
for k in vmode.keys():
|
for k in vmode.keys():
|
||||||
vmode[k].hide()
|
vmode[k].hide()
|
||||||
$building_cursor.hide()
|
$building_cursor.hide()
|
||||||
|
$"%line_cursor".hide()
|
||||||
$"%building_type".connect("item_selected", self, "change_building_type")
|
$"%building_type".connect("item_selected", self, "change_building_type")
|
||||||
|
|
||||||
func editor_event(evname: String, args: Array):
|
func editor_event(evname: String, args: Array):
|
||||||
@@ -69,6 +70,8 @@ func editor_event(evname: String, args: Array):
|
|||||||
pass
|
pass
|
||||||
elif evname == "mouse_drag_off":
|
elif evname == "mouse_drag_off":
|
||||||
pass
|
pass
|
||||||
|
elif evname == "line_cursor_motion":
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
breakpoint
|
breakpoint
|
||||||
func mouse_drag(position):
|
func mouse_drag(position):
|
||||||
|
|||||||
@@ -336,6 +336,20 @@ monitoring = false
|
|||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2, 0 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2, 0 )
|
||||||
shape = SubResource( 12 )
|
shape = SubResource( 12 )
|
||||||
|
|
||||||
|
[node name="line_cursor" type="MeshInstance" parent="."]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
mesh = SubResource( 10 )
|
||||||
|
material/0 = SubResource( 11 )
|
||||||
|
|
||||||
|
[node name="Area" type="Area" parent="line_cursor"]
|
||||||
|
collision_layer = 32768
|
||||||
|
collision_mask = 32768
|
||||||
|
monitoring = false
|
||||||
|
|
||||||
|
[node name="CollisionShape" type="CollisionShape" parent="line_cursor/Area"]
|
||||||
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2, 0 )
|
||||||
|
shape = SubResource( 12 )
|
||||||
|
|
||||||
[node name="building_rot_cursor" type="Spatial" parent="."]
|
[node name="building_rot_cursor" type="Spatial" parent="."]
|
||||||
|
|
||||||
[node name="building_rot_cursor" type="MeshInstance" parent="building_rot_cursor"]
|
[node name="building_rot_cursor" type="MeshInstance" parent="building_rot_cursor"]
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <scene/gui/button.h>
|
#include <scene/gui/button.h>
|
||||||
#include <scene/gui/line_edit.h>
|
#include <scene/gui/line_edit.h>
|
||||||
#include <scene/3d/immediate_geometry.h>
|
#include <scene/3d/immediate_geometry.h>
|
||||||
|
#include <scene/3d/camera.h>
|
||||||
#include <core/io/config_file.h>
|
#include <core/io/config_file.h>
|
||||||
#include <core/os/file_access.h>
|
#include <core/os/file_access.h>
|
||||||
#include <core/io/json.h>
|
#include <core/io/json.h>
|
||||||
@@ -214,6 +215,7 @@ static HandleCreateNewLine *new_line_handler = nullptr;
|
|||||||
RoadLinesEditor::RoadLinesEditor(WorldEditor *editor)
|
RoadLinesEditor::RoadLinesEditor(WorldEditor *editor)
|
||||||
: active(false)
|
: active(false)
|
||||||
, editor(editor)
|
, editor(editor)
|
||||||
|
, cursor_enabled(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,6 +248,13 @@ void RoadLinesEditor::update(float delta)
|
|||||||
if (!active)
|
if (!active)
|
||||||
activate();
|
activate();
|
||||||
// print_line("road_lines_editor");
|
// print_line("road_lines_editor");
|
||||||
|
if (!cursor_enabled && get_camera_mode() == 3) {
|
||||||
|
cursor_enabled = true;
|
||||||
|
get_as_node<Spatial>("%line_cursor")->show();
|
||||||
|
} else if (cursor_enabled && get_camera_mode() != 3) {
|
||||||
|
cursor_enabled = false;
|
||||||
|
get_as_node<Spatial>("%line_cursor")->hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoadLinesEditor::exit()
|
void RoadLinesEditor::exit()
|
||||||
@@ -261,7 +270,45 @@ void RoadLinesEditor::editor_command(const String &command, const Array &args)
|
|||||||
|
|
||||||
void RoadLinesEditor::editor_event(const String &event, const Array &args)
|
void RoadLinesEditor::editor_event(const String &event, const Array &args)
|
||||||
{
|
{
|
||||||
print_line("event: " + event);
|
print_line("RoadLinesEditor::event: " + event);
|
||||||
|
if (event == "mouse_press") {
|
||||||
|
if (cursor_enabled) {
|
||||||
|
Spatial *cursor = get_as_node<Spatial>("%line_cursor");
|
||||||
|
/*
|
||||||
|
var camera = get_viewport().get_camera()
|
||||||
|
var start = camera.project_ray_origin(position)
|
||||||
|
var normal = camera.project_ray_normal(position)
|
||||||
|
var end = start + normal * camera.get_zfar()
|
||||||
|
var space_state = get_world().direct_space_state
|
||||||
|
var result = space_state.intersect_ray(start, end, [], 1 << 15, false, true)
|
||||||
|
*/
|
||||||
|
Vector2 position = args[0];
|
||||||
|
Camera *cam = editor->get_viewport()->get_camera();
|
||||||
|
Vector3 start = cam->project_ray_origin(position);
|
||||||
|
Vector3 normal = cam->project_ray_normal(position);
|
||||||
|
Vector3 end = start + normal * cam->get_zfar();
|
||||||
|
PhysicsDirectSpaceState *space_state =
|
||||||
|
editor->get_world()->get_direct_space_state();
|
||||||
|
PhysicsDirectSpaceState::RayResult result;
|
||||||
|
Set<RID> exclude;
|
||||||
|
space_state->intersect_ray(start, end, result, exclude,
|
||||||
|
(1 << 15) | (1 << 0), true,
|
||||||
|
true);
|
||||||
|
if (result.rid != RID()) {
|
||||||
|
cursor->set_global_transform(
|
||||||
|
Transform(Basis(), result.position));
|
||||||
|
Array pargs;
|
||||||
|
pargs.push_back(result.position);
|
||||||
|
editor->emit_signal("editor_event",
|
||||||
|
"line_cursor_motion",
|
||||||
|
pargs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int RoadLinesEditor::get_camera_mode() const
|
||||||
|
{
|
||||||
|
return editor->get_camera_mode();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoadLinesEditor::update_ui()
|
void RoadLinesEditor::update_ui()
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ class ItemList;
|
|||||||
class RoadLinesEditor {
|
class RoadLinesEditor {
|
||||||
bool active;
|
bool active;
|
||||||
WorldEditor *editor;
|
WorldEditor *editor;
|
||||||
|
bool cursor_enabled;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RoadLinesEditor(WorldEditor *editor);
|
RoadLinesEditor(WorldEditor *editor);
|
||||||
@@ -16,6 +17,7 @@ public:
|
|||||||
void exit();
|
void exit();
|
||||||
void editor_command(const String &command, const Array &args);
|
void editor_command(const String &command, const Array &args);
|
||||||
void editor_event(const String &event, const Array &args);
|
void editor_event(const String &event, const Array &args);
|
||||||
|
int get_camera_mode() const;
|
||||||
void update_ui();
|
void update_ui();
|
||||||
void create_new_line_at_cursor(const String &line_name);
|
void create_new_line_at_cursor(const String &line_name);
|
||||||
template <class T> T *get_as_node(const String &path);
|
template <class T> T *get_as_node(const String &path);
|
||||||
|
|||||||
@@ -278,16 +278,8 @@ void WorldEditor::_notification(int which)
|
|||||||
if (!cam)
|
if (!cam)
|
||||||
return;
|
return;
|
||||||
float delta = get_physics_process_delta_time();
|
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 (dragging) {
|
||||||
|
/* Stop drag mode is mouse1 no longer pressed */
|
||||||
if (!Input::get_singleton()->is_action_pressed(
|
if (!Input::get_singleton()->is_action_pressed(
|
||||||
"mouse1")) {
|
"mouse1")) {
|
||||||
dragging = false;
|
dragging = false;
|
||||||
@@ -299,7 +291,6 @@ void WorldEditor::_notification(int which)
|
|||||||
emit_signal("editor_event", "mouse_drag_off",
|
emit_signal("editor_event", "mouse_drag_off",
|
||||||
args);
|
args);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
}
|
}
|
||||||
Transform cam_xform = cam->get_global_transform();
|
Transform cam_xform = cam->get_global_transform();
|
||||||
if (current_camera_mode == 1) {
|
if (current_camera_mode == 1) {
|
||||||
@@ -355,6 +346,12 @@ void WorldEditor::_notification(int which)
|
|||||||
|
|
||||||
void WorldEditor::_unhandled_input(const Ref<InputEvent> &event)
|
void WorldEditor::_unhandled_input(const Ref<InputEvent> &event)
|
||||||
{
|
{
|
||||||
|
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 (current_camera_mode != 1) {
|
if (current_camera_mode != 1) {
|
||||||
Ref<InputEventMouseMotion> motionevt = event;
|
Ref<InputEventMouseMotion> motionevt = event;
|
||||||
if (motionevt.is_valid())
|
if (motionevt.is_valid())
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ protected:
|
|||||||
StreamWorld *stream_world;
|
StreamWorld *stream_world;
|
||||||
Control *editor_menu;
|
Control *editor_menu;
|
||||||
void set_camera_mode(int mode);
|
void set_camera_mode(int mode);
|
||||||
int get_camera_mode() const;
|
|
||||||
void disable_all();
|
void disable_all();
|
||||||
void mode_buildings();
|
void mode_buildings();
|
||||||
void mode_navigation();
|
void mode_navigation();
|
||||||
@@ -38,5 +37,6 @@ public:
|
|||||||
WorldEditor();
|
WorldEditor();
|
||||||
virtual ~WorldEditor();
|
virtual ~WorldEditor();
|
||||||
void editor_command(const String &command, const Array &args);
|
void editor_command(const String &command, const Array &args);
|
||||||
|
int get_camera_mode() const;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user