Add card board (wip)

This commit is contained in:
tilcreator 2023-04-19 18:53:24 +02:00
parent 1bb6cea247
commit 0571825fde
8 changed files with 337 additions and 33 deletions

View File

@ -0,0 +1,57 @@
[gd_scene load_steps=3 format=3 uid="uid://b0jrrgiya70yt"]
[ext_resource type="PackedScene" uid="uid://dy5rd437h5hsw" path="res://logic-scenes/board/card.tscn" id="1_xrckx"]
[ext_resource type="PackedScene" uid="uid://vkcdj8c3ytbq" path="res://logic-scenes/board/post-it.tscn" id="2_ucudl"]
[node name="board of devs" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="card" parent="." instance=ExtResource("1_xrckx")]
layout_mode = 1
text = "this is a testjaklsd;jfasdjf;lasjdlkfjasld;jf;asjdf;"
compatible_postits = Array[Resource("res://logic-scenes/board/post-it.gd")]([])
[node name="post-it" parent="." instance=ExtResource("2_ucudl")]
layout_mode = 1
offset_left = 1.0
offset_top = 542.0
offset_right = 222.754
offset_bottom = 738.338
text = "bbbbbb"
[node name="post-it2" parent="." instance=ExtResource("2_ucudl")]
layout_mode = 1
offset_top = 271.0
offset_right = 222.754
offset_bottom = 467.338
text = "aaaaaaaaaaaaaaaaaaaaaaaaa"
[node name="card2" parent="." instance=ExtResource("1_xrckx")]
layout_mode = 1
offset_left = 312.0
offset_top = 3.0
offset_right = 312.24
offset_bottom = 2.88
text = "wooooooo"
compatible_postits = Array[Resource("res://logic-scenes/board/post-it.gd")]([])
[node name="post-it21" parent="." instance=ExtResource("2_ucudl")]
layout_mode = 1
offset_left = 313.0
offset_top = 545.0
offset_right = 534.754
offset_bottom = 741.338
text = "bar"
[node name="post-it22" parent="." instance=ExtResource("2_ucudl")]
layout_mode = 1
offset_left = 312.0
offset_top = 274.0
offset_right = 534.754
offset_bottom = 470.338
text = "foo"

View File

@ -0,0 +1,72 @@
extends Control
const dev_board_pre = preload("res://dev-util/board of devs.tscn")
var dev_board: Control
func _ready():
dev_board = dev_board_pre.instantiate()
if $cards.get_child_count(false) > 0:
$cards.get_children(false)[0].grab_focus()
# Testing code
for item in dev_board.find_children("*"):
if item is Card:
spawn_card((item as Card).duplicate())
elif item is PostIt:
spawn_postit((item as PostIt).duplicate())
func _process(delta: float):
pass
func spawn_card(card: Card):
$cards.add_child(card)
if $cards.get_child_count(false) == 1:
$cards.get_children(false)[0].grab_focus()
populate_focus_neighbors()
func spawn_postit(postit: PostIt):
$postits.add_child(postit)
populate_focus_neighbors()
func populate_focus_neighbors():
# TODO reorder cards based on position
if $cards.get_child_count(false) <= 0:
return
var first_card = $cards.get_children(false)[0]
var first_postit = $postits.get_children(false)[0] if $postits.get_child_count(false) > 0 else first_card
var first_board_card = $mindmap.get_children(false)[0] if $mindmap.get_child_count(false) > 0 else first_card
var cards = $cards.get_children(false) as Array[Card]
for i in cards.size():
var card = cards[i]
if card == first_card or not (card is Card):
continue
card.focus_neighbor_right = first_board_card # FIXME should be a valid focusable object, but it refuses
card.focus_neighbor_left = first_postit
card.focus_neighbor_up = cards[(i - 1) % cards.size()]
card.focus_neighbor_down = cards[(i + 1) % cards.size()]
var postits = $postits.get_children(false) as Array[PostIt]
for i in postits.size():
var postit = postits[i]
if not (postit is PostIt):
continue
postit.focus_neighbor_right = first_card
postit.focus_neighbor_left = first_board_card
postit.focus_neighbor_up = postits[(i - 1) % postits.size()]
postit.focus_neighbor_down = postits[(i + 1) % postits.size()]
var board_items = $mindmap.get_children(false) as Array
for i in board_items.size():
var board_item = board_items[i]
board_item.focus_neighbor_right = first_postit
board_item.focus_neighbor_left = first_card
board_item.focus_neighbor_up = board_items[(i - 1) % board_items.size()]
board_item.focus_neighbor_down = board_items[(i + 1) % board_items.size()]

View File

@ -0,0 +1,38 @@
[gd_scene load_steps=2 format=3 uid="uid://bpk4hhck7xb8a"]
[ext_resource type="Script" path="res://logic-scenes/board/board.gd" id="1_0rxlw"]
[node name="board" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_0rxlw")
[node name="mindmap" type="Panel" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="cards" type="Panel" parent="."]
custom_minimum_size = Vector2(100, 0)
layout_mode = 1
anchors_preset = 9
anchor_bottom = 1.0
offset_right = 30.0
grow_vertical = 2
[node name="postits" type="Panel" parent="."]
custom_minimum_size = Vector2(100, 0)
layout_mode = 1
anchors_preset = 11
anchor_left = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 0
grow_vertical = 2

View File

@ -0,0 +1,28 @@
@tool
extends Control
class_name Card
@export var text: String = "" :
set (value):
if is_inside_tree() or Engine.is_editor_hint():
$Label.text = value
text = value
@export var compatible_postits: Array[PostIt] = []
@export var voice_line: AudioStream = null
func _ready():
if not Engine.is_editor_hint() and is_inside_tree():
for postit in self.get_children(false):
self.compatible_postits.append(postit as PostIt)
$Label.text = self.text
func _process(delta: float) -> void:
pass
func _on_focus_entered():
print(self, "is focused")
func _on_focus_exited():
print(self, "is not focused")

View File

@ -0,0 +1,47 @@
[gd_scene load_steps=4 format=3 uid="uid://dy5rd437h5hsw"]
[ext_resource type="Script" path="res://logic-scenes/board/card.gd" id="1_emip0"]
[ext_resource type="Texture2D" uid="uid://dyirthpnyeh34" path="res://icon.png" id="2_aibwm"]
[sub_resource type="LabelSettings" id="LabelSettings_13ura"]
font_size = 30
outline_size = 10
outline_color = Color(0, 0, 0, 1)
[node name="card" type="Control"]
layout_mode = 3
anchor_right = 0.179
anchor_bottom = 0.239
offset_right = 0.23999
offset_bottom = -0.119995
grow_horizontal = 2
grow_vertical = 2
focus_mode = 2
script = ExtResource("1_emip0")
compatible_postits = Array[Resource("res://logic-scenes/board/post-it.gd")]([null, null, null])
[node name="TextureRect" type="TextureRect" parent="."]
layout_mode = 0
offset_right = 40.0
offset_bottom = 40.0
texture = ExtResource("2_aibwm")
[node name="Label" type="Label" parent="."]
layout_mode = 0
offset_left = 6.0
offset_top = 7.0
offset_right = 251.0
offset_bottom = 251.0
label_settings = SubResource("LabelSettings_13ura")
autowrap_mode = 3
[node name="postit anchor" type="Control" parent="."]
anchors_preset = 0
offset_left = 100.0
offset_top = 184.0
offset_right = 140.0
offset_bottom = 224.0
[connection signal="focus_entered" from="." to="." method="_on_focus_entered"]
[connection signal="focus_exited" from="." to="." method="_on_focus_exited"]
[connection signal="focus_entered" from="postit anchor" to="." method="_on_postit_anchor_focus_entered"]

View File

@ -0,0 +1,23 @@
@tool
extends Control
class_name PostIt
@export var text: String = "" :
set (value):
if is_inside_tree() or Engine.is_editor_hint():
$Label.text = value
text = value
@export var voice_line: AudioStream = null
func _ready() -> void:
$Label.text = self.text
func _process(delta: float) -> void:
pass
func _on_focus_entered():
print(self, "is focused")
func _on_focus_exited():
print(self, "is not focused")

View File

@ -0,0 +1,39 @@
[gd_scene load_steps=4 format=3 uid="uid://vkcdj8c3ytbq"]
[ext_resource type="Script" path="res://logic-scenes/board/post-it.gd" id="1_yvh5n"]
[ext_resource type="Texture2D" uid="uid://dq7jm5ufknbb6" path="res://vfx/lens-flare-particle.png" id="2_jr288"]
[sub_resource type="LabelSettings" id="LabelSettings_vm4x4"]
font_size = 30
outline_size = 10
outline_color = Color(0, 0, 0, 1)
[node name="post-it" type="Control"]
layout_mode = 3
anchor_right = 0.187
anchor_bottom = 0.239
offset_right = -124.28
offset_bottom = -100.12
grow_horizontal = 2
grow_vertical = 2
focus_mode = 2
script = ExtResource("1_yvh5n")
[node name="TextureRect" type="TextureRect" parent="."]
layout_mode = 0
offset_right = 135.0
offset_bottom = 138.0
texture = ExtResource("2_jr288")
[node name="Label" type="Label" parent="."]
layout_mode = 0
offset_left = 6.0
offset_top = 7.0
offset_right = 131.0
offset_bottom = 134.0
focus_mode = 2
label_settings = SubResource("LabelSettings_vm4x4")
autowrap_mode = 3
[connection signal="focus_entered" from="." to="." method="_on_focus_entered"]
[connection signal="focus_exited" from="." to="." method="_on_focus_exited"]

View File

@ -11,45 +11,45 @@ script/source = "extends TabContainer
var focus_list: Array
func _ready():
for child in get_children():
focus_list.append(_find_selectable_in(child))
for child in get_children():
focus_list.append(_find_selectable_in(child))
func _find_selectable_in(parent:Control):
if parent.focus_mode != FOCUS_NONE:
return parent
if parent.get_child_count() == 0:
return self
else:
for child in parent.get_children():
var ret = _find_selectable_in(child)
if not ret == self:
return ret
if parent.focus_mode != FOCUS_NONE:
return parent
if parent.get_child_count() == 0:
return self
else:
for child in parent.get_children():
var ret = _find_selectable_in(child)
if not ret == self:
return ret
func _unhandled_input(event):
if event.is_action_type():
if event.is_action_pressed(\"ui_left\"): previous()
elif event.is_action_pressed(\"ui_right\"): next()
if event.is_action_type():
if event.is_action_pressed(\"ui_left\"): previous()
elif event.is_action_pressed(\"ui_right\"): next()
func next():
if current_tab < get_tab_count()-1:
if !Input.is_action_just_released(\"mouse_left\"):
if not get_viewport().gui_get_focus_owner() == null:
focus_list[current_tab] = get_viewport().gui_get_focus_owner()
current_tab += 1
focus_list[current_tab].grab_focus()
else:
current_tab += 1
if current_tab < get_tab_count()-1:
if !Input.is_action_just_released(\"mouse_left\"):
if not get_viewport().gui_get_focus_owner() == null:
focus_list[current_tab] = get_viewport().gui_get_focus_owner()
current_tab += 1
focus_list[current_tab].grab_focus()
else:
current_tab += 1
func previous():
if current_tab > 0:
if !Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
if not get_viewport().gui_get_focus_owner() == null:
focus_list[current_tab] = get_viewport().gui_get_focus_owner()
current_tab -= 1
focus_list[current_tab].grab_focus()
else:
current_tab -= 1
if current_tab > 0:
if !Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
if not get_viewport().gui_get_focus_owner() == null:
focus_list[current_tab] = get_viewport().gui_get_focus_owner()
current_tab -= 1
focus_list[current_tab].grab_focus()
else:
current_tab -= 1
"
[sub_resource type="GDScript" id="GDScript_v567h"]