gcsx_scriptprop.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* GCSx
  2. ** SCRIPTPROP.CPP
  3. **
  4. ** Script 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. ScriptPropertiesDialog* ScriptPropertiesDialog::dialogScript = NULL;
  26. ScriptPropertiesDialog* ScriptPropertiesDialog::dialogLibrary = NULL;
  27. ScriptPropertiesDialog* ScriptPropertiesDialog::dialogNotes = NULL;
  28. ScriptPropertiesDialog* ScriptPropertiesDialog::createScript() { start_func
  29. if (!dialogScript) {
  30. dialogScript = new ScriptPropertiesDialog(Script::SCRIPT_CODE);
  31. }
  32. return dialogScript;
  33. }
  34. ScriptPropertiesDialog* ScriptPropertiesDialog::createLibrary() { start_func
  35. if (!dialogLibrary) {
  36. dialogLibrary = new ScriptPropertiesDialog(Script::SCRIPT_LIBRARY);
  37. }
  38. return dialogLibrary;
  39. }
  40. ScriptPropertiesDialog* ScriptPropertiesDialog::createNotes() { start_func
  41. if (!dialogNotes) {
  42. dialogNotes = new ScriptPropertiesDialog(Script::SCRIPT_NOTE);
  43. }
  44. return dialogNotes;
  45. }
  46. void ScriptPropertiesDialog::destroy() { start_func
  47. if (dialogScript) {
  48. delete dialogScript;
  49. dialogScript = NULL;
  50. }
  51. if (dialogLibrary) {
  52. delete dialogLibrary;
  53. dialogLibrary = NULL;
  54. }
  55. if (dialogNotes) {
  56. delete dialogNotes;
  57. dialogNotes = NULL;
  58. }
  59. }
  60. ScriptPropertiesDialog::ScriptPropertiesDialog(int type) : ImageDialog() { start_func
  61. initialized = 0;
  62. forType = type;
  63. }
  64. ScriptPropertiesDialog::~ScriptPropertiesDialog() { start_func
  65. }
  66. Dialog::ButtonAction ScriptPropertiesDialog::verifyEntry(int buttonId, Dialog::ButtonAction buttonType) { start_func
  67. if ((buttonType != BUTTON_APPLY) && (buttonType != BUTTON_OK)) return BUTTON_DEFAULT;
  68. // Another script/notes with same name?
  69. string lName = dynamic_cast<WTextBox*>(findWidget(ID_NAME))->state();
  70. toLower(lName);
  71. if (forType == Script::SCRIPT_CODE) {
  72. const Script* found = script->getWorld()->findScriptCode(lName);
  73. if ((found) && (found != script)) {
  74. guiErrorBox("A script by that name already exists- please choose another.", errorTitleDuplicateName);
  75. return BUTTON_NOTHING;
  76. }
  77. if (lName.empty()) {
  78. guiErrorBox("Please enter a name for this script.", errorTitleMissingName);
  79. return BUTTON_NOTHING;
  80. }
  81. }
  82. if (forType == Script::SCRIPT_NOTE) {
  83. const Script* found = script->getWorld()->findScriptNote(lName);
  84. if ((found) && (found != script)) {
  85. guiErrorBox("Notes by that name already exist- please choose another.", errorTitleDuplicateName);
  86. return BUTTON_NOTHING;
  87. }
  88. if (lName.empty()) {
  89. guiErrorBox("Please enter a name for these notes.", errorTitleMissingName);
  90. return BUTTON_NOTHING;
  91. }
  92. }
  93. if (forType == Script::SCRIPT_LIBRARY) {
  94. const Script* found = script->getWorld()->findScriptLib(lName);
  95. if ((found) && (found != script)) {
  96. guiErrorBox("A function library by that name already exists- please choose another.", errorTitleDuplicateName);
  97. return BUTTON_NOTHING;
  98. }
  99. if (lName.empty()) {
  100. guiErrorBox("Please enter a name for this function library.", errorTitleMissingName);
  101. return BUTTON_NOTHING;
  102. }
  103. }
  104. return Dialog::verifyEntry(buttonId, buttonType);
  105. }
  106. int ScriptPropertiesDialog::run(string* title, AnimGroup** animGroup, TileSet** tileSet, int* animTileId, const ScriptEdit* whichScript, WorldEdit* whichWorld) { start_func
  107. assert(title);
  108. if (forType == Script::SCRIPT_CODE) {
  109. assert(animGroup);
  110. assert(tileSet);
  111. assert(animTileId);
  112. }
  113. script = whichScript;
  114. // @TODO: Tooltips on this dialog
  115. if (!initialized) {
  116. Widget* w = NULL;
  117. w = new WStatic(ID_LABEL, "\tName:");
  118. w->addTo(this);
  119. w = new WTextBox(ID_NAME, title, 0);
  120. w->addTo(this);
  121. if (forType == Script::SCRIPT_CODE) {
  122. w = new WStatic(ID_LABEL, "\tDefault sprite:");
  123. w->addTo(this);
  124. addLibTree(ID_LIBRARY);
  125. w = new WStatic(ID_LABEL, "\tImage:");
  126. w->addTo(this);
  127. addImgChoose(ID_IMAGE);
  128. }
  129. w = new WButton(ID_OK, messageBoxOK, BUTTON_OK);
  130. w->addTo(this);
  131. w = new WButton(ID_CANCEL, messageBoxCancel, BUTTON_CANCEL);
  132. w->addTo(this);
  133. makePretty(2, 0);
  134. initialized = 1;
  135. }
  136. else {
  137. findWidget(ID_NAME)->changeStorage(title);
  138. }
  139. if (forType == Script::SCRIPT_CODE) {
  140. runPrep(whichWorld, *animGroup, *tileSet, *animTileId);
  141. setTitle("Script Properties");
  142. }
  143. else if (forType == Script::SCRIPT_LIBRARY) {
  144. setTitle("Function Library Properties");
  145. }
  146. else {
  147. setTitle("Notes Properties");
  148. }
  149. // Hit OK?
  150. if (runModal() == ID_OK) {
  151. if (forType == Script::SCRIPT_CODE) {
  152. runComplete(animGroup, tileSet, animTileId);
  153. }
  154. return 1;
  155. }
  156. if (forType == Script::SCRIPT_CODE) runComplete();
  157. return 0;
  158. }