Skip to content

Commit

Permalink
Merge pull request #39 from YarnSpinnerTool/tool_menu_item_bug
Browse files Browse the repository at this point in the history
fix #38 - work around tools menu items causing errors after rebuilding C#
  • Loading branch information
dogboydog authored Mar 4, 2024
2 parents 843cfbe + 9a6a21e commit 4baa647
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 39 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [0.2.2] 2024-03-04
* Fixed an error with Tools menu items for YarnSpinner not working after rebuilding C# code.

## [0.2.1] 2024-02-13
* Fixed a crash that could result from an attempted workaround of the 'assembly reload failed' error

Expand Down
17 changes: 11 additions & 6 deletions Samples/SampleEntryPoint.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
[ext_resource type="Theme" uid="uid://b2mp0b1wvnu8s" path="res://Samples/sample_default_theme.tres" id="2"]
[ext_resource type="Texture2D" uid="uid://pbrr5yyepbx8" path="res://addons/YarnSpinner-Godot/Editor/Icons/YarnSpinnerLogo.png" id="3_bcudv"]

[node name="SampleEntryPoint" type="CanvasLayer" node_paths=PackedStringArray("_spaceButton", "_visualNovelButton", "_markupPaletteButton", "_pausingTypewriterButton", "_roundedViewsButton")]
[node name="SampleEntryPoint" type="CanvasLayer"]
script = ExtResource("1")
_spaceButton = NodePath("HBoxContainer/VBoxContainer/Space")
_visualNovelButton = NodePath("HBoxContainer/VBoxContainer2/Visual Novel")
_markupPaletteButton = NodePath("HBoxContainer/VBoxContainer3/MarkupPalette")
_pausingTypewriterButton = NodePath("HBoxContainer/VBoxContainer4/PausingTypewriter")
_roundedViewsButton = NodePath("HBoxContainer/VBoxContainer5/RoundedViews")
_spaceButton = Object(Button,"_import_path":NodePath(""),"unique_name_in_owner":false,"process_mode":0,"process_priority":0,"process_physics_priority":0,"process_thread_group":0,"editor_description":"","visible":true,"modulate":Color(1, 1, 1, 1),"self_modulate":Color(1, 1, 1, 1),"show_behind_parent":false,"top_level":false,"clip_children":0,"light_mask":1,"visibility_layer":1,"z_index":0,"z_as_relative":true,"y_sort_enabled":false,"texture_filter":0,"texture_repeat":0,"material":null,"use_parent_material":false,"clip_contents":false,"custom_minimum_size":Vector2(180, 100),"layout_direction":0,"layout_mode":2,"size_flags_horizontal":1,"size_flags_vertical":1,"size_flags_stretch_ratio":1.0,"auto_translate":true,"localize_numeral_system":true,"tooltip_text":"","focus_neighbor_left":NodePath(""),"focus_neighbor_top":NodePath(""),"focus_neighbor_right":NodePath(""),"focus_neighbor_bottom":NodePath(""),"focus_next":NodePath(""),"focus_previous":NodePath(""),"focus_mode":2,"mouse_filter":0,"mouse_force_pass_scroll_events":true,"mouse_default_cursor_shape":0,"shortcut_context":null,"theme":ExtResource("2"),"theme_type_variation":&"","theme_override_colors/font_outline_color":Color(0, 0, 0, 1),"theme_override_constants/outline_size":5,"theme_override_font_sizes/font_size":27,"disabled":false,"toggle_mode":false,"button_pressed":false,"action_mode":1,"button_mask":1,"keep_pressed_outside":false,"button_group":null,"shortcut":null,"shortcut_feedback":true,"shortcut_in_tooltip":true,"text":"Space","icon":null,"flat":false,"alignment":1,"text_overrun_behavior":0,"clip_text":false,"icon_alignment":0,"vertical_icon_alignment":1,"expand_icon":false,"text_direction":0,"language":"","script":null)

_visualNovelButton = Object(Button,"_import_path":NodePath(""),"unique_name_in_owner":false,"process_mode":0,"process_priority":0,"process_physics_priority":0,"process_thread_group":0,"editor_description":"","visible":true,"modulate":Color(1, 1, 1, 1),"self_modulate":Color(1, 1, 1, 1),"show_behind_parent":false,"top_level":false,"clip_children":0,"light_mask":1,"visibility_layer":1,"z_index":0,"z_as_relative":true,"y_sort_enabled":false,"texture_filter":0,"texture_repeat":0,"material":null,"use_parent_material":false,"clip_contents":false,"custom_minimum_size":Vector2(180, 100),"layout_direction":0,"layout_mode":2,"size_flags_horizontal":1,"size_flags_vertical":1,"size_flags_stretch_ratio":1.0,"auto_translate":true,"localize_numeral_system":true,"tooltip_text":"","focus_neighbor_left":NodePath(""),"focus_neighbor_top":NodePath(""),"focus_neighbor_right":NodePath(""),"focus_neighbor_bottom":NodePath(""),"focus_next":NodePath(""),"focus_previous":NodePath(""),"focus_mode":2,"mouse_filter":0,"mouse_force_pass_scroll_events":true,"mouse_default_cursor_shape":0,"shortcut_context":null,"theme":ExtResource("2"),"theme_type_variation":&"","theme_override_colors/font_outline_color":Color(0, 0, 0, 1),"theme_override_constants/outline_size":5,"theme_override_font_sizes/font_size":27,"disabled":false,"toggle_mode":false,"button_pressed":false,"action_mode":1,"button_mask":1,"keep_pressed_outside":false,"button_group":null,"shortcut":null,"shortcut_feedback":true,"shortcut_in_tooltip":true,"text":"Visual Novel","icon":null,"flat":false,"alignment":1,"text_overrun_behavior":0,"clip_text":false,"icon_alignment":0,"vertical_icon_alignment":1,"expand_icon":false,"text_direction":0,"language":"","script":null)

_markupPaletteButton = Object(Button,"_import_path":NodePath(""),"unique_name_in_owner":false,"process_mode":0,"process_priority":0,"process_physics_priority":0,"process_thread_group":0,"editor_description":"","visible":true,"modulate":Color(1, 1, 1, 1),"self_modulate":Color(1, 1, 1, 1),"show_behind_parent":false,"top_level":false,"clip_children":0,"light_mask":1,"visibility_layer":1,"z_index":0,"z_as_relative":true,"y_sort_enabled":false,"texture_filter":0,"texture_repeat":0,"material":null,"use_parent_material":false,"clip_contents":false,"custom_minimum_size":Vector2(180, 100),"layout_direction":0,"layout_mode":2,"size_flags_horizontal":1,"size_flags_vertical":1,"size_flags_stretch_ratio":1.0,"auto_translate":true,"localize_numeral_system":true,"tooltip_text":"","focus_neighbor_left":NodePath(""),"focus_neighbor_top":NodePath(""),"focus_neighbor_right":NodePath(""),"focus_neighbor_bottom":NodePath(""),"focus_next":NodePath(""),"focus_previous":NodePath(""),"focus_mode":2,"mouse_filter":0,"mouse_force_pass_scroll_events":true,"mouse_default_cursor_shape":0,"shortcut_context":null,"theme":ExtResource("2"),"theme_type_variation":&"","theme_override_colors/font_outline_color":Color(0, 0, 0, 1),"theme_override_constants/outline_size":5,"theme_override_font_sizes/font_size":27,"disabled":false,"toggle_mode":false,"button_pressed":false,"action_mode":1,"button_mask":1,"keep_pressed_outside":false,"button_group":null,"shortcut":null,"shortcut_feedback":true,"shortcut_in_tooltip":true,"text":"Markup Palette","icon":null,"flat":false,"alignment":1,"text_overrun_behavior":0,"clip_text":false,"icon_alignment":0,"vertical_icon_alignment":1,"expand_icon":false,"text_direction":0,"language":"","script":null)

_pausingTypewriterButton = Object(Button,"_import_path":NodePath(""),"unique_name_in_owner":false,"process_mode":0,"process_priority":0,"process_physics_priority":0,"process_thread_group":0,"editor_description":"","visible":true,"modulate":Color(1, 1, 1, 1),"self_modulate":Color(1, 1, 1, 1),"show_behind_parent":false,"top_level":false,"clip_children":0,"light_mask":1,"visibility_layer":1,"z_index":0,"z_as_relative":true,"y_sort_enabled":false,"texture_filter":0,"texture_repeat":0,"material":null,"use_parent_material":false,"clip_contents":false,"custom_minimum_size":Vector2(180, 100),"layout_direction":0,"layout_mode":2,"size_flags_horizontal":1,"size_flags_vertical":1,"size_flags_stretch_ratio":1.0,"auto_translate":true,"localize_numeral_system":true,"tooltip_text":"","focus_neighbor_left":NodePath(""),"focus_neighbor_top":NodePath(""),"focus_neighbor_right":NodePath(""),"focus_neighbor_bottom":NodePath(""),"focus_next":NodePath(""),"focus_previous":NodePath(""),"focus_mode":2,"mouse_filter":0,"mouse_force_pass_scroll_events":true,"mouse_default_cursor_shape":0,"shortcut_context":null,"theme":ExtResource("2"),"theme_type_variation":&"","theme_override_colors/font_outline_color":Color(0, 0, 0, 1),"theme_override_constants/outline_size":5,"theme_override_font_sizes/font_size":27,"disabled":false,"toggle_mode":false,"button_pressed":false,"action_mode":1,"button_mask":1,"keep_pressed_outside":false,"button_group":null,"shortcut":null,"shortcut_feedback":true,"shortcut_in_tooltip":true,"text":"Pausing Typewriter","icon":null,"flat":false,"alignment":1,"text_overrun_behavior":0,"clip_text":false,"icon_alignment":0,"vertical_icon_alignment":1,"expand_icon":false,"text_direction":0,"language":"","script":null)

_roundedViewsButton = Object(Button,"_import_path":NodePath(""),"unique_name_in_owner":false,"process_mode":0,"process_priority":0,"process_physics_priority":0,"process_thread_group":0,"editor_description":"","visible":true,"modulate":Color(1, 1, 1, 1),"self_modulate":Color(1, 1, 1, 1),"show_behind_parent":false,"top_level":false,"clip_children":0,"light_mask":1,"visibility_layer":1,"z_index":0,"z_as_relative":true,"y_sort_enabled":false,"texture_filter":0,"texture_repeat":0,"material":null,"use_parent_material":false,"clip_contents":false,"custom_minimum_size":Vector2(180, 100),"layout_direction":0,"layout_mode":2,"size_flags_horizontal":1,"size_flags_vertical":1,"size_flags_stretch_ratio":1.0,"auto_translate":true,"localize_numeral_system":true,"tooltip_text":"","focus_neighbor_left":NodePath(""),"focus_neighbor_top":NodePath(""),"focus_neighbor_right":NodePath(""),"focus_neighbor_bottom":NodePath(""),"focus_next":NodePath(""),"focus_previous":NodePath(""),"focus_mode":2,"mouse_filter":0,"mouse_force_pass_scroll_events":true,"mouse_default_cursor_shape":0,"shortcut_context":null,"theme":ExtResource("2"),"theme_type_variation":&"","theme_override_colors/font_outline_color":Color(0, 0, 0, 1),"theme_override_constants/outline_size":5,"theme_override_font_sizes/font_size":27,"disabled":false,"toggle_mode":false,"button_pressed":false,"action_mode":1,"button_mask":1,"keep_pressed_outside":false,"button_group":null,"shortcut":null,"shortcut_feedback":true,"shortcut_in_tooltip":true,"text":"Rounded Views","icon":null,"flat":false,"alignment":1,"text_overrun_behavior":0,"clip_text":false,"icon_alignment":0,"vertical_icon_alignment":1,"expand_icon":false,"text_direction":0,"language":"","script":null)


[node name="ColorRect" type="ColorRect" parent="."]
anchors_preset = 15
Expand Down
2 changes: 2 additions & 0 deletions YarnSpinner-Godot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<ItemGroup>
<!-- Add some extra files for ease of developing samples -->
<None Include="addons\YarnSpinner-Godot\YarnSpinner-Godot.props"/>
<None Include="addons\YarnSpinner-Godot\plugin.cfg"/>
<None Include="**\*.md"/>
</ItemGroup>

<Import Project="addons\YarnSpinner-Godot\YarnSpinner-Godot.props" />
Expand Down
80 changes: 48 additions & 32 deletions addons/YarnSpinner-Godot/YarnSpinnerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,41 +42,57 @@ private struct ToolsMenuItem
private Dictionary<int, ToolsMenuItem>
_idToToolsMenuItem;

/// <summary>
/// This dictionary becomes null when rebuilding the C# code of the samples/
/// your project. To work around this, if we detect the dictionary is null,
/// we will re-initialize it.
/// </summary>
private Dictionary<int, ToolsMenuItem> IDToToolsMenuItem
{
get
{
if (_idToToolsMenuItem == null)
{
_idToToolsMenuItem = new()
{
[0] =
new ToolsMenuItem()
{
MenuName = "Create Yarn Script",
Handler = CreateYarnScript,
},
[1] =
new ToolsMenuItem()
{
MenuName = "Create Yarn Project",
Handler = CreateYarnProject,
},
[2] =
new ToolsMenuItem()
{
MenuName = "Create Markup Palette",
Handler = CreateMarkupPalette,
}
// TODO: actions source generation
// [8] =
// new ToolsMenuItem()
// {
// MenuName = "Update Yarn Commands",
// Handler = ActionSourceCodeGenerator.GenerateYarnActionSourceCode,
// }
//
};
}

return _idToToolsMenuItem;
}
}

private PopupMenu _popup;
public const string YARN_PROJECT_EXTENSION = ".yarnproject";

public override void _EnterTree()
{
_idToToolsMenuItem = new()
{
[0] =
new ToolsMenuItem()
{
MenuName = "Create Yarn Script",
Handler = CreateYarnScript,
},
[1] =
new ToolsMenuItem()
{
MenuName = "Create Yarn Project",
Handler = CreateYarnProject,
},
[2] =
new ToolsMenuItem()
{
MenuName = "Create Markup Palette",
Handler = CreateMarkupPalette,
}
// TODO: actions source generation
// [8] =
// new ToolsMenuItem()
// {
// MenuName = "Update Yarn Commands",
// Handler = ActionSourceCodeGenerator.GenerateYarnActionSourceCode,
// }
//
};

#if !GODOT4_2_OR_GREATER
editorInterface = GetEditorInterface();
#endif
Expand Down Expand Up @@ -116,7 +132,7 @@ public override void _EnterTree()
}

_popup = new PopupMenu();
foreach (var entry in _idToToolsMenuItem)
foreach (var entry in IDToToolsMenuItem)
{
_popup.AddItem(entry.Value.MenuName, entry.Key);
}
Expand Down Expand Up @@ -151,7 +167,7 @@ public override void _ExitTree()
/// <param name="id"></param>
public void OnPopupIDPressed(long id)
{
if (_idToToolsMenuItem.TryGetValue((int) id, out var menuItem))
if (IDToToolsMenuItem.TryGetValue((int) id, out var menuItem))
{
menuItem.Handler();
}
Expand Down
2 changes: 1 addition & 1 deletion addons/YarnSpinner-Godot/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="YarnSpinner-Godot"
description="Yarn language based dialogue system plugin for Godot"
author="dogboydog"
version="0.2.0"
version="0.2.2"
script="YarnSpinnerPlugin.cs"
3 changes: 3 additions & 0 deletions export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ application/product_name=""
application/file_description=""
application/copyright=""
application/trademarks=""
application/export_angle=0
ssh_remote_deploy/enabled=false
ssh_remote_deploy/host="user@host_ip"
ssh_remote_deploy/port="22"
Expand All @@ -61,6 +62,7 @@ Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorActi
Remove-Item -Recurse -Force '{temp_dir}'"
dotnet/include_scripts_content=false
dotnet/include_debug_symbols=true
dotnet/embed_build_outputs=false

[preset.1]

Expand Down Expand Up @@ -103,3 +105,4 @@ kill $(pgrep -x -f \"{temp_dir}/{exe_name} {cmd_args}\")
rm -rf \"{temp_dir}\""
dotnet/include_scripts_content=false
dotnet/include_debug_symbols=true
dotnet/embed_build_outputs=false

0 comments on commit 4baa647

Please sign in to comment.