From 722dbf6996d73571d1ad1af51b9975b003084adb Mon Sep 17 00:00:00 2001 From: Gustavo Maciel Date: Sun, 17 Dec 2023 11:47:13 -0300 Subject: [PATCH] feat: added set_ios_app_pause_on_background #99 --- addons/admob/sample/Main.gd | 1 + addons/admob/sample/Main.tscn | 25 +++++++++++++++++++++++-- addons/admob/sample/MobileAds.gd | 13 +++++++++++++ addons/admob/src/api/MobileAds.gd | 6 +++++- 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 addons/admob/sample/MobileAds.gd diff --git a/addons/admob/sample/Main.gd b/addons/admob/sample/Main.gd index 33ad887..20b20a1 100644 --- a/addons/admob/sample/Main.gd +++ b/addons/admob/sample/Main.gd @@ -33,6 +33,7 @@ func _ready() -> void: request_configuration.convert_to_dictionary() MobileAds.set_request_configuration(request_configuration) MobileAds.initialize(on_initialization_complete_listener) + func _on_initialization_complete(initialization_status : InitializationStatus) -> void: print("MobileAds initialization complete") diff --git a/addons/admob/sample/Main.tscn b/addons/admob/sample/Main.tscn index 11e3b2e..41d21e0 100644 --- a/addons/admob/sample/Main.tscn +++ b/addons/admob/sample/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=17 format=3 uid="uid://0esyp38ds6yg"] +[gd_scene load_steps=19 format=3 uid="uid://0esyp38ds6yg"] [ext_resource type="Script" path="res://addons/admob/sample/Main.gd" id="1_xm28w"] [ext_resource type="Texture2D" uid="uid://to8hnfn5fmrl" path="res://addons/admob/assets/icon-76.png" id="2_b280g"] @@ -11,6 +11,8 @@ [ext_resource type="PackedScene" uid="uid://iy12nk8vefwy" path="res://addons/admob/sample/Rewarded.tscn" id="8_atpxc"] [ext_resource type="PackedScene" uid="uid://cpxd2i7v6t6b6" path="res://addons/admob/sample/RewardedInterstitial.tscn" id="9_iwe72"] [ext_resource type="PackedScene" uid="uid://bnptawvmfxhhu" path="res://addons/admob/sample/Ump.tscn" id="10_7toto"] +[ext_resource type="AudioStream" uid="uid://f3f176vu6pfo" path="res://addons/admob/assets/music.ogg" id="12_3yie5"] +[ext_resource type="Script" path="res://addons/admob/sample/MobileAds.gd" id="12_tjkhy"] [sub_resource type="Theme" id="Theme_1p2mi"] default_font = ExtResource("3_acnhc") @@ -133,8 +135,10 @@ text = "AdMob Plugin - Poing Studios" [node name="Body" type="TabContainer" parent="Background/Content/Main"] layout_mode = 2 +current_tab = 5 [node name="Banner" parent="Background/Content/Main/Body" instance=ExtResource("6_xt5vc")] +visible = false layout_mode = 2 [node name="Interstitial" parent="Background/Content/Main/Body" instance=ExtResource("7_5rtn7")] @@ -154,13 +158,28 @@ visible = false layout_mode = 2 [node name="MobileAds" type="VBoxContainer" parent="Background/Content/Main/Body"] -visible = false layout_mode = 2 +script = ExtResource("12_tjkhy") [node name="GetInitializationStatus" type="Button" parent="Background/Content/Main/Body/MobileAds"] layout_mode = 2 text = "GetInitializationStatus" +[node name="SetiOSAppPauseOnBackgroundButton" type="CheckButton" parent="Background/Content/Main/Body/MobileAds"] +layout_mode = 2 +text = "Set iOS App Pause On Background" +alignment = 1 + +[node name="SetMuteMusic" type="CheckButton" parent="Background/Content/Main/Body/MobileAds"] +layout_mode = 2 +text = "Mute Music" +alignment = 1 + +[node name="Music" type="AudioStreamPlayer" parent="Background/Content/Main/Body/MobileAds"] +stream = ExtResource("12_3yie5") +volume_db = -10.0 +autoplay = true + [node name="Output" type="RichTextLabel" parent="Background/Content"] visible = false layout_mode = 2 @@ -174,3 +193,5 @@ visible_ratio = 0.480769 [connection signal="pressed" from="Background/Content/DonateButtons/HBoxContainer/Ko-fi" to="Background/Content/DonateButtons/HBoxContainer/Ko-fi" method="_on_pressed"] [connection signal="pressed" from="Background/Content/DonateButtons2/HBoxContainer/PayPal" to="Background/Content/DonateButtons2/HBoxContainer/PayPal" method="_on_pressed"] [connection signal="pressed" from="Background/Content/Main/Body/MobileAds/GetInitializationStatus" to="." method="_on_get_initialization_status_pressed"] +[connection signal="pressed" from="Background/Content/Main/Body/MobileAds/SetiOSAppPauseOnBackgroundButton" to="Background/Content/Main/Body/MobileAds" method="_on_set_ios_app_pause_on_background_button_pressed"] +[connection signal="pressed" from="Background/Content/Main/Body/MobileAds/SetMuteMusic" to="Background/Content/Main/Body/MobileAds" method="_on_mute_music_pressed"] diff --git a/addons/admob/sample/MobileAds.gd b/addons/admob/sample/MobileAds.gd new file mode 100644 index 0000000..3052bad --- /dev/null +++ b/addons/admob/sample/MobileAds.gd @@ -0,0 +1,13 @@ +extends VBoxContainer + +@onready var set_ios_app_pause_on_background_button := $SetiOSAppPauseOnBackgroundButton +@onready var set_mute_music := $SetMuteMusic +@onready var music := $Music + +func _on_set_ios_app_pause_on_background_button_pressed() -> void: + var enabled : bool = set_ios_app_pause_on_background_button.button_pressed + MobileAds.set_ios_app_pause_on_background(enabled) + +func _on_mute_music_pressed() -> void: + music.playing = not set_mute_music.button_pressed + diff --git a/addons/admob/src/api/MobileAds.gd b/addons/admob/src/api/MobileAds.gd index 963618d..1d61945 100644 --- a/addons/admob/src/api/MobileAds.gd +++ b/addons/admob/src/api/MobileAds.gd @@ -35,7 +35,7 @@ static func initialize(on_initialization_complete_listener : OnInitializationCom on_initialization_complete_listener.on_initialization_complete.call(initialization_status) ) -static func set_request_configuration(request_configuration : RequestConfiguration): +static func set_request_configuration(request_configuration : RequestConfiguration) -> void: if _plugin: #test_device_ids needs to be passed separarely because Dictionary can't serialize Arrays _plugin.set_request_configuration(request_configuration.convert_to_dictionary(), request_configuration.test_device_ids) @@ -45,3 +45,7 @@ static func get_initialization_status() -> InitializationStatus: var initialization_status_dictionary : Dictionary = _plugin.get_initialization_status() return InitializationStatus.create(initialization_status_dictionary) return null + +static func set_ios_app_pause_on_background(pause : bool) -> void: + if _plugin and OS.get_name() == "iOS": + _plugin.set_ios_app_pause_on_background(pause)