ManaPlus
Functions | Variables
game.cpp File Reference

(986a3bf)

#include "game.h"
#include "actormanager.h"
#include "client.h"
#include "configuration.h"
#include "effectmanager.h"
#include "eventsmanager.h"
#include "gamemodifiers.h"
#include "soundmanager.h"
#include "settings.h"
#include "being/crazymoves.h"
#include "being/localplayer.h"
#include "being/playerinfo.h"
#include "const/itemshortcut.h"
#include "const/spells.h"
#include "const/gui/chat.h"
#include "enums/being/beingdirection.h"
#include "fs/mkdir.h"
#include "fs/virtfs/fs.h"
#include "gui/dialogsmanager.h"
#include "gui/gui.h"
#include "gui/popupmanager.h"
#include "gui/viewport.h"
#include "gui/windowmanager.h"
#include "gui/windowmenu.h"
#include "gui/fonts/font.h"
#include "gui/shortcut/dropshortcut.h"
#include "gui/shortcut/emoteshortcut.h"
#include "gui/popups/popupmenu.h"
#include "gui/windows/bankwindow.h"
#include "gui/windows/clanwindow.h"
#include "gui/windows/cutinwindow.h"
#include "gui/windows/mailwindow.h"
#include "gui/windows/chatwindow.h"
#include "gui/windows/debugwindow.h"
#include "gui/windows/didyouknowwindow.h"
#include "gui/windows/emotewindow.h"
#include "gui/windows/equipmentwindow.h"
#include "gui/windows/inventorywindow.h"
#include "gui/windows/killstats.h"
#include "gui/windows/minimap.h"
#include "gui/windows/ministatuswindow.h"
#include "gui/windows/npcdialog.h"
#include "gui/windows/outfitwindow.h"
#include "gui/windows/setupwindow.h"
#include "gui/windows/shopwindow.h"
#include "gui/windows/shortcutwindow.h"
#include "gui/windows/skilldialog.h"
#include "gui/windows/socialwindow.h"
#include "gui/windows/statuswindow.h"
#include "gui/windows/tradewindow.h"
#include "gui/windows/questswindow.h"
#include "gui/windows/whoisonline.h"
#include "gui/widgets/tabs/chat/battletab.h"
#include "gui/widgets/createwidget.h"
#include "gui/widgets/emoteshortcutcontainer.h"
#include "gui/widgets/itemshortcutcontainer.h"
#include "gui/widgets/spellshortcutcontainer.h"
#include "gui/widgets/virtshortcutcontainer.h"
#include "gui/widgets/tabs/chat/gmtab.h"
#include "gui/widgets/tabs/chat/langtab.h"
#include "gui/widgets/tabs/chat/tradetab.h"
#include "input/inputmanager.h"
#include "input/joystick.h"
#include "input/keyboardconfig.h"
#include "input/touch/touchmanager.h"
#include "net/generalhandler.h"
#include "net/gamehandler.h"
#include "net/net.h"
#include "net/packetcounters.h"
#include "particle/particleengine.h"
#include "resources/delayedmanager.h"
#include "resources/mapreader.h"
#include "resources/screenshothelper.h"
#include "resources/db/mapdb.h"
#include "resources/map/map.h"
#include "resources/resourcemanager/resourcemanager.h"
#include "resources/sprite/animatedsprite.h"
#include "utils/delete2.h"
#include "utils/foreach.h"
#include "utils/gettext.h"
#include "utils/perfstat.h"
#include "utils/pnglib.h"
#include "utils/sdlcheckutils.h"
#include "utils/timer.h"
#include "listeners/assertlistener.h"
#include "listeners/errorlistener.h"
#include "net/tmwa/guildmanager.h"
#include <fstream>
#include "debug.h"

Go to the source code of this file.

Functions

static void initEngines ()
 
static void createGuiWindows ()
 
static void destroyGuiWindows ()
 

Variables

QuitDialogquitDialog = 0
 
WindowdisconnectedDialog = 0
 
bool mStatsReUpdated = false
 
const time_t adjustDelay = 10
 

Function Documentation

◆ createGuiWindows()

static void createGuiWindows ( )
static

Create all the various globally accessible gui windows

Definition at line 195 of file game.cpp.

196 {
197  if (setupWindow != nullptr)
199 
200  if (emoteShortcut != nullptr)
201  emoteShortcut->load();
202 
204 
205  // Create dialogs
208  if (chatWindow != nullptr)
209  {
211  chatWindow = nullptr;
212  }
214  "Chat");
218  localPlayer,
219  false);
221  nullptr,
222  nullptr,
223  true);
230  {
233  }
238  if (debugWindow != nullptr)
239  {
241  debugWindow = nullptr;
242  }
244  "Debug");
246  "ItemShortcut", "items.xml", 83, 460);
247 
248  for (unsigned f = 0; f < SHORTCUT_TABS - 1; f ++)
249  {
251  new ItemShortcutContainer(nullptr, f));
252  }
254  {
256  new ItemShortcutContainer(nullptr, SHORTCUT_TABS - 1));
257  }
258  if (config.getBoolValue("showDidYouKnow"))
259  {
262  }
263 
265  "EmoteShortcut",
266  new EmoteShortcutContainer(nullptr),
267  "emotes.xml",
268  130, 480);
271  "DropShortcut",
272  new VirtShortcutContainer(nullptr, dropShortcut),
273  "drops.xml",
274  0, 0);
276  "SpellShortcut",
277  "spells.xml",
278  265, 328);
279  for (unsigned f = 0; f < SPELL_SHORTCUT_TABS; f ++)
280  {
282  new SpellShortcutContainer(nullptr, f));
283  }
284 
292 
293  // TRANSLATORS: chat tab header
294  localChatTab = new ChatTab(chatWindow, _("General"),
295  GENERAL_CHANNEL, "#General", ChatTabType::INPUT);
297  if (config.getBoolValue("showChatHistory"))
298  localChatTab->loadFromLogFile("#General");
299 
300  // TRANSLATORS: chat tab header
301  debugChatTab = new ChatTab(chatWindow, _("Debug"), "",
302  "#Debug", ChatTabType::DEBUG);
304 
305  if (assertListener != nullptr)
306  {
307  const StringVect &messages = assertListener->getMessages();
308  FOR_EACH (StringVectCIter, it, messages)
309  {
310  debugChatTab->chatLog(*it,
314  }
316  }
317  if (config.getBoolValue("enableTradeTab"))
319  else
320  tradeChatTab = nullptr;
321 
322  if (config.getBoolValue("enableBattleTab"))
323  {
326  }
327  else
328  {
329  battleChatTab = nullptr;
330  }
331 
333  if (!isSafeMode)
335 
336  if (setupWindow != nullptr)
338 
339  if (localPlayer != nullptr)
341 
342  if (generalHandler != nullptr)
344 }
AssertListener * assertListener
BankWindow * bankWindow
Definition: bankwindow.cpp:40
BattleTab * battleChatTab
Definition: battletab.cpp:32
ChatTab * debugChatTab
Definition: chattab.cpp:63
ChatTab * localChatTab
Definition: chattab.cpp:62
ChatWindow * chatWindow
Definition: chatwindow.cpp:94
ClanWindow * clanWindow
Definition: clanwindow.cpp:38
const StringVect & getMessages() const
void setAllowHighlight(const bool n)
Definition: chattab.h:161
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
Definition: chattab.cpp:111
void loadFromLogFile(const std::string &name)
Definition: chattab.cpp:510
void scheduleDelete()
void showGMTab()
void loadState()
ChatTab * addSpecialChannelTab(const std::string &name, const bool switchTo)
bool getBoolValue(const std::string &key) const
void loadData(int num)
void setVisible(Visible visible)
static void init()
void updateStatus() const
virtual void gameStarted() const =0
void clearWindowsForReset()
Definition: setupwindow.h:68
void externalUpdate()
void addTab(const std::string &name, ShortcutContainer *const content)
virtual void setVisible(Visible visible)
Definition: window.cpp:778
virtual void scheduleDelete()
Definition: window.cpp:831
Configuration config
const std::string GENERAL_CHANNEL
Definition: chat.h:29
const std::string TRADE_CHANNEL
Definition: chat.h:31
const unsigned int SHORTCUT_TABS
Definition: itemshortcut.h:28
#define CREATEWIDGETV0(var, type)
Definition: createwidget.h:32
#define CREATEWIDGETV(var, type,...)
Definition: createwidget.h:25
CutInWindow * cutInWindow
Definition: cutinwindow.cpp:37
DebugWindow * debugWindow
Definition: debugwindow.cpp:43
#define delete2(var)
Definition: delete2.h:25
DidYouKnowWindow * didYouKnowWindow
DropShortcut * dropShortcut
bool isSafeMode
Definition: client.cpp:123
EmoteShortcut * emoteShortcut
EmoteWindow * emoteWindow
Definition: emotewindow.cpp:49
EquipmentWindow * equipmentWindow
EquipmentWindow * beingEquipmentWindow
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
Net::GeneralHandler * generalHandler
Definition: net.cpp:88
#define _(s)
Definition: gettext.h:35
const bool IgnoreRecord_false
Definition: ignorerecord.h:30
InventoryWindow * inventoryWindow
InventoryWindow * cartWindow
KillStats * killStats
Definition: killstats.cpp:45
LocalPlayer * localPlayer
MailWindow * mailWindow
Definition: mailwindow.cpp:54
Minimap * minimap
Definition: minimap.cpp:62
MiniStatusWindow * miniStatusWindow
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
ServerTypeT getNetworkType()
Definition: net.cpp:189
Inventory * getInventory()
Definition: playerinfo.cpp:195
Equipment * getEquipment()
Definition: playerinfo.cpp:220
Inventory * getCartInventory()
Definition: playerinfo.cpp:207
OutfitWindow * outfitWindow
QuestsWindow * questsWindow
SetupWindow * setupWindow
Definition: setupwindow.cpp:64
ShopWindow * shopWindow
Definition: shopwindow.cpp:101
ShortcutWindow * dropShortcutWindow
ShortcutWindow * spellShortcutWindow
ShortcutWindow * emoteShortcutWindow
ShortcutWindow * itemShortcutWindow
SkillDialog * skillDialog
Definition: skilldialog.cpp:66
SocialWindow * socialWindow
const unsigned int SPELL_SHORTCUT_TABS
Definition: spells.h:29
StatusWindow * statusWindow
StringVect::const_iterator StringVectCIter
Definition: stringvector.h:31
std::vector< std::string > StringVect
Definition: stringvector.h:29
TradeTab * tradeChatTab
Definition: tradetab.cpp:36
TradeWindow * tradeWindow
Definition: tradewindow.cpp:65
const bool TryRemoveColors_true
const bool Visible_false
Definition: visible.h:30
const bool Visible_true
Definition: visible.h:30
WhoIsOnline * whoIsOnline
Definition: whoisonline.cpp:82

References _, ChatWindow::addSpecialChannelTab(), ShortcutWindow::addTab(), assertListener, bankWindow, battleChatTab, beingEquipmentWindow, ChatMsgType::BY_SERVER, cartWindow, ChatTab::chatLog(), chatWindow, clanWindow, SetupWindow::clearWindowsForReset(), config, CREATEWIDGETV, CREATEWIDGETV0, cutInWindow, ChatTabType::DEBUG, debugChatTab, debugWindow, delete2, didYouKnowWindow, dropShortcut, dropShortcutWindow, emoteShortcut, emoteShortcutWindow, emoteWindow, equipmentWindow, SetupWindow::externalUpdate(), FOR_EACH, Net::GeneralHandler::gameStarted(), GENERAL_CHANNEL, generalHandler, Configuration::getBoolValue(), PlayerInfo::getCartInventory(), PlayerInfo::getEquipment(), PlayerInfo::getInventory(), AssertListener::getMessages(), Net::getNetworkType(), IgnoreRecord_false, GameModifiers::init(), ChatTabType::INPUT, inventoryWindow, isSafeMode, itemShortcutWindow, killStats, EmoteShortcut::load(), DidYouKnowWindow::loadData(), ChatTab::loadFromLogFile(), ChatWindow::loadState(), localChatTab, localPlayer, mailWindow, minimap, miniStatusWindow, outfitWindow, questsWindow, Window::scheduleDelete(), ChatWindow::scheduleDelete(), ChatTab::setAllowHighlight(), setupWindow, Window::setVisible(), DidYouKnowWindow::setVisible(), shopWindow, SHORTCUT_TABS, ChatWindow::showGMTab(), skillDialog, socialWindow, SPELL_SHORTCUT_TABS, spellShortcutWindow, statusWindow, ServerType::TMWATHENA, Catch::toString(), TRADE_CHANNEL, tradeChatTab, tradeWindow, TryRemoveColors_true, LocalPlayer::updateStatus(), Visible_false, Visible_true, and whoIsOnline.

Referenced by Game::Game().

◆ destroyGuiWindows()

static void destroyGuiWindows ( )
static

Destroy all the globally accessible gui windows

Definition at line 349 of file game.cpp.

350 {
351  if (generalHandler != nullptr)
353 
354  if (whoIsOnline != nullptr)
355  whoIsOnline->setAllowUpdate(false);
356 
357 #ifdef TMWA_SUPPORT
359 #endif // TMWA_SUPPORT
360 
362  delete2(localChatTab) // Need to do this first, so it can remove itself
368 #ifdef TMWA_SUPPORT
369  if (guildManager != nullptr && GuildManager::getEnableGuildBot())
370  guildManager->reload();
371 #endif // TMWA_SUPPORT
372 
373  logger->log("start deleting");
376  logger->log("end deleting");
401 }
static void clear()
static bool getEnableGuildBot()
Definition: guildmanager.h:56
void log(const char *const log_text,...)
Definition: logger.cpp:269
virtual void gameEnded() const =0
void setAllowUpdate(const bool n)
Definition: whoisonline.h:89
GmTab * gmChatTab
Definition: gmtab.cpp:34
GuildManager * guildManager
LangTab * langChatTab
Definition: langtab.cpp:28
Logger * logger
Definition: logger.cpp:89
WindowMenu * windowMenu
Definition: windowmenu.cpp:51

References bankWindow, battleChatTab, beingEquipmentWindow, cartWindow, chatWindow, clanWindow, GuildManager::clear(), cutInWindow, debugChatTab, debugWindow, delete2, dropShortcutWindow, emoteShortcutWindow, emoteWindow, equipmentWindow, Net::GeneralHandler::gameEnded(), generalHandler, GuildManager::getEnableGuildBot(), gmChatTab, guildManager, inventoryWindow, itemShortcutWindow, killStats, langChatTab, localChatTab, Logger::log(), logger, mailWindow, minimap, miniStatusWindow, outfitWindow, questsWindow, GuildManager::reload(), WhoIsOnline::setAllowUpdate(), shopWindow, skillDialog, socialWindow, spellShortcutWindow, statusWindow, tradeChatTab, tradeWindow, whoIsOnline, and windowMenu.

Referenced by Game::~Game().

◆ initEngines()

static void initEngines ( )
static

Initialize every game sub-engines in the right order

Definition at line 167 of file game.cpp.

168 {
171 #ifdef TMWA_SUPPORT
173 #endif // TMWA_SUPPORT
174 
175  crazyMoves = new CrazyMoves;
176 
178  particleEngine->setMap(nullptr);
180  BeingInfo::init();
181 
182  if (gameHandler != nullptr)
184 
185  keyboard.update();
186  if (joystick != nullptr)
187  joystick->update();
188 
190 }
ActorManager * actorManager
static void init()
Definition: beinginfo.cpp:223
static void init()
void update()
Definition: joystick.cpp:359
virtual void initEngines() const =0
void setMap(Map *const map)
static void setupEngine()
CrazyMoves * crazyMoves
Definition: crazymoves.cpp:47
EffectManager * effectManager
Net::GameHandler * gameHandler
Definition: net.cpp:91
Joystick * joystick
Definition: joystick.cpp:43
KeyboardConfig keyboard
ParticleEngine * particleEngine

References actorManager, crazyMoves, UpdateStatusListener::distributeEvent(), effectManager, gameHandler, GuildManager::init(), BeingInfo::init(), Net::GameHandler::initEngines(), joystick, keyboard, particleEngine, ParticleEngine::setMap(), ParticleEngine::setupEngine(), Joystick::update(), and KeyboardConfig::update().

Referenced by Game::Game().

Variable Documentation

◆ adjustDelay

const time_t adjustDelay = 10

◆ disconnectedDialog

Window* disconnectedDialog = 0

Definition at line 159 of file game.cpp.

Referenced by Game::Game(), and Game::slowLogic().

◆ mStatsReUpdated

bool mStatsReUpdated = false

Definition at line 161 of file game.cpp.

Referenced by ConnectionDialog::ConnectionDialog(), and KillStats::recalcStats().

◆ quitDialog

QuitDialog* quitDialog = 0

Definition at line 158 of file game.cpp.

Referenced by InputManager::handleEvent(), and Game::handleMove().