diff options
author | George L. Albany <Megacake1234@gmail.com> | 2023-02-21 08:49:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-21 08:49:46 +0100 |
commit | fb9e316a18139ea6b6ffe3b237796b42d7114738 (patch) | |
tree | 7eb315989e19d1e8eabea955330e3a2e5469c876 /game/src/Utility/StyleBoxCombinedTexture.gd | |
parent | 0b3f9cb21cfa86e98649066ff7d260b4f9022023 (diff) |
Add stylized theme to MainMenu (#12)
* Add stylized theme to MainMenu
Increase message queue memory size by 4
Add default_theme.theme
Refactor SampleGame.gd to better account for refactoring via @export nodes
Properly aligne SampleGame scene
Reorganize MainMenu into its own directory
Add main_menu_border_paper.png
Add main_menu_button.png
* Add background image to theme
Implement StyleBoxCombinedTexture
Allows drawing an array of textures all at once
Make MainMenu Panel a PanelContainer for consistency
* Implement MainMenu button press, hover, and focus styles
Improve MainMenu button disabled style
* Add Godot's latest documentation to the README.md
Diffstat (limited to 'game/src/Utility/StyleBoxCombinedTexture.gd')
-rw-r--r-- | game/src/Utility/StyleBoxCombinedTexture.gd | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/game/src/Utility/StyleBoxCombinedTexture.gd b/game/src/Utility/StyleBoxCombinedTexture.gd new file mode 100644 index 0000000..db54da4 --- /dev/null +++ b/game/src/Utility/StyleBoxCombinedTexture.gd @@ -0,0 +1,47 @@ +@tool +extends StyleBox +class_name StyleBoxCombinedTexture + +@export +var texture_settings : Array[TextureSetting] = []: + get: return texture_settings.duplicate() + set(v): + texture_settings = v + for setting in texture_settings: + setting.changed.connect(emit_changed) + emit_changed() + +func _get_draw_rect(rect : Rect2) -> Rect2: + var combined_rect : Rect2 = Rect2() + for setting in texture_settings: + if combined_rect.position.x > setting.expand_margin_left: + combined_rect.position.x = setting.expand_margin_left + if combined_rect.position.y > setting.expand_margin_top: + combined_rect.position.y = setting.expand_margin_top + if combined_rect.end.x < setting.expand_margin_right: + combined_rect.end.x = setting.expand_margin_right + if combined_rect.end.y < setting.expand_margin_bottom: + combined_rect.end.y = setting.expand_margin_bottom + return rect.grow_individual(combined_rect.position.x, combined_rect.position.y, combined_rect.end.x, combined_rect.end.y) + +func _draw(to_canvas_item : RID, rect : Rect2) -> void: + for setting in texture_settings: + if setting == null or setting.texture == null: + continue + var inner_rect : Rect2 = rect + inner_rect.position.x -= setting.expand_margin_left + inner_rect.position.y -= setting.expand_margin_top + inner_rect.size.x += setting.expand_margin_left + setting.expand_margin_right + inner_rect.size.y += setting.expand_margin_top + setting.expand_margin_bottom + RenderingServer.canvas_item_add_nine_patch( + to_canvas_item, + inner_rect, + setting.region_rect, + setting.texture.get_rid(), + Vector2(setting.texture_margin_left, setting.texture_margin_top), + Vector2(setting.texture_margin_right, setting.texture_margin_bottom), + setting.axis_stretch_horizontal, + setting.axis_stretch_vertical, + setting.draw_center, + setting.modulate_color + ) |