diff --git a/addons/SystemBarColorChanger/SystemBarColorChanger.gd b/addons/SystemBarColorChanger/SystemBarColorChanger.gd new file mode 100644 index 0000000..1d6c61e --- /dev/null +++ b/addons/SystemBarColorChanger/SystemBarColorChanger.gd @@ -0,0 +1,98 @@ +# MIT License +# +# Copyright (c) 2024-present Anish Mishra (syntaxerror247) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +@tool +extends Node + +const _plugin_name: String = "SystemBarColorChanger" +var is_light_status_bar: bool = false +var is_light_navigation_bar: bool = false + +var android_runtime: Object + +func _ready() -> void: + if Engine.has_singleton("AndroidRuntime"): + android_runtime = Engine.get_singleton("AndroidRuntime") + var layout_params = JavaClassWrapper.wrap("android.view.WindowManager$LayoutParams") + var window = android_runtime.getActivity().getWindow() + window.addFlags(layout_params.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) + else: + printerr("AndroidRuntime singleton not found! Try it on an Android device.") + + +func set_status_bar_color(color: Color) -> void: + if not android_runtime: + printerr("%s plugin not initialized!" % _plugin_name) + return + + var activity = android_runtime.getActivity() + var callable = func (): + var window = activity.getWindow() + window.setStatusBarColor(color.to_argb32()) + if is_light_status_bar != (color.get_luminance() > 0.6): + is_light_status_bar = color.get_luminance() > 0.6 + var wic = JavaClassWrapper.wrap("android.view.WindowInsetsController") + var insets_controller = window.getInsetsController() + insets_controller.setSystemBarsAppearance( + wic.APPEARANCE_LIGHT_STATUS_BARS if is_light_status_bar else 0, + wic.APPEARANCE_LIGHT_STATUS_BARS) + + activity.runOnUiThread(android_runtime.createRunnableFromGodotCallable(callable)) + + +func set_navigation_bar_color(color: Color) -> void: + if not android_runtime: + printerr("%s plugin not initialized!" % _plugin_name) + return + + var activity = android_runtime.getActivity() + var callable = func (): + var window = activity.getWindow() + window.setNavigationBarColor(color.to_argb32()) + if is_light_navigation_bar != (color.get_luminance() > 0.6): + is_light_navigation_bar = color.get_luminance() > 0.6 + var wic = JavaClassWrapper.wrap("android.view.WindowInsetsController") + var insets_controller = window.getInsetsController() + insets_controller.setSystemBarsAppearance( + wic.APPEARANCE_LIGHT_NAVIGATION_BARS if is_light_navigation_bar else 0, + wic.APPEARANCE_LIGHT_NAVIGATION_BARS) + + activity.runOnUiThread(android_runtime.createRunnableFromGodotCallable(callable)) + + +func set_translucent_system_bars(translucent = true) -> void: + if not android_runtime: + printerr("%s plugin not initialized!" % _plugin_name) + return + + var activity = android_runtime.getActivity() + var callable = func (): + var layout_params = JavaClassWrapper.wrap("android.view.WindowManager$LayoutParams") + var window = activity.getWindow() + if translucent: + window.addFlags(layout_params.FLAG_TRANSLUCENT_STATUS) + window.addFlags(layout_params.FLAG_TRANSLUCENT_NAVIGATION) + else: + window.clearFlags(layout_params.FLAG_TRANSLUCENT_STATUS) + window.clearFlags(layout_params.FLAG_TRANSLUCENT_NAVIGATION) + + activity.runOnUiThread(android_runtime.createRunnableFromGodotCallable(callable)) diff --git a/addons/SystemBarColorChanger/SystemBarColorChanger.gd.uid b/addons/SystemBarColorChanger/SystemBarColorChanger.gd.uid new file mode 100644 index 0000000..865e5cd --- /dev/null +++ b/addons/SystemBarColorChanger/SystemBarColorChanger.gd.uid @@ -0,0 +1 @@ +uid://btbu7ipw8efpj diff --git a/addons/SystemBarColorChanger/icon.png b/addons/SystemBarColorChanger/icon.png new file mode 100644 index 0000000..90671de Binary files /dev/null and b/addons/SystemBarColorChanger/icon.png differ diff --git a/addons/SystemBarColorChanger/icon.png.import b/addons/SystemBarColorChanger/icon.png.import new file mode 100644 index 0000000..9fde075 --- /dev/null +++ b/addons/SystemBarColorChanger/icon.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b21otadglrwgf" +path="res://.godot/imported/icon.png-62f6d5c31a8cda23c897eeed30370292.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/SystemBarColorChanger/icon.png" +dest_files=["res://.godot/imported/icon.png-62f6d5c31a8cda23c897eeed30370292.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/addons/SystemBarColorChanger/plugin.cfg b/addons/SystemBarColorChanger/plugin.cfg new file mode 100644 index 0000000..beb512b --- /dev/null +++ b/addons/SystemBarColorChanger/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="SystemBarColorChanger" +description="Plugin to change System Bar (status and navigation bar) color dynamically and enable translucent system bars on Android." +author="Anish" +version="2.0" +script="plugin.gd" diff --git a/addons/SystemBarColorChanger/plugin.gd b/addons/SystemBarColorChanger/plugin.gd new file mode 100644 index 0000000..a82624a --- /dev/null +++ b/addons/SystemBarColorChanger/plugin.gd @@ -0,0 +1,8 @@ +@tool +extends EditorPlugin + +func _enter_tree() -> void: + add_autoload_singleton("SystemBarColorChanger", "res://addons/SystemBarColorChanger/SystemBarColorChanger.gd") + +func _exit_tree() -> void: + remove_autoload_singleton("SystemBarColorChanger") diff --git a/addons/SystemBarColorChanger/plugin.gd.uid b/addons/SystemBarColorChanger/plugin.gd.uid new file mode 100644 index 0000000..226f878 --- /dev/null +++ b/addons/SystemBarColorChanger/plugin.gd.uid @@ -0,0 +1 @@ +uid://bcuens7c62isp diff --git a/export_presets.cfg b/export_presets.cfg index e915d13..95b407e 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -33,7 +33,7 @@ architectures/armeabi-v7a=false architectures/arm64-v8a=true architectures/x86=false architectures/x86_64=false -version/code=1 +version/code=2 version/name="1.0-alpha2" package/unique_name="com.godsvg.mobile" package/name="GodSVG Mobile" diff --git a/project.godot b/project.godot index 3aee4ec..76bb333 100644 --- a/project.godot +++ b/project.godot @@ -31,6 +31,7 @@ driver/driver="Dummy" Configs="*res://src/autoload/Configs.gd" State="*res://src/autoload/State.gd" HandlerGUI="*res://src/autoload/HandlerGUI.gd" +SystemBarColorChanger="*res://addons/SystemBarColorChanger/SystemBarColorChanger.gd" [display] @@ -40,6 +41,10 @@ window/energy_saving/keep_screen_on=false window/handheld/orientation=1 mouse_cursor/tooltip_position_offset=Vector2(0, 10) +[editor_plugins] + +enabled=PackedStringArray("res://addons/SystemBarColorChanger/plugin.cfg") + [filesystem] import/blender/enabled=false diff --git a/src/ui_parts/editor_scene.gd b/src/ui_parts/editor_scene.gd index f1a40fb..88ac1f4 100644 --- a/src/ui_parts/editor_scene.gd +++ b/src/ui_parts/editor_scene.gd @@ -18,6 +18,8 @@ func update_theme() -> void: stylebox.bg_color = ThemeUtils.overlay_panel_inner_color stylebox.set_content_margin_all(0) panel_container.add_theme_stylebox_override("panel", stylebox) + SystemBarColorChanger.set_status_bar_color(ThemeUtils.overlay_panel_inner_color) + SystemBarColorChanger.set_navigation_bar_color(ThemeUtils.overlay_panel_inner_color) func update_layout() -> void: @@ -31,6 +33,7 @@ func update_layout() -> void: var main_splitter := VSplitContainer.new() main_splitter.size_flags_horizontal = Control.SIZE_FILL main_splitter.add_theme_constant_override("separation", 6) + main_splitter.add_theme_constant_override("autohide", 0) main_splitter.split_offset = Configs.savedata.main_splitter_offset main_splitter.dragged.connect(_on_main_splitter_dragged) panel_container.add_child(main_splitter) @@ -61,6 +64,7 @@ func update_layout() -> void: var top_vertical_split_container := VSplitContainer.new() top_vertical_split_container.size_flags_vertical = Control.SIZE_EXPAND_FILL top_vertical_split_container.add_theme_constant_override("separation", 10) + top_vertical_split_container.add_theme_constant_override("autohide", 0) top_vertical_split_container.split_offset = Configs.savedata.top_vertical_splitter_offset top_vertical_split_container.dragged.connect(_on_top_vertical_splitter_dragged) top_vertical_split_container.add_child(create_layout_node(top_left[0]))