Доработка. Исправлен вылет при нажатии удалить.
This commit is contained in:
18
main.tscn
18
main.tscn
@@ -1,12 +1,12 @@
|
|||||||
[gd_scene load_steps=5 format=3 uid="uid://87gtvqd7bbje"]
|
[gd_scene load_steps=5 format=3 uid="uid://87gtvqd7bbje"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://main.gd" id="1_8p35p"]
|
[ext_resource type="Script" path="res://main.gd" id="1_v038r"]
|
||||||
[ext_resource type="Script" path="res://table/table.gd" id="2_xq1tk"]
|
[ext_resource type="Script" path="res://table/table.gd" id="2_mfyp6"]
|
||||||
[ext_resource type="Texture2D" uid="uid://cex4jiu1pcj3x" path="res://edit-add-0.png" id="3_f3g8t"]
|
[ext_resource type="Texture2D" uid="uid://cex4jiu1pcj3x" path="res://edit-add-0.png" id="3_6tmn6"]
|
||||||
[ext_resource type="Texture2D" uid="uid://cx746np1wexnd" path="res://edit-add-1.png" id="4_4ja4j"]
|
[ext_resource type="Texture2D" uid="uid://cx746np1wexnd" path="res://edit-add-1.png" id="4_1x5i2"]
|
||||||
|
|
||||||
[node name="main" type="Node2D"]
|
[node name="main" type="Node2D"]
|
||||||
script = ExtResource("1_8p35p")
|
script = ExtResource("1_v038r")
|
||||||
|
|
||||||
[node name="tabs" type="TabContainer" parent="."]
|
[node name="tabs" type="TabContainer" parent="."]
|
||||||
offset_right = 1594.0
|
offset_right = 1594.0
|
||||||
@@ -26,7 +26,7 @@ offset_right = 1.0
|
|||||||
offset_bottom = 10.0
|
offset_bottom = 10.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
script = ExtResource("2_xq1tk")
|
script = ExtResource("2_mfyp6")
|
||||||
node_type_file = "res://ячейка-1.tscn"
|
node_type_file = "res://ячейка-1.tscn"
|
||||||
|
|
||||||
[node name="btn_add" type="TextureButton" parent="tabs/threats"]
|
[node name="btn_add" type="TextureButton" parent="tabs/threats"]
|
||||||
@@ -35,8 +35,8 @@ offset_left = 1533.0
|
|||||||
offset_top = -2.0
|
offset_top = -2.0
|
||||||
offset_right = 1581.0
|
offset_right = 1581.0
|
||||||
offset_bottom = 46.0
|
offset_bottom = 46.0
|
||||||
texture_normal = ExtResource("3_f3g8t")
|
texture_normal = ExtResource("3_6tmn6")
|
||||||
texture_pressed = ExtResource("4_4ja4j")
|
texture_pressed = ExtResource("4_1x5i2")
|
||||||
|
|
||||||
[node name="btn_del" type="TextureButton" parent="tabs/threats"]
|
[node name="btn_del" type="TextureButton" parent="tabs/threats"]
|
||||||
layout_mode = 0
|
layout_mode = 0
|
||||||
@@ -54,5 +54,5 @@ layout_mode = 0
|
|||||||
offset_top = 100.0
|
offset_top = 100.0
|
||||||
offset_right = 1587.0
|
offset_right = 1587.0
|
||||||
offset_bottom = 861.0
|
offset_bottom = 861.0
|
||||||
script = ExtResource("2_xq1tk")
|
script = ExtResource("2_mfyp6")
|
||||||
node_type_file = "res://ячейка-1.tscn"
|
node_type_file = "res://ячейка-1.tscn"
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ extends GridContainer
|
|||||||
|
|
||||||
## Виджет "Таблица"
|
## Виджет "Таблица"
|
||||||
|
|
||||||
@export var node_gap: = Vector2(0.0, 0.0) ## Зазор между ячейками, который не возможно вычислить или получить
|
@export var node_gap: = Vector2(0.0, 0.0) ## Зазор между ячейками, который не возможно вычислить или получить
|
||||||
@export var selector_color: = Color(1.0, 1.0, 1.0, 1.0) ## Окрашивающий цвет для индикатора выбранного ряда
|
@export var selector_color: = Color(1.0, 1.0, 1.0, 1.0) ## Окрашивающий цвет для индикатора выбранного ряда
|
||||||
@export var selector_key_down: Key = KEY_DOWN ## Клавиша увеличения индекса выбранного ряда
|
@export var selector_key_down: Key = KEY_DOWN ## Клавиша увеличения индекса выбранного ряда
|
||||||
@export var selector_key_up: Key = KEY_UP ## Клавиша уменьшения индекса выбранного ряда
|
@export var selector_key_up: Key = KEY_UP ## Клавиша уменьшения индекса выбранного ряда
|
||||||
@export_file var node_type_file: = 'res://table/node.tscn': get = get_node_scene, set = load_node_scene ## Сцена ячейки устанавливаемая по умолчанию
|
@export_file var node_type_file: = 'res://table/node.tscn': get = get_node_scene, set = load_node_scene ## Сцена ячейки устанавливаемая по умолчанию
|
||||||
@export_file var selector_type_file: = 'res://table/selector.tscn': set = load_selector_scene ## Сцена индикатора для выбранного ряда
|
@export_file var selector_type_file: = 'res://table/selector.tscn': set = load_selector_scene ## Сцена индикатора для выбранного ряда
|
||||||
|
|
||||||
@@ -18,8 +18,9 @@ const SLCT_PREFIX = 'SLCT_' ## Префикс ключа индикато
|
|||||||
const HEAD_KEY_FORMAT = HEAD_PREFIX + INDEX_FORMAT ## Формат ключа заголовка
|
const HEAD_KEY_FORMAT = HEAD_PREFIX + INDEX_FORMAT ## Формат ключа заголовка
|
||||||
const NODE_KEY_FORMAT = NODE_PREFIX + INDEX_FORMAT ## Формат ключа ячейки
|
const NODE_KEY_FORMAT = NODE_PREFIX + INDEX_FORMAT ## Формат ключа ячейки
|
||||||
const ROW_SELECTOR_KEY_FORMAT = SLCT_PREFIX + INDEX_FORMAT ## Формат ключа индикаторов выбранного ряда
|
const ROW_SELECTOR_KEY_FORMAT = SLCT_PREFIX + INDEX_FORMAT ## Формат ключа индикаторов выбранного ряда
|
||||||
const META_NAME_USER_DATA = 'user_data'
|
const META_USER_DATA = 'user_data' ## Имя свойства для сохранения данных пользователя
|
||||||
const META_NAME_CALLEBLE = 'calleble'
|
const META_CALLABLE = 'callable' ## Имя свойства для сохранения вызываемого
|
||||||
|
const META_EVENT_NAME = 'event_name' ## Имя свойства для сохранения названия события
|
||||||
|
|
||||||
var header: GridContainer ## Заголовок таблицы
|
var header: GridContainer ## Заголовок таблицы
|
||||||
var in_focus: = false ## Фокус пользовательского ввода
|
var in_focus: = false ## Фокус пользовательского ввода
|
||||||
@@ -38,8 +39,8 @@ var scroll_adj: = Vector2(0, 0)
|
|||||||
|
|
||||||
func get_node_scene(): return node_type_file
|
func get_node_scene(): return node_type_file
|
||||||
func _assert_meta(i_col: int, i_row: int, pname: String, node): assert(node.has_meta(pname), 'ошибка: нет мета-свойства \"%s\" у ячейки колонка:%d ряд:%d' % [pname, i_col, i_row])
|
func _assert_meta(i_col: int, i_row: int, pname: String, node): assert(node.has_meta(pname), 'ошибка: нет мета-свойства \"%s\" у ячейки колонка:%d ряд:%d' % [pname, i_col, i_row])
|
||||||
func get_node_user_data(i_col: int, i_row: int): return get_node_meta(i_col, i_row, META_NAME_USER_DATA)
|
func get_node_user_data(i_col: int, i_row: int): return get_node_meta(i_col, i_row, META_USER_DATA)
|
||||||
func set_node_user_data(i_col: int, i_row: int, val) -> void: set_node_meta(i_col, i_row, META_NAME_USER_DATA, val)
|
func set_node_user_data(i_col: int, i_row: int, val) -> void: set_node_meta(i_col, i_row, META_USER_DATA, val)
|
||||||
|
|
||||||
|
|
||||||
## Закрепляет заголовок таблицы. [param scrl] - Прокрутка,
|
## Закрепляет заголовок таблицы. [param scrl] - Прокрутка,
|
||||||
@@ -48,7 +49,7 @@ func pin_header(scrl: ScrollContainer, prnt: Control):
|
|||||||
scrl.remove_child(header)
|
scrl.remove_child(header)
|
||||||
prnt.add_child(header)
|
prnt.add_child(header)
|
||||||
## TODO: Это значение следует получить из темы
|
## TODO: Это значение следует получить из темы
|
||||||
var v_separation: = 3.0
|
var v_separation = get_theme_constant('v_separation')
|
||||||
header.position = scrl.position - Vector2(0, header.size.y + v_separation)
|
header.position = scrl.position - Vector2(0, header.size.y + v_separation)
|
||||||
scroll = scrl
|
scroll = scrl
|
||||||
scroll_adj = scrl.position
|
scroll_adj = scrl.position
|
||||||
@@ -68,6 +69,9 @@ func selector_up():
|
|||||||
if i_row < 0:
|
if i_row < 0:
|
||||||
i_row = rows_count - 1
|
i_row = rows_count - 1
|
||||||
set_row_selected(i_row, true)
|
set_row_selected(i_row, true)
|
||||||
|
var node = get_node2(0, i_row)
|
||||||
|
if scroll is ScrollContainer:
|
||||||
|
scroll.ensure_control_visible(node)
|
||||||
emit_signal('selected_changed', i_row)
|
emit_signal('selected_changed', i_row)
|
||||||
|
|
||||||
|
|
||||||
@@ -84,6 +88,9 @@ func selector_down():
|
|||||||
i_row += 1
|
i_row += 1
|
||||||
i_row %= rows_count
|
i_row %= rows_count
|
||||||
set_row_selected(i_row, true)
|
set_row_selected(i_row, true)
|
||||||
|
var node = get_node2(0, i_row)
|
||||||
|
if scroll is ScrollContainer:
|
||||||
|
scroll.ensure_control_visible(node)
|
||||||
emit_signal('selected_changed', i_row)
|
emit_signal('selected_changed', i_row)
|
||||||
|
|
||||||
|
|
||||||
@@ -184,7 +191,7 @@ func set_columns_aligment(alignments: Array) -> void:
|
|||||||
##
|
##
|
||||||
func _input(event) -> void:
|
func _input(event) -> void:
|
||||||
if event is InputEventKey:
|
if event is InputEventKey:
|
||||||
if in_focus and event.pressed:
|
if event.pressed and in_focus:
|
||||||
if event.keycode == selector_key_up:
|
if event.keycode == selector_key_up:
|
||||||
selector_up()
|
selector_up()
|
||||||
elif event.keycode == selector_key_down:
|
elif event.keycode == selector_key_down:
|
||||||
@@ -392,9 +399,10 @@ func remove_row(i_row: int):
|
|||||||
var conn = get_node_meta(i_col, i_row, 'callable_focus_entered')
|
var conn = get_node_meta(i_col, i_row, 'callable_focus_entered')
|
||||||
node.disconnect('focus_entered', conn)
|
node.disconnect('focus_entered', conn)
|
||||||
|
|
||||||
if node.has_meta(META_NAME_CALLEBLE):
|
if node.has_meta(META_CALLABLE):
|
||||||
conn = node.get_meta(META_NAME_CALLEBLE)
|
conn = node.get_meta(META_CALLABLE)
|
||||||
node.disconnect('pressed', conn)
|
var event_name = node.get_meta(META_EVENT_NAME)
|
||||||
|
node.disconnect(event_name, conn)
|
||||||
|
|
||||||
remove_child(node)
|
remove_child(node)
|
||||||
nodes.erase(node_key)
|
nodes.erase(node_key)
|
||||||
@@ -459,12 +467,14 @@ func connect_columns(dest_node: Node, event_name: String, callback: String, clmn
|
|||||||
for i_col in clmns:
|
for i_col in clmns:
|
||||||
assert(i_col >= 0 and i_col < columns, 'ошибка: нет такой колонки: %d' % i_col)
|
assert(i_col >= 0 and i_col < columns, 'ошибка: нет такой колонки: %d' % i_col)
|
||||||
var node = get_node2(i_col, i_row)
|
var node = get_node2(i_col, i_row)
|
||||||
if node.has_meta(META_NAME_CALLEBLE):
|
if node.has_meta(META_CALLABLE):
|
||||||
var conn = node.get_meta(META_NAME_CALLEBLE)
|
var conn = node.get_meta(META_CALLABLE)
|
||||||
node.disconnect(event_name, conn)
|
node.disconnect(event_name, conn)
|
||||||
var conn = Callable(dest_node, callback).bind([node] + user_data)
|
var conn = Callable(dest_node, callback).bind([node] + user_data)
|
||||||
assert (OK == node.connect(event_name, conn))
|
assert (OK == node.connect(event_name, conn))
|
||||||
node.set_meta(META_NAME_CALLEBLE, conn)
|
node.set_meta(META_CALLABLE, conn)
|
||||||
|
node.set_meta(META_EVENT_NAME, event_name)
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
func set_rows_text(rows: Array) -> void:
|
func set_rows_text(rows: Array) -> void:
|
||||||
|
|||||||
@@ -362,6 +362,7 @@ func on_btn_add(table):
|
|||||||
var row = threat.update_rows()
|
var row = threat.update_rows()
|
||||||
table.add_row(TABLE_ROW_TYPES)
|
table.add_row(TABLE_ROW_TYPES)
|
||||||
table.set_row_text(table.get_rows_count()-1, row)
|
table.set_row_text(table.get_rows_count()-1, row)
|
||||||
|
table.set_node_user_data(0, table.get_rows_count()-1, threat)
|
||||||
init_opt_btns(table.get_rows_count()-1, table)
|
init_opt_btns(table.get_rows_count()-1, table)
|
||||||
table.connect_columns(self, 'text_submitted', 'on_edit_entry', TABLE_ENTRY_COLUMNS, [])
|
table.connect_columns(self, 'text_submitted', 'on_edit_entry', TABLE_ENTRY_COLUMNS, [])
|
||||||
table.connect_columns(self, 'item_selected', 'on_item_selected', COLUMN_OPT_BTN, [])
|
table.connect_columns(self, 'item_selected', 'on_item_selected', COLUMN_OPT_BTN, [])
|
||||||
@@ -374,6 +375,9 @@ func on_btn_del(table):
|
|||||||
var cell = table.get_node2(0, row_i[0])
|
var cell = table.get_node2(0, row_i[0])
|
||||||
treats.erase(cell.text)
|
treats.erase(cell.text)
|
||||||
table.remove_row(row_i[0])
|
table.remove_row(row_i[0])
|
||||||
|
for i in table.get_rows_count():
|
||||||
|
var treat = table.get_node_user_data(0, i)
|
||||||
|
treat.row_id = i
|
||||||
|
|
||||||
|
|
||||||
func pop_id():
|
func pop_id():
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[gd_scene load_steps=3 format=3 uid="uid://ccxre8mwhndjk"]
|
[gd_scene load_steps=3 format=3 uid="uid://ccxre8mwhndjk"]
|
||||||
|
|
||||||
[ext_resource type="Texture2D" uid="uid://dag8n0gknjwak" path="res://индикатор-1-0.png" id="1_i48re"]
|
[ext_resource type="Texture2D" uid="uid://dag8n0gknjwak" path="res://индикатор-1-0.png" id="1_dgtjm"]
|
||||||
[ext_resource type="Texture2D" uid="uid://b3ext3w4ftgg2" path="res://индикатор-1-1.png" id="2_be5ku"]
|
[ext_resource type="Texture2D" uid="uid://b3ext3w4ftgg2" path="res://индикатор-1-1.png" id="2_aqu5u"]
|
||||||
|
|
||||||
[node name="indicator_1" type="TextureButton"]
|
[node name="indicator_1" type="TextureButton"]
|
||||||
modulate = Color(1, 0.596078, 0.4, 1)
|
modulate = Color(1, 0.596078, 0.4, 1)
|
||||||
@@ -9,5 +9,5 @@ offset_right = 35.0
|
|||||||
offset_bottom = 29.0
|
offset_bottom = 29.0
|
||||||
toggle_mode = true
|
toggle_mode = true
|
||||||
button_mask = 0
|
button_mask = 0
|
||||||
texture_normal = ExtResource("1_i48re")
|
texture_normal = ExtResource("1_dgtjm")
|
||||||
texture_pressed = ExtResource("2_be5ku")
|
texture_pressed = ExtResource("2_aqu5u")
|
||||||
|
|||||||
Reference in New Issue
Block a user