Using lines cursor
This commit is contained in:
@@ -28,6 +28,7 @@ func _ready():
|
||||
for k in vmode.keys():
|
||||
vmode[k].hide()
|
||||
$building_cursor.hide()
|
||||
$"%line_cursor".hide()
|
||||
$"%building_type".connect("item_selected", self, "change_building_type")
|
||||
|
||||
func editor_event(evname: String, args: Array):
|
||||
@@ -69,6 +70,8 @@ func editor_event(evname: String, args: Array):
|
||||
pass
|
||||
elif evname == "mouse_drag_off":
|
||||
pass
|
||||
elif evname == "line_cursor_motion":
|
||||
pass
|
||||
else:
|
||||
breakpoint
|
||||
func mouse_drag(position):
|
||||
|
||||
@@ -336,6 +336,20 @@ monitoring = false
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2, 0 )
|
||||
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="MeshInstance" parent="building_rot_cursor"]
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <scene/gui/button.h>
|
||||
#include <scene/gui/line_edit.h>
|
||||
#include <scene/3d/immediate_geometry.h>
|
||||
#include <scene/3d/camera.h>
|
||||
#include <core/io/config_file.h>
|
||||
#include <core/os/file_access.h>
|
||||
#include <core/io/json.h>
|
||||
@@ -214,6 +215,7 @@ static HandleCreateNewLine *new_line_handler = nullptr;
|
||||
RoadLinesEditor::RoadLinesEditor(WorldEditor *editor)
|
||||
: active(false)
|
||||
, editor(editor)
|
||||
, cursor_enabled(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -246,6 +248,13 @@ void RoadLinesEditor::update(float delta)
|
||||
if (!active)
|
||||
activate();
|
||||
// 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()
|
||||
@@ -261,7 +270,45 @@ void RoadLinesEditor::editor_command(const String &command, 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()
|
||||
|
||||
@@ -5,6 +5,7 @@ class ItemList;
|
||||
class RoadLinesEditor {
|
||||
bool active;
|
||||
WorldEditor *editor;
|
||||
bool cursor_enabled;
|
||||
|
||||
public:
|
||||
RoadLinesEditor(WorldEditor *editor);
|
||||
@@ -16,6 +17,7 @@ public:
|
||||
void exit();
|
||||
void editor_command(const String &command, const Array &args);
|
||||
void editor_event(const String &event, const Array &args);
|
||||
int get_camera_mode() const;
|
||||
void update_ui();
|
||||
void create_new_line_at_cursor(const String &line_name);
|
||||
template <class T> T *get_as_node(const String &path);
|
||||
|
||||
@@ -278,16 +278,8 @@ 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) {
|
||||
/* Stop drag mode is mouse1 no longer pressed */
|
||||
if (!Input::get_singleton()->is_action_pressed(
|
||||
"mouse1")) {
|
||||
dragging = false;
|
||||
@@ -299,7 +291,6 @@ void WorldEditor::_notification(int which)
|
||||
emit_signal("editor_event", "mouse_drag_off",
|
||||
args);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
Transform cam_xform = cam->get_global_transform();
|
||||
if (current_camera_mode == 1) {
|
||||
@@ -355,6 +346,12 @@ void WorldEditor::_notification(int which)
|
||||
|
||||
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) {
|
||||
Ref<InputEventMouseMotion> motionevt = event;
|
||||
if (motionevt.is_valid())
|
||||
|
||||
@@ -9,7 +9,6 @@ protected:
|
||||
StreamWorld *stream_world;
|
||||
Control *editor_menu;
|
||||
void set_camera_mode(int mode);
|
||||
int get_camera_mode() const;
|
||||
void disable_all();
|
||||
void mode_buildings();
|
||||
void mode_navigation();
|
||||
@@ -38,5 +37,6 @@ public:
|
||||
WorldEditor();
|
||||
virtual ~WorldEditor();
|
||||
void editor_command(const String &command, const Array &args);
|
||||
int get_camera_mode() const;
|
||||
};
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user