]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Editor/HomePage/home_page.gd
Updated export config options
[wolf-seeking-sheep.git] / addons / dialogic / Editor / HomePage / home_page.gd
1 @tool
2 extends DialogicEditor
3
4 ## A Main page in the dialogic editor.
5
6 var tips: Array = []
7
8
9
10 func _get_icon() -> Texture:
11         return load("res://addons/dialogic/Editor/Images/plugin-icon.svg")
12
13
14 func _ready() -> void:
15         self_modulate = get_theme_color("font_color", "Editor")
16         self_modulate.a = 0.2
17
18         var edit_scale := DialogicUtil.get_editor_scale()
19         %HomePageBox.custom_minimum_size = Vector2(600, 350)*edit_scale
20         %TopPanel.custom_minimum_size.y = 100*edit_scale
21         %VersionLabel.set('theme_override_font_sizes/font_size', 10 * edit_scale)
22         var plugin_cfg := ConfigFile.new()
23         plugin_cfg.load("res://addons/dialogic/plugin.cfg")
24         %VersionLabel.text = plugin_cfg.get_value('plugin', 'version', 'unknown version')
25
26         %BottomPanel.self_modulate = get_theme_color("dark_color_3", "Editor")
27
28         %RandomTipLabel.add_theme_color_override("font_color", get_theme_color("property_color_z", "Editor"))
29         %RandomTipMoreButton.icon = get_theme_icon("ExternalLink", "EditorIcons")
30
31
32
33 func _register() -> void:
34         editors_manager.register_simple_editor(self)
35
36         self.alternative_text = "Welcome to dialogic!"
37
38
39
40 func _open(extra_info:Variant="") -> void:
41         if tips.is_empty():
42                 var file := FileAccess.open('res://addons/dialogic/Editor/HomePage/tips.txt', FileAccess.READ)
43                 tips = file.get_as_text().split('\n')
44                 tips = tips.filter(func(item): return !item.is_empty())
45
46         randomize()
47         var tip: String = tips[randi()%len(tips)]
48         var text := tip.get_slice(';',0).strip_edges()
49         var action := tip.get_slice(';',1).strip_edges()
50         if action == text:
51                 action = ""
52         show_tip(text, action)
53
54
55 func show_tip(text:String='', action:String='') -> void:
56         if text.is_empty():
57                 %TipBox.hide()
58                 %RandomTipLabel.hide()
59                 return
60
61         %TipBox.show()
62         %RandomTipLabel.show()
63         %RandomTip.text = '[i]'+text
64
65         if action.is_empty():
66                 %RandomTipMoreButton.hide()
67                 return
68
69         %RandomTipMoreButton.show()
70
71         if %RandomTipMoreButton.pressed.is_connected(_on_tip_action):
72                 %RandomTipMoreButton.pressed.disconnect(_on_tip_action)
73         %RandomTipMoreButton.pressed.connect(_on_tip_action.bind(action))
74
75
76 func _on_tip_action(action:String) -> void:
77         if action.begins_with('https://'):
78                 OS.shell_open(action)
79                 return
80         elif action.begins_with('editor://'):
81                 var editor_name := action.trim_prefix('editor://').get_slice('->',0)
82                 var extra_info := action.trim_prefix('editor://').get_slice('->',1)
83                 if editor_name in editors_manager.editors:
84                         editors_manager.open_editor(editors_manager.editors[editor_name].node, false, extra_info)
85                         return
86         print("Tip button doesn't do anything (", action, ")")