gcsx_worldprop.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* GCSx
  2. ** WORLDPROP.CPP
  3. **
  4. ** World 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. WorldPropertiesDialog* WorldPropertiesDialog::dialog = NULL;
  26. WorldPropertiesDialog* WorldPropertiesDialog::create() { start_func
  27. if (!dialog) {
  28. dialog = new WorldPropertiesDialog();
  29. }
  30. return dialog;
  31. }
  32. void WorldPropertiesDialog::destroy() { start_func
  33. if (dialog) {
  34. delete dialog;
  35. dialog = NULL;
  36. }
  37. }
  38. WorldPropertiesDialog::WorldPropertiesDialog() : Dialog("World Properties") { start_func
  39. initialized = 0;
  40. tree = NULL;
  41. }
  42. WorldPropertiesDialog::~WorldPropertiesDialog() { start_func
  43. if (tree) {
  44. WidgetScroll* ws = dynamic_cast<WidgetScroll*>(tree->getParent());
  45. if (ws) ws->newClient();
  46. delete tree;
  47. }
  48. }
  49. Dialog::ButtonAction WorldPropertiesDialog::verifyEntry(int buttonId, Dialog::ButtonAction buttonType) { start_func
  50. if ((buttonType != BUTTON_APPLY) && (buttonType != BUTTON_OK)) return BUTTON_DEFAULT;
  51. const string& title = dynamic_cast<WTextBox*>(findWidget(ID_TITLE))->state();
  52. if (title.empty()) {
  53. guiErrorBox("Please enter a title for this world.", errorTitleMissingName);
  54. return BUTTON_NOTHING;
  55. }
  56. return Dialog::verifyEntry(buttonId, buttonType);
  57. }
  58. int WorldPropertiesDialog::run(string* title, int* startScene, const WorldEdit* whichWorld) { start_func
  59. if (!initialized) {
  60. Widget* w = NULL;
  61. w = new WStatic(ID_LABEL, "\tTitle:");
  62. w->addTo(this);
  63. w = new WTextBox(ID_TITLE, title, 0);
  64. w->addTo(this);
  65. w = new WStatic(ID_LABEL, "\tStarting scene:");
  66. w->addTo(this);
  67. tree = new TreeView(blankString, NULL, 0, NULL, 1);
  68. tree->addTo(this, -1, 5);
  69. w = new WButton(ID_OK, messageBoxOK, BUTTON_OK);
  70. w->addTo(this);
  71. w = new WButton(ID_CANCEL, messageBoxCancel, BUTTON_CANCEL);
  72. w->addTo(this);
  73. makePretty(2, 0);
  74. initialized = 1;
  75. }
  76. else {
  77. findWidget(ID_TITLE)->changeStorage(title);
  78. }
  79. TreeView* item;
  80. tree->removeAll();
  81. tree->insert(new TreeView("(none)", this, 0, NULL), *startScene == 0);
  82. for (World::SceneIndex::const_iterator pos = whichWorld->beginScene(); pos != whichWorld->endScene(); ++pos) {
  83. const Scene* toAdd = (*pos).second;
  84. tree->insert(item = new TreeView(toAdd->getName(), this, toAdd->getId(), NULL), *startScene == toAdd->getId());
  85. item->setIcon(6);
  86. }
  87. // Hit OK?
  88. if (runModal() == ID_OK) {
  89. // Scene
  90. item = tree->findSelected();
  91. if (item) *startScene = item->getCode();
  92. else *startScene = 0;
  93. return 1;
  94. }
  95. return 0;
  96. }