From d214e3d4cfcd350a9e59f94a186d268188fff180 Mon Sep 17 00:00:00 2001 From: sasha80 Date: Fri, 22 Nov 2024 09:34:50 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0.=20=D0=9F=D0=BE=D0=B4=D1=81=D0=BA=D0=B0=D0=B7?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B0=D0=B5=D1=82=20=D1=81?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=BE=D1=8F=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=BA?= =?UTF-8?q?=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=BE/=D0=BE=D1=82=D0=BA=D0=BB?= =?UTF-8?q?=D1=8E=D1=87=D0=B5=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scenes/pribor-uyep/sch3.tscn | 3 ++- scripts/switch.gd | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 scripts/switch.gd diff --git a/scenes/pribor-uyep/sch3.tscn b/scenes/pribor-uyep/sch3.tscn index 72dd4c05..da34fc03 100644 --- a/scenes/pribor-uyep/sch3.tscn +++ b/scenes/pribor-uyep/sch3.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=10 format=3 uid="uid://dlkvu6bp6w5u7"] +[gd_scene load_steps=11 format=3 uid="uid://dlkvu6bp6w5u7"] [ext_resource type="Script" path="res://scenes/pribor-uyep/sch3-view.gd" id="1_ln7ac"] [ext_resource type="Texture2D" uid="uid://c6nve6f8sfyj2" path="res://data/состояние-исправности-0.png" id="2_ln52a"] @@ -6,6 +6,7 @@ [ext_resource type="Texture2D" uid="uid://c6booa8753u5t" path="res://data/состояние-исправности-2.png" id="4_nijdy"] [ext_resource type="Texture2D" uid="uid://c4mdrmk7h638f" path="res://data/nine-patch-round.png" id="5_skqdl"] [ext_resource type="Shader" path="res://shaders/color-invers.gdshader" id="6_ypnlb"] +[ext_resource type="Script" path="res://scripts/switch.gd" id="7_l6esm"] [sub_resource type="GDScript" id="GDScript_45hqb"] script/source = "@tool diff --git a/scripts/switch.gd b/scripts/switch.gd new file mode 100644 index 00000000..10710372 --- /dev/null +++ b/scripts/switch.gd @@ -0,0 +1,17 @@ +extends CheckButton + + +@export var off_tip: String = '(отключено)' +@export var on_tip: String = '(включено)' + + +func _ready() -> void: + if not (tooltip_text.contains(off_tip) or tooltip_text.contains(on_tip)): + tooltip_text += ' ' + tooltip_text += on_tip if button_pressed else off_tip + connect('toggled', _on_toggled) + + +func _on_toggled(state: bool): + var s = tooltip_text + tooltip_text = s.replace(off_tip, on_tip) if state else s.replace(on_tip, off_tip)