Skip to content

Commit

Permalink
Merge pull request godotengine#16 from ramatakinc/feature/3.x-ads-aut…
Browse files Browse the repository at this point in the history
…o_install_template

Add advertisement modules and core scaffolding
  • Loading branch information
hpvb authored Jul 12, 2023
2 parents 82e4f08 + ed2a95b commit ae403e2
Show file tree
Hide file tree
Showing 53 changed files with 2,372 additions and 572 deletions.
1 change: 1 addition & 0 deletions core/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ SConscript("math/SCsub")
SConscript("crypto/SCsub")
SConscript("io/SCsub")
SConscript("bind/SCsub")
SConscript("ramatak/SCsub")


# Build it all as a library
Expand Down
1 change: 1 addition & 0 deletions core/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ enum PropertyHint {
PROPERTY_HINT_NODE_PATH_VALID_TYPES,
PROPERTY_HINT_SAVE_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,". This opens a save dialog
PROPERTY_HINT_ENUM_SUGGESTION, ///< hint_text= "val1,val2,val3,etc"
PROPERTY_HINT_AD_UNIT,
PROPERTY_HINT_MAX,
// When updating PropertyHint, also sync the hardcoded list in VisualScriptEditorVariableEdit
};
Expand Down
3 changes: 3 additions & 0 deletions core/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ bool OS::has_feature(const String &p_feature) {
if (p_feature == get_name()) {
return true;
}
if (p_feature == "ramatak") {
return true;
}
#ifdef DEBUG_ENABLED
if (p_feature == "debug") {
return true;
Expand Down
4 changes: 2 additions & 2 deletions core/project_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ class ProjectSettings : public Object {

String project_data_dir_name;

bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
virtual bool _set(const StringName &p_name, const Variant &p_value);
virtual bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;

static ProjectSettings *singleton;
Expand Down
7 changes: 7 additions & 0 deletions core/ramatak/SCsub
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env python

Import("env")

env_templates = env.Clone()

env_templates.add_source_files(env.core_sources, "*.cpp")
57 changes: 57 additions & 0 deletions core/ramatak/monetization_settings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "monetization_settings.h"
#include "core/project_settings.h"

MonetizationSettings *MonetizationSettings::singleton = nullptr;

MonetizationSettings::MonetizationSettings() {
singleton = this;
}

MonetizationSettings::~MonetizationSettings() {
}

MonetizationSettings *MonetizationSettings::get_singleton() {
return singleton;
}

void MonetizationSettings::_bind_methods() {
ClassDB::bind_method(D_METHOD("delete_ad_unit", "ad_unit"), &MonetizationSettings::delete_ad_unit);
ClassDB::bind_method(D_METHOD("set_ad_unit_network_id", "ad_unit", "network", "network_specific_id"), &MonetizationSettings::set_ad_unit_network_id);
ClassDB::bind_method(D_METHOD("get_ad_unit_network_id", "ad_unit", "network"), &MonetizationSettings::get_ad_unit_network_id);
ClassDB::bind_method(D_METHOD("get_ad_units"), &MonetizationSettings::get_ad_units);
}

void MonetizationSettings::delete_ad_unit(StringName p_ad_unit) {
String ad_unit_setting = "ramatak/monetization/ad_units";
ProjectSettings *project_settings = ProjectSettings::get_singleton();

Dictionary dict = project_settings->get(ad_unit_setting);
Dictionary ad_unit_ids = dict.get(p_ad_unit, Dictionary());
ad_unit_ids.erase(p_ad_unit);
dict[p_ad_unit] = ad_unit_ids;
project_settings->set(ad_unit_setting, dict);
}

Array MonetizationSettings::get_ad_units() const {
return ad_units;
}

String MonetizationSettings::get_ad_unit_network_id(StringName p_ad_unit, String p_network) {
String ad_unit_setting = "ramatak/monetization/ad_units";
ProjectSettings *project_settings = ProjectSettings::get_singleton();

Dictionary dict = project_settings->get(ad_unit_setting);
Dictionary ad_unit_ids = dict[p_ad_unit];
return ad_unit_ids.get(p_network, "");
}

void MonetizationSettings::set_ad_unit_network_id(StringName p_ad_unit, String p_network, String p_id) {
String ad_unit_setting = "ramatak/monetization/ad_units";
ProjectSettings *project_settings = ProjectSettings::get_singleton();

Dictionary dict = project_settings->get(ad_unit_setting);
Dictionary ad_unit_ids = dict.get(p_ad_unit, Dictionary());
ad_unit_ids[p_network] = p_id;
dict[p_ad_unit] = ad_unit_ids;
project_settings->set(ad_unit_setting, dict);
}
32 changes: 32 additions & 0 deletions core/ramatak/monetization_settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef _MONETIZATION_SETTINGS_H
#define _MONETIZATION_SETTINGS_H

#include "core/class_db.h"
#include "core/object.h"
#include "servers/ramatak/ad_server.h"

class MonetizationSettings : public Object {
GDCLASS(MonetizationSettings, Object);

Array ad_units;

static MonetizationSettings *singleton;

protected:
static void _bind_methods();

public:
static MonetizationSettings *get_singleton();

void delete_ad_unit(StringName p_ad_unit);

void set_ad_unit_network_id(StringName p_ad_unit, String p_network, String p_id);
String get_ad_unit_network_id(StringName p_ad_unit, String p_network);

Array get_ad_units() const;

MonetizationSettings();
virtual ~MonetizationSettings();
};

#endif // _MONETIZATION_SETTINGS
2 changes: 2 additions & 0 deletions core/register_core_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
#include "core/packed_data_container.h"
#include "core/path_remap.h"
#include "core/project_settings.h"
#include "core/ramatak/monetization_settings.h"
#include "core/translation.h"
#include "core/undo_redo.h"

Expand Down Expand Up @@ -269,6 +270,7 @@ void register_core_singletons() {
Engine::get_singleton()->add_singleton(Engine::Singleton("InputMap", InputMap::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("JSON", _JSON::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("Time", Time::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("MonetizationSettings", MonetizationSettings::get_singleton()));
}

void unregister_core_types() {
Expand Down
2 changes: 2 additions & 0 deletions doc/classes/@GlobalScope.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<member name="ARVRServer" type="ARVRServer" setter="" getter="">
The [ARVRServer] singleton.
</member>
<member name="AdServer" type="AdServer" setter="" getter="">
</member>
<member name="AudioServer" type="AudioServer" setter="" getter="">
The [AudioServer] singleton.
</member>
Expand Down
69 changes: 69 additions & 0 deletions doc/classes/AdController.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="AdController" inherits="Node" version="3.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
Controls and configures non-banner ads like interstitials
</brief_description>
<description>
AdController is used to set up, display, and monitor the status of an interstitial or rewarded interstitial advertisement.
</description>
<tutorials>
</tutorials>
<methods>
<method name="hide">
<return type="void" />
<description>
Hides this advertisement.
</description>
</method>
<method name="show">
<return type="void" />
<description>
Shows this advertisement.
</description>
</method>
</methods>
<members>
<member name="ad_unit" type="String" setter="set_ad_unit" getter="get_ad_unit" default="&quot;&quot;">
The ad unit associated with this advertisement.
This is used to provide the selected ad network with the information it needs to configure your advertisement and ensure revenue is appropriately handled.
</member>
</members>
<signals>
<signal name="ad_clicked">
<description>
Emitted whenever the advertisement is clicked.
Due to platform-specific quirks, this may not be emitted until after the user returns to the app.
</description>
</signal>
<signal name="ad_closed">
<description>
The user closed the ad.
</description>
</signal>
<signal name="ad_error">
<argument index="0" name="message" type="String" />
<description>
There was an error during the loading or display of this advertisement.
The message argument provides more information about the error.
</description>
</signal>
<signal name="ad_loaded">
<description>
The advertisement has loaded. This does not indicate that it has been shown to the user.
</description>
</signal>
<signal name="ad_reward_earned">
<description>
For rewarded interstitial ads, this signal indicates that the reward is earned.
Handling this signal is mandatory to comply with advertisement network guidelines.
</description>
</signal>
<signal name="ad_shown">
<description>
The advertisement has been displayed to the user.
</description>
</signal>
</signals>
<constants>
</constants>
</class>
94 changes: 94 additions & 0 deletions doc/classes/AdServer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="AdServer" inherits="Object" version="3.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
The AdServer is a low-level interface with the Ramtak Mobile Studio advertisement system.
</brief_description>
<description>
While it is possible to use AdServer as a user, it's much more ergonomic to use the AdController and BannerAdController nodes.
</description>
<tutorials>
</tutorials>
<methods>
<method name="get_available_plugins" qualifiers="const">
<return type="Array" />
<description>
Regurns a list of available plugins in the current build.
</description>
</method>
<method name="get_plugin_priority_order" qualifiers="const">
<return type="Array" />
<description>
Returns the current priority order of advertisement plugins.
</description>
</method>
<method name="set_plugin_priority_order">
<return type="void" />
<argument index="0" name="priorities" type="Array" />
<description>
Sets the priority order of advertisement plugins.
</description>
</method>
</methods>
<signals>
<signal name="ad_clicked">
<argument index="0" name="request_id" type="int" />
<description>
Emitted whenever an advertisement is clicked. You probobaly want to be using the AdController/BannerAdController version of this signal.
</description>
</signal>
<signal name="ad_closed">
<argument index="0" name="request_id" type="int" />
<description>
Emitted whenever an advertisement is closed. You probobaly want to be using the AdController/BannerAdController version of this signal.
</description>
</signal>
<signal name="ad_error">
<argument index="0" name="request_id" type="int" />
<argument index="1" name="message" type="String" />
<description>
Emitted whenever an advertisement has an error. You probobaly want to be using the AdController/BannerAdController version of this signal.
</description>
</signal>
<signal name="ad_loaded">
<argument index="0" name="request_id" type="int" />
<description>
Emitted whenever an advertisement is loaded. You probobaly want to be using the AdController/BannerAdController version of this signal.
</description>
</signal>
<signal name="ad_reward_earned">
<argument index="0" name="request_id" type="int" />
<description>
Emitted whenever an advertisement reward is earned by the user. You probobaly want to be using the AdController/BannerAdController version of this signal.
</description>
</signal>
<signal name="ad_shown">
<argument index="0" name="request_id" type="int" />
<description>
Emitted whenever an advertisement is shown. You probobaly want to be using the AdController/BannerAdController version of this signal.
</description>
</signal>
</signals>
<constants>
<constant name="AdType::AD_TYPE_BANNER" value="0" enum="AdType">
Indicates a banner ad type.
</constant>
<constant name="AdType::AD_TYPE_INTERSTITIAL" value="1" enum="AdType">
Indicates an interstitial ad type.
</constant>
<constant name="AdType::AD_TYPE_REWARDED" value="2" enum="AdType">
Indicates a rewarded interstitial ad type.
</constant>
<constant name="BannerAdSize::BANNER_SIZE_SMALL" value="0" enum="BannerAdSize">
Indicates a small banner size.
</constant>
<constant name="BannerAdSize::BANNER_SIZE_LARGE" value="1" enum="BannerAdSize">
Indicates a large banner size.
</constant>
<constant name="BannerAdLocation::BANNER_LOCATION_BOTTOM" value="0" enum="BannerAdLocation">
Indicates a banner should be located on the bottom of the screen.
</constant>
<constant name="BannerAdLocation::BANNER_LOCATION_TOP" value="1" enum="BannerAdLocation">
Indicates a banner should be located on the top of the screen.
</constant>
</constants>
</class>
28 changes: 28 additions & 0 deletions doc/classes/BannerAdController.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="BannerAdController" inherits="AdController" version="3.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
Controls and configures banner ads
</brief_description>
<description>
BannerAdController is used to set up the size, location and status of a banner advertisement, and control its status.
It also includes signals inherited from AdController to monitor the status of a banner ad.
</description>
<tutorials>
</tutorials>
<methods>
</methods>
<members>
<member name="auto_show" type="bool" setter="set_auto_show" getter="get_auto_show" default="false">
When auto-show is enabled, the banner advertisement will be displayed to the user when this node enters the scene.
</member>
<member name="location" type="int" setter="set_location" getter="get_location" enum="AdServer.BannerAdLocation" default="0">
The location on the screen to display this banner advertisement.
</member>
<member name="size" type="int" setter="set_size" getter="get_size" enum="AdServer.BannerAdSize" default="0">
The size of the advertisement.
This is internally converted to an appropriate value for each ad network to ensure uniform behavior across networks.
</member>
</members>
<constants>
</constants>
</class>
13 changes: 13 additions & 0 deletions doc/classes/DummyAdPlugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="DummyAdPlugin" inherits="AdPlugin" version="3.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<methods>
</methods>
<constants>
</constants>
</class>
1 change: 1 addition & 0 deletions editor/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ if env["tools"]:
SConscript("icons/SCsub")
SConscript("import/SCsub")
SConscript("plugins/SCsub")
SConscript("ramatak/SCsub")

lib = env.add_library("editor", env.editor_sources)
env.Prepend(LIBS=[lib])
5 changes: 5 additions & 0 deletions editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "editor_properties_array_dict.h"
#include "editor_scale.h"
#include "scene/main/viewport.h"
#include "editor/ramatak/editor_property_ad_unit.h"

///////////////////// NULL /////////////////////////

Expand Down Expand Up @@ -2874,6 +2875,10 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
Vector<String> options = p_hint_text.split(",", false);
editor->setup(options, (p_hint == PROPERTY_HINT_ENUM_SUGGESTION));
add_property_editor(p_path, editor);
} else if (p_hint == PROPERTY_HINT_AD_UNIT) {
EditorPropertyAdUnit *editor = memnew(EditorPropertyAdUnit);
editor->setup();
add_property_editor(p_path, editor);
} else if (p_hint == PROPERTY_HINT_MULTILINE_TEXT) {
EditorPropertyMultilineText *editor = memnew(EditorPropertyMultilineText);
add_property_editor(p_path, editor);
Expand Down
Loading

0 comments on commit ae403e2

Please sign in to comment.