Example #1
0
    def __init__(self, parent):
        super().__init__(parent, "New Level Wizard")
        # Modal means you cannot touch the parent until this
        # closes
        self.setModal(True)

        self.level = Level()
        self.level.name = "Unnamed Level"
        self.level.author = Config.current.name
        self.level.music = ""
        self.level.background = ""
        self.level.license = "GPL 2+ / CC-by-sa 3.0"
        self.level.width = 300
        self.level.height = 35
        # self.level.spawn = (5, 25)

        # Each function returns a QWizardPage, which is then added
        self.add_page("Create A New Level", self.create_intro_page())
        self.add_page("General Info", self.create_main_page())
        self.addPage(self.create_license_page())

        # When 'Finish' pressed run finish()
        self.finish_callback.connect(self.finish)
        # When 'Cancel' pressed run cancel()
        self.rejected.connect(self.cancel)
Example #2
0
    def load_level(self, filename, set_title=True):
        logging.info("Loading: " + filename)

        # Clear object selection, it's a new level!
        self.tool_context.object_selection.clear()

        self.gui.properties_widget.clear_properties()

        # Set title if desired
        if set_title:
            self.gui.window.setWindowTitle("SuperTux Editor: [" + filename +
                                           "]")

        # if filename[-5:] == ".stwm":
        #     QMessageBox.warning(None, "Opening Worldmap File",
        #                    "[WARNING] Opening supertux worldmap file:\n'"+filename+"'\n" +
        #                    "Worldmaps usually use different tilesets to levels.\n"+
        #                    "Please select a different tileset to use (look for .strf files).")
        # if not self.gui_change_tileset():
        #    return
        #    print("Loading worldmap")

        level = Level.from_file(filename)

        if level.tileset_path != SuperTuxTileset.current.filename:
            tileset = SuperTuxTileset(32)
            tileset.load(
                os.path.join(Config.current.datadir, level.tileset_path))
            # tileset.load(level.tileset_path)

            self.gui_set_tileset(tileset)

            # Tileset has changed, reload level:
            level = Level.from_file(filename)

        self.set_level(level, "main")

        Config.current.add_recent_file(filename)
        self.menubar.update_recent_files()

        self.minimap.update_minimap()
        # TODO: We don't yet support multiple sectors, so we set the first sector's name.
        self.editor_map.set_sector_tab_label(0, level.sectors[0].name)
Example #3
0
    def finish(self, *pages):
        """Executed when "Finish" button clicked"""
        main_page_data = pages[1]

        # FIXME: Don't create game data in GUI code
        self.level = Level.from_size(main_page_data[2], main_page_data[3])
        # self.level.current_sector.music = self.level.music
        # self.level.current_sector.background = self.level.image
        self.level.name = main_page_data[0]
        self.level.author = main_page_data[1]
        Config.current.name = self.level.author
        self.level.current_sector.music = main_page_data[4]
        # self.level.spawn = ceil(main_page_data[2] / 10), int(main_page_data[3] / 2)
        self.level.tileset_path = os.path.join("images", "tiles.strf")
Example #4
0
    def gui_level_new(self):
        if False:
            dialog = NewLevelWizard(self.gui.window)
            dialog.exec_()
            if dialog.level:
                self.set_level(dialog.level, "main")

            if dialog.level is not None:

                def save_path_chosen(save_path):
                    dialog.level.save(save_path)
                    self.load_level(save_path)

                self.save_dialog.run(save_path_chosen)
        else:
            level = Level.from_size(100, 25)
            self.set_level(level, "main")
Example #5
0
 def test_level_resize(self):
     level = Level.from_file(test_levelfile)
     level.sectors[0].resize(Size(10, 10), Point(10, 10))
Example #6
0
 def test_level_new(self):
     level = Level.from_size(400, 300)
     self.assertEqual(level.name, "No Name")
Example #7
0
 def test_level_save(self):
     level = Level.from_file(test_levelfile)
     # with open("/tmp/test.stl", "w") as out:
     with io.StringIO() as out:
         level.save_io(out)
Example #8
0
 def test_level_load(self):
     level = Level.from_file(test_levelfile)
     self.assertEqual(level.name, "Welcome to Antarctica")
Example #9
0
    def __init__(self, flexlay):
        SuperTuxGUI.current = self
        supertux_gameobj_factory.supertux_gui = self

        self.use_worldmap = False

        self.tool_context = ToolContext()
        self.level = None
        self.sector = None

        self.gui = flexlay.create_gui_manager("SuperTux Editor")
        self.gui.window.setWindowIcon(
            QIcon("data/images/supertux/supertux-editor.png"))
        self.gui.window.set_on_close(self.on_window_close)

        self.button_panel = SuperTuxButtonPanel(self.gui, self)
        self.toolbox = SuperTuxToolbox(self.gui, self)

        self.editor_map = self.gui.create_editor_map_component()
        self.statusbar = self.gui.create_statusbar()
        self.workspace = self.editor_map.get_workspace()

        # Tools
        self.workspace.set_tool(InputEvent.MOUSE_MIDDLE, WorkspaceMoveTool())

        self.minimap = self.gui.create_minimap(self.editor_map)

        self.objectselector = self.gui.create_object_selector(42, 42)
        self.properties_widget = self.gui.create_properties_view()

        self.editor_map.sig_drop.connect(self.on_object_drop)
        for object_brush in supertux_gameobj_factory.create_object_brushes():
            self.objectselector.add_brush(object_brush)

        self.tileselector = self.gui.create_tile_selector()
        self.gui_set_tileset(SuperTuxTileset.current)

        self.layer_selector = self.gui.create_layer_selector(
            self.generate_tilemap_obj)

        # self.worldmapobjectselector = self.gui.create_object_selector(42, 42)
        # if False:
        #     self.worldmapobjectselector.sig_drop.connect(self.on_worldmap_object_drop)
        # for obj in worldmap_objects:
        #     self.objectselector.add_brush(ObjectBrush(Sprite.from_file(os.path.join(Config.current.datadir, obj[1])),
        #                                                       obj[0]))

        # Loading Dialogs
        self.load_dialog = OpenLevelFileDialog("Load SuperTux Level")
        self.load_dialog.set_directory(Config.current.datadir, "levels")
        self.save_dialog = SaveLevelFileDialog("Save SuperTux Level As...")
        self.save_dialog.set_directory(Config.current.datadir, "levels")
        self.addon_save_dialog = SaveAddonDialog("Save SuperTux Add-on As...")
        self.addon_save_dialog.set_directory(Config.current.datadir, "addons")

        self.register_keyboard_shortcuts()

        # Popup menu
        # objmap_select_tool.sig_on_right_click().connect(proc{ | x, y |
        #              print("Launching Menu at %s, %s" % (x, y))
        #              menu=Menu(Point(x, y))
        #              menu.add_item(mysprite, "Delete Object(s)", proc{
        #                              print("Trying to delete
        #                              {self.workspace.get_map().metadata}
        #                              {self.workspace.get_map().metadata.objects}")
        #                              cmd=ObjectDeleteCommand(self.workspace.get_map().metadata.objects)
        #                              for i in objmap_select_tool.get_selection():
        #                                  cmd.add_object(i)
        #                              self.workspace.get_map().execute(cmd)
        #                              objmap_select_tool.clear_selection()
        #                            })
        #              menu.add_item(mysprite, "Edit Properties", proc{
        #                                for i in objmap_select_tool.get_selection():
        #                                  i.metadata.property_dialog()
        #                              }
        #                            })
        #              menu.run()
        #            })

        # setting initial state
        level = Level.from_size(100, 50)
        self.set_level(level, "main")

        self.set_tilemap_paint_tool()

        # Must be after LayerSelector initialised
        self.menubar = SuperTuxMenuBar(self.gui, self)

        # Command line arguments, when game is run
        self.arguments = SuperTuxArguments()