new_addon.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # Flexlay - A Generic 2D Game Editor
  2. # Copyright (C) 2015 Karkus476 <karkus476@yahoo.com>
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. from typing import Any, Optional
  17. import random
  18. from PyQt5.QtWidgets import QWidget, QWizardPage, QTextEdit, QVBoxLayout
  19. from flexlay.util.config import Config
  20. from flexlay.gui.properties_widget import PropertiesWidget
  21. from flexlay.gui.generic_wizard import GenericWizard
  22. from supertux.addon import Addon
  23. class NewAddonWizard(GenericWizard):
  24. def __init__(self, parent: QWidget) -> None:
  25. super().__init__(parent, "New Addon Wizard")
  26. # Modal means you cannot touch the parent until this
  27. # closes
  28. self.setModal(True)
  29. assert Config.current is not None
  30. self.addon: Optional[Addon] = Addon()
  31. self.addon.id = "unnamed-addon"
  32. self.addon.version = 1
  33. self.addon.type = "worldmap"
  34. self.addon.title = "New add-on"
  35. self.addon.author = Config.current.name
  36. self.addon.license = "GPL 2+ / CC-by-sa 3.0"
  37. # self.level.spawn = (5, 25)
  38. # Each function returns a QWizardPage, which is then added
  39. self.add_page("Create A New Add-on", self.create_intro_page())
  40. self.add_page("General Info", self.create_main_page())
  41. self.addPage(self.create_license_page())
  42. # When 'Finish' pressed run finish()
  43. self.finish_callback.connect(self.finish)
  44. # When 'Cancel' pressed run cancel()
  45. self.rejected.connect(self.cancel)
  46. def finish(self, *pages: Any) -> None:
  47. """Executed when "Finish" button clicked"""
  48. main_page_data = pages[1]
  49. self.addon = Addon()
  50. self.addon.title = main_page_data[0]
  51. self.addon.author = main_page_data[1]
  52. self.addon.version = main_page_data[2]
  53. self.addon.id = main_page_data[3]
  54. self.addon.type = main_page_data[4]
  55. # self.level.current_sector.music = self.level.music
  56. # self.level.current_sector.background = self.level.image
  57. # self.level.name = main_page_data[0]
  58. # self.level.author = main_page_data[1]
  59. assert Config.current is not None
  60. Config.current.name = self.addon.author
  61. # self.level.current_sector.music = main_page_data[4]
  62. # self.level.spawn = ceil(main_page_data[2] / 10), int(main_page_data[3] / 2)
  63. # self.level.tileset_path = os.path.join("images", "tiles.strf")
  64. # Not Implemented
  65. def cancel(self) -> None:
  66. self.addon = None
  67. def create_intro_page(self) -> PropertiesWidget:
  68. """Creates the intro page containing a bit of text
  69. :return: PropertiesWidget Introduction Page
  70. """
  71. page_widget = PropertiesWidget(self)
  72. page_widget.add_label("Click 'Next' to continue.\n" +
  73. "In the future, this page will show some " +
  74. "checkboxes to allow experienced users " +
  75. "to view extra pages in this wizard.")
  76. return page_widget
  77. def create_main_page(self) -> PropertiesWidget:
  78. """Creates the main wizard page
  79. :return: PropertiesWidget to add to GenericWidget
  80. """
  81. page_widget = PropertiesWidget(self)
  82. # A list of names randomly selected as the 'Example
  83. # Level name.
  84. # Feel free to add more
  85. fun_names = ("Fire Meets Ice",
  86. "Flipper Hell",
  87. "Level 4",
  88. "Into the Deep",
  89. "Unknown Flying Penguin")
  90. # choice is random.choice
  91. assert self.addon is not None
  92. self.addon.title = "Example: " + random.choice(fun_names)
  93. page_widget.add_string("Title:", self.addon.title, None)
  94. page_widget.add_string("Author:", self.addon.author, None)
  95. page_widget.add_int("Version:", self.addon.version, None)
  96. page_widget.add_string("ID:", self.addon.id, None)
  97. page_widget.add_string("Type:", self.addon.type, None)
  98. return page_widget
  99. def create_license_page(self) -> QWizardPage:
  100. """Creates the license page
  101. @return QWizardPage The License Page of the wizard
  102. """
  103. page = QWizardPage()
  104. page.setTitle("Addon License")
  105. page.setSubTitle("You must set a license for your level, which " +
  106. "defines how others may use and share your level. " +
  107. "In the spirit of 'free and open source' " +
  108. "we ask that you make your level free " +
  109. "(as in 'free speech' not 'free WiFi')")
  110. self.license_input = QTextEdit("GPL 2+ / CC-by-sa 3.0")
  111. self.set_license()
  112. self.license_input.textChanged.connect(self.set_license)
  113. vbox = QVBoxLayout()
  114. vbox.addWidget(self.license_input)
  115. page.setLayout(vbox)
  116. return page
  117. def set_license(self) -> None: # Connected to signal
  118. assert self.addon is not None
  119. self.addon.license = self.license_input.toPlainText()
  120. # EOF #