| 1 |
$using std::string; |
| 2 |
$using std::vector; |
| 3 |
|
| 4 |
$using namespace gcn; |
| 5 |
|
| 6 |
|
| 7 |
class LuaActionListener |
| 8 |
{ |
| 9 |
LuaActionListener(lua_State *lua, lua_Object luaref); |
| 10 |
}; |
| 11 |
|
| 12 |
class CUIButton |
| 13 |
{ |
| 14 |
CUIButton(); |
| 15 |
~CUIButton(); |
| 16 |
|
| 17 |
int X; |
| 18 |
int Y; |
| 19 |
string Text; |
| 20 |
ButtonStyle *Style; |
| 21 |
LuaActionListener *Callback; |
| 22 |
}; |
| 23 |
|
| 24 |
$[ |
| 25 |
_uiButtonCallbacks = {} |
| 26 |
CUIButton.SetCallback = function(w, f) |
| 27 |
w.Callback = LuaActionListener(f) |
| 28 |
table.insert(_uiButtonCallbacks, w.Callback) |
| 29 |
end |
| 30 |
$] |
| 31 |
|
| 32 |
class CMapArea |
| 33 |
{ |
| 34 |
int X; |
| 35 |
int Y; |
| 36 |
int EndX; |
| 37 |
int EndY; |
| 38 |
int ScrollPaddingLeft; |
| 39 |
int ScrollPaddingRight; |
| 40 |
int ScrollPaddingTop; |
| 41 |
int ScrollPaddingBottom; |
| 42 |
}; |
| 43 |
|
| 44 |
class CViewport |
| 45 |
{ |
| 46 |
int Viewport2MapX(int x); |
| 47 |
int Viewport2MapY(int y); |
| 48 |
}; |
| 49 |
|
| 50 |
class CFiller |
| 51 |
{ |
| 52 |
CFiller(); |
| 53 |
|
| 54 |
CGraphic *G; |
| 55 |
int X; |
| 56 |
int Y; |
| 57 |
}; |
| 58 |
|
| 59 |
class vector |
| 60 |
{ |
| 61 |
TOLUA_TEMPLATE_BIND(T, CFiller, CUIButton, string) |
| 62 |
|
| 63 |
vector(); |
| 64 |
~vector(); |
| 65 |
|
| 66 |
const T& operator[](int index) const; |
| 67 |
T& operator[](int index); |
| 68 |
const T& at(int index) const; |
| 69 |
T& at(int index); |
| 70 |
|
| 71 |
const T& front() const; |
| 72 |
T& front(); |
| 73 |
const T& back() const; |
| 74 |
T& back(); |
| 75 |
|
| 76 |
void push_back(T val); |
| 77 |
void pop_back(); |
| 78 |
|
| 79 |
void assign(int num, const T& val); |
| 80 |
void clear(); |
| 81 |
bool empty() const; |
| 82 |
int size() const; |
| 83 |
}; |
| 84 |
|
| 85 |
|
| 86 |
class CButtonPanel |
| 87 |
{ |
| 88 |
int X; |
| 89 |
int Y; |
| 90 |
vector<CUIButton> Buttons; |
| 91 |
CColor AutoCastBorderColorRGB; |
| 92 |
bool ShowCommandKey; |
| 93 |
}; |
| 94 |
|
| 95 |
class CPieMenu |
| 96 |
{ |
| 97 |
CGraphic *G; |
| 98 |
int MouseButton; |
| 99 |
int X[8]; |
| 100 |
int Y[8]; |
| 101 |
|
| 102 |
void SetRadius(int radius); |
| 103 |
}; |
| 104 |
|
| 105 |
class CResourceInfo |
| 106 |
{ |
| 107 |
CGraphic *G; |
| 108 |
int IconFrame; |
| 109 |
int IconX; |
| 110 |
int IconY; |
| 111 |
int TextX; |
| 112 |
int TextY; |
| 113 |
}; |
| 114 |
|
| 115 |
class CInfoPanel |
| 116 |
{ |
| 117 |
int X; |
| 118 |
int Y; |
| 119 |
}; |
| 120 |
|
| 121 |
class CStatusLine |
| 122 |
{ |
| 123 |
void Set(const std::string status); |
| 124 |
const std::string &Get(); |
| 125 |
void Clear(); |
| 126 |
|
| 127 |
int Width; |
| 128 |
int TextX; |
| 129 |
int TextY; |
| 130 |
CFont *Font; |
| 131 |
}; |
| 132 |
|
| 133 |
class CUITimer |
| 134 |
{ |
| 135 |
int X; |
| 136 |
int Y; |
| 137 |
CFont *Font; |
| 138 |
}; |
| 139 |
|
| 140 |
class CUserInterface |
| 141 |
{ |
| 142 |
string NormalFontColor; |
| 143 |
string ReverseFontColor; |
| 144 |
|
| 145 |
vector<CFiller> Fillers; |
| 146 |
|
| 147 |
CResourceInfo Resources[MaxCosts]; |
| 148 |
CInfoPanel InfoPanel; |
| 149 |
CUIButton *SingleSelectedButton; |
| 150 |
|
| 151 |
vector<CUIButton> SelectedButtons; |
| 152 |
CFont *MaxSelectedFont; |
| 153 |
int MaxSelectedTextX; |
| 154 |
int MaxSelectedTextY; |
| 155 |
|
| 156 |
CUIButton *SingleTrainingButton; |
| 157 |
vector<CUIButton> TrainingButtons; |
| 158 |
vector<CUIButton> TransportingButtons; |
| 159 |
|
| 160 |
CColor CompletedBarColorRGB; |
| 161 |
bool CompletedBarShadow; |
| 162 |
|
| 163 |
CButtonPanel ButtonPanel; |
| 164 |
|
| 165 |
CPieMenu PieMenu; |
| 166 |
|
| 167 |
CViewport *MouseViewport; |
| 168 |
CMapArea MapArea; |
| 169 |
|
| 170 |
CFont *MessageFont; |
| 171 |
int MessageScrollSpeed; |
| 172 |
|
| 173 |
CUIButton MenuButton; |
| 174 |
CUIButton NetworkMenuButton; |
| 175 |
CUIButton NetworkDiplomacyButton; |
| 176 |
|
| 177 |
CMinimap Minimap; |
| 178 |
CStatusLine StatusLine; |
| 179 |
CUITimer Timer; |
| 180 |
}; |
| 181 |
|
| 182 |
extern CUserInterface UI; |
| 183 |
|
| 184 |
class CIcon |
| 185 |
{ |
| 186 |
static CIcon *New(const std::string ident); |
| 187 |
static CIcon *Get(const std::string ident); |
| 188 |
|
| 189 |
tolua_readonly tolua_property__s std::string Ident; |
| 190 |
CGraphic *G; |
| 191 |
int Frame; |
| 192 |
}; |
| 193 |
|
| 194 |
extern ButtonStyle *FindButtonStyle(const std::string style); |
| 195 |
|
| 196 |
extern bool GetMouseScroll(void); |
| 197 |
extern void SetMouseScroll(bool enabled); |
| 198 |
extern bool GetKeyScroll(void); |
| 199 |
extern void SetKeyScroll(bool enabled); |
| 200 |
extern bool GetGrabMouse(void); |
| 201 |
extern void SetGrabMouse(bool enabled); |
| 202 |
extern bool GetLeaveStops(void); |
| 203 |
extern void SetLeaveStops(bool enabled); |
| 204 |
extern void SetSavedMapPosition(int index, int x, int y); |
| 205 |
extern int GetDoubleClickDelay(void); |
| 206 |
extern void SetDoubleClickDelay(int delay); |
| 207 |
extern int GetHoldClickDelay(void); |
| 208 |
extern void SetHoldClickDelay(int delay); |
| 209 |
|
| 210 |
extern int CursorX; |
| 211 |
extern int CursorY; |
| 212 |
|
| 213 |
|
| 214 |
// |
| 215 |
// Guichan |
| 216 |
// |
| 217 |
|
| 218 |
class Color |
| 219 |
{ |
| 220 |
Color(int r, int g, int b, int a = 255); |
| 221 |
int r; |
| 222 |
int g; |
| 223 |
int b; |
| 224 |
int a; |
| 225 |
}; |
| 226 |
|
| 227 |
class Graphics |
| 228 |
{ |
| 229 |
enum { |
| 230 |
LEFT = 0, |
| 231 |
CENTER, |
| 232 |
RIGHT |
| 233 |
}; |
| 234 |
}; |
| 235 |
|
| 236 |
class Widget |
| 237 |
{ |
| 238 |
virtual void setWidth(int width); |
| 239 |
virtual int getWidth() const; |
| 240 |
virtual void setHeight(int height); |
| 241 |
virtual int getHeight() const; |
| 242 |
virtual void setSize(int width, int height); |
| 243 |
virtual void setX(int x); |
| 244 |
virtual int getX() const; |
| 245 |
virtual void setY(int y); |
| 246 |
virtual int getY() const; |
| 247 |
virtual void setPosition(int x, int y); |
| 248 |
virtual void setBorderSize(int width); |
| 249 |
virtual unsigned int getBorderSize() const; |
| 250 |
virtual void setEnabled(bool enabled); |
| 251 |
virtual bool isEnabled() const; |
| 252 |
virtual void setVisible(bool visible); |
| 253 |
virtual bool isVisible() const; |
| 254 |
|
| 255 |
virtual void setBaseColor(const Color color); |
| 256 |
virtual const Color &getBaseColor() const; |
| 257 |
virtual void setForegroundColor(const Color color); |
| 258 |
virtual const Color &getForegroundColor() const; |
| 259 |
virtual void setBackgroundColor(const Color color); |
| 260 |
virtual const Color &getBackgroundColor() const; |
| 261 |
virtual void setDisabledColor(const Color color); |
| 262 |
virtual const Color &getDisabledColor() const; |
| 263 |
|
| 264 |
static void setGlobalFont(CFont *font); |
| 265 |
virtual void setFont(CFont *font); |
| 266 |
|
| 267 |
virtual int getHotKey() const; |
| 268 |
virtual void setHotKey(const int key); |
| 269 |
virtual void setHotKey(const char *key); |
| 270 |
|
| 271 |
virtual void addActionListener(LuaActionListener *actionListener); |
| 272 |
virtual void requestFocus(); |
| 273 |
}; |
| 274 |
|
| 275 |
$[ |
| 276 |
Widget.setActionCallback = function(w, f) |
| 277 |
w._actioncb = LuaActionListener(f) |
| 278 |
w:addActionListener(w._actioncb) |
| 279 |
end |
| 280 |
$] |
| 281 |
|
| 282 |
class BasicContainer : public Widget |
| 283 |
{ |
| 284 |
}; |
| 285 |
|
| 286 |
class ScrollArea : public BasicContainer |
| 287 |
{ |
| 288 |
ScrollArea(); |
| 289 |
virtual void setContent(Widget *widget); |
| 290 |
virtual Widget *getContent(); |
| 291 |
virtual void setScrollbarWidth(int width); |
| 292 |
virtual int getScrollbarWidth(); |
| 293 |
}; |
| 294 |
|
| 295 |
class ImageWidget : public Widget |
| 296 |
{ |
| 297 |
ImageWidget(CGraphic *image); |
| 298 |
}; |
| 299 |
|
| 300 |
class Button : public Widget |
| 301 |
{ |
| 302 |
}; |
| 303 |
|
| 304 |
class ButtonWidget : public Button |
| 305 |
{ |
| 306 |
ButtonWidget(const std::string caption); |
| 307 |
virtual void setCaption(const std::string caption); |
| 308 |
virtual const std::string &getCaption() const; |
| 309 |
virtual void adjustSize(); |
| 310 |
}; |
| 311 |
|
| 312 |
class ImageButton : public Button |
| 313 |
{ |
| 314 |
ImageButton(); |
| 315 |
ImageButton(const std::string caption); |
| 316 |
|
| 317 |
void setNormalImage(CGraphic *image); |
| 318 |
void setPressedImage(CGraphic *image); |
| 319 |
void setDisabledImage(CGraphic *image); |
| 320 |
}; |
| 321 |
|
| 322 |
class RadioButton : public Widget |
| 323 |
{ |
| 324 |
RadioButton(); |
| 325 |
RadioButton(const std::string caption, const std::string group, bool marked = false); |
| 326 |
|
| 327 |
virtual bool isMarked(); |
| 328 |
virtual void setMarked(bool marked); |
| 329 |
virtual const std::string &getCaption() const; |
| 330 |
virtual void setCaption(const std::string caption); |
| 331 |
virtual void setGroup(const std::string group); |
| 332 |
virtual const std::string &getGroup() const; |
| 333 |
virtual void adjustSize(); |
| 334 |
}; |
| 335 |
|
| 336 |
class ImageRadioButton : public RadioButton |
| 337 |
{ |
| 338 |
ImageRadioButton(); |
| 339 |
ImageRadioButton(const std::string caption, const std::string group, bool marked = false); |
| 340 |
|
| 341 |
void setUncheckedNormalImage(CGraphic *image); |
| 342 |
void setUncheckedPressedImage(CGraphic *image); |
| 343 |
void setCheckedNormalImage(CGraphic *image); |
| 344 |
void setCheckedPressedImage(CGraphic *image); |
| 345 |
}; |
| 346 |
|
| 347 |
class CheckBox : public Widget |
| 348 |
{ |
| 349 |
CheckBox(); |
| 350 |
CheckBox(const std::string caption, bool marked = false); |
| 351 |
|
| 352 |
virtual bool isMarked() const; |
| 353 |
virtual void setMarked(bool marked); |
| 354 |
virtual const std::string &getCaption() const; |
| 355 |
virtual void setCaption(const std::string caption); |
| 356 |
virtual void adjustSize(); |
| 357 |
}; |
| 358 |
|
| 359 |
class ImageCheckBox : public CheckBox |
| 360 |
{ |
| 361 |
ImageCheckBox(); |
| 362 |
ImageCheckBox(const std::string caption, bool marked = false); |
| 363 |
|
| 364 |
void setUncheckedNormalImage(CGraphic *image); |
| 365 |
void setUncheckedPressedImage(CGraphic *image); |
| 366 |
void setCheckedNormalImage(CGraphic *image); |
| 367 |
void setCheckedPressedImage(CGraphic *image); |
| 368 |
}; |
| 369 |
|
| 370 |
class Slider : public Widget |
| 371 |
{ |
| 372 |
Slider(double scaleEnd = 1.0); |
| 373 |
Slider(double scaleStart, double scaleEnd); |
| 374 |
virtual void setScale(double scaleStart, double scaleEnd); |
| 375 |
virtual double getScaleStart() const; |
| 376 |
virtual void setScaleStart(double scaleStart); |
| 377 |
virtual double getScaleEnd() const; |
| 378 |
virtual void setScaleEnd(double scaleEnd); |
| 379 |
virtual double getValue(); |
| 380 |
virtual void setValue(double value); |
| 381 |
virtual void setMarkerLength(int length); |
| 382 |
virtual int getMarkerLength() const; |
| 383 |
virtual void setOrientation(unsigned int orientation); |
| 384 |
virtual unsigned int getOrientation() const; |
| 385 |
virtual void setStepLength(double length); |
| 386 |
virtual double getStepLength() const; |
| 387 |
|
| 388 |
enum { HORIZONTAL = 0, VERTICAL }; |
| 389 |
}; |
| 390 |
|
| 391 |
class ImageSlider : public Slider |
| 392 |
{ |
| 393 |
ImageSlider(double scaleEnd = 1.0); |
| 394 |
ImageSlider(double scaleStart, double scaleEnd); |
| 395 |
void setMarkerImage(CGraphic *image); |
| 396 |
void setBackgroundImage(CGraphic *image); |
| 397 |
}; |
| 398 |
|
| 399 |
class Label : public Widget |
| 400 |
{ |
| 401 |
Label(const std::string caption); |
| 402 |
const std::string &getCaption() const; |
| 403 |
void setCaption(const std::string caption); |
| 404 |
virtual void setAlignment(unsigned int alignment); |
| 405 |
virtual unsigned int getAlignment(); |
| 406 |
virtual void adjustSize(); |
| 407 |
}; |
| 408 |
|
| 409 |
class MultiLineLabel : public Widget |
| 410 |
{ |
| 411 |
MultiLineLabel(); |
| 412 |
MultiLineLabel(const std::string caption); |
| 413 |
|
| 414 |
virtual void setCaption(const std::string caption); |
| 415 |
virtual const std::string &getCaption() const; |
| 416 |
virtual void setAlignment(unsigned int alignment); |
| 417 |
virtual unsigned int getAlignment(); |
| 418 |
virtual void setVerticalAlignment(unsigned int alignment); |
| 419 |
virtual unsigned int getVerticalAlignment(); |
| 420 |
virtual void setLineWidth(int width); |
| 421 |
virtual int getLineWidth(); |
| 422 |
virtual void adjustSize(); |
| 423 |
virtual void draw(gcn::Graphics *graphics); |
| 424 |
|
| 425 |
enum { |
| 426 |
LEFT = 0, |
| 427 |
CENTER, |
| 428 |
RIGHT, |
| 429 |
TOP, |
| 430 |
BOTTOM |
| 431 |
}; |
| 432 |
}; |
| 433 |
|
| 434 |
// FIXME Combine with ScrollArea in our own widget |
| 435 |
//class TextBox : public Widget |
| 436 |
//{ |
| 437 |
// TextBox(const std::string text); |
| 438 |
//}; |
| 439 |
|
| 440 |
class TextField : public Widget |
| 441 |
{ |
| 442 |
TextField(const std::string text); |
| 443 |
virtual void setText(const std::string text); |
| 444 |
virtual std::string &getText(); |
| 445 |
void setMaxLengthBytes(int maxLengthBytes); |
| 446 |
int getMaxLengthBytes() const; |
| 447 |
}; |
| 448 |
|
| 449 |
class ListBox : public Widget |
| 450 |
{ |
| 451 |
}; |
| 452 |
|
| 453 |
class ListBoxWidget : public ScrollArea |
| 454 |
{ |
| 455 |
ListBoxWidget(unsigned int width, unsigned int height); |
| 456 |
void setList(lua_State *lua, lua_Object *lo); |
| 457 |
void setSelected (int selected); |
| 458 |
int getSelected(); |
| 459 |
}; |
| 460 |
|
| 461 |
class Window : public BasicContainer |
| 462 |
{ |
| 463 |
Window(); |
| 464 |
Window(const std::string caption); |
| 465 |
Window(Widget *content, const std::string caption = ""); |
| 466 |
|
| 467 |
virtual void setCaption(const std::string caption); |
| 468 |
virtual const std::string &getCaption() const; |
| 469 |
virtual void setAlignment(unsigned int alignment); |
| 470 |
virtual unsigned int getAlignment() const; |
| 471 |
virtual void setContent(Widget* widget); |
| 472 |
virtual Widget* getContent() const; |
| 473 |
virtual void setPadding(unsigned int padding); |
| 474 |
virtual unsigned int getPadding() const; |
| 475 |
virtual void setTitleBarHeight(unsigned int height); |
| 476 |
virtual unsigned int getTitleBarHeight(); |
| 477 |
virtual void setMovable(bool movable); |
| 478 |
virtual bool isMovable() const; |
| 479 |
virtual void resizeToContent(); |
| 480 |
virtual void setOpaque(bool opaque); |
| 481 |
virtual bool isOpaque(); |
| 482 |
}; |
| 483 |
|
| 484 |
class Windows : public Window |
| 485 |
{ |
| 486 |
Windows(const std::string text, int width, int height); |
| 487 |
void add(Widget *widget, int x, int y); |
| 488 |
}; |
| 489 |
|
| 490 |
class ScrollingWidget : public ScrollArea |
| 491 |
{ |
| 492 |
ScrollingWidget(int width, int height); |
| 493 |
void add(Widget *widget, int x, int y); |
| 494 |
void restart(); |
| 495 |
void setSpeed(float speed); |
| 496 |
float getSpeed(); |
| 497 |
}; |
| 498 |
|
| 499 |
class DropDown : public BasicContainer |
| 500 |
{ |
| 501 |
virtual int getSelected(); |
| 502 |
virtual void setSelected(int selected); |
| 503 |
virtual void setScrollArea(ScrollArea* scrollArea); |
| 504 |
virtual ScrollArea *getScrollArea(); |
| 505 |
virtual void setListBox(ListBox* listBox); |
| 506 |
virtual ListBox *getListBox(); |
| 507 |
}; |
| 508 |
|
| 509 |
class DropDownWidget : public DropDown |
| 510 |
{ |
| 511 |
DropDownWidget(); |
| 512 |
void setList(lua_State *lua, lua_Object *lo); |
| 513 |
virtual ListBox *getListBox(); |
| 514 |
virtual void setSize(int width, int height); |
| 515 |
}; |
| 516 |
|
| 517 |
class StatBoxWidget : public Widget |
| 518 |
{ |
| 519 |
StatBoxWidget(int width, int height); |
| 520 |
|
| 521 |
void setCaption(const std::string s); |
| 522 |
const std::string &getCaption() const; |
| 523 |
void setPercent(const int percent); |
| 524 |
int getPercent() const; |
| 525 |
}; |
| 526 |
|
| 527 |
class Container : public BasicContainer |
| 528 |
{ |
| 529 |
Container(); |
| 530 |
virtual void setOpaque(bool opaque); |
| 531 |
virtual bool isOpaque() const; |
| 532 |
virtual void add(Widget *widget, int x, int y); |
| 533 |
virtual void remove(Widget *widget); |
| 534 |
virtual void clear(); |
| 535 |
}; |
| 536 |
|
| 537 |
class MenuScreen : public Container |
| 538 |
{ |
| 539 |
MenuScreen(); |
| 540 |
|
| 541 |
int run(bool loop = true); |
| 542 |
void stop(int result = 0); |
| 543 |
void stopAll(int result = 0); |
| 544 |
void addLogicCallback(LuaActionListener *actionListener); |
| 545 |
void setDrawMenusUnder(bool drawunder); |
| 546 |
bool getDrawMenusUnder(); |
| 547 |
}; |
| 548 |
$renaming MenuScreen @ CMenuScreen |
| 549 |
|
| 550 |
$[ |
| 551 |
function MenuScreen() |
| 552 |
local menu = CMenuScreen() |
| 553 |
|
| 554 |
-- Store the widget in the container. This way we keep a reference |
| 555 |
-- to the widget until the container gets deleted. |
| 556 |
local guichanadd = Container.add |
| 557 |
function menu:add(widget, x, y) |
| 558 |
if not self._addedWidgets then |
| 559 |
self._addedWidgets = {} |
| 560 |
end |
| 561 |
self._addedWidgets[widget] = true |
| 562 |
guichanadd(self, widget, x, y) |
| 563 |
end |
| 564 |
|
| 565 |
return menu |
| 566 |
end |
| 567 |
$] |
| 568 |
|