13 constexpr
float FlashOn = 0.3f;
14 constexpr
float FlashOff = 0.4f;
18 return Ptr{
new FlyMap(s, up)};
22 :
State(s,
bl::engine::StateMask::Menu)
24 , selected(std::numeric_limits<unsigned int>::max()) {
25 const auto& joinPath = bl::util::FileUtil::joinPath;
27 auto& tp = s.
engine().renderer().texturePool();
29 townMenu.create(s.
engine(),
30 s.
engine().renderer().getObserver(),
31 bl::menu::ArrowSelector::create(8.f, sf::Color::Black));
33 mapTxtr = tp.getOrLoadTexture(joinPath(ImgPath,
"FlyMap/background.png"));
34 map.create(s.
engine(), mapTxtr);
36 townTxtr = tp.getOrLoadTexture(joinPath(ImgPath,
"FlyMap/town.png"));
37 towns.create(s.
engine(), townTxtr);
40 cursorTxtr = tp.getOrLoadTexture(joinPath(ImgPath,
"FlyMap/cursor.png"));
41 cursor.create(s.
engine(), cursorTxtr);
42 cursor.getTransform().setOrigin(cursorTxtr->size() * 0.5f);
43 cursor.setParent(map);
49 const glm::vec2 ms(mapTxtr->size());
50 const std::string path =
54 playerTxtr = tp.getOrLoadTexture(joinPath(ImgPath, path));
55 player.create(s.
engine(), playerTxtr);
56 player.getTransform().setOrigin(playerTxtr->size() * 0.5f);
57 player.getTransform().setPosition(pp.x / ws.x * ms.x, pp.y / ws.y * ms.y);
58 player.setParent(map);
61 panelTxtr = tp.getOrLoadTexture(joinPath(ImgPath,
"FlyMap/sidePanel.png"));
62 panel.create(s.
engine(), panelTxtr);
63 panel.getTransform().setPosition(mapTxtr->size().x, 0.f);
66 townName.getTransform().setPosition(100.f, 375.f);
67 townName.wordWrap(180.f);
68 townName.setParent(panel);
71 townDesc.wordWrap(180.f);
72 townDesc.getTransform().setPosition(10.f, 415.f);
73 townDesc.setParent(panel);
76 bl::menu::Item::Ptr back =
78 back->getSignal(bl::menu::Item::Selected).willAlwaysCall(std::bind(&FlyMap::clearHover,
this));
79 back->getSignal(bl::menu::Item::Activated).willAlwaysCall(std::bind(&FlyMap::close,
this));
80 townMenu.setRootItem(back);
82 bl::menu::Item* prev = back.get();
83 bl::gfx::BatchSprite townSprite;
84 townSprite.disableAutoCommit(
true);
85 townSprite.getLocalTransform().setOrigin(townTxtr->size() * 0.5f);
86 const sf::FloatRect src(0.f, 0.f, townTxtr->size().x, townTxtr->size().y);
89 if (visited.find(t.name) != visited.end() && t.mapPos != sf::Vector2i{} && t.pcSpawn > 0) {
90 bl::menu::Item::Ptr it = bl::menu::TextItem::create(
92 it->getSignal(bl::menu::Item::Selected)
93 .willAlwaysCall(std::bind(&FlyMap::hoverTown,
this, i));
94 it->getSignal(bl::menu::Item::Activated)
95 .willAlwaysCall(std::bind(&FlyMap::selectTown,
this, i));
96 townMenu.addItem(it, prev, bl::menu::Item::Top);
101 townSprite.create(s.
engine(), towns, src);
102 townSprite.getLocalTransform().setPosition(t.mapPos.x, t.mapPos.y);
105 if (prev != back.get()) { townMenu.attachExisting(prev, back.get(), bl::menu::Item::Bottom); }
106 townMenu.setSelectedItem(prev);
107 townMenu.setPosition({8.f, 4.f});
108 townMenu.setMaximumSize({200.f, 316.f});
109 inputDriver.drive(&townMenu);
115 systems.
engine().inputSystem().getActor().addListener(*
this);
117 auto overlay = engine.renderer().getObserver().pushScene<bl::rc::Overlay>();
118 map.addToScene(overlay, bl::rc::UpdateSpeed::Static);
119 towns.addToScene(overlay, bl::rc::UpdateSpeed::Static);
120 if (player.entity() != bl::ecs::InvalidEntity) {
121 player.addToScene(overlay, bl::rc::UpdateSpeed::Static);
123 cursor.addToScene(overlay, bl::rc::UpdateSpeed::Static);
124 panel.addToScene(overlay, bl::rc::UpdateSpeed::Static);
125 townName.addToScene(overlay, bl::rc::UpdateSpeed::Static);
126 townDesc.addToScene(overlay, bl::rc::UpdateSpeed::Static);
127 townMenu.addToOverlay(panel.entity());
132 systems.
engine().inputSystem().getActor().removeListener(*
this);
133 engine.renderer().getObserver().popScene();
138 bool FlyMap::observe(
const bl::input::Actor&,
unsigned int activatedControl,
139 bl::input::DispatchType,
bool fromEvent) {
141 else { inputDriver.sendControl(activatedControl, fromEvent); }
145 void FlyMap::clearHover() {
146 townName.getSection().setString(
"");
147 townDesc.getSection().setString(
"Select a location to fly to.");
148 cursor.stopFlashing();
149 cursor.setHidden(
true);
152 void FlyMap::hoverTown(
unsigned int i) {
154 townName.getSection().setString(t.name);
155 townDesc.getSection().setString(t.description);
156 cursor.getTransform().setPosition(t.mapPos.x, t.mapPos.y);
157 cursor.setHidden(
false);
158 cursor.flash(FlashOn, FlashOff);
159 townName.getTransform().setOrigin(townName.getLocalBounds().width * 0.5f,
160 townName.getLocalBounds().height * 0.5f);
163 void FlyMap::selectTown(
unsigned int i) {
168 "Fly to " + t.name +
"?",
170 std::bind(&FlyMap::onFlyChoice,
this, std::placeholders::_1, t));
174 "the right item... one day.",
175 std::bind(&FlyMap::messageDone,
this));
180 std::bind(&FlyMap::messageDone,
this));
184 void FlyMap::onFlyChoice(
const std::string& c,
const core::map::Town& town) {
192 std::bind(&FlyMap::messageDone,
this));
197 void FlyMap::messageDone() {}
Parent namespace for all functionality unique to the game.
bool canFlyFromHere() const
Returns whether or not the player can fly from this map.
static const std::vector< Town > & FlyMapTowns()
Returns the set of towns that can be flown to.
sf::Vector2f sizePixels() const
Returns the size of the map in pixels.
Represents a town, route, or region within a map. Maps may have many towns. Individual tiles are asso...
bool hasItem(item::Id item) const
Returns true if at least one of the given items is owned.
std::unordered_set< std::string > visitedTowns
static const sf::VulkanFont & MenuFont()
static int PixelsPerTile()
static const std::string & MenuImagePath()
bool startFlight(unsigned int destSpawn)
Starts flight to the given spawn.
void displayMessage(const std::string &message, const Callback &cb=[](const std::string &) {})
Displays a message in the HUD textbox. Messages are queued in order that they arrive.
void promptUser(const std::string &prompt, const std::vector< std::string > &choices, const Callback &cb)
Asks the player a question through the HUD.
player::State & state()
Returns the state of the player.
const bl::tmap::Position & position() const
Returns the current position of the player.
Owns all primary systems and a reference to the engine.
const bl::engine::Engine & engine() const
Const accessor for the Engine.
Player & player()
Returns the player system.
Flight & flight()
Returns the flight system.
HUD & hud()
Returns the HUD.
World & world()
Modifiable accessor for the world system.
map::Map & activeMap()
Returns a reference to the active map.
Engine state for the fly map.
virtual void update(bl::engine::Engine &engine, float dt, float) override
Updates the state and menus and whatnot.
virtual void deactivate(bl::engine::Engine &engine) override
Deactivates the state.
virtual const char * name() const override
Returns "FlyMap".
virtual void activate(bl::engine::Engine &engine) override
Activates the state.
static bl::engine::State::Ptr create(core::system::Systems &systems, bool &unpause)
Creates the fly map state.
Parent to all game states. Provides some commonly required data like core game systems.
core::system::Systems & systems