Class StarpointEditor

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Runnable

    public class StarpointEditor
    extends Game
    implements java.lang.Runnable
    The Starpoint level editor. Extends Game for directly providing test mode.
    See Also:
    Serialized Form
    • Field Detail

      • PLANET_COUNT

        public static final int PLANET_COUNT
        Number of flash animation planets.
        See Also:
        Constant Field Values
      • itemCategories

        public java.lang.String[] itemCategories
        Categories for item selection.
      • itemClasses

        public static java.lang.String[][] itemClasses
        Item classes.
      • shopitemClasses

        public static java.lang.String[] shopitemClasses
        Item classes available in shop.
      • flashitemClasses

        public static java.lang.String[] flashitemClasses
        Item classes available in FlashAnimations (for game entry).
      • FLASHITEM_COUNT

        public static final int FLASHITEM_COUNT
        Number of possible initial items in FlashAnimations.
      • figures

        public static java.lang.String[] figures
        Enemy figures.
      • soundNames

        public static java.lang.String[] soundNames
      • figureList

        public static Figure[] figureList
        Array of figures for editing purposes.
      • fogs

        public static java.lang.String[] fogs
        Array of fog classes.
      • itemList

        protected Item[][] itemList
        Array of items and item categories for editing purposes.
      • itemMap

        protected java.util.HashMap<java.lang.String,​Item> itemMap
        Maps item classes to the corresponding editing item.
      • figureMap

        protected java.util.HashMap<java.lang.String,​Figure> figureMap
        Maps figure classes to corresponding editing figure.
      • exitUpdateThread

        protected boolean exitUpdateThread
        Flag for keeping updater thread running.
      • clickMode

        protected EditorClickMode clickMode
        Current click mode (edit or mark).
      • levelChangeListener

        protected java.util.LinkedList<LevelChangeListener> levelChangeListener
        List of levelchange event listeners.
      • editingItem

        protected java.lang.String editingItem
        Currently selected item.
      • editingEnemy

        protected java.lang.String editingEnemy
        Currently selected enemy.
      • editingFog

        protected java.lang.String editingFog
        Currently selected for.
      • focussedPainter

        protected Painter focussedPainter
        Currently focussed painter.
      • selectedPoint

        protected Point selectedPoint
        The currently selected point.
      • selectedThing

        protected Thing selectedThing
        The currently selected thing.
      • planetNames

        public java.lang.String[] planetNames
        Planet names.
      • HELPTEXTS

        protected final java.lang.String[] HELPTEXTS
    • Constructor Detail

      • StarpointEditor

        public StarpointEditor​(StarpointController controller,
                               GameInfo gameInfo)
        Creates a new StarpointEditor.
        Parameters:
        controller - The Controller.
        gameInfo - The GameInfo.
    • Method Detail

      • createState

        public GameState createState()
        Creates a GameState object representing the current state of the game.
        Overrides:
        createState in class Game
        Returns:
        The GameState.
      • getLevelInputStream

        protected java.io.InputStream getLevelInputStream()
        Gets the InputStream for reading level information.
        Overrides:
        getLevelInputStream in class Game
        Returns:
        A resource input string from the controller to the game infos ini file.
      • createFigures

        public void createFigures()
        Creates the editor figures.
      • createFogs

        public void createFogs()
        Initializes the fog classes.
      • initializeLevelSet

        public void initializeLevelSet()
        Initializes the LevelSet from the Level ini file. Replaces the GameInfos level ini file by either the first own saved level set, or starts in level set selection mode, if more than one exist.
        Overrides:
        initializeLevelSet in class Game
      • getLevelSetManager

        public FileManager getLevelSetManager()
        Gets the level set manager.
        Returns:
        The LevelSet Manager
      • getLevelResourceName

        protected java.lang.String getLevelResourceName()
        Gets the resource name for the LevelIni-File.
        Overrides:
        getLevelResourceName in class Game
        Returns:
        "customLevel.ini".
      • selectPreviousLevel

        public void selectPreviousLevel()
        Steps back to the previous level.
        Overrides:
        selectPreviousLevel in class Game
      • selectNextLevel

        public void selectNextLevel()
        Steps fore to the previous level.
        Overrides:
        selectNextLevel in class Game
      • selectLevel

        public void selectLevel​(int n)
        Steps to the level.
        Parameters:
        n - The level index.
      • switchToNextLevel

        protected boolean switchToNextLevel()
        Switches to the next level. If the last level has been reached, currentLevel is set to null and false is returned
        Overrides:
        switchToNextLevel in class Game
        Returns:
        true, if there is a next level.
      • selectLevelInternal

        protected void selectLevelInternal()
        Internally handles level selection.
      • createAndPlaceEnemyFigures

        protected void createAndPlaceEnemyFigures​(LevelInfo li,
                                                  java.util.List<Figure> figures,
                                                  Field field,
                                                  java.util.List<java.lang.Integer> ids)
        Initializes the enemy figures for a new level and places tham.
        Overrides:
        createAndPlaceEnemyFigures in class Game
        Parameters:
        li - The LevelInfo.
        figures - The list of figures to add the enemies to.
        field - The field.
        ids - A list of already placed figures ids.
      • reinitialize

        public void reinitialize()
        Reinitializes the Editor level
      • getLevelInfo

        public LevelInfo getLevelInfo()
        Gets the (normal) current LevelInfo. If a FlashAnimation or shop is currently edited, it returns the info of the last selected normal level.
        Returns:
        The current orr last selected LevelInfo.
      • getFlashAnimationInfo

        public FlashAnimationInfo getFlashAnimationInfo()
        Gets the current FlashAnimationInfo. If no FlashAnimation is currently edited, it returns null.
        Returns:
        The current FlashAnimation or null.
      • getShopInfo

        public ShopInfo getShopInfo()
        Gets the current ShopInfo. If no ShopInfo is currently edited, it returns null.
        Returns:
        The current ShopInfo or null.
      • run

        public void run()
        Frequently updates the field if a normal level is edited.
        Specified by:
        run in interface java.lang.Runnable
      • getEditingMode

        public EditingMode getEditingMode()
        Gets the current editing mode.
        Returns:
        The editing mode.
      • setEditingMode

        public void setEditingMode​(EditingMode editingMode)
        Sets the current editing mode.
        Parameters:
        editingMode - The editing mode.
      • pointClicked

        public void pointClicked​(Point p,
                                 boolean mouse1)
        Handles a mouse click on a field editor point. Either colors the point, or places an item, enemy or fog. if mouse-flag is false, the point color is randomized, or thing is removed from point.
        Parameters:
        p - The point.
        mouse1 - Flag, if first mouse button was clicked.
      • setEditingColor

        public void setEditingColor​(int editingColor)
      • setEditingItem

        public void setEditingItem​(java.lang.String editingItem)
      • setSelectedThing

        public void setSelectedThing​(Item item)
      • setEditingFog

        public void setEditingFog​(java.lang.String editingFog)
      • addLevelChangeListener

        public void addLevelChangeListener​(LevelChangeListener listener)
      • removeLevelChangeListener

        public void removeLevelChangeListener​(LevelChangeListener listener)
      • getFocussedPainter

        public Painter getFocussedPainter()
        Gets the currently focussed editor painter.
        Returns:
        The focussed painter.
      • setFocussedPainter

        public void setFocussedPainter​(Painter focussedPainter)
        Sets the currently focussed editor painter.
        Parameters:
        focussedPainter - The focussed painter.
      • resetLevel

        public void resetLevel()
        Resets the current level or shop or animation to the state when starting editing it.
      • hasFixedItem

        public boolean hasFixedItem​(PointState p)
        Checks, if the point has a fixed item on it.
        Parameters:
        p - The point.
        Returns:
        true, if point contains fixed item.
      • hasFixedItem

        public boolean hasFixedItem​(Point p)
        Checks, if the point has a fixed item on it.
        Parameters:
        p - The point.
        Returns:
        true, if point contains fixed item.
      • findItemInfo

        public ItemInfo findItemInfo​(Point p)
        Finds the item info for an item on the given point.
        Parameters:
        p - The point.
        Returns:
        The item info or null, if no enemy on this point.
      • findItemInfo

        public ItemInfo findItemInfo​(PointState p)
        Finds the item info for an item on the given point.
        Parameters:
        p - The point.
        Returns:
        The item info or null, if no enemy on this point.
      • findEnemyInfo

        public EnemyInfo findEnemyInfo​(Point p)
        Finds the enemy info for an enemy on the given point.
        Parameters:
        p - The point.
        Returns:
        The enemy info or null, if no enemy on this point.
      • quitEditor

        public void quitEditor()
        Quits the editor (stops the update timer).
      • restart

        public StarpointEditor restart()
        Restarts the editor (restarts the update timer).
        Returns:
        This editor.
      • getLevelSet

        public LevelSet getLevelSet()
        Gets the LevelSet.
        Overrides:
        getLevelSet in class Game
        Returns:
        The LevelSet.
      • deleteLevel

        public void deleteLevel()
        Deletes the currently selected level.
      • insertNewLevel

        public void insertNewLevel()
        Inserts a new level.
      • insertCopyLevel

        public void insertCopyLevel()
        Inserts a copy of the current level or shop.
      • insertShop

        public void insertShop()
        Inserts a new shop.
      • insertFlashAnimation

        public void insertFlashAnimation()
        Inserts a new FlashAnimation (by copying the initialization info from the previous one).
      • insertLevelInfo

        protected void insertLevelInfo​(AbstractLevelInfo levelInfo)
        Inserts a new LevelInfo behind the currently selected and selects it.
        Parameters:
        levelInfo - The LevelInfo to insert.
      • fireLevelSetChangedEvent

        protected void fireLevelSetChangedEvent()
        Fires a level set change event.
      • setSelectedThingProperties

        public void setSelectedThingProperties​(int energy,
                                               int maxEnergy)
        Sets energy and maxenergy for the selected thing.
        Parameters:
        energy - The energy.
        maxEnergy - The max energy.
      • findRandomItemInfo

        public ItemInfo findRandomItemInfo​(java.lang.String simpleName)
        Returns the random item info for the given classname in the currently selected LevelInfo.
        Parameters:
        simpleName - The Classname.
        Returns:
        The random ItemInfo for the classname, or null, if item class is not in the list of random items.
      • getEditingEnemy

        public java.lang.String getEditingEnemy()
        Gets the selected Enemy.
        Returns:
        The Enemy.
      • setEditingEnemy

        public void setEditingEnemy​(java.lang.String editingEnemy)
        Sets the selected Enemy.
        Parameters:
        editingEnemy - The Enemy.
      • getClickMode

        public EditorClickMode getClickMode()
        Gets the current click mode.
        Returns:
        The ClickMode.
      • setClickMode

        public void setClickMode​(EditorClickMode clickMode)
        Sets the ClickMode.
        Parameters:
        clickMode - The new click mode.
      • getHelpText

        public java.lang.String getHelpText()
        Returns:
        the helpIndex
      • isShowingHelp

        public boolean isShowingHelp()
        Returns:
        the helpIndex
      • isWaitingForConfirm

        public boolean isWaitingForConfirm()
        Checks if editor is waiting for confirm answer.
        Returns:
        the helpIndex
      • showHelp

        public void showHelp()
        Shows help or switches to the next help page.
      • getSelectedThing

        public Thing getSelectedThing()
        Gets the currently selected Thing. Might be either a fixed item on the field or a random item.
        Returns:
        The currently selected Thing.
      • getSelectedShopItem

        public ShopItemInfo getSelectedShopItem()
        Gets the currently selected ShopItemInfo.
        Returns:
        The currently selected ShopItemInfo.
      • setSelectedShopItem

        public void setSelectedShopItem​(ShopItemInfo shopItem)
      • getSelectedPoint

        public Point getSelectedPoint()
        Gets the currently selected point.
        Returns:
        The currently selected point.
      • setSelectedPoint

        public void setSelectedPoint​(Point selectedPoint)
        Sets the selected point (and as well selects anything on this point.)
        Parameters:
        selectedPoint - The point to select.
      • isShowingThingProps

        public boolean isShowingThingProps()
        Checks, if a thing properties of selected thing or shop item should be shown.
        Returns:
        true, if a thing properties of selected thing or shop item should be shown.
      • getItemList

        public Item[][] getItemList()
        Gets the array of shop items.
        Returns:
        The item array (first index is category).
      • getItemForClassname

        public Item getItemForClassname​(java.lang.String className)
        Gets the item for the given class name.
        Parameters:
        className - Item class.
        Returns:
        The item.
      • getFlashAnimationItem

        public Item getFlashAnimationItem​(int index)
        Gets the flash animation item for the given index.
        Parameters:
        index - Item index.
        Returns:
        The item.
      • getShopItemForClassname

        public Item getShopItemForClassname​(java.lang.String className)
        Gets the shop item for the given class name.
        Parameters:
        className - Item class.
        Returns:
        The item.
      • getOrCreateShopItem

        public ShopItemInfo getOrCreateShopItem​(int itemIndex)
        Gets or creates a new ShopItemInfo for the given item index (referring to StarpointEditor.shopItems).
        Parameters:
        itemIndex - The index.
        Returns:
        The ShopItemInfo.
      • removeShopInfoItem

        public void removeShopInfoItem​(int itemIndex)
      • testGame

        public void testGame()
        Starts a test game with the currently selected level.
      • initializeShop

        protected Shop initializeShop​(ShopInfo si)
        (Re-)Initializes the shop with the given ShopInfo.
        Overrides:
        initializeShop in class Game
        Parameters:
        si - The ShopInfo.
        Returns:
        The Shop.
      • initializeFlashAnimationInfo

        protected void initializeFlashAnimationInfo​(FlashAnimationInfo currentLevelInfo)
        Initializes the flash animation with the given FlashAnimationInfo.
        Overrides:
        initializeFlashAnimationInfo in class Game
        Parameters:
        currentLevelInfo - The FlashAnimationInfo.
      • initializePlayerLists

        protected void initializePlayerLists()
      • switchLevelAfterLevelOver

        protected void switchLevelAfterLevelOver()
        Switches to the next levels flash effect after all level over messages are shown. Determines whether to show replay first. Otherwise, either the next level is initialized, or the game finish animation is started, if the last level is over.
        Overrides:
        switchLevelAfterLevelOver in class Game
      • saveLevelSet

        public boolean saveLevelSet()
        Saves the current state of the edited level set to the file "customLevel.ini".
        Returns:
        true, if saving was successful.
      • findSoundIndex

        public int findSoundIndex​(java.lang.String search)
        Finds the search string (or ones beginning with this string) index in the soundNames array.
        Parameters:
        search - The search string.
        Returns:
        The first index in the array or -1, if not contained.
      • setSelectedShopItemProperties

        public void setSelectedShopItemProperties​(int price,
                                                  int energy,
                                                  int maxEnergy,
                                                  int maxCond)
        Applies the properties to the currently selected shop item (and to the currently edited shop info.).
        Parameters:
        price - The Price.
        energy - The Energy.
        maxEnergy - The MaxEnergy.
        maxCond - The item max condition.
      • getSelectedFlashImageIndex

        public int getSelectedFlashImageIndex()
        Gets the selected flash image index.
        Returns:
        the selectedFlashImageIndex
      • setSelectedFlashImageIndex

        public void setSelectedFlashImageIndex​(int selectedFlashImageIndex)
        Sets the selected flash image index.
        Parameters:
        selectedFlashImageIndex - The selectedFlashImageIndex to set.
      • addSelectedFlashImageIndex

        public FlashInfo addSelectedFlashImageIndex​(int xpos,
                                                    int ypos,
                                                    double factor)
        Adds the selected flash image to the FlashAnimationInfo.
        Parameters:
        xpos - The x position to place to.
        ypos - The y position to place to.
        factor - Scaling factor.
        Returns:
        The created FlashInfo.
      • removeFlashImageOrText

        public boolean removeFlashImageOrText​(int xpos,
                                              int ypos)
        Removes a flash image or text at the given position from the FlashAnimationInfo.
        Parameters:
        xpos - The x position to remove from.
        ypos - The y position to remove from.
        Returns:
        true, if there is an image to remove, false otherwise.
      • findFlashInfo

        public FlashInfo findFlashInfo​(int xpos,
                                       int ypos)
        Searches for a planet image or text at the given coordinates.
        Parameters:
        xpos - X.
        ypos - Y.
        Returns:
        The FlashInfo for the planet or text or null, if none found.
      • findPlanetFlashInfo

        public FlashInfo findPlanetFlashInfo​(int xpos,
                                             int ypos)
        Searches for a planet image at the given coordinates.
        Parameters:
        xpos - X.
        ypos - Y.
        Returns:
        The FlashInfo for the planet or null, if none found.
      • findTextFlashInfo

        public FlashInfo findTextFlashInfo​(int xpos,
                                           int ypos)
        Searches for a text at the given coordinates.
        Parameters:
        xpos - X.
        ypos - Y.
        Returns:
        The FlashInfo for the planet or null, if none found.
      • getPlanetImage

        public java.lang.String getPlanetImage​(int index)
        Gets the planet image for the given index.
        Parameters:
        index - The index.
        Returns:
        The planet image.
      • createNewLevelSet

        public void createNewLevelSet()
        Creates a new level set.
      • addFlashAnimationText

        public FlashInfo addFlashAnimationText​(java.lang.String text,
                                               int xpos,
                                               int ypos,
                                               double factor,
                                               int color)
        Adds the given text to the FlashAnimationInfo.
        Parameters:
        text - The text.
        xpos - The x position to place to.
        ypos - The y position to place to.
        factor - Scaling factor.
        color - Text color.
        Returns:
        The created FlashInfo.
      • startLevelSetSelection

        public void startLevelSetSelection()
        Starts selection of saved level sets.
      • isSelectingLevelSet

        public boolean isSelectingLevelSet()
        Checks, if level set selection is active.
        Returns:
        true, if selecting level set.
      • quitLevelSetSelection

        public void quitLevelSetSelection()
        Quits the levelset selection.
      • loadLevelSet

        public void loadLevelSet​(java.lang.String filename,
                                 java.lang.String info)
        Loads a level set from the given file and quits the level selection mode.
        Parameters:
        filename - LevelSet file.
        info - LevelSet info.
      • isFlashTextInfo

        public boolean isFlashTextInfo​(FlashInfo selectedFlashInfo)
        Checks, if the given FlashInfo is in the list of text infos of the current FlashAnimationInfo.
        Parameters:
        selectedFlashInfo - The FlashInfo.
        Returns:
        true, if the given FlashInfo is in the list of text infos of the current FlashAnimationInfo.
      • getEditingColor

        public int getEditingColor()
        Returns:
        the editingColor
      • getEditingFog

        public java.lang.String getEditingFog()
      • getEditingItem

        public java.lang.String getEditingItem()
      • getSelectedFlashAnimationItem

        public ItemInfo getSelectedFlashAnimationItem()
      • setSelectedFlashAnimationItem

        public void setSelectedFlashAnimationItem​(ItemInfo i)
      • setSelectedFlashAnimationItemProperties

        public void setSelectedFlashAnimationItemProperties​(int energy,
                                                            int maxEnergy)
      • isRandomPoint

        public boolean isRandomPoint​(PointState p)
      • isInitialized

        public boolean isInitialized()
        Returns:
        the initialized
      • confirm

        public void confirm()
        Call to confirm confirm question
      • unconfirm

        public void unconfirm()
        Call to cancel confirm question
      • isHasUnsavedChanges

        public boolean isHasUnsavedChanges()
        Returns:
        the hasUnsavedChanges
      • setUnsavedChanges

        public void setUnsavedChanges()
        Sets unsaved changes to true.