Skip to content

Commit

Permalink
Merge pull request #40 from luismariotti1/main
Browse files Browse the repository at this point in the history
Main
  • Loading branch information
luismariotti1 authored Jul 21, 2021
2 parents e3f46c4 + 7a2b675 commit c793795
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 28 deletions.
5 changes: 2 additions & 3 deletions Figures/Figures.gd
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func select_figure():
is_select = true
SM.set_position()
Insp.reload_atributes = true
print(is_select)


func get_id():
Expand Down Expand Up @@ -89,9 +88,9 @@ func delete():

func create_dic_to_properties():
info = [
{"id": "rotation", "label": "rotation", "value": rotation},
{"id": "rotation", "label": "Rotation", "value": rotation},
{"type": "checkbox", "id": "flip", "label": "Flip", "value": {"X": flip_x, "Y": flip_y}},
{"id": "line_width", "label": "line width", "value": line_width},
{"id": "line_width", "label": "Line Width", "value": line_width},
{
"listLabel": "Translate",
"type": "list",
Expand Down
2 changes: 1 addition & 1 deletion Figures/Hexagon/Hexagon.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ func init(id):
_figure_name = "hexagon (" + String(_id) + ")"
selection_button.init(_figure_name, self)
create_dic_to_properties()
info.insert(0, {"id": "edge", "label": "edge", "value": edge})
info.insert(0, {"id": "edge", "label": "Edge", "value": edge})
set_properties_in_inspector()


Expand Down
19 changes: 17 additions & 2 deletions Figures/Irregular.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var _is_ready = false
var geometry = Geometry
var new_line: PoolVector2Array
var can_create_vertex = true
var last_position
var vertex_color = ColorN("black")


func init(id):
Expand All @@ -29,11 +31,13 @@ func set_ready():

func create_next_vertex(pos):
if vertex.size() == 0:
last_position = pos
vertex.append(Vector2(0, 0))
inital_pos = pos
translate = inital_pos
else:
if can_create_vertex:
last_position = pos
vertex.append(pos - inital_pos)
if inital_pos.distance_to(pos) <= 0.2 and vertex.size() > 2:
set_ready()
Expand All @@ -42,8 +46,10 @@ func create_next_vertex(pos):
func _physics_process(_delta):
if is_select:
selection_button.pressed = true
vertex_color = ColorN("green")
update_values()
else:
vertex_color = ColorN("black")
selection_button.pressed = false
can_create_new_vertex()
#transformations
Expand Down Expand Up @@ -113,12 +119,21 @@ func pre_render(vertex_mod):
draw_circle(new_line[1], 4, Color(0, 0, 0, 1))


func min_dist():
var next_position = CP.mouse_position_to_cartesian(get_global_mouse_position())
if last_position.distance_to(next_position) < 0.02:
return false
else:
return true


func can_create_new_vertex():
var next_position = CP.mouse_position_to_cartesian(get_global_mouse_position()) - inital_pos
min_dist()
if vertex.size() > 1:
if (
valid_angle(PoolVector2Array([vertex[vertex.size() - 1], next_position]))
and valid_position(new_line)
and valid_position(new_line) and min_dist()
):
can_create_vertex = true
else:
Expand All @@ -133,4 +148,4 @@ func custom_draw_polygon():
for i in range(vertex_mod.size() - 1):
draw_line(vertex_mod[i], vertex_mod[i + 1], color, line_width)
for i in range(vertex_mod.size()):
draw_circle(vertex_mod[i], 4, Color(0, 0, 0, 1))
draw_circle(vertex_mod[i], 4, vertex_color)
3 changes: 2 additions & 1 deletion Figures/Regular.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ func set_edge(value):


func update_local_values():
edge = float(Insp.get_properties_by_id("edge"))
if Insp.get_properties_by_id("edge"):
edge = float(Insp.get_properties_by_id("edge"))


func _physics_process(_delta):
Expand Down
2 changes: 1 addition & 1 deletion Figures/Square/Square.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func init(id):
_figure_name = "square (" + String(_id) + ")"
selection_button.init(_figure_name, self)
create_dic_to_properties()
info.insert(0, {"id": "edge", "label": "edge", "value": edge})
info.insert(0, {"id": "edge", "label": "Edge", "value": edge})
# var list_of_vertices_insp = {"listLabel": "vertex", "type": "list", "infos": []}
# for i in range(vertex.size()):
# list_of_vertices_insp["infos"].insert(
Expand Down
2 changes: 1 addition & 1 deletion Figures/Triangle/Triangle.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ func init(id):
_figure_name = "triangle (" + String(_id) + ")"
selection_button.init(_figure_name, self)
create_dic_to_properties()
info.insert(0, {"id": "edge", "label": "edge", "value": edge})
info.insert(0, {"id": "edge", "label": "Edge", "value": edge})
set_properties_in_inspector()


Expand Down
37 changes: 25 additions & 12 deletions GUI/Display/Display.gd
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func _process(_delta):
set_margin(MARGIN_BOTTOM, Res.get_display_res().size.y)
if is_clicking and is_in_display(clicked_position) and clicked_position != null:
create_object()
if creating and PN.get_button_selected() != "Vertex":
figures[figures.size() - 1].queue_free()
figures.remove(figures.size() - 1)
creating = false


func is_in_display(Position):
Expand Down Expand Up @@ -59,6 +63,19 @@ func create_object():
)
)

func delete_object():
var position_list = SM.get_position()
ids_avaiable.append(figures[position_list].get_id())
figures[position_list].delete()
figures[figures.size() - 1].set_is_selected(false)
figures[position_list].queue_free()
figures.remove(position_list)
if figures.size() != 0:
figures[figures.size() - 1].select_figure()
else:
Insp.clear()
Insp.reload_atributes = true


func _input(event):
if PN.get_button_selected() != "":
Expand Down Expand Up @@ -86,7 +103,9 @@ func _input(event):
)
if figures[figures.size() - 1]._is_ready == true:
if ids_avaiable.size() > 0:
ids_avaiable.sort()
figures[figures.size() - 1].init(ids_avaiable[0])
ids_avaiable.remove(0)
else:
figures[figures.size() - 1].init(figures.size() - 1)
figures[figures.size() - 1].select_figure()
Expand All @@ -95,7 +114,6 @@ func _input(event):
Insp.reload_atributes = true
creating = false


if PN.get_button_selected() != "Vertex":
add_child(new_figure)
figures.append(new_figure)
Expand Down Expand Up @@ -124,14 +142,9 @@ func _input(event):
Insp.reload_atributes = true

if event.is_action_pressed("delete_figure") and figures.size() > 0:
var position_list = SM.get_position()
ids_avaiable.append(figures[position_list].get_id())
figures[position_list].delete()
figures[figures.size() - 1].set_is_selected(false)
figures[position_list].queue_free()
figures.remove(position_list)
if figures.size() != 0:
figures[figures.size() - 1].select_figure()
else:
Insp.clear()
Insp.reload_atributes = true
delete_object()

if event.is_action_pressed("cancel") and creating:
figures[figures.size() - 1].queue_free()
figures.remove(figures.size() - 1)
creating = false
13 changes: 6 additions & 7 deletions GUI/Menus/MenuBar/MenuBarButton/MenuBarButton.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ onready var PN = get_node("/root/PanelInfo")
var _title
var _id: int

func init(id, title,tamanho, sub_title, scuts):

func init(id, title, tamanho, sub_title, scuts):
_id = id
_title = title
text = title

for i in range(tamanho):
get_popup().add_item(String(sub_title[i]))

for j in range(scuts.size()):
get_popup().set_item_shortcut(j, set_shortcut(scuts[j]), true)

get_popup().connect("id_pressed", self, "_on_MenuBarButton_pressed")


Expand All @@ -25,12 +26,10 @@ func set_shortcut(key):
inputeventkey.control = true
shortcut.set_shortcut(inputeventkey)
return shortcut



func _on_MenuBarButton_pressed(id):
var item_name = get_popup().get_item_text(id)
# print("btton clicked parent in menuBarButton >> ", get_parent().button_clicked)
var item_name = get_popup().get_item_text(id)
if item_name == "About":
var popup = load("res://GUI/PopUp/About/About.tscn").instance()
get_tree().get_root().get_node("Main/Layout").add_child(popup)
Expand All @@ -42,4 +41,4 @@ func _on_MenuBarButton_pressed(id):
elif item_name == "Square":
PN.set_button_selected(item_name)
elif item_name == "Hexagon":
PN.set_button_selected(item_name)
PN.set_button_selected(item_name)
5 changes: 5 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ delete_figure={
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777224,"unicode":0,"echo":false,"script":null)
]
}
cancel={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777217,"unicode":0,"echo":false,"script":null)
]
}

[rendering]

Expand Down

0 comments on commit c793795

Please sign in to comment.