diff --git a/docs/_data/api.yml b/docs/_data/api.yml index 39244b4..1f4892a 100644 --- a/docs/_data/api.yml +++ b/docs/_data/api.yml @@ -749,6 +749,28 @@ type: number desc: One of the gpgs.COLLECTION_ constants + +#***************************************************************************************************** +# Events +#***************************************************************************************************** + + - name: event_increment + type: function + desc: Increments an event specified by eventId by the given amount. + + parameters: + - name: eventId + type: string + + - name: amount + type: number + +#***************************************************************************************************** + + - name: event_get + type: function + desc: Asynchronously gets all events. + #***************************************************************************************************** # Popup position #***************************************************************************************************** @@ -886,6 +908,11 @@ desc: The message type that GPGS sends when finishing the asynchronous operation after calling `gpgs.leaderboard_get_player_score()` + - name: MSG_GET_EVENTS + type: number + desc: The message type that GPGS sends when finishing the asynchronous operation + after calling `gpgs.event_get()` + #***************************************************************************************************** # Status #***************************************************************************************************** diff --git a/gpgs/src/gpgs_extension.cpp b/gpgs/src/gpgs_extension.cpp index c2b95e3..101d970 100644 --- a/gpgs/src/gpgs_extension.cpp +++ b/gpgs/src/gpgs_extension.cpp @@ -66,10 +66,17 @@ struct GPGS_Leaderboard jmethodID m_LoadCurrentPlayerScore; }; +struct GPGS_Events +{ + jmethodID m_IncrementEvent; + jmethodID m_LoadEvents; +}; + static GPGS g_gpgs; static GPGS_Disk g_gpgs_disk; static GPGS_Achievement g_gpgs_achievement; static GPGS_Leaderboard g_gpgs_leaderboard; +static GPGS_Events g_gpgs_events; // generic JNI calls @@ -609,6 +616,29 @@ static int GpgsLeaderboard_ShowLeaderboard(lua_State* L) return 0; } +//****************************************************************************** +// GPGPS Events +//****************************************************************************** + + +static int GpgsEvent_Increment(lua_State* L) +{ + DM_LUA_STACK_CHECK(L, 0); + + const char* eventId = luaL_checkstring(L, 1); + lua_Number amount = luaL_checknumber(L, 2); + CallVoidMethodCharInt(g_gpgs.m_GpgsJNI, g_gpgs_events.m_IncrementEvent, eventId, amount); + return 0; +} + + +static int GpgsEvent_Get(lua_State* L) +{ + DM_LUA_STACK_CHECK(L, 0); + CallVoidMethod(g_gpgs.m_GpgsJNI, g_gpgs_events.m_LoadEvents); + return 0; +} + // Extension methods static void OnActivityResult(void *env, void* activity, int32_t request_code, int32_t result_code, void* result) @@ -664,6 +694,9 @@ static const luaL_reg Gpgs_methods[] = {"leaderboard_get_player_centered_scores", GpgsLeaderboard_GetPlayerCenteredScores}, {"leaderboard_show", GpgsLeaderboard_ShowLeaderboard}, {"leaderboard_get_player_score", GpgsLeaderboard_GetPlayerScore}, + //events + {"event_increment", GpgsEvent_Increment}, + {"event_get", GpgsEvent_Get}, {0,0} }; @@ -701,6 +734,7 @@ static void LuaInit(lua_State* L) SETCONSTANT(MSG_GET_TOP_SCORES) SETCONSTANT(MSG_GET_PLAYER_CENTERED_SCORES) SETCONSTANT(MSG_GET_PLAYER_SCORE) + SETCONSTANT(MSG_GET_EVENTS) SETCONSTANT(STATUS_SUCCESS) SETCONSTANT(STATUS_FAILED) @@ -780,6 +814,9 @@ static void InitJNIMethods(JNIEnv* env, jclass cls) g_gpgs_leaderboard.m_ShowLeaderboard = env->GetMethodID(cls, "showLeaderboard", "(Ljava/lang/String;II)V"); g_gpgs_leaderboard.m_LoadCurrentPlayerScore = env->GetMethodID(cls, "loadCurrentPlayerLeaderboardScore", "(Ljava/lang/String;II)V"); + g_gpgs_events.m_IncrementEvent = env->GetMethodID(cls, "incrementEvent", "(Ljava/lang/String;I)V"); + g_gpgs_events.m_LoadEvents = env->GetMethodID(cls, "loadEvents", "()V"); + //private methods g_gpgs.m_activityResult = env->GetMethodID(cls, "activityResult", "(IILandroid/content/Intent;)V"); } diff --git a/gpgs/src/gpgs_extension.h b/gpgs/src/gpgs_extension.h index e76b256..bffe080 100644 --- a/gpgs/src/gpgs_extension.h +++ b/gpgs/src/gpgs_extension.h @@ -69,7 +69,8 @@ enum MESSAGE_ID MSG_GET_ACHIEVEMENTS = 7, MSG_GET_TOP_SCORES = 8, MSG_GET_PLAYER_CENTERED_SCORES = 9, - MSG_GET_PLAYER_SCORE = 10 + MSG_GET_PLAYER_SCORE = 10, + MSG_GET_EVENTS = 11 }; // Internal to the extension diff --git a/gpgs/src/java/com/defold/gpgs/GpgsJNI.java b/gpgs/src/java/com/defold/gpgs/GpgsJNI.java index 65d96bb..e2e6c7f 100644 --- a/gpgs/src/java/com/defold/gpgs/GpgsJNI.java +++ b/gpgs/src/java/com/defold/gpgs/GpgsJNI.java @@ -40,6 +40,10 @@ import com.google.android.gms.games.achievement.Achievement; import com.google.android.gms.games.achievement.AchievementBuffer; +import com.google.android.gms.games.EventsClient; +import com.google.android.gms.games.event.Event; +import com.google.android.gms.games.event.EventBuffer; + import java.io.IOException; import org.json.JSONArray; @@ -73,6 +77,7 @@ public class GpgsJNI { private static final int MSG_GET_TOP_SCORES = 8; private static final int MSG_GET_PLAYER_CENTERED_SCORES = 9; private static final int MSG_GET_PLAYER_SCORE = 10; + private static final int MSG_GET_EVENTS = 11; // duplicate of enums from gpgs_extension.h: private static final int STATUS_SUCCESS = 1; @@ -803,4 +808,57 @@ else if (a.getState() == Achievement.STATE_REVEALED) { .addOnFailureListener(newOnFailureListener(MSG_ACHIEVEMENTS, "Unable to get achievements.")); } } + + private EventsClient mEventsClient = null; + + private boolean initEvents() { + if (mSignedInAccount == null) { + return false; + } + if (mEventsClient == null) { + mEventsClient = Games.getEventsClient(activity, mSignedInAccount); + } + return true; + } + + public void incrementEvent(String eventId, int amount) { + if(initEvents()) { + mEventsClient.increment(eventId, amount); + } + } + + public void loadEvents() { + if(initEvents()) { + Task> task = mEventsClient.load(false); + task.addOnSuccessListener(new OnSuccessListener>() { + @Override + public void onSuccess(AnnotatedData data) { + EventBuffer buffer = data.get(); + String message = null; + try { + JSONArray result = new JSONArray(); + for (Event e : buffer) { + JSONObject json = new JSONObject(); + json.put("id", e.getEventId()); + json.put("fomatted_value", e.getFormattedValue()); + json.put("value", e.getValue()); + json.put("description", e.getDescription()); + json.put("image", e.getIconImageUri()); + json.put("name", e.getName()); + json.put("visible", e.isVisible()); + result.put(json.toString()); + } + message = result.toString(); + buffer.release(); + } catch (JSONException e) { + message = "{ 'error':'Error while converting event to JSON: " + e.getMessage() + + "', 'status': '" + STATUS_FAILED + " }"; + } + gpgsAddToQueue(MSG_GET_EVENTS, message); + } + }) + .addOnFailureListener(newOnFailureListener(MSG_GET_EVENTS, "Unable to get events.")); + } + } + } diff --git a/main/events.collection b/main/events.collection new file mode 100644 index 0000000..479f88c --- /dev/null +++ b/main/events.collection @@ -0,0 +1,37 @@ +name: "events" +scale_along_z: 0 +embedded_instances { + id: "go" + data: "components {\n" + " id: \"monarch\"\n" + " component: \"/main/events.gui\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "" + position { + x: 0.0 + y: 0.0 + z: 0.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale3 { + x: 1.0 + y: 1.0 + z: 1.0 + } +} diff --git a/main/events.gui b/main/events.gui new file mode 100644 index 0000000..96876d7 --- /dev/null +++ b/main/events.gui @@ -0,0 +1,875 @@ +script: "/main/events.gui_script" +fonts { + name: "larryfont" + font: "/dirtylarry/larryfont.font" +} +textures { + name: "dirtylarry" + texture: "/dirtylarry/dirtylarry.atlas" +} +background_color { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 +} +nodes { + position { + x: 170.0 + y: 60.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEMPLATE + id: "back" + layer: "" + inherit_alpha: true + alpha: 1.0 + template: "/dirtylarry/button.gui" + template_node_child: false +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 300.0 + y: 88.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "button/button_normal" + id: "back/larrybutton" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "back" + layer: "" + inherit_alpha: true + slice9 { + x: 32.0 + y: 32.0 + z: 32.0 + w: 32.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + overridden_fields: 38 + template_node_child: true + size_mode: SIZE_MODE_MANUAL +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "BACK" + font: "larryfont" + id: "back/larrylabel" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "back/larrybutton" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 1.0 + overridden_fields: 8 + template_node_child: true + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: 170.0 + y: 653.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEMPLATE + id: "kill_zombie" + layer: "" + inherit_alpha: true + alpha: 1.0 + template: "/dirtylarry/button.gui" + template_node_child: false +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 300.0 + y: 88.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "button/button_normal" + id: "kill_zombie/larrybutton" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "kill_zombie" + layer: "" + inherit_alpha: true + slice9 { + x: 32.0 + y: 32.0 + z: 32.0 + w: 32.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + overridden_fields: 38 + template_node_child: true + size_mode: SIZE_MODE_MANUAL +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "Kill Zombie" + font: "larryfont" + id: "kill_zombie/larrylabel" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "kill_zombie/larrybutton" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 1.0 + overridden_fields: 8 + template_node_child: true + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: 170.0 + y: 532.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEMPLATE + id: "earn_gold" + layer: "" + inherit_alpha: true + alpha: 1.0 + template: "/dirtylarry/button.gui" + template_node_child: false +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 300.0 + y: 88.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "button/button_normal" + id: "earn_gold/larrybutton" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "earn_gold" + layer: "" + inherit_alpha: true + slice9 { + x: 32.0 + y: 32.0 + z: 32.0 + w: 32.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + overridden_fields: 38 + template_node_child: true + size_mode: SIZE_MODE_MANUAL +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "Earn Gold" + font: "larryfont" + id: "earn_gold/larrylabel" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "earn_gold/larrybutton" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 1.0 + overridden_fields: 8 + template_node_child: true + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: 170.0 + y: 411.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEMPLATE + id: "spend_gold" + layer: "" + inherit_alpha: true + alpha: 1.0 + template: "/dirtylarry/button.gui" + template_node_child: false +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 300.0 + y: 88.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "button/button_normal" + id: "spend_gold/larrybutton" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "spend_gold" + layer: "" + inherit_alpha: true + slice9 { + x: 32.0 + y: 32.0 + z: 32.0 + w: 32.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + overridden_fields: 38 + template_node_child: true + size_mode: SIZE_MODE_MANUAL +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "Spend Gold" + font: "larryfont" + id: "spend_gold/larrylabel" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "spend_gold/larrybutton" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 1.0 + overridden_fields: 8 + template_node_child: true + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: 656.0 + y: 653.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEMPLATE + id: "get" + layer: "" + inherit_alpha: true + alpha: 1.0 + template: "/dirtylarry/button.gui" + template_node_child: false +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 300.0 + y: 88.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "button/button_normal" + id: "get/larrybutton" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "get" + layer: "" + inherit_alpha: true + slice9 { + x: 32.0 + y: 32.0 + z: 32.0 + w: 32.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + overridden_fields: 38 + template_node_child: true + size_mode: SIZE_MODE_MANUAL +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "Get" + font: "larryfont" + id: "get/larrylabel" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "get/larrybutton" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 1.0 + overridden_fields: 8 + template_node_child: true + text_leading: 1.0 + text_tracking: 0.0 +} +nodes { + position { + x: 505.0 + y: 569.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 600.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "" + font: "larryfont" + id: "events" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_NW + outline { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: true + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 1.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 +} +material: "/builtins/materials/gui.material" +adjust_reference: ADJUST_REFERENCE_PARENT +max_nodes: 512 diff --git a/main/events.gui_script b/main/events.gui_script new file mode 100644 index 0000000..0f0dcf4 --- /dev/null +++ b/main/events.gui_script @@ -0,0 +1,50 @@ +local dirtylarry = require "dirtylarry.dirtylarry" +local monarch = require "monarch.monarch" + + +function gpgs_callback(self, message_id, message) + print(message_id) + pprint(message) + if message_id == gpgs.MSG_GET_EVENTS then + local s = "" + for _,event in ipairs(message) do + event = json.decode(event) + s = s .. ("%s (%s) = %s\n"):format(event.name, event.id, event.value) + end + gui.set_text(gui.get_node("events"), s) + end +end + +function init(self) + msg.post(".", "acquire_input_focus") + if gpgs then + gpgs.set_callback(gpgs_callback) + end +end + +function on_input(self, action_id, action) + dirtylarry:button("kill_zombie", action_id, action, function () + gpgs.event_increment("CgkIq5-gxcsVEAIQAw", 1) + end) + + dirtylarry:button("earn_gold", action_id, action, function () + gpgs.event_increment("CgkIq5-gxcsVEAIQBA", 1) + end) + + dirtylarry:button("spend_gold", action_id, action, function () + gpgs.event_increment("CgkIq5-gxcsVEAIQBQ", 1) + end) + + dirtylarry:button("get", action_id, action, function () + gpgs.event_get() + end) + + dirtylarry:button("back", action_id, action, function () + monarch.back() + end) +end + +function on_reload(self) + -- Add input-handling code here + -- Remove this function if not needed +end diff --git a/main/main.collection b/main/main.collection index 0a97f23..8b0b439 100644 --- a/main/main.collection +++ b/main/main.collection @@ -325,3 +325,61 @@ embedded_instances { z: 1.0 } } +embedded_instances { + id: "events" + data: "components {\n" + " id: \"screen_proxy\"\n" + " component: \"/monarch/screen_proxy.script\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + " properties {\n" + " id: \"screen_id\"\n" + " value: \"events\"\n" + " type: PROPERTY_TYPE_HASH\n" + " }\n" + "}\n" + "embedded_components {\n" + " id: \"collectionproxy\"\n" + " type: \"collectionproxy\"\n" + " data: \"collection: \\\"/main/events.collection\\\"\\n" + "exclude: false\\n" + "\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "" + position { + x: 0.0 + y: 0.0 + z: 0.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale3 { + x: 1.0 + y: 1.0 + z: 1.0 + } +} diff --git a/main/menu.gui b/main/menu.gui index 6fe15d5..7d36550 100644 --- a/main/menu.gui +++ b/main/menu.gui @@ -983,6 +983,164 @@ nodes { text_leading: 1.0 text_tracking: 0.0 } +nodes { + position { + x: 170.0 + y: 169.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEMPLATE + id: "events" + layer: "" + inherit_alpha: true + alpha: 1.0 + template: "/dirtylarry/button.gui" + template_node_child: false +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 300.0 + y: 88.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "button/button_normal" + id: "events/larrybutton" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "events" + layer: "" + inherit_alpha: true + slice9 { + x: 32.0 + y: 32.0 + z: 32.0 + w: 32.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: true + size_mode: SIZE_MODE_MANUAL +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "Events\t" + font: "larryfont" + id: "events/larrylabel" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "events/larrybutton" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 1.0 + overridden_fields: 8 + template_node_child: true + text_leading: 1.0 + text_tracking: 0.0 +} material: "/builtins/materials/gui.material" adjust_reference: ADJUST_REFERENCE_PARENT max_nodes: 512 diff --git a/main/menu.gui_script b/main/menu.gui_script index be76173..ca06764 100644 --- a/main/menu.gui_script +++ b/main/menu.gui_script @@ -47,7 +47,11 @@ function on_input(self, action_id, action) dirtylarry:button("leaderboards", action_id, action, function () monarch.show("leaderboards") end) - + + dirtylarry:button("events", action_id, action, function () + monarch.show("events") + end) + dirtylarry:button("popup_pos", action_id, action, function () change_popup_pos(self) end)