diff --git a/icon.png.import b/icon.png.import new file mode 100644 index 0000000..96cbf46 --- /dev/null +++ b/icon.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.png" +dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/src/Branch.tscn b/src/Branch.tscn index 0098502..1f8e815 100644 --- a/src/Branch.tscn +++ b/src/Branch.tscn @@ -1,203 +1,17 @@ [gd_scene load_steps=3 format=2] -[ext_resource path="res://assets/antler.jpg" type="Texture" id=1] - -[sub_resource type="GDScript" id=1] -script/source = "extends Control - -# Declare member variables here. Examples: -# var a = 2 -# var b = \"text\" - -var child -var parents = [] - -# Called when the node enters the scene tree for the first time. -func _ready(): - pass # Replace with function body. - -func setIndividuals(_child, _parents): - if _child: - child = _child - if _parents: - parents = _parents - - calcPositions() - -func calcPositions(): - var parent_positions = [] - var child_positions = [] - var child_box_size - - if child: - child_box_size = Vector2(0, child.getRect().size.y/2) - child_positions.append(child.rect_position - child_box_size/1.5) - else: - child_box_size = Vector2(0, 200) - child_positions.append(0) - - if parents[0]: - parent_positions.append(parents[0].rect_position + child_box_size/2) - else: - parent_positions.append(0) - - if parents[1]: - parent_positions.append(parents[1].rect_position + child_box_size/2) - else: - parent_positions.append(0) - - setPosition(child_positions, parent_positions) - - -func setPosition(childrenpos, parentspos): - - if !childrenpos[0]: - if parentspos[0] and parentspos[1]: - childrenpos[0] = parentspos[0] + (parentspos[0] - parentspos[1])/2 - else: - printerr(\"cannot render branch without parents or children\") - return false - - rect_position = childrenpos[0] - - if has_node(\"LineLeft\"): - - var connector_right = get_node(\"LineRight\") - var connector_left = get_node(\"LineLeft\") - var relative_right = Vector2(0,0) - var relative_left = Vector2(0,0) - - if parentspos[0]: - relative_left = parentspos[0] - childrenpos[0] - - if parentspos[1]: - relative_right = parentspos[1] - childrenpos[0] - - connector_right.width = 140 - connector_left.width = 140 - - if relative_right != Vector2(0,0): - connector_right.points = PoolVector2Array(get_points(Vector2(0, 0), relative_right)) - connector_right.show() - else: - connector_right.hide() - - if relative_left != Vector2(0,0): - connector_left.points = PoolVector2Array(get_points(Vector2(0, 0), relative_left)) - connector_left.show() - else: - connector_left.hide() - -# -# get_node(\"Line2D\").position = childrenpos[0] -# -# var maxpoints = get_node(\"Line2D\").points.size() -# -# if parentspos[0]: -# get_points -# get_node(\"Line2D\").points[0] = parentspos[0] - childrenpos[0] -# -# if parentspos[1]: -# get_node(\"Line2D\").points[maxpoints-1] = parentspos[1] - childrenpos[0] - else: - - var connector_right = get_node(\"ConnectorRight\") - var connector_left = get_node(\"ConnectorLeft\") - var relative_right = Vector2(0,0) - var relative_left = Vector2(0,0) - - if parentspos[0]: - relative_left = parentspos[0] - childrenpos[0] - - if parentspos[1]: - relative_right = parentspos[1] - childrenpos[0] - - var all_polygons - - if relative_right != Vector2(0,0): - all_polygons = get_polygons(Vector2(0, 0), relative_right) - connector_right.polygon = PoolVector2Array(all_polygons[0]) - connector_right.uv = PoolVector2Array(all_polygons[1]) - connector_right.show() - else: - connector_right.hide() - - if relative_left != Vector2(0,0): - all_polygons = get_polygons(relative_left, Vector2(0, 0)) - connector_left.polygon = PoolVector2Array(all_polygons[0]) - connector_left.uv = PoolVector2Array(all_polygons[1]) - connector_left.show() - else: - connector_left.hide() - -func get_points(from: Vector2, to: Vector2): - var points = [] - - var step_width = 80 - - var polycount = max(1, floor(from.distance_to(to) / step_width)) - step_width = floor((to-from).x / polycount) - - var new_point - - # print(\"from: \", from, \" to: \", to, \" polycount: \", polycount, \" ratio: \", ratio, \" thickness: \", thickness) - - randomize() - - # way from top left to top middle - for i in range(polycount+1): - new_point = lerp(from, to, i/polycount) + rand_vector() - points.append(new_point) - - return points - -func get_polygons(from : Vector2, to : Vector2): - var polygon_points = [] - var uv_points = [] - - var step_width = 80 - var thickness - - var polycount = max(1, floor(from.distance_to(to) / step_width)) - step_width = floor((to-from).x / polycount) - - var ratio = from.distance_to(to) / to.distance_to(from) - - thickness = clamp(abs(ratio), 0.6, 2) * sign(ratio) * 100 - - var new_point - - # print(\"from: \", from, \" to: \", to, \" polycount: \", polycount, \" ratio: \", ratio, \" thickness: \", thickness) - - randomize() - - # way from top left to top middle - for i in range(polycount+1): - new_point = lerp(from, to, i/polycount) + rand_vector() - polygon_points.append(new_point) - uv_points.append(new_point + rand_vector(-20, 20)) - - # and back from bottom middle to bottom left - for i in range(polycount+1): - new_point = lerp(to, from, i/polycount) + rand_vector() + Vector2(0, thickness)* sign(ratio) - polygon_points.append(new_point) - uv_points.append(new_point + rand_vector(-20, 20)) - - return [polygon_points, uv_points] - - -func rand_vector(rand_min = -8, rand_max = 8): - return Vector2(floor(rand_range(rand_min,rand_max)), floor(rand_range(rand_min,rand_max)))" +[ext_resource path="res://src/Branch.gd" type="Script" id=1] +[ext_resource path="res://assets/antler.jpg" type="Texture" id=2] [node name="Branch" type="Control"] -script = SubResource( 1 ) +script = ExtResource( 1 ) [node name="LineLeft" type="Line2D" parent="."] z_index = -1 points = PoolVector2Array( -50, -10, -44.1667, -3.81437, -35.1922, -2.68076, -28.0621, -0.232655, -19.9627, -0.744202, -12.9715, 2.23981, -7.34454, 6.24692, -1.29124, 9.40145, 0, 10 ) width = 80.0 default_color = Color( 1, 1, 1, 1 ) -texture = ExtResource( 1 ) +texture = ExtResource( 2 ) texture_mode = 1 begin_cap_mode = 2 end_cap_mode = 2 @@ -208,7 +22,7 @@ z_index = -1 points = PoolVector2Array( 0, 10, 3.22741, 8.97517, 9.02493, 4.71229, 15.7603, 2.41033, 22.3251, 0.449406, 28.2079, 0.619923, 35.2843, -0.573685, 44.4921, -3.81347, 48.9255, -7.47955, 50, -10 ) width = 80.0 default_color = Color( 1, 1, 1, 1 ) -texture = ExtResource( 1 ) +texture = ExtResource( 2 ) texture_mode = 1 begin_cap_mode = 2 end_cap_mode = 2 diff --git a/src/Branch2.tscn b/src/Branch2.tscn index d438553..174bfd9 100644 --- a/src/Branch2.tscn +++ b/src/Branch2.tscn @@ -3,7 +3,6 @@ [ext_resource path="res://src/Branch.gd" type="Script" id=1] [ext_resource path="res://assets/antler.jpg" type="Texture" id=2] - [node name="Branch" type="Control"] script = ExtResource( 1 ) diff --git a/src/Tree.gd b/src/Tree.gd index a1058a3..5c49559 100644 --- a/src/Tree.gd +++ b/src/Tree.gd @@ -25,13 +25,22 @@ func _enter_tree(): poi.setScale( 1 ) poi.setLevel(0) add_child(poi) + # elements, that should be moved to the center of the tree + # after alle other elements has been placed move_to_center.append(poi) + # partner of poi goes to the right + # renderPartners(id, level, column, side, scale): renderPartners(poi.uid, 0, 0, 1, 1) + + # siblings of poit goes to the left + # renderSiblings(id, level, column, side): renderSiblings(poi.uid, 0, 0, -1) level_counts['level0'] = [0] + # render parents and grandparents + # renderParents(child, level, column = 0): renderParents(poi, -1) func _exit_tree(): @@ -42,6 +51,8 @@ func _exit_tree(): # get_child(i).queue_free() remove_child(get_child(i)) level_counts = {} + move_to_center = [] + rect_position = Vector2(0,0) # Called when the node enters the scene tree for the first time. func _ready(): @@ -96,17 +107,6 @@ func renderParents(child, level, column = 0): side *= -1 renderBranch(child, individuals, level) -# not in use -func renderChildren(id, level): - var individuals = findChildren(id) - if individuals: - for individual in individuals: - if individual: - individual.setPosition( getFreePosition(level) ) - individual.setLevel(level) - add_child(individual) - renderChildren(individual.uid, level+1) - func renderPartners(id, level, column, side, scale): var individuals = findPartners(id) var i = 1 @@ -124,8 +124,20 @@ func renderPartners(id, level, column, side, scale): add_child(individual) if level == 0: move_to_center.append(individual) + + # children are always coming from the individual in the tree + # therefor we could spare this information, + # and only show the link from which partner (who is on the tree) the kid is + # TODO + # right now only for POI kids + # maybe limit it to individual.uid AND current id (otherwise kids brought to the marrage are also listed) + # if level == 0: + # renderChildren(individual.uid, level+1, newcolumn, side) + i += 1 + + # TODO - branches between partner of siblings # var family = individuals.duplicate() # family.append(findIndividual(id)) @@ -133,6 +145,23 @@ func renderPartners(id, level, column, side, scale): return i-1 +func renderChildren(id, level, column, side): + var individuals = findChildren(id) + if individuals: + var i = 1 + for individual in individuals: + if individual: + var newcolumn = getFreePosition(level, column+ i * side, [0,0], 0) + + individual.setPosition( calcPosition(level, newcolumn) ) + individual.setScale( 0.65 ) + individual.setLevel(level) + add_child(individual) + if level == 0: + move_to_center.append(individual) + #renderChildren(individual.uid, level+1) + i += 1 + func renderSiblings(id, level, column, side): var individuals = findSiblings(id) if individuals: @@ -247,7 +276,8 @@ func setFamilyField(index, field, value): func addIndividual(id, personname, birth, death, occupation, location, gender): # var node = Individual.new(); var node = Individual.instance(); - node.node_init(id, personname, birth, death, occupation, location, gender, '..\\icon.png', '..') + #node.node_init(id, personname, birth, death, occupation, location, gender, '..\\icon.png', '..') + node.node_init(id, personname, birth, death, occupation, location, gender, '', '') _individuals.append(node) return _individuals.size()-1 diff --git a/src/autoloads/config.gd b/src/autoloads/config.gd index 5757f1b..88d396c 100644 --- a/src/autoloads/config.gd +++ b/src/autoloads/config.gd @@ -17,7 +17,8 @@ func read_config(): var err = config.load("settings.cfg") if err == OK: # if not, something went wrong with the file loading print("loading settings.cfg") - familytreeFilename = config.get_value("familytree", "filename", "Stammbaum.ged") + #familytreeFilename = config.get_value("familytree", "filename", "Stammbaum.ged") + familytreeFilename = config.get_value("familytree", "filename", "") familytreeDirectory = config.get_value("familytree", "directory", "_familytree/") familytreeServer = config.get_value("familytree", "server", "") personOfInterest = config.get_value("familytree", "poi", "I1") diff --git a/src/main.gd b/src/main.gd index b41d3ae..0f54dcb 100644 --- a/src/main.gd +++ b/src/main.gd @@ -62,16 +62,19 @@ func update_tree_size(): var moving_by = 0 if tree_node.move_to_center.size(): + print("correcting ", tree_node.move_to_center.size(), " elements") for node in tree_node.move_to_center: - if node is preload("Individual.gd"): + if node is preload("res://src/Individual.gd"): +# print("moving Individual ", node.personname) if moving_by == 0: moving_by = rect.size.x/2 - node.rect_position.x + rect.position.x node.rect_position.x += moving_by - if node is preload("Branch.gd"): + elif node is preload("res://src/Branch.gd"): +# print("moving branch ", node.parents) yield(get_tree(),"idle_frame") node.setIndividuals(null, null) - - +# else: +# print("moving unknown node ", node.name) print("calculated rect size: ", rect.size) print("calculated rect position: ", rect.position.abs()) @@ -86,7 +89,7 @@ func update_tree_size(): get_node("Center/VBox").rect_min_size.x = rect.size.x yield(get_tree(),"idle_frame") - var fontsize = rect.size.x / 40 + var fontsize = max(rect.size.x / 40, 150) get_node("Center/VBox/Center/Headline").rect_min_size.x = rect.size.x get_node("Center/VBox/Center/Headline").rect_min_size.y = fontsize * 1.1 yield(get_tree(),"idle_frame") @@ -110,8 +113,9 @@ func update_tree_size(): get_node("Center/Background").rect_min_size = rect.grow(200).grow_individual(0, fontsize*2, 0, 0 ).size yield(get_tree(),"idle_frame") - get_node("Center/VBox/Center").rect_position = rect.position - yield(get_tree(),"idle_frame") + #get_node("Center/VBox/Center").rect_position = rect.position + #get_node("Center/VBox/Center").rect_position = Vector2(0,0) + #yield(get_tree(),"idle_frame") get_node("Center/VBox/TreeContainer").rect_min_size = rect.size yield(get_tree(),"idle_frame") diff --git a/src/parser.gd b/src/parser.gd index 7a5cce9..e343d60 100644 --- a/src/parser.gd +++ b/src/parser.gd @@ -10,7 +10,11 @@ extends Node func file_prepare(tree): - loadfile(tree, config.familytreeFilename, config.familytreeDirectory, config.familytreeServer) + if config.familytreeFilename and config.familytreeFilename.length(): + loadfile(tree, config.familytreeFilename, config.familytreeDirectory, config.familytreeServer) + else: + # if no family tree filename is given - generate simple tree + file_ready(tree, "") func loadfile(tree, familytreeFilename : String, familytreeDirectory : String, familytreeServer: String):