gcsx_tilesetprop.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /* GCSx
  2. ** TILESETPROP.CPP
  3. **
  4. ** Tileset properties dialog
  5. */
  6. /*****************************************************************************
  7. ** Copyright (C) 2003-2006 Janson
  8. **
  9. ** This program is free software; you can redistribute it and/or modify
  10. ** it under the terms of the GNU General Public License as published by
  11. ** the Free Software Foundation; either version 2 of the License, or
  12. ** (at your option) any later version.
  13. **
  14. ** This program is distributed in the hope that it will be useful,
  15. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ** GNU General Public License for more details.
  18. **
  19. ** You should have received a copy of the GNU General Public License
  20. ** along with this program; if not, write to the Free Software
  21. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  22. *****************************************************************************/
  23. #include "all.h"
  24. // Properties dialog
  25. TileSetPropertiesDialog* TileSetPropertiesDialog::dialogFontSet = NULL;
  26. TileSetPropertiesDialog* TileSetPropertiesDialog::dialogTileSet = NULL;
  27. TileSetPropertiesDialog* TileSetPropertiesDialog::createFontSet() { start_func
  28. if (!dialogFontSet) {
  29. dialogFontSet = new TileSetPropertiesDialog(1);
  30. }
  31. return dialogFontSet;
  32. }
  33. TileSetPropertiesDialog* TileSetPropertiesDialog::createTileSet() { start_func
  34. if (!dialogTileSet) {
  35. dialogTileSet = new TileSetPropertiesDialog(0);
  36. }
  37. return dialogTileSet;
  38. }
  39. void TileSetPropertiesDialog::destroy() { start_func
  40. if (dialogFontSet) {
  41. delete dialogFontSet;
  42. dialogFontSet = NULL;
  43. }
  44. if (dialogTileSet) {
  45. delete dialogTileSet;
  46. dialogTileSet = NULL;
  47. }
  48. }
  49. TileSetPropertiesDialog::TileSetPropertiesDialog(int font) : Dialog(font ? "Font Properties" : "Image/Tile Set Properties") { start_func
  50. initialized = 0;
  51. isFont = font;
  52. }
  53. Dialog::ButtonAction TileSetPropertiesDialog::verifyEntry(int buttonId, Dialog::ButtonAction buttonType) { start_func
  54. if ((buttonType != BUTTON_APPLY) && (buttonType != BUTTON_OK)) return BUTTON_DEFAULT;
  55. // Another tileset with same name?
  56. string lName = dynamic_cast<WTextBox*>(findWidget(ID_NAME))->state();
  57. toLower(lName);
  58. const TileSet* found = tileset->getWorld()->findTileSet(lName);
  59. if ((found) && (found != tileset)) {
  60. guiErrorBox("A library by that name already exists- please choose another.", errorTitleDuplicateName);
  61. return BUTTON_NOTHING;
  62. }
  63. if (lName.empty()) {
  64. guiErrorBox("Please enter a name for this library.", errorTitleMissingName);
  65. return BUTTON_NOTHING;
  66. }
  67. // Count OK?
  68. int w = dynamic_cast<WNumberBox*>(findWidget(ID_WIDTH))->state();
  69. int h = dynamic_cast<WNumberBox*>(findWidget(ID_HEIGHT))->state();
  70. int count;
  71. if (isFont) count = dynamic_cast<WCheckBox*>(findWidget(ID_COUNT))->state() ? TileSet::TILE_FONTSET_EXT_COUNT : TileSet::TILE_FONTSET_NORMAL_COUNT;
  72. else count = dynamic_cast<WNumberBox*>(findWidget(ID_COUNT))->state();
  73. int sWidth, sHeight, perLine;
  74. int actualCount = TileSetEdit::calculateTileSurfaceSizing(w, h, count, sWidth, sHeight, perLine);
  75. assert(actualCount <= count);
  76. if (actualCount != count) {
  77. guiErrorBox(formatString("Too many images- the most %dx%d images you may have is %d.", w, h, actualCount), errorTitleImageOverflow);
  78. return BUTTON_NOTHING;
  79. }
  80. // @TODO: Reduction in tiles or size causes warning if not new
  81. // @TODO: Loss of tiles used within a layer causes more detailed warning
  82. return Dialog::verifyEntry(buttonId, buttonType);
  83. }
  84. int TileSetPropertiesDialog::run(string* title, int* width, int* height, int* count, int* maps, int* fixedWidth, int* defaultTransparent, const TileSet* whichTileset) { start_func
  85. tileset = whichTileset;
  86. int fixedPerLine = *fixedWidth ? 1 : 0;
  87. int numPerLine = *fixedWidth;
  88. if (numPerLine < 1) numPerLine = 16;
  89. int extendedFont = 0;
  90. if (*count == TileSet::TILE_FONTSET_EXT_COUNT) extendedFont = 1;
  91. if (!initialized) {
  92. Widget* w = NULL;
  93. WCheckBox* c = NULL;
  94. w = new WStatic(ID_LABEL, "\tName:");
  95. w->addTo(this);
  96. w = new WTextBox(ID_NAME, title, 0);
  97. w->addTo(this);
  98. w = new WStatic(ID_LABEL, "\tWidth:");
  99. w->addTo(this);
  100. w = new WNumberBox(ID_WIDTH, width, MIN_TILESIZE, MAX_TILESIZE);
  101. w->addTo(this);
  102. w = new WStatic(ID_LABEL, "\tHeight:");
  103. w->addTo(this);
  104. w = new WNumberBox(ID_HEIGHT, height, MIN_TILESIZE, MAX_TILESIZE);
  105. w->addTo(this);
  106. if (isFont) {
  107. w = new WCheckBox(ID_COUNT, "\tExtended font (224 characters)", &extendedFont, 1);
  108. w->addTo(this);
  109. }
  110. else {
  111. w = new WStatic(ID_LABEL, "N\tumber of images:");
  112. w->addTo(this);
  113. w = new WNumberBox(ID_COUNT, count, 0, MAX_TILES);
  114. w->addTo(this);
  115. w = new WStatic(ID_LABEL, "Number of \tcollision maps:");
  116. w->addTo(this);
  117. w = new WNumberBox(ID_MAPS, maps, 0, MAX_COLLMAPS);
  118. w->setToolTip("Set to zero if you do not need pixel-based collision maps");
  119. w->addTo(this);
  120. w = new WRadioButton(ID_TRANSPARENT, "Default to \ttransparent", defaultTransparent, 1);
  121. w->setToolTip("Blank tiles will be fully transparent");
  122. w->addTo(this);
  123. w = new WRadioButton(ID_TRANSPARENT, "Default to \tsolid black", defaultTransparent, 0);
  124. w->setToolTip("Blank tiles will be solid, opaque black");
  125. w->addTo(this);
  126. c = new WCheckBox(ID_FIXED, "Fi\txed image count per line", &fixedPerLine, 1);
  127. c->affectControl(ID_FIXEDCOUNT, 1);
  128. c->setToolTip("If not set, images will rearrange to fill the browsing window");
  129. c->addTo(this);
  130. w = new WStatic(ID_LABEL, "\tImages per line:");
  131. w->addTo(this);
  132. w = new WNumberBox(ID_FIXEDCOUNT, &numPerLine, 1, MAX_TILES);
  133. w->addTo(this);
  134. }
  135. w = new WButton(ID_OK, messageBoxOK, BUTTON_OK);
  136. w->addTo(this);
  137. w = new WButton(ID_CANCEL, messageBoxCancel, BUTTON_CANCEL);
  138. w->addTo(this);
  139. makePretty();
  140. initialized = 1;
  141. }
  142. else {
  143. findWidget(ID_NAME)->changeStorage(title);
  144. findWidget(ID_WIDTH)->changeStorage(width);
  145. findWidget(ID_HEIGHT)->changeStorage(height);
  146. if (isFont) {
  147. findWidget(ID_COUNT)->changeStorage(&extendedFont);
  148. }
  149. else {
  150. findWidget(ID_COUNT)->changeStorage(count);
  151. findWidget(ID_MAPS)->changeStorage(maps);
  152. findWidget(ID_FIXED)->changeStorage(&fixedPerLine);
  153. findWidget(ID_FIXEDCOUNT)->changeStorage(&numPerLine);
  154. findWidget(ID_TRANSPARENT, 0)->changeStorage(defaultTransparent);
  155. findWidget(ID_TRANSPARENT, 1)->changeStorage(defaultTransparent);
  156. }
  157. }
  158. // Hit OK?
  159. if (runModal() == ID_OK) {
  160. *fixedWidth = fixedPerLine ? numPerLine : 0;
  161. if (isFont) {
  162. *count = extendedFont ? TileSet::TILE_FONTSET_EXT_COUNT : TileSet::TILE_FONTSET_NORMAL_COUNT;
  163. *maps = 0;
  164. }
  165. return 1;
  166. }
  167. return 0;
  168. }