75#if defined(_WIN32) || defined(__APPLE__)
91#include <guichan/exception.hpp>
118static Uint32 nextSecond(Uint32 interval,
void *param)
129 static int lastSelected = -1;
131 if (selected == lastSelected && !timer.
passed())
135 lastSelected = selected;
148 const auto ticks = SDL_GetTicks();
157 if (ticks >
mBaseTicks && targetTicks > ticks)
159 SDL_Delay(targetTicks - ticks);
174 mStateAfterOkDialog(mState)
207#if SDL_VERSION_ATLEAST(2, 24, 0)
208 SDL_SetHint(SDL_HINT_WINDOWS_DPI_AWARENESS,
"permonitorv2");
213 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0)
215 Log::critical(
strprintf(
"Could not initialize SDL: %s",
220 SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH,
"1");
224 Log::critical(
strprintf(
"%s couldn't be set as write directory! "
243 int loc1 = path.find_last_of(
'/');
244 int loc2 = path.find_last_of(
'\\');
245 int loc = std::max(loc1, loc2);
247 int loc = path.find_last_of(
'/');
272 videoSettings.
openGL = useOpenGL;
287 Log::info(
"Loading icon from file: %s", iconFile.c_str());
289 static SDL_SysWMinfo pInfo;
292 HICON icon = (HICON) LoadImage(NULL,
294 IMAGE_ICON, 64, 64, LR_LOADFROMFILE);
297 icon = LoadIcon(GetModuleHandle(NULL),
"A");
300 SetClassLongPtr(pInfo.info.win.window, GCLP_HICON, (LONG_PTR) icon);
302 mIcon = IMG_Load(iconFile.c_str());
325 catch (
const char *err)
370 const bool noServerList =
branding.
getValue(
"onlineServerList", std::string()).empty();
423 SDL_FreeSurface(
mIcon);
443 while (SDL_PollEvent(&event))
451 case SDL_WINDOWEVENT:
452 switch (event.window.event) {
453 case SDL_WINDOWEVENT_SIZE_CHANGED:
494 catch (gcn::Exception e)
496 const char *err = e.getMessage().c_str();
497 Log::warn(
"Guichan input exception: %s", err);
564 auto *top =
static_cast<gcn::Container*
>(
gui->getTop());
588 event.setInt(
"newState",
mState);
682 Log::info(
"State: WORLD SELECT ATTEMPT");
753 _(
"Requesting characters"),
787 _(
"Connecting to the game server"),
797 _(
"Changing game servers"),
802 Log::info(
"Memorizing selected character %s",
830 Log::info(
"State: ACCOUNT CHANGE ERROR");
858 Log::info(
"State: CHANGE PASSWORD ATTEMPT");
865 Log::info(
"State: CHANGE PASSWORD SUCCESS");
867 _(
"Password changed successfully!"),
879 Log::info(
"State: CHANGE EMAIL ATTEMPT");
884 Log::info(
"State: CHANGE EMAIL SUCCESS");
886 _(
"Email changed successfully!"),
906 _(
"Farewell, come back any time..."),
971 const std::string &message,
974 auto *okDialog =
new OkDialog(title, message);
975 okDialog->addActionListener(
this);
988 if (event.getId() ==
"Setup")
994 if (window->isVisible())
995 window->requestMoveToTop();
999 if (event.getId() ==
"ok")
1007 std::string portableName =
mRootDir +
"portable.xml";
1008 struct stat statbuf;
1010 if (!stat(portableName.c_str(), &statbuf) && S_ISREG(statbuf.st_mode))
1014 portable.
init(portableName);
1016 Log::info(
"Portable file: %s", portableName.c_str());
1020 dir = portable.
getValue(
"dataDir",
"");
1031 dir = portable.
getValue(
"configDir",
"");
1042 dir = portable.
getValue(
"screenshotDir",
"");
1046 Log::info(
"Portable screenshot dir: %s",
1064#if defined __HAIKU__
1068 mLocalDataDir = getSpecialFolderLocation(FOLDERID_LocalAppData);
1079 Log::critical(
strprintf(
_(
"%s doesn't exist and can't be created! "
1090#elif defined __HAIKU__
1102 Log::critical(
strprintf(
_(
"%s doesn't exist and can't be created! "
1115 const std::string configPath =
mConfigDir +
"/config.xml";
1121 Log::info(
"Couldn't read configuration file: %s", configPath.c_str());
1162 std::string::size_type loc = newDir.find(
"/", 0);
1164 while (loc != std::string::npos)
1166 newDir.replace(loc, 1,
"\\");
1167 loc = newDir.find(
"/", loc);
1170 if (!CreateDirectory(newDir.c_str(), 0) &&
1171 GetLastError() != ERROR_ALREADY_EXISTS)
1173 Log::error(
"%s can't be made, but doesn't exist!",
1176 strprintf(
_(
"Error creating updates directory!\n(%s)"),
1181 Log::error(
"%s/%s can't be made, but doesn't exist!",
1184 strprintf(
_(
"Error creating updates directory!\n(%s/%s)"),
1214 if (screenshotSuffix.empty())
1217 if (!screenshotSuffix.empty())
1273 return !(SDL_GetWindowFlags(
getVideo().window()) & SDL_WINDOW_MINIMIZED);
1278 return SDL_GetWindowFlags(
getVideo().window()) & SDL_WINDOW_INPUT_FOCUS;
1283 return SDL_GetWindowFlags(
getVideo().window()) & SDL_WINDOW_MOUSE_FOCUS;
ChatLogger * chatLogger
Chat log object.
const std::string & getName() const
Returns the name of the being.
The Change password dialog.
Character selection dialog.
void setServerName(const std::string &serverName)
void setLogDir(const std::string &logDir)
The core part of the client.
State mStateAfterOkDialog
Client(const Options &options)
void initConfiguration()
Initialize configuration.
void showErrorDialog(const std::string &message, State state)
Pops up an error dialog with the given message, and switches to the given state when Ok is pressed.
void action(const gcn::ActionEvent &event) override
bool initUpdatesDir()
Parse the update host and determine the updates directory Then verify that the directory exists (crea...
void accountLogin(LoginData *loginData)
void initHomeDir()
Initializes the home directory.
static bool hasMouseFocus()
std::string mLocalDataDir
static bool hasInputFocus()
SDL_TimerID mSecondsCounterId
static Video & getVideo()
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...
std::string mScreenshotDir
ServerInfo mCurrentServer
static Client * mInstance
void handleWindowSizeChanged(int width, int height)
Should be called after the window has been resized.
std::string getValue(const std::string &key, const std::string &deflt) const
Gets a value as string.
Configuration handler for reading (and writing).
std::string getStringValue(const std::string &key) const
void setDefaultValues(DefaultsData *defaultsData)
Set the default values for each keys.
void init(const std::string &filename, bool useResManager=false)
Reads config file and parse all options into memory.
Desktop widget, for drawing a background image and color.
void reloadWallpaper()
Has to be called after updates have been loaded.
The class which keeps track of the emote shortcuts.
void trigger(Channel channel) const
Sends this event to all classes listening to the given channel.
void limitFps(int fpsLimit)
A simple but effective frame rate limiter.
The main class responsible for running the game.
void videoResized(int width, int height)
void handleInput()
Continuous input handling.
bool keyDownEvent(SDL_KeyboardEvent &event)
Handles an SDL_KEYDOWN event and returns whether it was consumed.
void logic()
This method takes the game a small step further.
A central point of control for graphics.
int getHeight() const
Returns the logical height of the screen.
int getWidth() const
Returns the logical width of the screen.
bool videoResized(int width, int height)
Called when the application window has been resized.
Theme * getTheme() const
The global GUI theme.
void logic() override
Performs logic of the GUI.
Hair information database.
static void SDLdisableTransparency()
Disable the transparency handling (for low CPUs in SDL Mode)
Item information database generic definition.
The class which keeps track of the item shortcuts.
void setNewKey(SDL_Keycode value)
Set the value of the new key.
int getNewKeyIndex() const
Get the index of the new key to be assigned.
void callbackNewKey()
Calls a function back so the key re-assignment(s) can be seen.
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.
void init()
Initializes the keyboard config explicitly.
void setNewKeyIndex(int value)
Set the index of the new key to be assigned.
bool remember
Whether to store the username.
bool registerLogin
Whether an account is being registered.
Item information database TmwAthena specific class.
virtual void requestCharacters()=0
virtual void disconnect()=0
virtual void flushNetwork()=0
virtual void changePassword(const std::string &username, const std::string &oldPassword, const std::string &newPassword)=0
virtual void registerAccount(LoginData *loginData)=0
virtual void disconnect()=0
virtual void changeEmail(const std::string &email)=0
virtual Worlds getWorlds() const =0
virtual void unregisterAccount(const std::string &username, const std::string &password)=0
virtual void chooseServer(unsigned int server)=0
virtual void getRegistrationDetails()=0
virtual void loginAccount(LoginData *loginData)=0
void init()
Initialise player relations manager (load config file etc.)
static std::string getPath(const std::string &file)
Returns the real path to a file.
static void deleteInstance()
Deletes the class instance if it exists.
static void searchAndAddArchives(const std::string &path, const std::string &ext, bool append)
Searches for zip files and adds them to the search path.
static bool addToSearchPath(const std::string &path, bool append)
Adds a directory or archive to the search path.
The server choice dialog.
static ServerType parseType(const std::string &type)
static ServerType defaultServerTypeForPort(uint16_t port)
static uint16_t defaultPortForServerType(ServerType type)
void playMusic(const std::string &fileName)
Starts background music.
void fadeOutMusic(int ms=1000)
Fades out currently running background music track.
void init()
Installs the sound engine.
void setMusicVolume(int volume)
void logic()
The sound logic.
void close()
Removes all sound functionalities.
void setSfxVolume(int volume)
void setNotificationsVolume(int volume)
static std::string prepareThemePath()
void setMinimumOpacity(float minimumOpacity)
Set the minimum opacity allowed to skins.
Simple timer that can be used to check if a certain amount of time has passed.
bool passed() const
Returns whether the timer has passed.
void set(uint32_t ms=0)
Sets the timer with an optional duration in milliseconds.
Item information database TmwAthena specific class.
Update progress window GUI.
Class controlling the game's color palette.
SDL_Window * window() const
void updateWindowSize()
Handles a change in window size, possibly adjusting the scale.
void present()
Present the next frame.
Graphics * initialize(const VideoSettings &settings)
Try to create a window with the given settings.
virtual void setVisible(bool visible)
Overloads window setVisible by Guichan to allow sticky window handling.
void scheduleDelete()
Schedule this window for deletion.
The server select dialog.
A helper class for parsing an XML document, which also cleans it up again (RAII).
Node rootNode() const
Returns the root node of the document (or NULL if there was a load error).
std::string_view name() const
Helper class for writing out XML data.
HairDB hairDB
Hair styles and colors info database.
Config config
Global settings (config.xml)
Configuration paths
XML default paths information reader.
volatile int frame_count
Counts the frames during one second.
bool isDoubleClick(int selected)
Returns whether this call and the last call were done for the same selected index and within a short ...
UserPalette * userPalette
ChatLogger * chatLogger
Chat log object.
volatile int fps
Frames counted in the last second.
Configuration branding
XML branding information reader.
ItemDB * itemDb
Items info database.
@ STATE_CHANGEPASSWORD_SUCCESS
@ STATE_CHANGEEMAIL_SUCCESS
@ STATE_UNREGISTER_ATTEMPT
@ STATE_ACCOUNTCHANGE_ERROR
@ STATE_UNREGISTER_SUCCESS
@ STATE_CHANGEPASSWORD_ATTEMPT
@ STATE_CHANGEEMAIL_ATTEMPT
@ STATE_WORLD_SELECT_ATTEMPT
void serialize(XML::Writer &writer, const Config &config)
void deserialize(XML::Node node, ItemShortcutEntry &itemShortcut)
DefaultsData * getBrandingDefaults()
DefaultsData * getPathsDefaults()
EmoteShortcut * emoteShortcut
SDLInput * guiInput
GUI input.
ItemShortcut * itemShortcut
LocalPlayer * local_player
int mkdir_r(const char *pathname)
Create a directory, making leading components first if necessary.
const char * getPrefDir(const char *org, const char *app)
bool setWriteDir(const std::string &path)
Sets the write directory.
bool mkdir(const std::string &path)
Creates a directory in the write path.
const char * getUserDir()
bool isDirectory(const std::string &path)
Checks whether the given path is a directory.
const char * getBaseDir()
void init()
Initializes the log system.
void setLogToStandardOut(bool value)
Sets whether the log should be written to standard output.
void warn(const char *log_text,...) LOG_PRINTF_ATTR
void setLogFile(const std::string &logFilename)
Sets the file to log to and opens it.
void info(const char *log_text,...) LOG_PRINTF_ATTR
void error(const char *log_text,...) LOG_PRINTF_ATTR
LoginHandler * getLoginHandler()
void connectToServer(ServerInfo &server)
Handles server detection and connection.
ServerType getNetworkType()
GameHandler * getGameHandler()
CharHandler * getCharHandler()
GeneralHandler * getGeneralHandler()
void init()
Initializes some internals.
void beginFrame()
Called at the start of each frame, updates the above variables.
PlayerRelationsManager player_relations
std::string getDirectoryFromURL(const std::string &url)
Derives a directory from the given URL, stripping the schema and replacing certain invalid characters...
std::string strprintf(char const *format,...)
A safe version of sprintf that returns a std::string of the result.
A structure holding the values of various options that can be passed from the command line.
std::string screenshotDir
std::string lastCharacter
bool useScreenshotDirectorySuffix
std::string screenshotDirectorySuffix
std::vector< WorldInfo * > Worlds