82#include <guichan/focushandler.hpp>
122static void initEngines()
140static void createGuiWindows()
173#define del_0(X) { delete X; X = 0; }
178static void destroyGuiWindows()
219 auto *top =
static_cast<gcn::Container*
>(
gui->getTop());
266static bool saveScreenshot()
268 static unsigned int screenshotCount = 0;
295 std::ostringstream filenameSuffix;
296 std::ostringstream filename;
297 std::ifstream testExists;
301 if (
mkdir_r(screenshotDirectory.c_str()) != 0)
303 Log::info(
"Directory %s doesn't exist and can't be created! "
304 "Setting screenshot directory to home.",
305 screenshotDirectory.c_str());
312 filenameSuffix.str(std::string());
314 <<
"_Screenshot_" << screenshotCount <<
".png";
315 filename.str(std::string());
316 filename << screenshotDirectory <<
"/" << filenameSuffix.str();
317 testExists.open(filename.str());
318 found = !testExists.is_open();
327 std::string screenshotLink;
328#if SDL_VERSION_ATLEAST(2, 0, 14)
329 screenshotLink =
strprintf(
"@@screenshot:%s|%s@@",
330 filenameSuffix.str().c_str(),
331 filenameSuffix.str().c_str());
333 screenshotLink = filenameSuffix.str();
336 screenshotLink.c_str()));
344 SDL_FreeSurface(screenshot);
384static void handleItemPickUp()
402 gcn::Window *requestedWindow =
nullptr;
435 dialog->
action(gcn::ActionEvent(
nullptr,
"ok"));
467 bool wearOutfit =
false;
468 bool copyOutfit =
false;
476 if (wearOutfit || copyOutfit)
479 switch (event.keysym.sym)
490 outfitNum =
event.keysym.sym - SDLK_1;
688 if (target->canTalk())
696 requestedWindow->setVisible(!requestedWindow->isVisible());
697 if (requestedWindow->isVisible())
698 requestedWindow->requestMoveToTop();
737 unsigned char direction = 0;
883 Log::info(
"Error while loading %s", fullMap.c_str());
885 strprintf(
_(
"Error while loading %s"), fullMap.c_str()));
900 std::string newMusic = newMap ? newMap->
getMusicFile() : std::string();
901 if (newMusic != oldMusic)
903 if (newMusic.empty())
913 event.setString(
"mapPath", mapPath);
ActorSpriteManager * actorSpriteManager
ChannelManager * channelManager
#define DEFAULT_CHAT_WINDOW_SCROLL
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.
void setPlayer(LocalPlayer *player)
Sets the current player.
void setMap(Map *map)
Sets the map on which ActorSprites are created.
void clear()
Destroys all ActorSprites except the local player.
void logic()
Performs ActorSprite logic and deletes ActorSprite scheduled to be deleted.
virtual void setMap(Map *map)
void setDirection(uint8_t direction)
Sets the current direction.
void setMap(Map *map) final
uint8_t getDirection() const
Returns the current direction.
int getTileX() const override
Returns the tile x coord.
bool isAlive() const
Returns whether this being is still alive.
int getTileY() const override
Returns the tile y coord.
A tab for the chat window.
bool isInputFocused() const
Checks whether ChatWindow is Focused or not.
bool requestChatFocus()
Request focus for typing chat message.
void scroll(int amount)
Scrolls the chat window.
void nextTab()
Switch to the next tab in order.
void prevTab()
Switch to the previous tab in order.
void showOkDialog(const std::string &title, const std::string &message, State state)
Pops up an OkDialog with the given title and message, and switches to the given state when Ok is pres...
static const std::string & getScreenshotDirectory()
static Client * instance()
Provides access to the client instance.
A class to parse and handle user commands.
std::string getValue(const std::string &key, const std::string &deflt) const
Gets a value as string.
An emote shortcut container.
void useEmote(int index)
Try to use the Emote specified by the index.
void trigger(Channel channel) const
Sends this event to all classes listening to the given channel.
An item lying on the floor.
The main class responsible for running the game.
int getCurrentTileWidth() const
Convenience functions used to get the current tile width and height.
void videoResized(int width, int height)
Timer mParticleEngineTimer
int getCurrentTileHeight() const
void handleInput()
Continuous input handling.
bool keyDownEvent(SDL_KeyboardEvent &event)
Handles an SDL_KEYDOWN event and returns whether it was consumed.
Game()
Constructs the game, creating all the managers, handlers, engines and GUI windows that make up the ga...
void changeMap(const std::string &mapName)
Changes the currently active map.
~Game()
Destructor, cleans up the game.
void logic()
This method takes the game a small step further.
virtual SDL_Surface * getScreenshot()=0
Takes a screenshot and returns it as SDL surface.
int getHeight() const
Returns the logical height of the screen.
int getWidth() const
Returns the logical width of the screen.
gcn::FocusHandler * getFocusHandler() const
void loadHelp(const std::string &helpFile)
Loads help in the dialog.
static bool writePNG(SDL_Surface *surface, const std::string &filename)
static bool isAnyInputFocused()
An item shortcut container.
void useItem(int index)
Try to use the item specified by the index.
static void init()
Initializes the joystick subsystem.
void update()
Updates the direction and button information.
static int getNumberOfJoysticks()
Returns the number of available joysticks.
bool buttonPressed(unsigned char no) const
void refreshActiveKeys()
Takes a snapshot of all the active keys.
int getKeyEmoteOffset(SDL_Keycode keyValue) const
Get the key function index for an emote by providing the offset value.
bool isEnabled() const
Get the enable flag, which will stop the user from doing actions.
int getKeyIndex(SDL_Keycode keyValue) const
Get the key function index by providing the keys value.
bool isKeyActive(int index) const
Checks if the key is active, by providing the key function index.
@ KEY_WINDOW_EMOTE_SHORTCUT
void setTarget(Being *target)
Sets the target being of the player.
Being * getTarget() const
Returns the current target of the player.
void setShowIp(bool show)
void setWalkingDir(int dir)
Sets a new direction to keep walking in, when using the keyboard or the joystick.
void pickUp(FloorItem *item)
void attack(Being *target=nullptr, bool keep=false)
static Map * readMap(const std::string &filename)
Read an XML map from a file.
std::string getMusicFile() const
void update(int dt)
Updates animations.
void initializeParticleEffects(Particle *particleEngine)
Initializes all added particle effects.
int getTileHeight() const
Returns the tile height used by this map.
int getTileWidth() const
Returns the tile width of this map.
The player mini-status dialog.
void toggle()
Toggles the displaying of the minimap.
void setMap(Map *map)
Sets the map image that should be displayed.
virtual void setDirection(char direction)=0
static bool isAnyInputFocused()
void action(const gcn::ActionEvent &event) override
Called when receiving actions from the widgets.
bool isWaitingForTheServer() const
bool isTextInputFocused() const
static NpcDialog * getActive()
Returns the first active instance.
void close() override
Notifies the server that the client has performed a close action.
void wearOutfit(int outfit)
void copyOutfit(int outfit)
A particle spawned by a ParticleEmitter.
static void setupEngine()
Gives a particle the properties of an engine root particle and loads the particle-related config sett...
virtual bool update()
Updates particle position, returns false when the particle should be deleted.
void clear()
Deletes all child particles and emitters.
unsigned int getDefault() const
Retrieves the default permissions.
void setDefault(unsigned int permissions)
Sets the default permissions.
void action(const gcn::ActionEvent &event) override
Event handling method.
void clearWindowsForReset()
A window around a ShortcutContainer.
void fadeOutAndPlayMusic(const std::string &fileName, int ms=1000)
Fades out a background music and play a new one.
void fadeOutMusic(int ms=1000)
Fades out currently running background music track.
The player status dialog.
bool passed() const
Returns whether the timer has passed.
void extend(uint32_t ms)
Extend the timer by the given number of milliseconds.
void set(uint32_t ms=0)
Sets the timer with an optional duration in milliseconds.
void setMap(Map *map)
Sets the map displayed by the viewport.
void closePopupMenu()
Closes the popup menu.
virtual void setVisible(bool visible)
Overloads window setVisible by Guichan to allow sticky window handling.
Configuration paths
XML default paths information reader.
Configuration branding
XML branding information reader.
CommandHandler * commandHandler
EffectManager * effectManager
EmoteShortcut * emoteShortcut
void serverNotice(const std::string &message)
Particle * particleEngine
AbilitiesWindow * abilitiesWindow
InventoryWindow * inventoryWindow
SocialWindow * socialWindow
TradeWindow * tradeWindow
OutfitWindow * outfitWindow
ChannelManager * channelManager
QuestsWindow * questsWindow
EffectManager * effectManager
ShortcutWindow * emoteShortcutWindow
ShortcutWindow * itemShortcutWindow
ActorSpriteManager * actorSpriteManager
MiniStatusWindow * miniStatusWindow
EquipmentWindow * equipmentWindow
Viewport * viewport
Viewport on the map.
DebugWindow * debugWindow
StatusWindow * statusWindow
CommandHandler * commandHandler
SkillDialog * skillDialog
ItemShortcut * itemShortcut
LocalPlayer * local_player
const int DEFAULT_TILE_LENGTH
int mkdir_r(const char *pathname)
Create a directory, making leading components first if necessary.
const char * getUserDir()
void info(const char *log_text,...) LOG_PRINTF_ATTR
void error(const char *log_text,...) LOG_PRINTF_ATTR
GameHandler * getGameHandler()
PlayerHandler * getPlayerHandler()
Inventory * getInventory()
Returns the player's inventory.
Equipment * getEquipment()
Returns the player's equipment.
bool isTalking()
Returns true if the player is involved in a NPC interaction, false otherwise.
int getNPCPostCount()
Returns the number of currently open NPC post windows.
unsigned deltaTimeMs()
The time in milliseconds since the last frame, but never more than 1000.
PlayerRelationsManager player_relations
std::string strprintf(char const *format,...)
A safe version of sprintf that returns a std::string of the result.
WindowContainer * windowContainer