1 #ifndef EDITOR_COMPONENTS_EDITMAP_HPP
2 #define EDITOR_COMPONENTS_EDITMAP_HPP
4 #include <BLIB/Cameras/2D/Camera2D.hpp>
5 #include <BLIB/Interfaces/GUI.hpp>
27 :
public bl::gui::Element
31 typedef std::shared_ptr<EditMap>
Ptr;
34 using PositionCb = std::function<void(
const sf::Vector2f& pixels,
const sf::Vector2i& tiles)>;
102 void newMap(
const std::string& filename,
const std::string&
name,
const std::string&
tileset,
103 unsigned int width,
unsigned int height);
160 void setLayerVisible(
unsigned int level,
unsigned int layer,
bool visible);
192 void resize(
unsigned int width,
unsigned int height,
bool modLeft,
bool modTop);
246 void setAmbientLight(std::uint8_t lower, std::uint8_t upper,
bool sunlight);
297 void shiftLayer(
unsigned int level,
unsigned int layer,
bool up);
305 void removeLayer(
unsigned int level,
unsigned int layer);
316 void setTile(
unsigned int level,
unsigned int layer,
const sf::Vector2i& position,
328 void setTileArea(
unsigned int level,
unsigned int layer,
const sf::IntRect& area,
340 void fillTile(
unsigned int level,
unsigned int layer,
const sf::Vector2i& position,
377 void setCatch(
unsigned int level,
const sf::Vector2i& position, std::uint8_t
id);
386 void setCatchArea(
unsigned int level,
const sf::IntRect& area, std::uint8_t
id);
395 void fillCatch(
unsigned int level,
const sf::Vector2i& position, std::uint8_t
id);
413 void addSpawn(
unsigned int level,
const sf::Vector2i& tile,
unsigned int id,
414 bl::tmap::Direction dir);
422 void rotateSpawn(
unsigned int level,
const sf::Vector2i& tile);
430 void removeSpawn(
unsigned int level,
const sf::Vector2i& position);
447 const sf::Vector2i& position)
const;
472 std::pair<core::item::Id, bool>
getItem(
unsigned int level,
const sf::Vector2i& position);
491 void removeItem(
unsigned int level,
const sf::Vector2i& position);
499 void setLight(
const sf::Vector2i& positionPixels,
unsigned int radius);
506 void removeLight(
const sf::Vector2i& positionPixels);
546 const std::vector<core::map::CatchRegion>&
catchRegions()
const;
589 void setTownTile(
const sf::Vector2i& position, std::uint8_t
id);
605 void fillTownTiles(
const sf::Vector2i& position, std::uint8_t
id);
632 using Ptr = std::shared_ptr<Action>;
634 virtual ~Action() =
default;
637 virtual const char* description()
const = 0;
639 std::vector<Action::Ptr> history;
640 unsigned int historyHead;
641 unsigned int saveHead;
642 void addAction(
const Action::Ptr& action);
644 struct EditCameraController :
public bl::cam::CameraController2D {
645 EditCameraController(
EditMap* owner);
646 virtual ~EditCameraController() =
default;
647 virtual void update(
float dt)
override;
648 void reset(
const sf::Vector2i&
size);
650 void updateDepthPlanes();
651 bl::cam::Camera2D& getCamera() {
return camera(); }
663 EditCameraController* camera;
664 bool controlsEnabled;
665 std::string savefile;
666 std::vector<bool> levelFilter;
667 std::vector<std::vector<bool>> layerFilter;
668 sf::IntRect selection;
670 struct SpawnGraphics {
671 bl::gfx::Sprite arrow;
675 struct CatchTileLayerGraphics {
676 bl::gfx::BatchedShapes2D shapeBatch;
677 bl::ctr::Vector2D<bl::gfx::BatchRectangle> tiles;
679 ~CatchTileLayerGraphics();
682 struct BatchSpriteOverlayLayer {
683 bl::gfx::BatchedSprites batch;
684 bl::ctr::Vector2D<bl::gfx::BatchSprite> tiles;
686 ~BatchSpriteOverlayLayer();
689 bl::gfx::Rectangle selectRect;
690 bl::ctr::Vector2D<bl::gfx::BatchRectangle> townSquares;
691 bl::gfx::BatchedShapes2D townSquareBatch;
692 bl::gfx::VertexBuffer2D grid;
693 std::unordered_map<unsigned int, SpawnGraphics> spawnSprites;
694 std::list<CatchTileLayerGraphics> catchTileOverlay;
695 std::optional<bl::util::ImageStitcher> colStitcher;
696 bl::rc::res::TextureRef collisionTilesTexture;
697 std::vector<glm::vec2> collisionTextureCoords;
698 std::list<BatchSpriteOverlayLayer> collisionTileOverlay;
699 std::optional<bl::util::ImageStitcher> levelTransitionsStitcher;
700 bl::rc::res::TextureRef levelTransitionsTexture;
701 std::vector<glm::vec2> levelTransitionsTextureCoords;
702 std::optional<BatchSpriteOverlayLayer> levelTransitionsOverlay;
703 std::list<bl::gfx::Rectangle> eventsOverlay;
704 sf::Color currentEventFillColor;
705 float eventColorTime;
708 std::atomic_bool exportInProgress;
710 unsigned int prevOverlayLevel;
711 sf::IntRect prevSelection;
712 glm::vec2 prevCenter;
714 std::uint8_t prevAmbientLightLow;
715 std::uint8_t prevAmbientLightHigh;
718 std::atomic_bool exportComplete;
720 std::string outputPath;
721 bl::rc::vk::RenderTexture::Handle renderTexture;
722 bl::cam::Camera2D* camera;
725 bl::rc::tfr::TextureExport* exportJob;
730 void exportRendering();
733 unsigned int overlayLevel;
734 unsigned int nextItemId;
735 bool setRenderTarget;
739 bool doLoad(
const std::string& file);
740 void stitchOverlayTextures();
741 bool editorActivate();
745 void updateSpawnRotation(std::uint16_t
id);
746 void updateAllDepths();
747 void updateLevelDepths(
unsigned int level);
748 void swapRenderLevels(
unsigned int i1,
unsigned int i2);
749 void updateLayerDepths(
unsigned int level,
unsigned int layer);
750 void swapRenderLayers(
unsigned int level,
unsigned int l1,
unsigned int l2);
751 void updateLayerVisibility(
unsigned int level,
unsigned int layer,
bool hide);
752 void updateCatchTileColor(
unsigned int level,
unsigned int x,
unsigned int y);
753 void updateTownTileColor(
unsigned int x,
unsigned int y);
754 void updateCollisionTileTexture(
unsigned int level,
unsigned int x,
unsigned int y);
755 void updateLevelTransitionTexture(
unsigned int x,
unsigned int y);
756 void addEventGfx(
unsigned int i);
757 void removeEventGfx(
unsigned int i);
758 sf::Color nextEventFillColor(
float dt);
760 virtual sf::Vector2f minimumRequisition()
const override;
761 virtual bl::gui::rdr::Component* doPrepareRender(bl::gui::rdr::Renderer& renderer)
override;
762 virtual bool handleScroll(
const bl::gui::Event& scroll)
override;
763 virtual void update(
float dt)
override;
772 class SetYSortLayerAction;
773 class SetTopLayerAction;
778 class RemoveLevelAction;
Id
Represents an item in its simplist form.
Collision
The different types of collisions in maps.
LevelTransition
Represents a level transition in a map. Level transitions are applied when an entity moves either ont...
All classes and functionality used for implementing the game editor.
Represents a class of catchable peoplemon.
Represents a character to be spawned into a map on load.
Represents an event in a Map. A script that is run on a trigger within a given region.
The primary map class that represents a usable map in the game.
bl::resource::Ref< Tileset > tileset
system::Systems * systems
const std::string & name() const
Returns the name of the map.
Basic struct representing a spawn in a Map.
Represents a town, route, or region within a map. Maps may have many towns. Individual tiles are asso...
Owns all primary systems and a reference to the engine.
Wrapper over the core::Map class that is directly usable in a bl::gui::GUI.
const std::string & currentFile() const
Returns the current file the map is saving to.
void removeLayer(unsigned int level, unsigned int layer)
Deletes the given layer.
void removeTown(std::uint8_t i)
Removes a town.
bool spawnIdUnused(unsigned int id) const
Tells whether or not the given id is in use.
bool editorLoad(const std::string &filename)
Loads the map contents from the given file.
void resize(unsigned int width, unsigned int height, bool modLeft, bool modTop)
void setTownTile(const sf::Vector2i &position, std::uint8_t id)
Sets the town tile at the given position.
std::function< void(const sf::Vector2f &pixels, const sf::Vector2i &tiles)> PositionCb
Called when the map is clicked.
void createEvent(const core::map::Event &event)
Creates a new map event.
const core::map::Event * getEvent(const sf::Vector2i &position)
Returns a pointer to an event that overlaps the given position.
std::function< void()> ActionCb
Called on various event types.
const char * redoDescription() const
Returns the description of what action will be redone if redo is called.
virtual ~EditMap()
Destroy the Edit Map object.
void setTile(unsigned int level, unsigned int layer, const sf::Vector2i &position, core::map::Tile::IdType id, bool isAnim)
Sets a single tile.
void showGrid(bool show)
Set whether or not to render a grid between tiles.
void setWeather(core::map::Weather::Type weather)
Set the weather in the map.
bool unsavedChanges() const
Returns whether or not the map has been updated since last being saved.
void setPlaylist(const std::string &playlist)
Sets the playlist of the map.
std::pair< core::item::Id, bool > getItem(unsigned int level, const sf::Vector2i &position)
Returns spawn info the item at the given position, if any.
void appendTopLayer(unsigned int level)
Creates a new (empty) top layer.
void editCatchRegion(std::uint8_t index, const core::map::CatchRegion &zone)
Modifies the catch region at the given index.
bool editorSave()
Saves the map to the file it was loaded from or created with.
void setControlsEnabled(bool enabled)
Enables or disables the map camera and click controls.
void removeNpcSpawn(const core::map::CharacterSpawn *spawn)
Removes a character spawn.
void removeAllTiles(core::map::Tile::IdType id, bool isAnim)
Removes all tiles that reference the given id in the tileset. This should be called before removing a...
const std::string & getOnEnterScript() const
Get the OnEnter script.
void shiftLevel(unsigned int level, bool up)
Shifts the given level up or down.
void removeSpawn(unsigned int level, const sf::Vector2i &position)
Removes the spawn at the given position.
void addTown()
Adds a town.
void appendYsortLayer(unsigned int level)
Creates a new (empty) y-sort layer.
void removeLight(const sf::Vector2i &positionPixels)
Removes the light near the given position if one is there.
void setOnEnterScript(const std::string &script)
Set the OnEnter script.
void editNpcSpawn(const core::map::CharacterSpawn *orig, const core::map::CharacterSpawn &spawn)
Edits an existing character spawn.
void removeEvent(const core::map::Event *event)
Deletes the given event.
void setOnExitScript(const std::string &script)
Set the OnExit script.
const std::vector< core::map::CatchRegion > & catchRegions() const
Returns a reference to all catch regions.
static Ptr create(const PositionCb &clickCb, const PositionCb &moveCb, const ActionCb &actionCb, const ActionCb &syncCb, core::system::Systems &systems)
Creates a new EditMap.
void addNpcSpawn(const core::map::CharacterSpawn &spawn)
Adds a character spawn to the map.
void appendBottomLayer(unsigned int level)
Creates a new (empty) bottom layer.
void setLevelVisible(unsigned int level, bool visible)
Shows or hides the given level.
void setLayerVisible(unsigned int level, unsigned int layer, bool visible)
Shows or hides the given layer.
void setCatchArea(unsigned int level, const sf::IntRect &area, std::uint8_t id)
Sets a range of catch tiles to a single value.
void setCollisionArea(unsigned int level, const sf::IntRect &area, core::map::Collision id)
Sets a range of collision tiles to a single value.
void redo()
Reapplies the next action in the edit history.
void editEvent(const core::map::Event *orig, const core::map::Event &event)
Alters the value of the given event.
void setName(const std::string &name)
Set the name of the map.
const char * undoDescription() const
Returns the description of what action will be undone if undo is called.
void setLight(const sf::Vector2i &positionPixels, unsigned int radius)
Spawn or modify the light near the given position to the new size.
void setLevelTileArea(const sf::IntRect &area, core::map::LevelTransition lt)
Sets a selection of level tiles.
void removeLevel(unsigned int level)
Removes the given level.
void rotateSpawn(unsigned int level, const sf::Vector2i &tile)
Rotates a player spawn.
std::shared_ptr< EditMap > Ptr
Pointer to an EditMap.
RenderOverlay
Optional render overlays depending on editor state.
@ Collisions
Renders collisions for the current level.
@ Towns
Renders colored tiles to indicate towns/routes.
@ LevelTransitions
Renders level transitions.
@ CatchTiles
Renders catch tiles for the current level.
@ Events
Renders events in the map.
@ Spawns
Renders spawns in the map.
void addSpawn(unsigned int level, const sf::Vector2i &tile, unsigned int id, bl::tmap::Direction dir)
Adds a new player spawn to the map.
void addCatchRegion()
Adds a new catch region to the map.
void setTileArea(unsigned int level, unsigned int layer, const sf::IntRect &area, core::map::Tile::IdType id, bool isAnim)
Sets a range of tiles to a given value. Tries to avoid overcrowding for large tiles.
void fillTownTiles(const sf::Vector2i &position, std::uint8_t id)
Performs a bucket fill of town tiles from the given position.
void staticRender(const RenderMapWindow ¶ms)
Renders the map contents.
void setTownTileArea(const sf::IntRect &area, std::uint8_t id)
Sets a region of town tiles to the given town.
void fillTile(unsigned int level, unsigned int layer, const sf::Vector2i &position, core::map::Tile::IdType id, bool isAnim)
Performs a bucket fill of tiles starting from the given position.
void setRenderOverlay(RenderOverlay overlay, unsigned int level)
Sets which overlay gets rendered on top of the map.
const core::map::CharacterSpawn * getNpcSpawn(unsigned int level, const sf::Vector2i &position) const
Get the Npc Spawn at the given position, if any.
void showSelection(const sf::IntRect &selection)
Sets the tile selection to render. Set width or height to 0 to hide. Set width or height to negative ...
void newMap(const std::string &filename, const std::string &name, const std::string &tileset, unsigned int width, unsigned int height)
Clears the current map and creates a new map with the given parameters.
void editTown(std::uint8_t i, const core::map::Town &town)
Modifies an existing town.
void fillCollision(unsigned int level, const sf::Vector2i &position, core::map::Collision id)
Performs a bucket fill of collisions from the given starting position.
void shiftLayer(unsigned int level, unsigned int layer, bool up)
Shifts a layer up or down in the render order. This will also move layers between bottom,...
void addOrEditItem(unsigned int level, const sf::Vector2i &position, core::item::Id item, bool visible)
Spawns or modifies an item at the given position and level.
void removeCatchRegion(std::uint8_t index)
Removes the catch region at the given index.
void removeItem(unsigned int level, const sf::Vector2i &position)
Removes the item from the given position if one is present.
void setAmbientLight(std::uint8_t lower, std::uint8_t upper, bool sunlight)
Set the maps default ambient light settings.
void setCatch(unsigned int level, const sf::Vector2i &position, std::uint8_t id)
Sets a single catch tile.
void fillCatch(unsigned int level, const sf::Vector2i &position, std::uint8_t id)
Performs a bucket fill of catch tiles from the given position.
void appendLevel()
Creates a new level.
const std::string & getOnExitScript() const
Get the OnExit script.
void setLevelTile(const sf::Vector2i &position, core::map::LevelTransition lt)
Sets the given level tile.
void setCollision(unsigned int level, const sf::Vector2i &position, core::map::Collision id)
Sets a single collision tile.
void undo()
Undoes the previous action in the edit history.
GUI renderer component for the map itself.
Options window to help trigger map renderings.
Page for map editing. Tiles, levels, events, NPC's, weather, lighting, everything.
Subpage for creating, editing, deleting, and placing towns in maps.