No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ThemeEditor.gd 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. tool
  2. extends Control
  3. var editor_reference
  4. onready var master_tree = get_node('../MasterTree')
  5. onready var settings_editor = get_node('../SettingsEditor')
  6. var current_theme = ''
  7. # The amazing and revolutionary path system that magically works and you can't
  8. # complain because "that is not how you are supposed to work". If there was only
  9. # a way to set an id and then access that node via id...
  10. # Here you have paths in all its glory. Praise the paths (っ´ω`c)♡
  11. onready var n = {
  12. # Text
  13. 'theme_text_shadow': $VBoxContainer/HBoxContainer2/Text/GridContainer/HBoxContainer2/CheckBoxShadow,
  14. 'theme_text_shadow_color': $VBoxContainer/HBoxContainer2/Text/GridContainer/HBoxContainer2/ColorPickerButtonShadow,
  15. 'theme_text_color': $VBoxContainer/HBoxContainer2/Text/GridContainer/ColorPickerButton,
  16. 'theme_font': $VBoxContainer/HBoxContainer2/Text/GridContainer/FontButton,
  17. 'theme_shadow_offset_x': $VBoxContainer/HBoxContainer2/Text/GridContainer/HBoxContainer/ShadowOffsetX,
  18. 'theme_shadow_offset_y': $VBoxContainer/HBoxContainer2/Text/GridContainer/HBoxContainer/ShadowOffsetY,
  19. 'theme_text_speed': $VBoxContainer/HBoxContainer2/Text/GridContainer/TextSpeed,
  20. 'alignment': $VBoxContainer/HBoxContainer2/Text/GridContainer/HBoxContainer3/Alignment,
  21. # Dialog box
  22. 'background_texture_button_visible': $VBoxContainer/HBoxContainer2/DialogBox/GridContainer/HBoxContainer3/CheckBox,
  23. 'theme_background_image': $VBoxContainer/HBoxContainer2/DialogBox/GridContainer/HBoxContainer3/BackgroundTextureButton,
  24. 'theme_next_image': $VBoxContainer/HBoxContainer2/DialogBox/GridContainer/NextIndicatorButton,
  25. 'theme_action_key': $VBoxContainer/HBoxContainer2/DialogBox/GridContainer/BoxContainer/ActionOptionButton,
  26. 'theme_background_color_visible': $VBoxContainer/HBoxContainer2/DialogBox/GridContainer/HBoxContainer2/CheckBox,
  27. 'theme_background_color': $VBoxContainer/HBoxContainer2/DialogBox/GridContainer/HBoxContainer2/ColorPickerButton,
  28. 'theme_text_margin': $VBoxContainer/HBoxContainer2/DialogBox/GridContainer/HBoxContainer/TextOffsetV,
  29. 'theme_text_margin_h': $VBoxContainer/HBoxContainer2/DialogBox/GridContainer/HBoxContainer/TextOffsetH,
  30. 'size_w': $VBoxContainer/HBoxContainer2/DialogBox/GridContainer/HBoxContainer4/BoxSizeW,
  31. 'size_h': $VBoxContainer/HBoxContainer2/DialogBox/GridContainer/HBoxContainer4/BoxSizeH,
  32. 'bottom_gap': $VBoxContainer/HBoxContainer2/DialogBox/GridContainer/HBoxContainer5/BottomGap,
  33. # Buttons
  34. 'button_text_color_enabled': $VBoxContainer/HBoxContainer2/ButtonStyle/GridContainer/HBoxContainer4/CheckBox2,
  35. 'button_text_color': $VBoxContainer/HBoxContainer2/ButtonStyle/GridContainer/HBoxContainer4/ButtonTextColor,
  36. 'button_background': $VBoxContainer/HBoxContainer2/ButtonStyle/GridContainer/HBoxContainer2/ColorPickerButton,
  37. 'button_background_visible': $VBoxContainer/HBoxContainer2/ButtonStyle/GridContainer/HBoxContainer2/CheckBox,
  38. 'button_image': $VBoxContainer/HBoxContainer2/ButtonStyle/GridContainer/HBoxContainer3/BackgroundTextureButton,
  39. 'button_image_visible': $VBoxContainer/HBoxContainer2/ButtonStyle/GridContainer/HBoxContainer3/CheckBox,
  40. 'button_offset_x': $VBoxContainer/HBoxContainer2/ButtonStyle/GridContainer/HBoxContainer/TextOffsetH,
  41. 'button_offset_y': $VBoxContainer/HBoxContainer2/ButtonStyle/GridContainer/HBoxContainer/TextOffsetV,
  42. 'button_separation': $VBoxContainer/HBoxContainer2/ButtonStyle/GridContainer/VerticalSeparation,
  43. # Definitions
  44. 'glossary_font': $VBoxContainer/HBoxContainer2/Glossary/GridContainer/FontButton,
  45. 'glossary_color': $VBoxContainer/HBoxContainer2/Glossary/GridContainer/ColorPickerButton,
  46. # Text preview
  47. 'preview_panel': $VBoxContainer/Panel,
  48. 'text_preview': $VBoxContainer/HBoxContainer3/TextEdit,
  49. }
  50. func _ready():
  51. # Signal connection to free up some memory
  52. connect("visibility_changed", self, "_on_visibility_changed")
  53. # Force preview update
  54. _on_visibility_changed()
  55. func load_theme(filename):
  56. current_theme = filename
  57. var theme = DialogicResources.get_theme_config(filename)
  58. # Settings
  59. n['theme_action_key'].text = theme.get_value('settings', 'action_key', 'ui_accept')
  60. # Background
  61. n['theme_background_image'].text = DialogicResources.get_filename_from_path(theme.get_value('background', 'image', 'res://addons/dialogic/Images/background/background-2.png'))
  62. n['background_texture_button_visible'].pressed = theme.get_value('background', 'use_image', true)
  63. n['theme_background_color'].color = Color(theme.get_value('background', 'color', '#ff000000'))
  64. n['theme_background_color_visible'].pressed = theme.get_value('background', 'use_color', false)
  65. n['theme_next_image'].text = DialogicResources.get_filename_from_path(theme.get_value('next_indicator', 'image', 'res://addons/dialogic/Images/next-indicator.png'))
  66. var size_value = theme.get_value('box', 'size', Vector2(910, 167))
  67. n['size_w'].value = size_value.x
  68. n['size_h'].value = size_value.y
  69. n['bottom_gap'].value = theme.get_value('box', 'bottom_gap', 40)
  70. # Buttons
  71. n['button_text_color_enabled'].pressed = theme.get_value('buttons', 'text_color_enabled', true)
  72. n['button_text_color'].color = Color(theme.get_value('buttons', 'text_color', "#ffffffff"))
  73. n['button_background'].color = Color(theme.get_value('buttons', 'background_color', "#ff000000"))
  74. n['button_background_visible'].pressed = theme.get_value('buttons', 'use_background_color', false)
  75. n['button_image'].text = DialogicResources.get_filename_from_path(theme.get_value('buttons', 'image', 'res://addons/dialogic/Images/background/background-2.png'))
  76. n['button_image_visible'].pressed = theme.get_value('buttons', 'use_image', true)
  77. n['button_offset_x'].value = theme.get_value('buttons', 'padding', Vector2(5,5)).x
  78. n['button_offset_y'].value = theme.get_value('buttons', 'padding', Vector2(5,5)).y
  79. n['button_separation'].value = theme.get_value('buttons', 'gap', 5)
  80. # Definitions
  81. n['glossary_color'].color = Color(theme.get_value('definitions', 'color', "#ffffffff"))
  82. n['glossary_font'].text = DialogicResources.get_filename_from_path(theme.get_value('definitions', 'font', "res://addons/dialogic/Fonts/GlossaryFont.tres"))
  83. # Text
  84. n['theme_text_speed'].value = theme.get_value('text','speed', 2)
  85. n['theme_font'].text = DialogicResources.get_filename_from_path(theme.get_value('text', 'font', 'res://addons/dialogic/Fonts/DefaultFont.tres'))
  86. n['theme_text_color'].color = Color(theme.get_value('text', 'color', '#ffffffff'))
  87. n['theme_text_shadow'].pressed = theme.get_value('text', 'shadow', false)
  88. n['theme_text_shadow_color'].color = Color(theme.get_value('text', 'shadow_color', '#9e000000'))
  89. n['theme_shadow_offset_x'].value = theme.get_value('text', 'shadow_offset', Vector2(2,2)).x
  90. n['theme_shadow_offset_y'].value = theme.get_value('text', 'shadow_offset', Vector2(2,2)).y
  91. n['theme_text_margin'].value = theme.get_value('text', 'margin', Vector2(20, 10)).x
  92. n['theme_text_margin_h'].value = theme.get_value('text', 'margin', Vector2(20, 10)).y
  93. n['alignment'].text = theme.get_value('text', 'alignment', 'Left')
  94. match n['alignment'].text:
  95. 'Left':
  96. n['alignment'].select(0)
  97. 'Center':
  98. n['alignment'].select(1)
  99. 'Right':
  100. n['alignment'].select(2)
  101. # Preview text
  102. n['text_preview'].text = theme.get_value('text', 'preview', 'This is preview text. You can use [color=#A5EFAC]BBCode[/color] to style it.\n[wave amp=50 freq=2]You can even use effects![/wave]')
  103. func new_theme():
  104. var theme_file = 'theme-' + str(OS.get_unix_time()) + '.cfg'
  105. DialogicResources.add_theme(theme_file)
  106. master_tree.build_themes(theme_file)
  107. load_theme(theme_file)
  108. # Check if it is the only theme to set as default
  109. if DialogicUtil.get_theme_list().size() == 1:
  110. print('only theme, setting as default')
  111. settings_editor.set_value('theme', 'default', theme_file)
  112. func _on_BackgroundTextureButton_pressed():
  113. editor_reference.godot_dialog("*.png")
  114. editor_reference.godot_dialog_connect(self, "_on_background_selected")
  115. func _on_background_selected(path, target):
  116. DialogicResources.set_theme_value(current_theme, 'background','image', path)
  117. n['theme_background_image'].text = DialogicResources.get_filename_from_path(path)
  118. func _on_NextIndicatorButton_pressed():
  119. editor_reference.godot_dialog("*.png")
  120. editor_reference.godot_dialog_connect(self, "_on_indicator_selected")
  121. func _on_indicator_selected(path, target):
  122. DialogicResources.set_theme_value(current_theme, 'next_indicator','image', path)
  123. n['theme_next_image'].text = DialogicResources.get_filename_from_path(path)
  124. func _on_ColorPickerButton_color_changed(color):
  125. DialogicResources.set_theme_value(current_theme, 'text','color', '#' + color.to_html())
  126. func _on_ColorPickerButtonShadow_color_changed(color):
  127. DialogicResources.set_theme_value(current_theme, 'text','shadow_color', '#' + color.to_html())
  128. func _on_CheckBoxShadow_toggled(button_pressed):
  129. DialogicResources.set_theme_value(current_theme, 'text','shadow', button_pressed)
  130. func _on_ShadowOffset_value_changed(_value):
  131. DialogicResources.set_theme_value(current_theme, 'text','shadow_offset', Vector2(n['theme_shadow_offset_x'].value,n['theme_shadow_offset_y'].value))
  132. func _on_PreviewButton_pressed():
  133. for i in n['preview_panel'].get_children():
  134. i.free()
  135. var dialogic_node = load("res://addons/dialogic/Dialog.tscn")
  136. var preview_dialog = dialogic_node.instance()
  137. preview_dialog.preview = true
  138. preview_dialog.get_node('DefinitionInfo').in_theme_editor = true
  139. preview_dialog.get_node('TextBubble/NextIndicator/AnimationPlayer').play('IDLE')
  140. preview_dialog.dialog_script['events'] = [{
  141. "character":"",
  142. "portrait":"",
  143. "text": preview_dialog.parse_definitions(n['text_preview'].text)
  144. }]
  145. # Settings
  146. preview_dialog.settings = DialogicResources.get_settings_config()
  147. # Alignment
  148. n['preview_panel'].add_child(preview_dialog)
  149. # Not sure why but I need to reload the theme again for it to work properly
  150. preview_dialog.load_dialog()
  151. preview_dialog.current_theme = preview_dialog.load_theme(current_theme)
  152. # maintaining the preview panel big enough for the dialog box
  153. n['preview_panel'].rect_min_size.y = preview_dialog.current_theme.get_value('box', 'size', Vector2(910, 167)).y + 90 + preview_dialog.current_theme.get_value('box', 'bottom_gap', 40)
  154. n['preview_panel'].rect_size.y = 0
  155. func _on_ActionOptionButton_item_selected(index):
  156. DialogicResources.set_theme_value(current_theme, 'settings','action_key', n['theme_action_key'].text)
  157. func _on_ActionOptionButton_pressed():
  158. n['theme_action_key'].clear()
  159. n['theme_action_key'].add_item('[Select Action]')
  160. InputMap.load_from_globals()
  161. for a in InputMap.get_actions():
  162. n['theme_action_key'].add_item(a)
  163. func _on_FontButton_pressed():
  164. editor_reference.godot_dialog("*.tres")
  165. editor_reference.godot_dialog_connect(self, "_on_Font_selected")
  166. func _on_Font_selected(path, target):
  167. DialogicResources.set_theme_value(current_theme, 'text','font', path)
  168. n['theme_font'].text = DialogicResources.get_filename_from_path(path)
  169. func _on_textSpeed_value_changed(value):
  170. DialogicResources.set_theme_value(current_theme, 'text','speed', value)
  171. func _on_TextMargin_value_changed(value):
  172. var final_vector = Vector2(
  173. n['theme_text_margin'].value,
  174. n['theme_text_margin_h'].value
  175. )
  176. DialogicResources.set_theme_value(current_theme, 'text', 'margin', final_vector)
  177. func _on_BackgroundColor_CheckBox_toggled(button_pressed):
  178. DialogicResources.set_theme_value(current_theme, 'background', 'use_color', button_pressed)
  179. func _on_BackgroundColor_ColorPickerButton_color_changed(color):
  180. DialogicResources.set_theme_value(current_theme, 'background', 'color', '#' + color.to_html())
  181. func _on_BackgroundTexture_CheckBox_toggled(button_pressed):
  182. DialogicResources.set_theme_value(current_theme, 'background', 'use_image', button_pressed)
  183. func _on_button_background_visible_toggled(button_pressed):
  184. DialogicResources.set_theme_value(current_theme, 'buttons', 'use_background_color', button_pressed)
  185. func _on_button_background_color_color_changed(color):
  186. DialogicResources.set_theme_value(current_theme, 'buttons', 'background_color', '#' + color.to_html())
  187. func _on_ButtonOffset_value_changed(value):
  188. var final_vector = Vector2(
  189. n['button_offset_x'].value,
  190. n['button_offset_y'].value
  191. )
  192. DialogicResources.set_theme_value(current_theme, 'buttons', 'padding', final_vector)
  193. func _on_VerticalSeparation_value_changed(value):
  194. DialogicResources.set_theme_value(current_theme, 'buttons', 'gap', n['button_separation'].value)
  195. func _on_button_texture_toggled(button_pressed):
  196. DialogicResources.set_theme_value(current_theme, 'buttons', 'use_image', button_pressed)
  197. func _on_ButtonTextureButton_pressed():
  198. editor_reference.godot_dialog("*.png")
  199. editor_reference.godot_dialog_connect(self, "_on_button_texture_selected")
  200. func _on_button_texture_selected(path, target):
  201. DialogicResources.set_theme_value(current_theme, 'buttons', 'image', path)
  202. n['button_image'].text = DialogicResources.get_filename_from_path(path)
  203. func _on_ButtonTextColor_color_changed(color):
  204. DialogicResources.set_theme_value(current_theme, 'buttons', 'text_color', '#' + color.to_html())
  205. func _on_Custom_Button_Color_toggled(button_pressed):
  206. DialogicResources.set_theme_value(current_theme, 'buttons', 'text_color_enabled', button_pressed)
  207. func _on_GlossaryColorPicker_color_changed(color):
  208. DialogicResources.set_theme_value(current_theme, 'definitions', 'color', '#' + color.to_html())
  209. func _on_GlossaryFontButton_pressed():
  210. editor_reference.godot_dialog("*.tres")
  211. editor_reference.godot_dialog_connect(self, "_on_Glossary_Font_selected")
  212. func _on_Glossary_Font_selected(path, target):
  213. DialogicResources.set_theme_value(current_theme, 'definitions', 'font', path)
  214. n['glossary_font'].text = DialogicResources.get_filename_from_path(path)
  215. func _on_visibility_changed():
  216. if visible:
  217. # Refreshing the dialog
  218. _on_PreviewButton_pressed()
  219. else:
  220. # Erasing all previews since them keeps working
  221. # on background
  222. for i in n['preview_panel'].get_children():
  223. i.queue_free()
  224. func _on_BoxSize_value_changed(value):
  225. var size_value = Vector2(n['size_w'].value, n['size_h'].value)
  226. DialogicResources.set_theme_value(current_theme, 'box', 'size', size_value)
  227. func _on_BottomGap_value_changed(value):
  228. DialogicResources.set_theme_value(current_theme, 'box', 'bottom_gap', value)
  229. func _on_Alignment_item_selected(index):
  230. if index == 0:
  231. DialogicResources.set_theme_value(current_theme, 'text', 'alignment', 'Left')
  232. elif index == 1:
  233. DialogicResources.set_theme_value(current_theme, 'text', 'alignment', 'Center')
  234. elif index == 2:
  235. DialogicResources.set_theme_value(current_theme, 'text', 'alignment', 'Right')
  236. func _on_Preview_text_changed():
  237. DialogicResources.set_theme_value(current_theme, 'text', 'preview', n['text_preview'].text)