Changeset 79 for UI/ui_lua.cpp


Ignore:
Timestamp:
11/03/09 03:50:41 (4 years ago)
Author:
knowknowledge
Message:

Cleaned up the TAG game

Created two global tables: swarm and it to make things more packaged.
Pulled the decision making into a set of stand alone function 'plans'.
Each ship has their own plan, and since the plans are partially state
based, each ship moves unpredictably. This plan model could be adapted
to work for much more complex

Added a Window that gives live feedback on which ship is IT.
This window reflects the rotation of the IT ship.

Unlike the earlier version, users should be able to figure out what's
going on now. Like the earlier version, the AI do not do the smart
thing and just flee, since that would be boring.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • UI/ui_lua.cpp

    r74 r79  
    1313#include "ui_window.h" 
    1414#include "ui_button.h" 
     15#include "ui_picture.h" 
    1516 
    1617void UI_Lua::RegisterUI(lua_State *luaVM){ 
     
    2021                {"newButton", &UI_Lua::newButton}, 
    2122                {"newLabel", &UI_Lua::newLabel}, 
     23                {"newPicture", &UI_Lua::newPicture}, 
     24                {"add", &UI_Lua::add}, 
    2225                {"close", &UI_Lua::close}, 
    23                 {"add", &UI_Lua::add}, 
     26                {"rotatePicture", &UI_Lua::rotatePicture}, 
     27                {"setText", &UI_Lua::setText}, 
    2428                {NULL, NULL} 
    2529        }; 
     
    113117} 
    114118 
     119int UI_Lua::newPicture(lua_State *luaVM){ 
     120        int n = lua_gettop(luaVM);  // Number of arguments 
     121        if (n != 6) 
     122                return luaL_error(luaVM, "Got %d arguments expected 6 (class, x, y, w, h, caption )", n); 
     123 
     124        double x = luaL_checknumber (luaVM, 2); 
     125        double y = luaL_checknumber (luaVM, 3); 
     126        double w = luaL_checknumber (luaVM, 4); 
     127        double h = luaL_checknumber (luaVM, 5); 
     128        string filename = luaL_checkstring (luaVM, 6); 
     129 
     130        // Allocate memory for a pointer to object 
     131        Picture **pic= (Picture**)lua_newuserdata(luaVM, sizeof(Picture*)); 
     132        *pic = new Picture(x,y,w,h,filename); 
     133 
     134        // Note: We're not putting this Label anywhere! 
     135        //       Lua will have to do that for us. 
     136        //       This may be a bad idea (memory leaks from bad lua scripts) 
     137 
     138        return 1; 
     139} 
     140 
    115141int UI_Lua::add(lua_State *luaVM){ 
    116142        int n = lua_gettop(luaVM);  // Number of arguments 
     
    124150        return 0; 
    125151} 
     152 
     153int UI_Lua::rotatePicture(lua_State *luaVM){ 
     154        int n = lua_gettop(luaVM);  // Number of arguments 
     155        if (n != 2) 
     156                return luaL_error(luaVM, "Got %d arguments expected 2 (self, angle )", n); 
     157 
     158        Picture **pic= (Picture**)lua_touserdata(luaVM,1); 
     159        double angle = luaL_checknumber (luaVM, 2); 
     160        (*pic)->Rotate(angle); 
     161 
     162        return 1; 
     163} 
     164 
     165int UI_Lua::setText(lua_State *luaVM){ 
     166        int n = lua_gettop(luaVM);  // Number of arguments 
     167        if (n != 2) 
     168                return luaL_error(luaVM, "Got %d arguments expected 2 (self, text)", n); 
     169 
     170        Label **label= (Label**)lua_touserdata(luaVM,1); 
     171        string text = luaL_checkstring(luaVM, 2); 
     172        (*label)->setText(text); 
     173 
     174        return 1; 
     175} 
Note: See TracChangeset for help on using the changeset viewer.