49 addMouseListener(
this);
83 gcnGraphics->setColor(gcn::Color(64, 64, 64));
84 gcnGraphics->fillRectangle(
85 gcn::Rectangle(0, 0, getWidth(), getHeight()));
96 const int player_x = (int) playerPos.
x - midTileX;
97 const int player_y = (int) playerPos.
y - midTileY;
99 const float ticks =
Time::deltaTimeMs() /
static_cast<float>(MILLISECONDS_IN_A_TICK);
100 float scrollFraction = 1.0f;
162 if ( mapWidthPixels < graphics->getWidth()
163 || mapHeightPixels < graphics->getHeight())
165 gcnGraphics->setColor(gcn::Color(0, 0, 0));
166 gcnGraphics->fillRectangle(
167 gcn::Rectangle(0, 0, getWidth(), getHeight()));
182 const float strength = std::pow(effect.
decay, effect.
age);
183 const float phase = std::sin(effect.
age);
186 scrollX += strength * phase * effect.
x;
187 scrollY += strength * phase * effect.
y;
217 auto *being =
static_cast<Being*
>(actor);
226 auto *being =
dynamic_cast<Being*
>(actor);
230 const Vector &beingPos = being->getPosition();
231 std::string idString =
toString(being->getId());
233 beingPos.
x - scrollX,
234 beingPos.
y - scrollY,
235 gcn::Graphics::CENTER);
245 float direction = rand()%628 / 100.0f;
246 float x = std::sin(direction) * intensity;
247 float y = std::cos(direction) * intensity;
256 effect.
decay = decay;
259 effect.
timer.
set(duration * MILLISECONDS_IN_A_TICK);
277 mMouseX =
static_cast<int>(logicalX);
278 mMouseY =
static_cast<int>(logicalY);
284 const Uint8 *keys = SDL_GetKeyboardState(
nullptr);
285 gcn::MouseEvent mouseEvent(
nullptr,
286 (keys[SDL_SCANCODE_LSHIFT] || keys[SDL_SCANCODE_RSHIFT]),
290 gcn::MouseEvent::DRAGGED,
291 gcn::MouseEvent::LEFT,
305 unsigned char walkMask;
317 static Path debugPath;
318 static Vector lastMouseDestination =
Vector(0.0f, 0.0f);
322 if (mouseDestination.
x != lastMouseDestination.
x
323 || mouseDestination.
y != lastMouseDestination.
y)
346 lastMouseDestination = mouseDestination;
355 auto *being =
dynamic_cast<Being*
>(actor);
359 const Vector &beingPos = being->getPosition();
364 const int radius = being->getCollisionRadius();
365 graphics->fillRectangle(gcn::Rectangle(
370 radius * 2, radius * 2));
397 for (
auto pos : path)
402 graphics->fillRectangle(gcn::Rectangle(squareX - 4, squareY - 4,
407 squareX + 4, squareY + 12, gcn::Graphics::CENTER);
413 if (
event.getSource() !=
this)
427 const int pixelX =
event.getX() + (int)
mPixelViewX;
428 const int pixelY =
event.getY() + (int)
mPixelViewY;
437 if (
event.getButton() == gcn::MouseEvent::RIGHT)
460 if (
event.getButton() == gcn::MouseEvent::LEFT)
505 else if (
event.getButton() == gcn::MouseEvent::MIDDLE)
539 bool isInventory,
bool canDrop)
ActorSpriteManager * actorSpriteManager
FloorItem * findItem(int id) const
Returns a specific FloorItem, by id.
Being * findNearestLivingBeing(int x, int y, int maxTileDist, ActorSprite::Type type=Being::UNKNOWN, Being *excluded=nullptr) const
Returns a being nearest to specific coordinates.
Being * findBeingByPixel(int x, int y) const
Returns a being at the specific pixel.
const ActorSprites & getAll() const
Returns the whole list of beings.
const Vector & getPosition() const
Returns the pixel position of this actor.
Type getType() const final
Returns the type of the ActorSprite.
int getCollisionRadius() const
Returns the being's pixel radius used to detect collisions.
void drawSpeech(int offsetX, int offsetY)
Draws the speech text above the being.
bool isAlive() const
Returns whether this being is still alive.
Cursor getHoverCursor() const
Action getCurrentAction() const
Get the being's action currently performed.
void listen(Event::Channel channel)
A central point of control for graphics.
int getHeight() const
Returns the logical height of the screen.
void drawText(const std::string &text, int x, int y, gcn::Graphics::Alignment alignment, const gcn::Color &color, gcn::Font *font, bool outline=false, bool shadow=false, const std::optional< gcn::Color > &outlineColor={}, const std::optional< gcn::Color > &shadowColor={})
void setColor(const gcn::Color &color) override
virtual void windowToLogical(int windowX, int windowY, float &logicalX, float &logicalY) const =0
Converts a window coordinate to a logical coordinate.
int getWidth() const
Returns the logical width of the screen.
void setCursorType(Cursor cursor)
Sets which cursor should be used.
Represents one or more instances of a certain item type.
bool isKeyActive(int index) const
Checks if the key is active, by providing the key function index.
void setTarget(Being *target)
Sets the target being of the player.
int getAttackRange() const
Gets the attack range.
virtual void setDestination(int x, int y)
Sets a new destination for this being to walk to.
void setGotoTarget(Being *target)
Sets going to being to attack.
bool withinRange(Actor *target, int range) const
Returns whether the target is in range (in pixels).
void pickUp(FloorItem *item)
void attack(Being *target=nullptr, bool keep=false)
void pathSetByMouse()
Tells that the path has been set by mouse.
Path findPixelPath(int startPixelX, int startPixelY, int destPixelX, int destPixelY, int radius, unsigned char walkmask, int maxCost=20)
Find a pixel path from one location to the next using free offsets.
void draw(Graphics *graphics, int scrollX, int scrollY)
Draws the map to the given graphics output.
int getHeight() const
Returns the height of this map in tiles.
int getTileHeight() const
Returns the tile height used by this map.
int getDebugFlags() const
MetaTile * getMetaTile(int x, int y) const
Get tile reference.
int getWidth() const
Returns the width of this map in tiles.
void setDebugFlags(int flags)
int getTileWidth() const
Returns the tile width of this map.
void drawCollision(Graphics *graphics, int scrollX, int scrollY, int debugFlags) const
Visualizes collision layer for debugging.
Path findTilePath(int startPixelX, int startPixelY, int endPixelX, int endPixelY, unsigned char walkMask, int maxCost=20)
Find a tile-centered path in pixel coordinates from one location to the next.
@ DEBUG_BEING_COLLISION_RADIUS
void draw(gcn::Graphics *graphics, int xOff, int yOff)
Draw the text.
bool passed() const
Returns whether the timer has passed.
bool isSet() const
Returns whether the timer has been set.
void set(uint32_t ms=0)
Sets the timer with an optional duration in milliseconds.
int mMouseX
Current mouse position in pixels.
int getMouseY() const
Returns mouse y in pixels.
void mousePressed(gcn::MouseEvent &event) override
Handles mouse press on map.
void _drawPath(Graphics *graphics, const Path &path, gcn::Color color=gcn::Color(255, 0, 0))
Draws the given path.
void logic() override
Implements player to keep following mouse.
std::list< ShakeEffect > mShakeEffects
void mouseMoved(gcn::MouseEvent &event) override
Handles mouse move on map.
Being * mHoverBeing
Being mouse is currently over.
int getMouseX() const
Returns mouse x in pixels.
Timer mLocalWalkTimer
Timer for sending walk messages.
void setMap(Map *map)
Sets the map displayed by the viewport.
PopupMenu * mPopupMenu
Popup menu.
void event(Event::Channel channel, const Event &event) override
float mPixelViewY
Current viewpoint in pixels.
void mouseDragged(gcn::MouseEvent &event) override
Handles mouse move on map.
int mDebugFlags
Flags for showing debug graphics.
BeingPopup * mBeingPopup
Being information popup.
void closePopupMenu()
Closes the popup menu.
void draw(gcn::Graphics *graphics) override
Draws the viewport.
Map * mMap
The current map.
float mPixelViewX
Current viewpoint in pixels.
void _followMouse()
Make the player go to the mouse position.
void _drawDebugPath(Graphics *graphics)
Finds a path from the player to the mouse, and draws it.
void setDebugFlags(int debugFlags)
Sets which debug flags (see Map::DebugFlags) should be enabled.
void hideBeingPopup()
Hides the BeingPopup.
void updateCursorType()
Updates the cursor type.
void mouseReleased(gcn::MouseEvent &event) override
Handles mouse button release on map.
void showPopup(Window *parent, int x, int y, Item *item, bool isInventory=true, bool canDrop=true)
Shows a popup for an item.
FloorItem * mHoverItem
FloorItem mouse is currently over.
void shakeScreen(int intensity)
Makes the screen shake in a random direction.
int mMouseY
Current mouse position in pixels.
void logic() override
Do GUI logic.
void draw(gcn::Graphics *graphics) override
Adds debug drawing.
Config config
Global settings (config.xml)
LocalPlayer * local_player
ServerType getNetworkType()
PlayerHandler * getPlayerHandler()
bool isTalking()
Returns true if the player is involved in a NPC interaction, false otherwise.
unsigned deltaTimeMs()
The time in milliseconds since the last frame, but never more than 1000.
std::list< Position > Path
std::string toString(const T &arg)
Converts the given value to a string using std::stringstream.
TextManager * textManager
const int walkingMouseDelay
Delay between two mouse calls when dragging mouse and move the player.