stratagus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Stratagus-CVS] stratagus src/ui/ccl_ui.c data/ccl/ui.lua data/...


From: address@hidden
Subject: [Stratagus-CVS] stratagus src/ui/ccl_ui.c data/ccl/ui.lua data/...
Date: 10 Jan 2004 16:14:05 +1100

CVSROOT:        /home/strat
Module name:    stratagus
Changes by:      <address@hidden>       04/01/10 16:14:05

Modified files:
        src/ui         : ccl_ui.c 
        data/ccl       : ui.lua 
        data/ccl/human : ui.lua 
        data/ccl/orc   : ui.lua 

Log message:
        Changed DefineCursor to use a table

Patches:
Index: stratagus/data/ccl/human/ui.lua
diff -u stratagus/data/ccl/human/ui.lua:1.2 stratagus/data/ccl/human/ui.lua:1.3
--- stratagus/data/ccl/human/ui.lua:1.2 Fri Nov 21 04:16:27 2003
+++ stratagus/data/ccl/human/ui.lua     Sat Jan 10 16:14:04 2004
@@ -26,20 +26,32 @@
 --      along with this program; if not, write to the Free Software
 --      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  
USA
 --
---     $Id: ui.lua,v 1.2 2003/11/20 17:16:27 jsalmon3 Exp $
+--     $Id: ui.lua,v 1.3 2004/01/10 05:14:04 jsalmon3 Exp $
 
-DefineCursor("cursor-point", "human",
-    "image", "ui/human/cursors/human_gauntlet.png",
-    "hot-spot", { 3,  2}, "size", {28, 32} )
-DefineCursor("cursor-green-hair", "human",
-    "image", "ui/human/cursors/green_eagle.png",
-    "hot-spot", {15, 15}, "size", {32, 32} )
-DefineCursor("cursor-yellow-hair", "human",
-    "image", "ui/human/cursors/yellow_eagle.png",
-    "hot-spot", {15, 15}, "size", {32, 32} )
-DefineCursor("cursor-red-hair", "human",
-    "image", "ui/human/cursors/red_eagle.png",
-    "hot-spot", {15, 15}, "size", {32, 32} )
+DefineCursor({
+  Name = "cursor-point",
+  Race = "human",
+  File = "ui/human/cursors/human_gauntlet.png",
+  HotSpot = { 3,  2},
+  Size = {28, 32}})
+DefineCursor({
+  Name = "cursor-green-hair",
+  Race = "human",
+  File = "ui/human/cursors/green_eagle.png",
+  HotSpot = {15, 15},
+  Size = {32, 32}})
+DefineCursor({
+  Name = "cursor-yellow-hair",
+  Race = "human",
+  File = "ui/human/cursors/yellow_eagle.png",
+  HotSpot = {15, 15},
+  Size = {32, 32}})
+DefineCursor({
+  Name = "cursor-red-hair",
+  Race = "human",
+  File = "ui/human/cursors/red_eagle.png",
+  HotSpot = {15, 15},
+  Size = {32, 32}})
 
 --;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 --     * Race human.
Index: stratagus/data/ccl/orc/ui.lua
diff -u stratagus/data/ccl/orc/ui.lua:1.2 stratagus/data/ccl/orc/ui.lua:1.3
--- stratagus/data/ccl/orc/ui.lua:1.2   Sun Nov 30 12:33:26 2003
+++ stratagus/data/ccl/orc/ui.lua       Sat Jan 10 16:14:04 2004
@@ -26,20 +26,32 @@
 --      along with this program; if not, write to the Free Software
 --      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  
USA
 --
---     $Id: ui.lua,v 1.2 2003/11/30 01:33:26 jsalmon3 Exp $
+--     $Id: ui.lua,v 1.3 2004/01/10 05:14:04 jsalmon3 Exp $
 
-DefineCursor("cursor-point", "orc",
-    "image", "ui/orc/cursors/orcish_claw.png",
-    "hot-spot", { 3,  2}, "size", {26, 32} )
-DefineCursor("cursor-green-hair", "orc",
-    "image", "ui/orc/cursors/green_crosshairs.png",
-    "hot-spot", {15, 15}, "size", {32, 32} )
-DefineCursor("cursor-yellow-hair", "orc",
-    "image", "ui/orc/cursors/yellow_crosshairs.png",
-    "hot-spot", {15, 15}, "size", {32, 32} )
-DefineCursor("cursor-red-hair", "orc",
-    "image", "ui/orc/cursors/red_crosshairs.png",
-    "hot-spot", {15, 15}, "size", {32, 32} )
+DefineCursor({
+  Name = "cursor-point",
+  Race = "orc",
+  File = "ui/orc/cursors/orcish_claw.png",
+  HotSpot = { 3,  2},
+  Size = {26, 32}})
+DefineCursor({
+  Name = "cursor-green-hair",
+  Race = "orc",
+  File = "ui/orc/cursors/green_crosshairs.png",
+  HotSpot = {15, 15},
+  Size = {32, 32}})
+DefineCursor({
+  Name = "cursor-yellow-hair",
+  Race = "orc",
+  File = "ui/orc/cursors/yellow_crosshairs.png",
+  HotSpot = {15, 15},
+  Size = {32, 32}})
+DefineCursor({
+  Name = "cursor-red-hair",
+  Race = "orc",
+  File = "ui/orc/cursors/red_crosshairs.png",
+  HotSpot = {15, 15},
+  Size = {32, 32}})
 
 --;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 --     * Race orc.
Index: stratagus/data/ccl/ui.lua
diff -u stratagus/data/ccl/ui.lua:1.1 stratagus/data/ccl/ui.lua:1.2
--- stratagus/data/ccl/ui.lua:1.1       Thu Nov 20 09:12:30 2003
+++ stratagus/data/ccl/ui.lua   Sat Jan 10 16:14:03 2004
@@ -26,32 +26,74 @@
 --      along with this program; if not, write to the Free Software
 --      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  
USA
 --
---     $Id: ui.lua,v 1.1 2003/11/19 22:12:30 jsalmon3 Exp $
+--     $Id: ui.lua,v 1.2 2004/01/10 05:14:03 jsalmon3 Exp $
 
 Load("ccl/human/ui.lua")
 Load("ccl/orc/ui.lua")
 
-DefineCursor("cursor-glass", "any",
-    "image", "ui/cursors/magnifying_glass.png",
-    "hot-spot", {11, 11}, "size", {34, 35} )
-DefineCursor("cursor-cross", "any",
-    "image", "ui/cursors/small_green_cross.png",
-    "hot-spot", { 8,  8}, "size", {18, 18} )
-DefineCursor("cursor-scroll", "any",
-    "image", "ui/cursors/cross.png", "hot-spot", {15, 15}, "size", {32, 32} )
-DefineCursor("cursor-arrow-e", "any",
-    "image", "ui/cursors/arrow_E.png", "hot-spot", {22, 10}, "size", {32, 24} )
-DefineCursor("cursor-arrow-ne", "any",
-    "image", "ui/cursors/arrow_NE.png", "hot-spot", {20,  2}, "size", {32, 24} 
)
-DefineCursor("cursor-arrow-n", "any",
-    "image", "ui/cursors/arrow_N.png", "hot-spot", {12,  2}, "size", {32, 24} )
-DefineCursor("cursor-arrow-nw", "any",
-    "image", "ui/cursors/arrow_NW.png", "hot-spot", { 2,  2}, "size", {32, 24} 
)
-DefineCursor("cursor-arrow-w", "any",
-    "image", "ui/cursors/arrow_W.png", "hot-spot", { 4, 10}, "size", {32, 24} )
-DefineCursor("cursor-arrow-s", "any",
-    "image", "ui/cursors/arrow_S.png", "hot-spot", {12, 22}, "size", {32, 24} )
-DefineCursor("cursor-arrow-sw", "any",
-    "image", "ui/cursors/arrow_SW.png", "hot-spot", { 2, 18}, "size", {32, 24} 
)
-DefineCursor("cursor-arrow-se", "any",
-    "image", "ui/cursors/arrow_SE.png", "hot-spot", {20, 18}, "size", {32, 24} 
)
+DefineCursor({
+  Name = "cursor-glass",
+  Race = "any",
+  File = "ui/cursors/magnifying_glass.png",
+  HotSpot = {11, 11},
+  Size = {34, 35}})
+DefineCursor({
+  Name = "cursor-cross",
+  Race = "any",
+  File = "ui/cursors/small_green_cross.png",
+  HotSpot = { 8,  8},
+  Size = {18, 18}})
+DefineCursor({
+  Name = "cursor-scroll",
+  Race = "any",
+  File = "ui/cursors/cross.png",
+  HotSpot = {15, 15},
+  Size = {32, 32}})
+DefineCursor({
+  Name = "cursor-arrow-e",
+  Race = "any",
+  File = "ui/cursors/arrow_E.png",
+  HotSpot = {22, 10},
+  Size = {32, 24}})
+DefineCursor({
+  Name = "cursor-arrow-ne",
+  Race = "any",
+  File = "ui/cursors/arrow_NE.png",
+  HotSpot = {20,  2},
+  Size = {32, 24}})
+DefineCursor({
+  Name = "cursor-arrow-n",
+  Race = "any",
+  File = "ui/cursors/arrow_N.png",
+  HotSpot = {12,  2},
+  Size = {32, 24}})
+DefineCursor({
+  Name = "cursor-arrow-nw",
+  Race = "any",
+  File = "ui/cursors/arrow_NW.png",
+  HotSpot = { 2,  2},
+  Size = {32, 24}})
+DefineCursor({
+  Name = "cursor-arrow-w",
+  Race = "any",
+  File = "ui/cursors/arrow_W.png",
+  HotSpot = { 4, 10},
+  Size = {32, 24}})
+DefineCursor({
+  Name = "cursor-arrow-s",
+  Race = "any",
+  File = "ui/cursors/arrow_S.png",
+  HotSpot = {12, 22},
+  Size = {32, 24}})
+DefineCursor({
+  Name = "cursor-arrow-sw",
+  Race = "any",
+  File = "ui/cursors/arrow_SW.png",
+  HotSpot = { 2, 18},
+  Size = {32, 24}})
+DefineCursor({
+  Name = "cursor-arrow-se",
+  Race = "any",
+  File = "ui/cursors/arrow_SE.png",
+  HotSpot = {20, 18},
+  Size = {32, 24}})
Index: stratagus/src/ui/ccl_ui.c
diff -u stratagus/src/ui/ccl_ui.c:1.181 stratagus/src/ui/ccl_ui.c:1.182
--- stratagus/src/ui/ccl_ui.c:1.181     Fri Jan  9 16:44:42 2004
+++ stratagus/src/ui/ccl_ui.c   Sat Jan 10 16:14:02 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ccl_ui.c,v 1.181 2004/01/09 05:44:42 jsalmon3 Exp $
+//      $Id: ccl_ui.c,v 1.182 2004/01/10 05:14:02 jsalmon3 Exp $
 
 //@{
 
@@ -600,103 +600,114 @@
 local int CclDefineCursor(lua_State* l)
 {
        const char* value;
-       char* s1;
-       char* s2;
+       const char* name;
+       const char* race;
+       const char* file;
+       int hotx;
+       int hoty;
+       int w;
+       int h;
+       int rate;
        int i;
        CursorType* ct;
-       int args;
-       int j;
 
-       j = 0;
-       s1 = strdup(LuaToString(l, j + 1));
-       ++j;
-       s2 = strdup(LuaToString(l, j + 1));
-       ++j;
-       if (!strcmp(s2, "any")) {
-               free(s2);
-               s2 = NULL;
+       if (lua_gettop(l) != 1 || !lua_istable(l, 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+       }
+       name = race = file = NULL;
+       hotx = hoty = w = h = 0;
+       rate = 200;
+       lua_pushnil(l);
+       while (lua_next(l, 1)) {
+               value = LuaToString(l, -2);
+               if (!strcmp(value, "Name")) {
+                       name = LuaToString(l, -1);
+               } else if (!strcmp(value, "Race")) {
+                       race = LuaToString(l, -1);
+               } else if (!strcmp(value, "File")) {
+                       file = LuaToString(l, -1);
+               } else if (!strcmp(value, "HotSpot")) {
+                       if (!lua_istable(l, -1) || luaL_getn(l, -1) != 2) {
+                               lua_pushstring(l, "incorrect argument");
+                               lua_error(l);
+                       }
+                       lua_rawgeti(l, -1, 1);
+                       hotx = LuaToNumber(l, -1);
+                       lua_pop(l, 1);
+                       lua_rawgeti(l, -1, 2);
+                       hoty = LuaToNumber(l, -1);
+                       lua_pop(l, 1);
+               } else if (!strcmp(value, "Size")) {
+                       if (!lua_istable(l, -1) || luaL_getn(l, -1) != 2) {
+                               lua_pushstring(l, "incorrect argument");
+                               lua_error(l);
+                       }
+                       lua_rawgeti(l, -1, 1);
+                       w = LuaToNumber(l, -1);
+                       lua_pop(l, 1);
+                       lua_rawgeti(l, -1, 2);
+                       h = LuaToNumber(l, -1);
+                       lua_pop(l, 1);
+               } else if (!strcmp(value, "Rate")) {
+                       rate = LuaToNumber(l, -1);
+               } else {
+                       lua_pushfstring(l, "Unsupported tag: %s", value);
+                       lua_error(l);
+               }
+               lua_pop(l, 1);
+       }
+
+       DebugCheck(!name || !file || !w || !h);
+
+       if (!strcmp(race, "any")) {
+               race = NULL;
        }
 
        //
-       //              Look if this kind of cursor already exists.
+       //  Look if this kind of cursor already exists.
        //
        ct = NULL;
        i = 0;
        if (Cursors) {
                for (; Cursors[i].OType; ++i) {
                        //
-                       //              Race not same, not found.
+                       //  Race not same, not found.
                        //
-                       if (Cursors[i].Race && s2) {
-                               if (strcmp(Cursors[i].Race, s2)) {
+                       if (Cursors[i].Race && race) {
+                               if (strcmp(Cursors[i].Race, race)) {
                                        continue;
                                }
-                       } else if (Cursors[i].Race != s2) {
+                       } else if (Cursors[i].Race != race) {
                                continue;
                        }
-                       if (!strcmp(Cursors[i].Ident, s1)) {
+                       if (!strcmp(Cursors[i].Ident, name)) {
                                ct = &Cursors[i];
                                break;
                        }
                }
        }
        //
-       //              Not found, make a new slot.
+       //  Not found, make a new slot.
        //
-       if (ct) {
-               free(s1);
-               free(s2);
-       } else {
+       if (!ct) {
                ct = calloc(i + 2, sizeof(CursorType));
                memcpy(ct, Cursors, sizeof(CursorType) * i);
                free(Cursors);
                Cursors = ct;
                ct = &Cursors[i];
                ct->OType = CursorTypeType;
-               ct->Ident = s1;
-               ct->Race = s2;
-               ct->FrameRate = 200;
+               ct->Ident = strdup(name);
+               ct->Race = race ? strdup(race) : NULL;
        }
 
-       //
-       //              Parse the arguments, already the new tagged format.
-       //
-       args = lua_gettop(l);
-       for (; j < args; ++j) {
-               value = LuaToString(l, j + 1);
-               ++j;
-               if (!strcmp(value, "image")) {
-                       free(ct->File);
-                       ct->File = strdup(LuaToString(l, j + 1));
-               } else if (!strcmp(value, "hot-spot")) {
-                       if (!lua_istable(l, j + 1) || luaL_getn(l, j + 1) != 2) 
{
-                               lua_pushstring(l, "incorrect argument");
-                               lua_error(l);
-                       }
-                       lua_rawgeti(l, j + 1, 1);
-                       ct->HotX = LuaToNumber(l, -1);
-                       lua_pop(l, 1);
-                       lua_rawgeti(l, j + 1, 2);
-                       ct->HotY = LuaToNumber(l, -1);
-                       lua_pop(l, 1);
-               } else if (!strcmp(value, "size")) {
-                       if (!lua_istable(l, j + 1) || luaL_getn(l, j + 1) != 2) 
{
-                               lua_pushstring(l, "incorrect argument");
-                               lua_error(l);
-                       }
-                       lua_rawgeti(l, j + 1, 1);
-                       ct->Width = LuaToNumber(l, -1);
-                       lua_pop(l, 1);
-                       lua_rawgeti(l, j + 1, 2);
-                       ct->Height = LuaToNumber(l, -1);
-                       lua_pop(l, 1);
-               } else if (!strcmp(value, "rate")) {
-                       ct->FrameRate = LuaToNumber(l, j + 1);
-               } else {
-                       lua_pushfstring(l, "Unsupported tag: %s", value);
-                       lua_error(l);
-               }
-       }
+       free(ct->File);
+       ct->File = strdup(file);
+       ct->HotX = hotx;
+       ct->HotY = hoty;
+       ct->Width = w;
+       ct->Height = h;
+       ct->FrameRate = rate;
 
        return 0;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]