Merge with chun and jin
[apps/native/sample/adventure.git] / src / map.c
index 689965a..4d3c3f9 100644 (file)
--- a/src/map.c
+++ b/src/map.c
 #include <Elementary.h>
-#include "main.h"
-#include "log.h"
 #include "map.h"
-#include "util.h"
 
-const char *const MAP_EDJE = "map.edj";
+#define CITY_MAX 3
+#define WORLD_W 443
+#define WORLD_H 259
 
-Evas_Object *map_create(Evas_Object *parent)
+static Evas_Object *main_layout = NULL;
+static Evas_Object *map_layout = NULL;
+static city_data_s city[CITY_MAX] = {{{0, 0, 0, 0, 0, 0}, NULL},
+                                     {{0, 0, 0, 0, 0, 0}, NULL},
+                                     {{0, 0, 0, 0, 0, 0}, NULL}};
+
+static void
+map_geom_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+   Evas_Coord x, y, w, h;
+   evas_object_geometry_get(obj, &x, &y, &w, &h);
+
+   int idx;
+   for (idx = 0; CITY_MAX > idx; idx++)
+     {
+        if (!city[idx].obj) continue;
+        evas_object_move(city[idx].obj,
+                         (x + city[idx].ci.x) - (city[idx].w / 2),
+                         (y + city[idx].ci.y) - (city[idx].h / 2));
+     }
+}
+
+static void
+map_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+   int idx;
+   for (idx = 0; CITY_MAX > idx; idx++)
+     {
+        evas_object_del(city[idx].obj);
+        city[idx].obj = NULL;
+     }
+}
+
+Evas_Object *
+create_momentic_layout(Evas_Object *parent, const char *full_path)
+{
+   //Main Layout
+   main_layout = elm_layout_add(parent);
+   elm_layout_file_set(main_layout, full_path, "main");
+   evas_object_size_hint_weight_set(main_layout, EVAS_HINT_EXPAND,
+                                    EVAS_HINT_EXPAND);
+
+   //Map
+   map_layout = elm_layout_add(main_layout);
+   elm_layout_file_set(map_layout, full_path, "map");
+   evas_object_event_callback_add(map_layout, EVAS_CALLBACK_RESIZE, map_geom_cb, NULL);
+   evas_object_event_callback_add(map_layout, EVAS_CALLBACK_MOVE, map_geom_cb, NULL);
+   evas_object_event_callback_add(map_layout, EVAS_CALLBACK_DEL, map_del_cb, NULL);
+   elm_object_part_content_set(main_layout, "map", map_layout);
+
+   return main_layout;
+}
+
+Eina_Bool
+add_city_to_map(int idx, city_s *ci)
 {
-       Evas_Object *map = NULL;
-       char *path = NULL;
-       char full_path[PATH_LEN] = {0, };
+   if (idx >= CITY_MAX) return EINA_FALSE;
+   if (0 > idx) return EINA_FALSE;
+   if (city[idx].obj) return EINA_FALSE;
+
+   Evas_Coord x, y;
+   evas_object_geometry_get(map_layout, &x, &y, NULL, NULL);
+
+   char buf[256];
+   snprintf(buf, sizeof(buf), "city%d", idx);
+   city[idx].obj = elm_layout_add(map_layout);
+   elm_layout_file_set(city[idx].obj, "momentic.edj", buf);
+   evas_object_smart_member_add(city[idx].obj, map_layout);
+   evas_object_show(city[idx].obj);
 
-       retv_if(!parent, NULL);
+   Evas_Object *edje = elm_layout_edje_get(city[idx].obj);
+   city[idx].w = atoi(edje_object_data_get(edje, "width"));
+   city[idx].h = atoi(edje_object_data_get(edje, "height"));
+   memcpy(&city[idx].ci, ci, sizeof(city_s));
 
-       path = app_get_resource_path();
-       retv_if(!path, NULL);
+   evas_object_resize(city[idx].obj, city[idx].w, city[idx].h);
+   evas_object_move(city[idx].obj,
+                    ci->x + x - (city[idx].w / 2),
+                    ci->y + y - (city[idx].h / 2));
 
-       snprintf(full_path, sizeof(full_path), "%s/edje/%s", path, MAP_EDJE);
-       free(path);
+   Elm_Transit *trans;
 
-       map = elm_layout_add(parent);
-       retv_if(!map, NULL);
-       elm_layout_file_set(map, full_path, "main");
-       evas_object_show(map);
+   //Effect 1
+   trans = elm_transit_add();
+   elm_transit_object_add(trans, city[idx].obj);
+   elm_transit_effect_zoom_add(trans, 3.0, 1.0);
+   elm_transit_effect_color_add(trans, 0, 0, 0, 0, 255, 255, 255, 255);
+   elm_transit_tween_mode_set(trans, ELM_TRANSIT_TWEEN_MODE_DECELERATE);
+   elm_transit_duration_set(trans, 0.35);
+   elm_transit_go(trans);
 
-       return map;
+   //Effect 2 
+   Evas_Object *effect =
+      (Evas_Object *) edje_object_part_object_get(edje, "effect");
+   evas_object_render_op_set(effect, EVAS_RENDER_ADD);
+   trans = elm_transit_add();
+   elm_transit_object_add(trans, effect);
+   elm_transit_effect_color_add(trans, 0, 0, 0, 0, 127, 127, 127, 127);
+   elm_transit_duration_set(trans, 0.75);
+   elm_transit_repeat_times_set(trans, -1);
+   elm_transit_auto_reverse_set(trans, EINA_TRUE);
+   elm_transit_go(trans);
+
+   return EINA_TRUE;
 }
 
-void map_destroy(Evas_Object *map)
+static void
+trans_del_cb(void *data, Elm_Transit *trans)
 {
-       ret_if(!map);
+   int idx = (int) data;
+   evas_object_del(city[idx].obj);
+   city[idx].obj = NULL;
+}
+
+Eina_Bool
+remove_city_from_map(int idx)
+{
+   if (idx >= CITY_MAX) return EINA_FALSE;
+   if (0 > idx) return EINA_FALSE;
+   if (!city[idx].obj) return EINA_FALSE;
+
+   Elm_Transit *trans = elm_transit_add();
+   elm_transit_object_add(trans, city[idx].obj);
+   elm_transit_effect_zoom_add(trans, 1.0, 2.0);
+   elm_transit_effect_color_add(trans, 255, 255, 255, 255, 0, 0, 0, 0);
+   elm_transit_tween_mode_set(trans, ELM_TRANSIT_TWEEN_MODE_DECELERATE);
+   elm_transit_duration_set(trans, 0.35);
+   elm_transit_del_cb_set(trans, trans_del_cb, (void *)idx);
+   elm_transit_go(trans);
 
-       evas_object_del(map);
+   return EINA_TRUE;
 }