[Tux4kids-commits] [SCM] tuxhistory - Educational history game branch, master, updated. 807d63f6ccb65681ece995eff90ddabb00b0de2d

julio (none) julio at julio-desktop.
Tue Aug 10 22:13:00 UTC 2010


The following commit has been merged in the master branch:
commit 807d63f6ccb65681ece995eff90ddabb00b0de2d
Author: julio <julio at julio-desktop.(none)>
Date:   Tue Aug 10 17:12:11 2010 -0500

    GUI improvments

diff --git a/data/images/gui/Makefile.am b/data/images/gui/Makefile.am
index 169cc37..a41f107 100644
--- a/data/images/gui/Makefile.am
+++ b/data/images/gui/Makefile.am
@@ -4,4 +4,7 @@
 
 guidir = $(pkgdatadir)/images/gui
 
-dist_gui_DATA = byzantine.png
+dist_gui_DATA = byzantine.png \
+build.png \
+kill.png \
+pawn.png 
diff --git a/data/images/gui/build.png b/data/images/gui/build.png
new file mode 100644
index 0000000..da770d6
Binary files /dev/null and b/data/images/gui/build.png differ
diff --git a/data/images/gui/kill.png b/data/images/gui/kill.png
new file mode 100644
index 0000000..eba1e5a
Binary files /dev/null and b/data/images/gui/kill.png differ
diff --git a/data/images/gui/pawn.png b/data/images/gui/pawn.png
new file mode 100644
index 0000000..2e8d22c
Binary files /dev/null and b/data/images/gui/pawn.png differ
diff --git a/src/Makefile.am b/src/Makefile.am
index 1a2f309..41e271b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -37,6 +37,7 @@ tuxhistory_SOURCES = tuxhistory.c \
 	fileops_media.c \
 	options.c	\
 	credits.c	\
+	panel.c		\
 	hashtable.c \
 	highscore.c	\
 	llist.c		\
@@ -73,6 +74,7 @@ EXTRA_DIST = 	credits.h 	\
 	loaders.h	\
 	titlescreen.h   \
 	map.h		\
+	panel.h		\
 	objects.h	\
 	options.h	\
 	setup.h		\
diff --git a/src/ai.c b/src/ai.c
index 040da39..9ebdafa 100644
--- a/src/ai.c
+++ b/src/ai.c
@@ -475,7 +475,7 @@ int ai_state_update(list_node *node)
                         node->obj.state.path_flag = 0;
                         node->obj.state.count = 0;
                     }
-                    ai_free_path(node->obj.state.path);
+                    //ai_free_path(node->obj.state.path);
                 }
             }
         }
diff --git a/src/fileops.h b/src/fileops.h
index a679fe9..14d48e4 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -76,6 +76,9 @@ enum {
   IMG_EXPLORED,
   IMG_NOVISIBLE,
   IMG_GUIBG_BYZANTINE,
+  IMG_GUIBUILD,
+  IMG_GUIKILL,
+  IMG_GUIPAWN,
   NUM_IMAGES
 };
 
diff --git a/src/fileops_media.c b/src/fileops_media.c
index 8ed135b..fc0e95f 100644
--- a/src/fileops_media.c
+++ b/src/fileops_media.c
@@ -67,7 +67,10 @@ int load_image_data()
   "others/wrong.png",
   "others/explored.png",
   "others/novisible.png",
-  "gui/byzantine.png"
+  "gui/byzantine.png",
+  "gui/build.png",
+  "gui/kill.png",
+  "gui/pawn.png"
   };
 
 
diff --git a/src/game.c b/src/game.c
index 1a68407..c26cf97 100644
--- a/src/game.c
+++ b/src/game.c
@@ -40,6 +40,7 @@
 #include "llist.h"
 #include "tuxrts.h"
 #include "ai.h"
+#include "panel.h"
 
 
 #define FPS 50 /* 15 frames per second */
@@ -131,7 +132,7 @@ static int game_init(void)
     SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
     SDL_Flip(screen);
 
-    generate_map();
+    //generate_map();
 
     //SDL_Flip(map_image);
     quit = 0;
@@ -203,6 +204,13 @@ static int game_init(void)
     if(tuxrts_init("objects", "map", 2))
         return 1;
 
+    Pscreen.x = map_image->w/2 - panel.panel_game.w/2;
+    Pscreen.y = map_image->h/2 - panel.panel_game.h/2;
+    origin.x = Pscreen.x;
+    origin.y = Pscreen.y;
+    origin.w = panel.panel_game.w;
+    origin.h = panel.panel_game.h;
+
     return 0;
 }
 
@@ -277,8 +285,8 @@ static void draw_unexplored(int player, th_point point)
         gmaps[player][point.x][point.y].drawed == 0 )
     {
         //printf(" + ");
-        dest.x = gmaps[0][point.x][point.y].rect.x - Pscreen.x;
-        dest.y = gmaps[0][point.x][point.y].rect.y - Pscreen.y;
+        dest.x = gmaps[0][point.x][point.y].rect.x - Pscreen.x + panel.panel_game.x;
+        dest.y = gmaps[0][point.x][point.y].rect.y - Pscreen.y + panel.panel_game.y;
 
         //Is the point visible or unexplored? If so plaint!
         if(gmaps[player][point.x][point.y].visible == 0)
@@ -316,9 +324,6 @@ static void draw_unexplored(int player, th_point point)
                 (Pscreen.y - images[IMG_EXPLORED]->h));*/
 }
 
-
-
-
 static void game_draw(int player)
 {
     SDL_Rect dest;
@@ -333,16 +338,11 @@ static void game_draw(int player)
     origin.x = Pscreen.x;
     origin.y = Pscreen.y;
 
-    dest.x = 0;
-    dest.y = 0;
-
-
     /*TODO: Separate each Layer drawing in different functions.*/
 
     /*First layer: terrain*/
-    SDL_BlitSurface(map_image, &origin, screen, &dest);
+    SDL_BlitSurface(map_image, &origin, screen, &panel.panel_game);
 
-    
     /*Second layer: objects*/
 
     obj_node = list_nodes;
@@ -370,16 +370,16 @@ static void game_draw(int player)
                   )
                 {
                     dest.x = gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.x - 
-                        origin.x - objects[obj_node->obj.name_enum]->w/2;
+                        origin.x - objects[obj_node->obj.name_enum]->w/2 + panel.panel_game.x;
                     dest.y = gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.y - 
-                        origin.y - objects[obj_node->obj.name_enum]->h/2;
+                        origin.y - objects[obj_node->obj.name_enum]->h/2 + panel.panel_game.y;
                     if(obj_node->obj.actual_live < obj_node->obj.live 
                             && obj_node->obj.type == FOREST)
                         SDL_BlitSurface(objects[FOREST_USED], NULL, screen, &dest);
                     else
                         SDL_BlitSurface(objects[obj_node->obj.name_enum], NULL, screen, &dest);
                 }
-                // Is the any object selected?
+                // Is any object selected?
                 if(selection.selected_num != -1)
                 {
                     if(selection.selected_objs[0] != NULL)
@@ -448,73 +448,8 @@ static void game_draw(int player)
 
 unexp_draw:
 
-    /*Third layer: User Interface*/
-
-    //TODO: Write a panel function to manipulate the game...
-    dest2.x = 0;
-    dest2.y = 0;//(screen->h / 20) * 19;
-    dest2.h = screen->h / 20;
-    dest2.w = images[IMG_GUIBG_BYZANTINE]->w;
-
-    dest.x = 0;
-    dest.y = 0;
-
-    SDL_BlitSurface(images[IMG_GUIBG_BYZANTINE], &dest2, screen, &dest);
-    sprintf(tmp_text,"Wood %5d   Food %5d   Stone %5d   Gold %5d ", 
-                                player_vars[1].wood,
-                                player_vars[1].food,
-                                player_vars[1].stone,
-                                player_vars[1].gold);
-            
-    th_ShowMessage(tmp_text, 16, dest.x+2, dest.y+2);
-
-    dest.x = 0;
-    dest.y = (screen->h / 5) * 4;
-    SDL_BlitSurface(images[IMG_GUIBG_BYZANTINE], NULL, screen, &dest);
-    
-    if(selection.selected_num != -1)
-    {
-        if(selection.selected_objs[0] != NULL)
-        {
-            dest.x = dest.x + 10;
-            dest.y = dest.y + 10;
-            dest.h = 100;
-            dest.w = screen->w / 5;
-            //FillRect(dest, 0x000000);
-
-            dest.x = dest.x + 2;
-            dest.y = dest.y + 2;
-
-            th_ShowMessage(selection.selected_objs[0]->rname, 12, dest.x+2, dest.y+2);
-
-            sprintf(tmp_text,"%d / %d", selection.selected_objs[0]->actual_live,
-                                        selection.selected_objs[0]->live);
-            //printf("dir is: %s\n", tmp_text);
-            th_ShowMessage(tmp_text, 15, 
-                    objects[selection.selected_objs[0]->name_enum]->w + dest.x + 10, dest.y+20);
-
-
-            dest.y = dest.y + 20;
-
-            SDL_BlitSurface(objects[selection.selected_objs[0]->name_enum], NULL, screen, &dest);
-        }
-    }
-
-    dest.x = (screen->w - mini_map_image->w - 5);
-    dest.y = (screen->h - mini_map_image->h - 5);
-    SDL_BlitSurface(mini_map_image, NULL, screen, &dest);
-
-    dest.x = (screen->w - images[IMG_STOP]->w - 5);
-    dest.y = glyph_offset;
-    SDL_BlitSurface(images[IMG_STOP], NULL, screen, &dest);
-    
-
-    /*dest.x = 20;
-    dest.y = 20;
-    dest.h = 100;
-    dest.w = 100;
 
-    draw_rect(screen, dest);*/
+    panel_draw(selection.selected_objs[0], selection.selected_num);
 
 }
 
@@ -530,11 +465,11 @@ static void game_handle_mouse(void)
     if(Pmousemap.x != -1 && Pmousemap.y != -1)
     {
    
-        if( Pscreen.x < (map_image->w - screen->h) &&
+/*        if( Pscreen.x < (map_image->w - screen->w) &&
             Pscreen.x > 0 &&
             Pscreen.y < (map_image->h - screen->h) &&
-            Pscreen.y > 0)
-        {
+            Pscreen.y > panel.panel_header_dest.h)
+        {*/
             // Is the mouse close to the border? Move the
             // map...
             if(io.Pmouse.x < screen_margin_in && Pscreen.x > IN_SCROLL){
@@ -547,8 +482,9 @@ static void game_handle_mouse(void)
             if(io.Pmouse.y < screen_margin_in && Pscreen.y > IN_SCROLL){
                 Pscreen.y = Pscreen.y - IN_SCROLL;
             }
-            if(io.Pmouse.y > screen->h - screen_margin_in &&
-                    (Pscreen.y + screen->h) < (map_image->h - IN_SCROLL)){
+            if(io.Pmouse.y > (screen->h - screen_margin_in)&&
+                (Pscreen.y + panel.panel_game.h)
+                < (map_image->h - IN_SCROLL)){
                 Pscreen.y = Pscreen.y + IN_SCROLL;
             }
 
@@ -565,11 +501,12 @@ static void game_handle_mouse(void)
                 Pscreen.y = Pscreen.y - OUT_SCROLL;
             }
             if(io.Pmouse.y > screen->h - screen_margin_out &&
-                    (Pscreen.y + screen->h) < (map_image->h - OUT_SCROLL)){
+                (Pscreen.y + panel.panel_game.h) 
+                < (map_image->h - OUT_SCROLL)){
                 Pscreen.y = Pscreen.y + OUT_SCROLL;
             }
             
-        }
+        //}
         // TODO: Selecting rectangle is incompleat
         if( io.select_rect.x > Pscreen.x &&
             io.select_rect.x < Pscreen.x + screen->w &&
@@ -587,74 +524,84 @@ static void game_handle_mouse(void)
     }
     if(io.mousedown_flag != 0)
     {
-        //printf("Mouse down, ... ");
         if(io.mouseclicked_flag != 0)
         {
-            //io.select.x = Plclick.x;
-            //io.select.y = Plclick.y; 
-            Pmousemap = mouse_map(io.Plclick, Pscreen);
-            if(Pmousemap.x != -1 && Pmousemap.y != -1)
+            if(panel_click(&io.Plclick))
+            {
+                io.mouseclicked_flag = 0;
+            }
+            else
             {
-                printf("Mouse clicked in a valid tile!\n");
-                io.mousedown_flag = 0;
-                io.select_rect.x = gmaps[0][Pmousemap.x][Pmousemap.y].rect.x; 
-                io.select_rect.y = gmaps[0][Pmousemap.x][Pmousemap.y].rect.y;
-                io.select_xy.x = Pmousemap.x;
-                io.select_xy.y = Pmousemap.y;
+                Pmousemap = mouse_map(io.Plclick, Pscreen);
+                if(Pmousemap.x != -1 && Pmousemap.y != -1)
+                {
+                    printf("Mouse clicked in a valid tile!\n");
+                    io.mousedown_flag = 0;
+                    io.select_rect.x = gmaps[0][Pmousemap.x][Pmousemap.y].rect.x; 
+                    io.select_rect.y = gmaps[0][Pmousemap.x][Pmousemap.y].rect.y;
+                    io.select_xy.x = Pmousemap.x;
+                    io.select_xy.y = Pmousemap.y;
 
-                // Search for a object in current selected tile and
-                // select that object
+                    // Search for a object in current selected tile and
+                    // select that object
 
-                selection.selected_objs[0]=rts_get_object(human_player,Pmousemap);
+                    selection.selected_objs[0]=rts_get_object(human_player,Pmousemap);
 
-                if(selection.selected_objs[0] != NULL)
-                {
-                    selection.selected_num = 0;
-                    printf("Selected: %s, in (%d, %d)\n", selection.selected_objs[0]->name,
+                    if(selection.selected_objs[0] != NULL)
+                    {
+                        selection.selected_num = 0;
+                        printf("Selected: %s, in (%d, %d)\n", selection.selected_objs[0]->name,
                             selection.selected_objs[0]->x,
                             selection.selected_objs[0]->y);
+                    }
+                    else
+                    {
+                        selection.selected_num = -1;
+                    }
                 }
-                else
-                {
-                    selection.selected_num = -1;
-                }
-                
             }
         }
     }
     if(io.mousedownr_flag != 0)
     {
-        Pmousemap = mouse_map(io.Prclick, Pscreen);
-        if(Pmousemap.x != -1 && Pmousemap.y != -1)
+        if(panel_rclick(&io.Plclick))
         {
-            io.go_rect.x = gmaps[0][Pmousemap.x][Pmousemap.y].rect.x; 
-            io.go_rect.y = gmaps[0][Pmousemap.x][Pmousemap.y].rect.y;
             io.mousedownr_flag = 0;
-            if( io.go_rect.x > Pscreen.x &&
-                io.go_rect.x < Pscreen.x + screen->w &&
-                io.go_rect.y > Pscreen.y &&
-                io.go_rect.y < Pscreen.y + screen->h)
+        }
+        else
+        {
+            Pmousemap = mouse_map(io.Prclick, Pscreen);
+            if(Pmousemap.x != -1 && Pmousemap.y != -1)
             {
-                io.go_rect_dest.x = io.go_rect.x - Pscreen.x;
-                io.go_rect_dest.y = io.go_rect.y - Pscreen.y;
-                io.go_xy.x = Pmousemap.x;
-                io.go_xy.y = Pmousemap.y;
-                if(rts_valid_tile(0,1,io.go_xy))
+                io.go_rect.x = gmaps[0][Pmousemap.x][Pmousemap.y].rect.x; 
+                io.go_rect.y = gmaps[0][Pmousemap.x][Pmousemap.y].rect.y + panel.panel_header_dest.h;
+                io.mousedownr_flag = 0;
+                if( io.go_rect.x > Pscreen.x &&
+                    io.go_rect.x < Pscreen.x + screen->w &&
+                    io.go_rect.y > Pscreen.y &&
+                    io.go_rect.y < Pscreen.y + screen->h)
                 {
-                    printf("Is a valid tile...\n");
-                    io.go_valid_flag = 1;
+                    io.go_rect_dest.x = io.go_rect.x - Pscreen.x;
+                    io.go_rect_dest.y = io.go_rect.y - Pscreen.y;
+                    io.go_xy.x = Pmousemap.x;
+                    io.go_xy.y = Pmousemap.y;
+                    if(rts_valid_tile(0,1,io.go_xy))
+                    {
+                        printf("Is a valid tile...\n");
+                        io.go_valid_flag = 1;
+                    }
+                    else
+                    {
+                        printf("Is a invalid tile...\n");
+                        io.go_valid_flag = 0;
+                    }
                 }
                 else
                 {
-                    printf("Is a invalid tile...\n");
-                    io.go_valid_flag = 0;
+                    io.go_rect_dest.x = -1;
+                    io.go_rect_dest.y = -1;
                 }
             }
-            else
-            {
-                io.go_rect_dest.x = -1;
-                io.go_rect_dest.y = -1;
-            }
         }
     }
     else
diff --git a/src/graphs.c b/src/graphs.c
index afb2668..17f8a96 100644
--- a/src/graphs.c
+++ b/src/graphs.c
@@ -30,7 +30,7 @@ static int gmaps_alloc(int xsize, int ysize, int maps)
     xsize++;
     ysize++;
     gmaps = (gnode ***)malloc(maps * sizeof(gnode **));
-    if(gmaps[i] == NULL)
+    if(gmaps == NULL)
     {
         printf("Error: Allocation of objects faild!\n");
         return 1; 
diff --git a/src/llist.c b/src/llist.c
index 01c7808..5747785 100644
--- a/src/llist.c
+++ b/src/llist.c
@@ -51,10 +51,19 @@ void list_remove(list_node** ptr)
     if(ptr != NULL && *ptr != NULL)
     {
         node = *ptr;
-        tmp = (*ptr)->prev;
-        *ptr = (*ptr)->next;
+        if(node->prev)
+        {
+            tmp = (*ptr)->prev;
+        }
+        else
+        {
+            tmp = NULL;
+            list_nodes = (*ptr)->next;
+        }
+        *ptr = (*ptr)->next; //
         (*ptr)->prev = tmp;
-        tmp->next = *ptr;
+        if(tmp)
+            tmp->next = *ptr;
         free(node);
     }
 }
diff --git a/src/map.c b/src/map.c
index e73397d..5e16212 100644
--- a/src/map.c
+++ b/src/map.c
@@ -29,6 +29,7 @@
 #include "hashtable.h"
 #include "llist.h"
 #include "graphs.h"
+#include "panel.h"
 
 SDL_Surface* map_image;
 SDL_Surface* mini_map_image;
@@ -636,6 +637,8 @@ endineriter:
 void free_anchormap(void)
 {
     int i;
+    if(!anchor_map)
+        return;
     for(i = 0; i < (int)(map_image->w / terrain[0]->w); i++)
         FREE(anchor_map[i]);
     FREE(anchor_map);
@@ -813,13 +816,13 @@ th_point mouse_map(th_point mouse_p, th_point screen_p)
     th_point Pmousemap;
     th_point Ptilemap;
 
+
     Pmousemap.x = (int)(mouse_p.x + screen_p.x + terrain[TUNDRA_CENTER_1]->w/2)/terrain[TUNDRA_CENTER_1]->w;
-    Pmousemap.y = (int)(mouse_p.y + screen_p.y)/terrain[TUNDRA_CENTER_1]->h;
+    Pmousemap.y = (int)(mouse_p.y + screen_p.y - panel.panel_header_dest.h)/terrain[TUNDRA_CENTER_1]->h;
     
     Ptilemap.x = (int)(mouse_p.x + screen_p.x + terrain[TUNDRA_CENTER_1]->w/2)%terrain[TUNDRA_CENTER_1]->w;
-    Ptilemap.y = (int)(mouse_p.y + screen_p.y)%terrain[TUNDRA_CENTER_1]->h;
+    Ptilemap.y = (int)(mouse_p.y + screen_p.y - panel.panel_header_dest.h)%terrain[TUNDRA_CENTER_1]->h;
     
-
     anchor_p = &anchor_map[Pmousemap.x][Pmousemap.y];
     if(anchor_p->x == -1 && anchor_p->y == -1)
     {
diff --git a/src/panel.c b/src/panel.c
index d29905e..790ec81 100644
--- a/src/panel.c
+++ b/src/panel.c
@@ -15,65 +15,165 @@
 #include<string.h>
 
 #include "SDL.h"
+#include "SDL_rotozoom.h"
 #include "SDL_extras.h"
 #include "panel.h"
 #include "objects.h"
 #include "tuxhistory.h"
+#include "setup.h"
 #include "fileops.h"
 #include "players.h"
 
+
+int panel_init(void)
+{
+    int i;
+    float zoom;
+    SDL_Surface *tmp_surf;
+
+    panel.panel_dest.x = 0;
+    panel.panel_dest.y = (screen->h / 5) * 4;
+    panel.panel_dest.w = screen->w;
+    panel.panel_dest.h = screen->h / 5;
+
+    panel.panel_description.x = panel.panel_dest.x + 10;
+    panel.panel_description.y = panel.panel_dest.y + 10;
+    panel.panel_description.w = panel.panel_dest.w / 7;
+    panel.panel_description.h = (panel.panel_dest.h / 5) * 4;
+
+    for(i = 0; i < 5; i++)
+    {
+        panel.panel_option[i].x = panel.panel_description.x + 
+            panel.panel_description.w + 10 + (images[IMG_GUIBUILD]->w+10)*i;
+        panel.panel_option[i].y = panel.panel_description.y;
+        panel.panel_option[i].w = images[IMG_GUIBUILD]->w;
+        panel.panel_option[i].h = images[IMG_GUIBUILD]->h;
+    }
+
+    panel.panel_actions[0] = INACTIVE;
+    panel.panel_actions[1] = INACTIVE;
+    panel.panel_actions[2] = INACTIVE;
+    panel.panel_actions[3] = INACTIVE;
+    panel.panel_actions[4] = INACTIVE;
+
+    panel.panel_header_dest.x = 0;
+    panel.panel_header_dest.y = 0;
+    panel.panel_header_dest.w = screen->w;
+    panel.panel_header_dest.h = screen->h/20;
+
+    panel.panel_header_origin.x = 0;
+    panel.panel_header_origin.y = 0;
+    panel.panel_header_origin.w = screen->w / 20;
+    panel.panel_header_origin.h = images[IMG_GUIBG_BYZANTINE]->w;
+
+    panel.panel_game.x = 0;
+    panel.panel_game.y = screen->h/20;
+    panel.panel_game.w = screen->w;
+    panel.panel_game.h = (screen->h / 5) * 4;
+
+    panel.panel_minimap.x = (screen->w - mini_map_image->w - 5);
+    panel.panel_minimap.y = (screen->h - mini_map_image->h - 5);
+    panel.panel_minimap.x = mini_map_image->w;
+    panel.panel_minimap.y = mini_map_image->h;
+
+    zoom = (float)screen->w/(float)images[IMG_GUIBG_BYZANTINE]->w;
+
+    //rotozoomSurface (SDL_Surface *src, double angle, double zoom, int smooth);
+    tmp_surf = rotozoomSurface(images[IMG_GUIBG_BYZANTINE], 0, zoom, 1);
+
+    if (tmp_surf == NULL)
+    {
+      fprintf(stderr,
+              "\nError: Zoom of GUI Backgrund not possible\n");
+      return 0;
+    }
+
+    SDL_FreeSurface(images[IMG_GUIBG_BYZANTINE]);
+    images[IMG_GUIBG_BYZANTINE] = tmp_surf;
+
+
+    return 1;
+
+}
+
+// TODO: This is all hard coded. In a future we need make this menu 
+// from the object xml file info!
 void panel_draw(th_obj *select, int num)
 {
     SDL_Rect dest, dest2;
     char tmp_text[100];
+    int menu_y =(screen->h / 5) * 4;
 
     //TODO: Write a panel function to manipulate the game...
-    dest2.x = 0;
-    dest2.y = 0;
-    dest2.h = screen->h / 20;
-    dest2.w = images[IMG_GUIBG_BYZANTINE]->w;
 
-    dest.x = 0;
-    dest.y = 0;
 
-    SDL_BlitSurface(images[IMG_GUIBG_BYZANTINE], &dest2, screen, &dest);
+    SDL_BlitSurface(images[IMG_GUIBG_BYZANTINE], &panel.panel_header_dest, screen, 
+            &panel.panel_header_origin);
     sprintf(tmp_text,"Wood %5d   Food %5d   Stone %5d   Gold %5d ", 
                                 player_vars[1].wood,
                                 player_vars[1].food,
                                 player_vars[1].stone,
                                 player_vars[1].gold);
             
-    th_ShowMessage(tmp_text, 16, dest.x+2, dest.y+2);
+    th_ShowMessage(tmp_text, 16, panel.panel_header_dest.x+2, panel.panel_header_dest.y+2);
 
-    dest.x = 0;
-    dest.y = (screen->h / 5) * 4;
-    SDL_BlitSurface(images[IMG_GUIBG_BYZANTINE], NULL, screen, &dest);
+
+    SDL_BlitSurface(images[IMG_GUIBG_BYZANTINE], NULL, screen, &panel.panel_dest);
     
     if(num != -1)
     {
         if(select != NULL)
         {
-            dest.x = dest.x + 10;
-            dest.y = dest.y + 10;
-            dest.h = 100;
-            dest.w = screen->w / 5;
-            //FillRect(dest, 0x000000);
-
-            dest.x = dest.x + 2;
-            dest.y = dest.y + 2;
-
-            th_ShowMessage(select->rname, 12, dest.x+2, dest.y+2);
+            FillRect(panel.panel_description, 0x000000);
 
+            th_ShowMessage(select->rname, 12, panel.panel_description.x+2, 
+                    panel.panel_description.y+2);
             sprintf(tmp_text,"%d / %d", select->actual_live,
                                         select->live);
-            //printf("dir is: %s\n", tmp_text);
             th_ShowMessage(tmp_text, 15, 
-                    objects[select->name_enum]->w + dest.x + 10, dest.y+20);
-
+                    objects[select->name_enum]->w + panel.panel_description.x + 10, 
+                    panel.panel_description.y+20);
 
-            dest.y = dest.y + 20;
+            dest.x = panel.panel_description.x + 5;
+            dest.y = panel.panel_description.y + 20;
 
             SDL_BlitSurface(objects[select->name_enum], NULL, screen, &dest);
+            
+            if(select->name_enum == VILLAGER_MILKMAID)
+            {
+                SDL_BlitSurface(images[IMG_GUIBUILD], NULL, screen, &panel.panel_option[0]);
+                panel.panel_actions[0] = BUILD;
+
+                SDL_BlitSurface(images[IMG_GUIKILL], NULL, screen, &panel.panel_option[4]);
+                panel.panel_actions[4] = DIE;
+
+                panel.panel_actions[1] = INACTIVE;
+                panel.panel_actions[2] = INACTIVE;  
+                panel.panel_actions[3] = INACTIVE;
+            }
+            else if(select->name_enum == VILLAGE_CENTER)
+            {
+                SDL_BlitSurface(images[IMG_GUIPAWN], NULL, screen, &panel.panel_option[0]);
+                panel.panel_actions[0] = BUILD;
+
+                SDL_BlitSurface(images[IMG_GUIKILL], NULL, screen, &panel.panel_option[4]);
+                panel.panel_actions[4] = DIE;
+
+                panel.panel_actions[1] = INACTIVE;
+                panel.panel_actions[2] = INACTIVE;  
+                panel.panel_actions[3] = INACTIVE;  
+            }
+            else if(select->name_enum == HOUSE)
+            {
+                SDL_BlitSurface(images[IMG_GUIKILL], NULL, screen, &panel.panel_option[4]);
+                panel.panel_actions[4] = DIE;
+
+                panel.panel_actions[0] = INACTIVE;
+                panel.panel_actions[1] = INACTIVE;
+                panel.panel_actions[2] = INACTIVE;  
+                panel.panel_actions[3] = INACTIVE;  
+    
+            }
         }
     }
 
@@ -84,5 +184,58 @@ void panel_draw(th_obj *select, int num)
     dest.x = (screen->w - images[IMG_STOP]->w - 5);
     dest.y = glyph_offset;
     SDL_BlitSurface(images[IMG_STOP], NULL, screen, &dest);
+}
+
+static int rect_coll(th_point *p, SDL_Rect *r)
+{
+    if( p->x >= r->x        &&
+        p->x <= r->x + r->w &&
+        p->y >= r->y        &&
+        p->y <= r->y + r->h )
+        return 1;
+    else
+        return 0;
+}
+
+
+
+int panel_click(th_point *point)
+{
+    if(rect_coll(point, &panel.panel_header_dest))
+    {
+        printf("Click in header!\n");
+        return 1;
+    }
+    else if(rect_coll(point, &panel.panel_dest))
+    {
+        printf("Click in panel!\n");
     
+        if(rect_coll(point, &panel.panel_description))
+        {
+            printf("Click in the object description\n");
+        }
+        if(rect_coll(point, &panel.panel_minimap))
+        {
+            printf("Click in minimap!\n");
+        }
+        return 1;
+    }
+    return 0;
+}
+
+
+int panel_rclick(th_point *point)
+{
+    if(rect_coll(point, &panel.panel_header_dest))
+    {
+        printf("Right Click in header!\n");
+        return 1;
+    }
+    else if(rect_coll(point, &panel.panel_dest))
+    {
+        printf("Right Click in panel!\n");
+        return 1;
+    }
+    return 0;
 }
+
diff --git a/src/panel.h b/src/panel.h
index 9cf7a9c..06604ff 100644
--- a/src/panel.h
+++ b/src/panel.h
@@ -14,8 +14,26 @@
 #ifndef PANEL_H
 #define PANEL_H
 
+#include "SDL.h"
 #include "objects.h"
 
+typedef struct th_panel{
+    SDL_Rect panel_minimap;
+    SDL_Rect panel_description;
+    SDL_Rect panel_option[5];
+    int panel_actions[5];
+    SDL_Rect panel_dest;
+    SDL_Rect panel_origin;
+    SDL_Rect panel_header_dest;
+    SDL_Rect panel_header_origin;
+    SDL_Rect panel_game;
+}th_panel;
+
+th_panel panel;
+
+int panel_init(void);
 void panel_draw(th_obj *, int);
+int panel_click(th_point *point);
+int panel_rclick(th_point *point);
 
 #endif
diff --git a/src/tuxrts.c b/src/tuxrts.c
index a0d25f8..bc6714c 100644
--- a/src/tuxrts.c
+++ b/src/tuxrts.c
@@ -65,22 +65,12 @@ int tuxrts_init(char *object_name, char *map_name, int players)
     }
     generate_map();
 
-    zoom = (float)screen->w/(float)images[IMG_GUIBG_BYZANTINE]->w;
 
-    //rotozoomSurface (SDL_Surface *src, double angle, double zoom, int smooth);
-    tmp_surf = rotozoomSurface(images[IMG_GUIBG_BYZANTINE], 0, zoom, 1);
-
-    if (tmp_surf == NULL)
+    if(!panel_init())
     {
-      fprintf(stderr,
-              "\nError: Zoom of GUI Backgrund not possible\n");
-      return 0;
+        printf("Error loading GUI.\n");
+        return 0;
     }
-
-    SDL_FreeSurface(images[IMG_GUIBG_BYZANTINE]);
-    images[IMG_GUIBG_BYZANTINE] = tmp_surf;
-
-
     return 1;
 }
 

-- 
tuxhistory - Educational history game



More information about the Tux4kids-commits mailing list