00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00030
00031
00032
00033
00034
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <string.h>
00038
00039 #include "stratagus.h"
00040 #include "script.h"
00041 #include "interface.h"
00042 #include "ui.h"
00043 #include "video.h"
00044 #include "map.h"
00045 #include "menus.h"
00046 #include "font.h"
00047 #include "unit.h"
00048 #include "unit_manager.h"
00049 #include "unittype.h"
00050 #include "title.h"
00051
00052
00053
00054
00055
00056 std::string ClickMissile;
00057 std::string DamageMissile;
00058
00059 std::map<std::string, ButtonStyle *> ButtonStyleHash;
00060
00061 static int HandleCount = 1;
00062
00063 CPreference Preference;
00064
00065
00066
00067
00068
00074 static int CclSetMouseScrollSpeedDefault(lua_State *l)
00075 {
00076 LuaCheckArgs(l, 1);
00077 UI.MouseScrollSpeedDefault = LuaToNumber(l, 1);
00078 return 0;
00079 }
00080
00086 static int CclSetMouseScrollSpeedControl(lua_State *l)
00087 {
00088 LuaCheckArgs(l, 1);
00089 UI.MouseScrollSpeedControl = LuaToNumber(l, 1);
00090 return 0;
00091 }
00092
00098 static int CclSetClickMissile(lua_State *l)
00099 {
00100 int args;
00101
00102 args = lua_gettop(l);
00103 if (args > 1 || (args == 1 && (!lua_isnil(l, 1) && !lua_isstring(l, 1)))) {
00104 LuaError(l, "incorrect argument");
00105 }
00106 ClickMissile.clear();
00107 if (args == 1 && !lua_isnil(l, 1)) {
00108 ClickMissile = lua_tostring(l, 1);
00109 }
00110
00111 return 0;
00112 }
00113
00119 static int CclSetDamageMissile(lua_State *l)
00120 {
00121 int args;
00122
00123 args = lua_gettop(l);
00124 if (args > 1 || (args == 1 && (!lua_isnil(l, 1) && !lua_isstring(l, 1)))) {
00125 LuaError(l, "incorrect argument");
00126 }
00127 DamageMissile.clear();
00128 if (args == 1 && !lua_isnil(l, 1)) {
00129 DamageMissile = lua_tostring(l, 1);
00130 }
00131
00132 return 0;
00133 }
00134
00140 static int CclSetVideoResolution(lua_State *l)
00141 {
00142 LuaCheckArgs(l, 2);
00143 if (CclInConfigFile) {
00144
00145 if (!Video.Width || !Video.Height) {
00146 Video.Width = LuaToNumber(l, 1);
00147 Video.Height = LuaToNumber(l, 2);
00148 }
00149 }
00150 return 0;
00151 }
00152
00158 static int CclGetVideoResolution(lua_State *l)
00159 {
00160 LuaCheckArgs(l, 0);
00161 lua_pushnumber(l, Video.Width);
00162 lua_pushnumber(l, Video.Height);
00163 return 2;
00164 }
00165
00171 static int CclSetVideoFullScreen(lua_State *l)
00172 {
00173 LuaCheckArgs(l, 1);
00174 if (CclInConfigFile) {
00175
00176 if (!VideoForceFullScreen) {
00177 Video.FullScreen = LuaToBoolean(l, 1);
00178 }
00179 }
00180 return 0;
00181 }
00182
00188 static int CclGetVideoFullScreen(lua_State *l)
00189 {
00190 LuaCheckArgs(l, 0);
00191 lua_pushboolean(l, Video.FullScreen);
00192 return 1;
00193 }
00194
00200 static int CclSetTitleScreens(lua_State *l)
00201 {
00202 const char *value;
00203 int i;
00204 int args;
00205 int j;
00206 int subargs;
00207 int k;
00208
00209 if (TitleScreens) {
00210 for (i = 0; TitleScreens[i]; ++i) {
00211 delete TitleScreens[i];
00212 }
00213 delete[] TitleScreens;
00214 TitleScreens = NULL;
00215 }
00216
00217 args = lua_gettop(l);
00218 TitleScreens = new TitleScreen *[args + 1];
00219 memset(TitleScreens, 0, (args + 1) * sizeof(TitleScreen *));
00220
00221 for (j = 0; j < args; ++j) {
00222 if (!lua_istable(l, j + 1)) {
00223 LuaError(l, "incorrect argument");
00224 }
00225 TitleScreens[j] = new TitleScreen;
00226 TitleScreens[j]->Iterations = 1;
00227 lua_pushnil(l);
00228 while (lua_next(l, j + 1)) {
00229 value = LuaToString(l, -2);
00230 if (!strcmp(value, "Image")) {
00231 TitleScreens[j]->File = LuaToString(l, -1);
00232 } else if (!strcmp(value, "Music")) {
00233 TitleScreens[j]->Music = LuaToString(l, -1);
00234 } else if (!strcmp(value, "StretchImage")) {
00235 TitleScreens[j]->StretchImage = LuaToBoolean(l, -1);
00236 } else if (!strcmp(value, "Timeout")) {
00237 TitleScreens[j]->Timeout = LuaToNumber(l, -1);
00238 } else if (!strcmp(value, "Iterations")) {
00239 TitleScreens[j]->Iterations = LuaToNumber(l, -1);
00240 } else if (!strcmp(value, "Labels")) {
00241 if (!lua_istable(l, -1)) {
00242 LuaError(l, "incorrect argument");
00243 }
00244 subargs = lua_objlen(l, -1);
00245 TitleScreens[j]->Labels = new TitleScreenLabel *[subargs + 1];
00246 memset(TitleScreens[j]->Labels, 0, (subargs + 1) * sizeof(TitleScreenLabel *));
00247 for (k = 0; k < subargs; ++k) {
00248 lua_rawgeti(l, -1, k + 1);
00249 if (!lua_istable(l, -1)) {
00250 LuaError(l, "incorrect argument");
00251 }
00252 TitleScreens[j]->Labels[k] = new TitleScreenLabel;
00253 lua_pushnil(l);
00254 while (lua_next(l, -2)) {
00255 value = LuaToString(l, -2);
00256 if (!strcmp(value, "Text")) {
00257 TitleScreens[j]->Labels[k]->Text = LuaToString(l, -1);
00258 } else if (!strcmp(value, "Font")) {
00259 TitleScreens[j]->Labels[k]->Font = CFont::Get(LuaToString(l, -1));
00260 } else if (!strcmp(value, "Pos")) {
00261 if (!lua_istable(l, -1) || lua_objlen(l, -1) != 2) {
00262 LuaError(l, "incorrect argument");
00263 }
00264 lua_rawgeti(l, -1, 1);
00265 TitleScreens[j]->Labels[k]->Xofs = LuaToNumber(l, -1);
00266 lua_pop(l, 1);
00267 lua_rawgeti(l, -1, 2);
00268 TitleScreens[j]->Labels[k]->Yofs = LuaToNumber(l, -1);
00269 lua_pop(l, 1);
00270 } else if (!strcmp(value, "Flags")) {
00271 int subsubargs;
00272 int subk;
00273
00274 if (!lua_istable(l, -1)) {
00275 LuaError(l, "incorrect argument");
00276 }
00277 subsubargs = lua_objlen(l, -1);
00278 for (subk = 0; subk < subsubargs; ++subk) {
00279 lua_rawgeti(l, -1, subk + 1);
00280 value = LuaToString(l, -1);
00281 lua_pop(l, 1);
00282 if (!strcmp(value, "center")) {
00283 TitleScreens[j]->Labels[k]->Flags |= TitleFlagCenter;
00284 } else {
00285 LuaError(l, "incorrect flag");
00286 }
00287 }
00288 } else {
00289 LuaError(l, "Unsupported key: %s" _C_ value);
00290 }
00291 lua_pop(l, 1);
00292 }
00293 lua_pop(l, 1);
00294 }
00295 } else {
00296 LuaError(l, "Unsupported key: %s" _C_ value);
00297 }
00298 lua_pop(l, 1);
00299 }
00300 }
00301
00302 return 0;
00303 }
00304
00310 static int CclDefineCursor(lua_State *l)
00311 {
00312 const char *value;
00313 std::string name;
00314 std::string file;
00315 int hotx;
00316 int hoty;
00317 int w;
00318 int h;
00319 int rate;
00320 int i;
00321 CCursor *ct;
00322
00323 LuaCheckArgs(l, 1);
00324 if (!lua_istable(l, 1)) {
00325 LuaError(l, "incorrect argument");
00326 }
00327 hotx = hoty = w = h = rate = 0;
00328 lua_pushnil(l);
00329 while (lua_next(l, 1)) {
00330 value = LuaToString(l, -2);
00331 if (!strcmp(value, "Name")) {
00332 name = LuaToString(l, -1);
00333 } else if (!strcmp(value, "File")) {
00334 file = LuaToString(l, -1);
00335 } else if (!strcmp(value, "HotSpot")) {
00336 if (!lua_istable(l, -1) || lua_objlen(l, -1) != 2) {
00337 LuaError(l, "incorrect argument");
00338 }
00339 lua_rawgeti(l, -1, 1);
00340 hotx = LuaToNumber(l, -1);
00341 lua_pop(l, 1);
00342 lua_rawgeti(l, -1, 2);
00343 hoty = LuaToNumber(l, -1);
00344 lua_pop(l, 1);
00345 } else if (!strcmp(value, "Size")) {
00346 if (!lua_istable(l, -1) || lua_objlen(l, -1) != 2) {
00347 LuaError(l, "incorrect argument");
00348 }
00349 lua_rawgeti(l, -1, 1);
00350 w = LuaToNumber(l, -1);
00351 lua_pop(l, 1);
00352 lua_rawgeti(l, -1, 2);
00353 h = LuaToNumber(l, -1);
00354 lua_pop(l, 1);
00355 } else if (!strcmp(value, "Rate")) {
00356 rate = LuaToNumber(l, -1);
00357 } else {
00358 LuaError(l, "Unsupported tag: %s" _C_ value);
00359 }
00360 lua_pop(l, 1);
00361 }
00362
00363 Assert(!name.empty() && !file.empty() && w && h);
00364
00365
00366
00367
00368 ct = NULL;
00369 i = 0;
00370 if (AllCursors.size()) {
00371 for (; i < (int)AllCursors.size(); ++i) {
00372 if (AllCursors[i].Ident == name) {
00373 ct = &AllCursors[i];
00374 break;
00375 }
00376 }
00377 }
00378
00379
00380
00381 if (!ct) {
00382 CCursor c;
00383 AllCursors.push_back(c);
00384 ct = &AllCursors.back();
00385 ct->Ident = name;
00386 }
00387
00388 ct->G = CGraphic::New(file, w, h);
00389 ct->HotX = hotx;
00390 ct->HotY = hoty;
00391 ct->FrameRate = rate;
00392
00393 return 0;
00394 }
00395
00401 static int CclSetGameCursor(lua_State *l)
00402 {
00403 LuaCheckArgs(l, 1);
00404 GameCursor = CursorByIdent(LuaToString(l, 1));
00405 return 0;
00406 }
00407
00413 static int CclDefineViewports(lua_State *l)
00414 {
00415 const char *value;
00416 int i;
00417 int args;
00418 int slot;
00419
00420 i = 0;
00421 args = lua_gettop(l);
00422 for (int j = 0; j < args; ++j) {
00423 value = LuaToString(l, j + 1);
00424 ++j;
00425 if (!strcmp(value, "mode")) {
00426 UI.ViewportMode = (ViewportModeType)(int)LuaToNumber(l, j + 1);
00427 } else if (!strcmp(value, "viewport")) {
00428 if (!lua_istable(l, j + 1) && lua_objlen(l, j + 1) != 3) {
00429 LuaError(l, "incorrect argument");
00430 }
00431 lua_rawgeti(l, j + 1, 1);
00432 UI.Viewports[i].MapX = LuaToNumber(l, -1);
00433 lua_pop(l, 1);
00434 lua_rawgeti(l, j + 1, 2);
00435 UI.Viewports[i].MapY = LuaToNumber(l, -1);
00436 lua_pop(l, 1);
00437 lua_rawgeti(l, j + 1, 3);
00438 slot = (int)LuaToNumber(l, -1);
00439 if (slot != -1) {
00440 UI.Viewports[i].Unit = UnitSlots[slot];
00441 }
00442 lua_pop(l, 1);
00443 ++i;
00444 } else {
00445 LuaError(l, "Unsupported tag: %s" _C_ value);
00446 }
00447 }
00448 UI.NumViewports = i;
00449
00450 return 0;
00451 }
00452
00458 static int CclRightButtonAttacks(lua_State *l)
00459 {
00460 LuaCheckArgs(l, 0);
00461 RightButtonAttacks = true;
00462 return 0;
00463 }
00464
00470 static int CclRightButtonMoves(lua_State *l)
00471 {
00472 LuaCheckArgs(l, 0);
00473 RightButtonAttacks = false;
00474 return 0;
00475 }
00476
00484 ButtonStyle *FindButtonStyle(const std::string &style)
00485 {
00486 return ButtonStyleHash[style];
00487 }
00488
00495 static void ParseButtonStyleProperties(lua_State *l, ButtonStyleProperties *p)
00496 {
00497 const char *value;
00498 std::string file;
00499 int w;
00500 int h;
00501
00502 if (!lua_istable(l, -1)) {
00503 LuaError(l, "incorrect argument");
00504 }
00505
00506 w = h = 0;
00507
00508 lua_pushnil(l);
00509 while (lua_next(l, -2)) {
00510 value = LuaToString(l, -2);
00511 if (!strcmp(value, "File")) {
00512 file = LuaToString(l, -1);
00513 } else if (!strcmp(value, "Size")) {
00514 if (!lua_istable(l, -1) || lua_objlen(l, -1) != 2) {
00515 LuaError(l, "incorrect argument");
00516 }
00517 lua_rawgeti(l, -1, 1);
00518 w = LuaToNumber(l, -1);
00519 lua_pop(l, 1);
00520 lua_rawgeti(l, -1, 2);
00521 h = LuaToNumber(l, -1);
00522 lua_pop(l, 1);
00523 } else if (!strcmp(value, "Frame")) {
00524 p->Frame = LuaToNumber(l, -1);
00525 } else if (!strcmp(value, "Border")) {
00526 if (!lua_istable(l, -1)) {
00527 LuaError(l, "incorrect argument");
00528 }
00529 lua_pushnil(l);
00530 while (lua_next(l, -2)) {
00531 value = LuaToString(l, -2);
00532 if (!strcmp(value, "Color")) {
00533 if (!lua_istable(l, -1) || lua_objlen(l, -1) != 3) {
00534 LuaError(l, "incorrect argument");
00535 }
00536 lua_rawgeti(l, -1, 1);
00537 p->BorderColorRGB.r = LuaToNumber(l, -1);
00538 lua_pop(l, 1);
00539 lua_rawgeti(l, -1, 2);
00540 p->BorderColorRGB.g = LuaToNumber(l, -1);
00541 lua_pop(l, 1);
00542 lua_rawgeti(l, -1, 3);
00543 p->BorderColorRGB.b = LuaToNumber(l, -1);
00544 lua_pop(l, 1);
00545 } else if (!strcmp(value, "Size")) {
00546 p->BorderSize = LuaToNumber(l, -1);
00547 } else {
00548 LuaError(l, "Unsupported tag: %s" _C_ value);
00549 }
00550 lua_pop(l, 1);
00551 }
00552 } else if (!strcmp(value, "TextPos")) {
00553 if (!lua_istable(l, -1) || lua_objlen(l, -1) != 2) {
00554 LuaError(l, "incorrect argument");
00555 }
00556 lua_rawgeti(l, -1, 1);
00557 p->TextX = LuaToNumber(l, -1);
00558 lua_pop(l, 1);
00559 lua_rawgeti(l, -1, 2);
00560 p->TextY = LuaToNumber(l, -1);
00561 lua_pop(l, 1);
00562 } else if (!strcmp(value, "TextAlign")) {
00563 value = LuaToString(l, -1);
00564 if (!strcmp(value, "Center")) {
00565 p->TextAlign = TextAlignCenter;
00566 } else if (!strcmp(value, "Right")) {
00567 p->TextAlign = TextAlignRight;
00568 } else if (!strcmp(value, "Left")) {
00569 p->TextAlign = TextAlignLeft;
00570 } else {
00571 LuaError(l, "Invalid text alignment: %s" _C_ value);
00572 }
00573 } else if (!strcmp(value, "TextNormalColor")) {
00574 p->TextNormalColor = LuaToString(l, -1);
00575 } else if (!strcmp(value, "TextReverseColor")) {
00576 p->TextReverseColor = LuaToString(l, -1);
00577 } else {
00578 LuaError(l, "Unsupported tag: %s" _C_ value);
00579 }
00580 lua_pop(l, 1);
00581 }
00582
00583 if (!file.empty()) {
00584 p->Sprite = CGraphic::New(file, w, h);
00585 }
00586 }
00587
00593 static int CclDefineButtonStyle(lua_State *l)
00594 {
00595 const char *style;
00596 const char *value;
00597 ButtonStyle *b;
00598
00599 LuaCheckArgs(l, 2);
00600 if (!lua_istable(l, 2)) {
00601 LuaError(l, "incorrect argument");
00602 }
00603
00604 style = LuaToString(l, 1);
00605 b = ButtonStyleHash[style];
00606 if (!b) {
00607 b = ButtonStyleHash[style] = new ButtonStyle;
00608
00609 b->Default.TextX = b->Hover.TextX = b->Clicked.TextX = 0xFFFFFF;
00610 }
00611
00612 lua_pushnil(l);
00613 while (lua_next(l, 2)) {
00614 value = LuaToString(l, -2);
00615 if (!strcmp(value, "Size")) {
00616 if (!lua_istable(l, -1) || lua_objlen(l, -1) != 2) {
00617 LuaError(l, "incorrect argument");
00618 }
00619 lua_rawgeti(l, -1, 1);
00620 b->Width = LuaToNumber(l, -1);
00621 lua_pop(l, 1);
00622 lua_rawgeti(l, -1, 2);
00623 b->Height = LuaToNumber(l, -1);
00624 lua_pop(l, 1);
00625 } else if (!strcmp(value, "Font")) {
00626 b->Font = CFont::Get(LuaToString(l, -1));
00627 } else if (!strcmp(value, "TextNormalColor")) {
00628 b->TextNormalColor = LuaToString(l, -1);
00629 } else if (!strcmp(value, "TextReverseColor")) {
00630 b->TextReverseColor = LuaToString(l, -1);
00631 } else if (!strcmp(value, "TextPos")) {
00632 if (!lua_istable(l, -1) || lua_objlen(l, -1) != 2) {
00633 LuaError(l, "incorrect argument");
00634 }
00635 lua_rawgeti(l, -1, 1);
00636 b->TextX = LuaToNumber(l, -1);
00637 lua_pop(l, 1);
00638 lua_rawgeti(l, -1, 2);
00639 b->TextY = LuaToNumber(l, -1);
00640 lua_pop(l, 1);
00641 } else if (!strcmp(value, "TextAlign")) {
00642 value = LuaToString(l, -1);
00643 if (!strcmp(value, "Center")) {
00644 b->TextAlign = TextAlignCenter;
00645 } else if (!strcmp(value, "Right")) {
00646 b->TextAlign = TextAlignRight;
00647 } else if (!strcmp(value, "Left")) {
00648 b->TextAlign = TextAlignLeft;
00649 } else {
00650 LuaError(l, "Invalid text alignment: %s" _C_ value);
00651 }
00652 } else if (!strcmp(value, "Default")) {
00653 ParseButtonStyleProperties(l, &b->Default);
00654 } else if (!strcmp(value, "Hover")) {
00655 ParseButtonStyleProperties(l, &b->Hover);
00656 } else if (!strcmp(value, "Clicked")) {
00657 ParseButtonStyleProperties(l, &b->Clicked);
00658 } else {
00659 LuaError(l, "Unsupported tag: %s" _C_ value);
00660 }
00661 lua_pop(l, 1);
00662 }
00663
00664 if (b->Default.TextX == 0xFFFFFF) {
00665 b->Default.TextX = b->TextX;
00666 b->Default.TextY = b->TextY;
00667 }
00668 if (b->Hover.TextX == 0xFFFFFF) {
00669 b->Hover.TextX = b->TextX;
00670 b->Hover.TextY = b->TextY;
00671 }
00672 if (b->Clicked.TextX == 0xFFFFFF) {
00673 b->Clicked.TextX = b->TextX;
00674 b->Clicked.TextY = b->TextY;
00675 }
00676
00677 if (b->Default.TextAlign == TextAlignUndefined) {
00678 b->Default.TextAlign = b->TextAlign;
00679 }
00680 if (b->Hover.TextAlign == TextAlignUndefined) {
00681 b->Hover.TextAlign = b->TextAlign;
00682 }
00683 if (b->Clicked.TextAlign == TextAlignUndefined) {
00684 b->Clicked.TextAlign = b->TextAlign;
00685 }
00686
00687 return 0;
00688 }
00689
00694 int AddHandler(lua_State *l)
00695 {
00696 lua_pushstring(l, "_handlers_");
00697 lua_gettable(l, LUA_GLOBALSINDEX);
00698 if (lua_isnil(l, -1)) {
00699 lua_pop(l, 1);
00700 lua_pushstring(l, "_handlers_");
00701 lua_newtable(l);
00702 lua_settable(l, LUA_GLOBALSINDEX);
00703 lua_pushstring(l, "_handlers_");
00704 lua_gettable(l, LUA_GLOBALSINDEX);
00705 }
00706 lua_pushvalue(l, -2);
00707 lua_rawseti(l, -2, HandleCount);
00708 lua_pop(l, 1);
00709
00710 return HandleCount++;
00711 }
00712
00716 void CallHandler(unsigned int handle, int value)
00717 {
00718 lua_pushstring(Lua, "_handlers_");
00719 lua_gettable(Lua, LUA_GLOBALSINDEX);
00720 lua_rawgeti(Lua, -1, handle);
00721 lua_pushnumber(Lua, value);
00722 LuaCall(1, 1);
00723 lua_pop(Lua, 1);
00724 }
00725
00731 static int CclDefineButton(lua_State *l)
00732 {
00733 char buf[64];
00734 const char *value;
00735 const char *s2;
00736 ButtonAction ba;
00737
00738 LuaCheckArgs(l, 1);
00739 if (!lua_istable(l, 1)) {
00740 LuaError(l, "incorrect argument");
00741 }
00742
00743
00744
00745
00746 lua_pushnil(l);
00747 while (lua_next(l, 1)) {
00748 value = LuaToString(l, -2);
00749 if (!strcmp(value, "Pos")) {
00750 ba.Pos = LuaToNumber(l, -1);
00751 } else if (!strcmp(value, "Level")) {
00752 ba.Level = LuaToNumber(l, -1);
00753 } else if (!strcmp(value, "Icon")) {
00754 ba.Icon.Name = LuaToString(l, -1);
00755 } else if (!strcmp(value, "Action")) {
00756 value = LuaToString(l, -1);
00757 if (!strcmp(value, "move")) {
00758 ba.Action = ButtonMove;
00759 } else if (!strcmp(value, "stop")) {
00760 ba.Action = ButtonStop;
00761 } else if (!strcmp(value, "attack")) {
00762 ba.Action = ButtonAttack;
00763 } else if (!strcmp(value, "repair")) {
00764 ba.Action = ButtonRepair;
00765 } else if (!strcmp(value, "harvest")) {
00766 ba.Action = ButtonHarvest;
00767 } else if (!strcmp(value, "button")) {
00768 ba.Action = ButtonButton;
00769 } else if (!strcmp(value, "build")) {
00770 ba.Action = ButtonBuild;
00771 } else if (!strcmp(value, "train-unit")) {
00772 ba.Action = ButtonTrain;
00773 } else if (!strcmp(value, "patrol")) {
00774 ba.Action = ButtonPatrol;
00775 } else if (!strcmp(value, "stand-ground")) {
00776 ba.Action = ButtonStandGround;
00777 } else if (!strcmp(value, "attack-ground")) {
00778 ba.Action = ButtonAttackGround;
00779 } else if (!strcmp(value, "cast-spell")) {
00780 ba.Action = ButtonSpellCast;
00781 } else if (!strcmp(value, "unload")) {
00782 ba.Action = ButtonUnload;
00783 } else if (!strcmp(value, "cancel")) {
00784 ba.Action = ButtonCancel;
00785 } else if (!strcmp(value, "cancel-train-unit")) {
00786 ba.Action = ButtonCancelTrain;
00787 } else if (!strcmp(value, "cancel-build")) {
00788 ba.Action = ButtonCancelBuild;
00789 } else {
00790 LuaError(l, "Unsupported button action: %s" _C_ value);
00791 }
00792 } else if (!strcmp(value, "Value")) {
00793 if (!lua_isnumber(l, -1) && !lua_isstring(l, -1)) {
00794 LuaError(l, "incorrect argument");
00795 }
00796 if (lua_isnumber(l, -1)) {
00797 sprintf_s(buf, sizeof(buf), "%ld", (long int)lua_tonumber(l, -1));
00798 s2 = buf;
00799 } else {
00800 s2 = lua_tostring(l, -1);
00801 }
00802 ba.ValueStr = s2;
00803 } else if (!strcmp(value, "Allowed")) {
00804 value = LuaToString(l, -1);
00805 if (!strcmp(value, "check-true")) {
00806 ba.Allowed = ButtonCheckTrue;
00807 } else if (!strcmp(value, "check-false")) {
00808 ba.Allowed = ButtonCheckFalse;
00809 } else if (!strcmp(value, "check-units-or")) {
00810 ba.Allowed = ButtonCheckUnitsOr;
00811 } else if (!strcmp(value, "check-units-and")) {
00812 ba.Allowed = ButtonCheckUnitsAnd;
00813 } else if (!strcmp(value, "check-network")) {
00814 ba.Allowed = ButtonCheckNetwork;
00815 } else if (!strcmp(value, "check-no-network")) {
00816 ba.Allowed = ButtonCheckNoNetwork;
00817 } else if (!strcmp(value, "check-no-work")) {
00818 ba.Allowed = ButtonCheckNoWork;
00819 } else if (!strcmp(value, "check-attack")) {
00820 ba.Allowed = ButtonCheckAttack;
00821 } else {
00822 LuaError(l, "Unsupported action: %s" _C_ value);
00823 }
00824 } else if (!strcmp(value, "AllowArg")) {
00825 int subargs;
00826 int k;
00827 std::string allowstr;
00828
00829 if (!lua_istable(l, -1)) {
00830 LuaError(l, "incorrect argument");
00831 }
00832 subargs = lua_objlen(l, -1);
00833 for (k = 0; k < subargs; ++k) {
00834 lua_rawgeti(l, -1, k + 1);
00835 s2 = LuaToString(l, -1);
00836 lua_pop(l, 1);
00837 allowstr += s2;
00838 if (k != subargs - 1) {
00839 allowstr += ",";
00840 }
00841 }
00842 ba.AllowStr = allowstr;
00843 } else if (!strcmp(value, "Hint")) {
00844 ba.Hint = LuaToString(l, -1);
00845 } else if (!strcmp(value, "ForUnit")) {
00846 int subargs;
00847 int k;
00848 std::string umask;
00849
00850 if (!lua_istable(l, -1)) {
00851 LuaError(l, "incorrect argument");
00852 }
00853
00854 umask = ",";
00855 subargs = lua_objlen(l, -1);
00856 for (k = 0; k < subargs; ++k) {
00857 lua_rawgeti(l, -1, k + 1);
00858 s2 = LuaToString(l, -1);
00859 lua_pop(l, 1);
00860 umask += s2;
00861 umask += ",";
00862 }
00863 ba.UnitMask = umask;
00864 if (ba.UnitMask.compare(0, 3, ",*,") == 0) {
00865 ba.UnitMask = "*";
00866 }
00867 } else {
00868 LuaError(l, "Unsupported tag: %s" _C_ value);
00869 }
00870 lua_pop(l, 1);
00871 }
00872 AddButton(ba.Pos, ba.Level, ba.Icon.Name, ba.Action, ba.ValueStr,
00873 ba.Allowed, ba.AllowStr, ba.Hint, ba.UnitMask);
00874
00875 return 0;
00876 }
00877
00881 void SelectionChanged(void)
00882 {
00883
00884 UI.StatusLine.Clear();
00885 ClearCosts();
00886 CurrentButtonLevel = 0;
00887 UI.ButtonPanel.Update();
00888 GameCursor = UI.Point.Cursor;
00889 CursorBuilding = NULL;
00890 CursorState = CursorStatePoint;
00891 UI.ButtonPanel.Update();
00892 }
00893
00897 void SelectedUnitChanged(void)
00898 {
00899 UI.ButtonPanel.Update();
00900 }
00901
00907 static int CclAddMessage(lua_State *l)
00908 {
00909 LuaCheckArgs(l, 1);
00910 SetMessage("%s", LuaToString(l, 1));
00911 return 0;
00912 }
00913
00919 static int CclSetGroupKeys(lua_State *l)
00920 {
00921 LuaCheckArgs(l, 1);
00922 UiGroupKeys = LuaToString(l, 1);
00923 return 0;
00924 }
00925
00931 static int CclPresentMap(lua_State *l)
00932 {
00933 LuaCheckArgs(l, 5);
00934
00935 Map.Info.Description = LuaToString(l, 1);
00936
00937 Map.Info.MapWidth = LuaToNumber(l, 3);
00938 Map.Info.MapHeight = LuaToNumber(l, 4);
00939 Map.Info.MapUID = LuaToNumber(l, 5);
00940
00941 return 0;
00942 }
00943
00949 static int CclDefineMapSetup(lua_State *l)
00950 {
00951 LuaCheckArgs(l, 1);
00952 Map.Info.Filename = LuaToString(l, 1);
00953
00954 return 0;
00955 }
00956
00960 void UserInterfaceCclRegister(void)
00961 {
00962 lua_register(Lua, "AddMessage", CclAddMessage);
00963
00964 lua_register(Lua, "SetMouseScrollSpeedDefault", CclSetMouseScrollSpeedDefault);
00965 lua_register(Lua, "SetMouseScrollSpeedControl", CclSetMouseScrollSpeedControl);
00966
00967 lua_register(Lua, "SetClickMissile", CclSetClickMissile);
00968 lua_register(Lua, "SetDamageMissile", CclSetDamageMissile);
00969
00970 lua_register(Lua, "SetVideoResolution", CclSetVideoResolution);
00971 lua_register(Lua, "GetVideoResolution", CclGetVideoResolution);
00972 lua_register(Lua, "SetVideoFullScreen", CclSetVideoFullScreen);
00973 lua_register(Lua, "GetVideoFullScreen", CclGetVideoFullScreen);
00974
00975 lua_register(Lua, "SetTitleScreens", CclSetTitleScreens);
00976
00977 lua_register(Lua, "DefineCursor", CclDefineCursor);
00978 lua_register(Lua, "SetGameCursor", CclSetGameCursor);
00979 lua_register(Lua, "DefineViewports", CclDefineViewports);
00980
00981 lua_register(Lua, "RightButtonAttacks", CclRightButtonAttacks);
00982 lua_register(Lua, "RightButtonMoves", CclRightButtonMoves);
00983
00984 lua_register(Lua, "DefineButton", CclDefineButton);
00985
00986 lua_register(Lua, "DefineButtonStyle", CclDefineButtonStyle);
00987
00988 lua_register(Lua, "PresentMap", CclPresentMap);
00989 lua_register(Lua, "DefineMapSetup", CclDefineMapSetup);
00990
00991 lua_register(Lua, "SetGroupKeys", CclSetGroupKeys);
00992 }
00993