Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions addons/SystemBarColorChanger/SystemBarColorChanger.gd
Original file line number Diff line number Diff line change
@@ -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))
1 change: 1 addition & 0 deletions addons/SystemBarColorChanger/SystemBarColorChanger.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://btbu7ipw8efpj
Binary file added addons/SystemBarColorChanger/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions addons/SystemBarColorChanger/icon.png.import
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions addons/SystemBarColorChanger/plugin.cfg
Original file line number Diff line number Diff line change
@@ -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"
8 changes: 8 additions & 0 deletions addons/SystemBarColorChanger/plugin.gd
Original file line number Diff line number Diff line change
@@ -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")
1 change: 1 addition & 0 deletions addons/SystemBarColorChanger/plugin.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://bcuens7c62isp
2 changes: 1 addition & 1 deletion export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/ui_parts/editor_scene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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]))
Expand Down