summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.cpp3
-rw-r--r--src/gui/login.cpp17
-rw-r--r--src/gui/serverdialog.cpp62
-rw-r--r--src/gui/serverdialog.h6
-rw-r--r--src/gui/setup_players.cpp6
-rw-r--r--src/gui/setup_video.cpp73
-rw-r--r--src/gui/setup_video.h3
-rw-r--r--src/gui/socialwindow.cpp26
-rw-r--r--src/gui/truetypefont.cpp22
-rw-r--r--src/gui/viewport.cpp18
-rw-r--r--src/gui/viewport.h5
-rw-r--r--src/gui/widgets/avatarlistbox.cpp9
-rw-r--r--src/gui/widgets/browserbox.cpp257
-rw-r--r--src/gui/widgets/browserbox.h60
-rw-r--r--src/gui/widgets/chattab.cpp1
-rw-r--r--src/gui/widgets/desktop.cpp4
-rw-r--r--src/gui/widgets/itemcontainer.cpp42
-rw-r--r--src/gui/widgets/itemshortcutcontainer.cpp1
18 files changed, 317 insertions, 298 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index f8dc3e82..c8568b0f 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -160,6 +160,9 @@ Gui::~Gui()
void Gui::logic()
{
+ ResourceManager *resman = ResourceManager::getInstance();
+ resman->clearScheduled();
+
// Fade out mouse cursor after extended inactivity
if (mMouseInactivityTimer < 100 * 15)
{
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index b243fd04..b12e6a5d 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -91,8 +91,6 @@ LoginDialog::LoginDialog(LoginData *loginData):
mPassField->requestFocus();
mLoginButton->setEnabled(canSubmit());
- mRegisterButton->setEnabled(Net::getLoginHandler()
- ->isRegistrationEnabled());
}
LoginDialog::~LoginDialog()
@@ -120,10 +118,17 @@ void LoginDialog::action(const gcn::ActionEvent &event)
}
else if (event.getId() == "register")
{
- mLoginData->username = mUserField->getText();
- mLoginData->password = mPassField->getText();
-
- Client::setState(STATE_REGISTER_PREP);
+ if (Net::getLoginHandler()->isRegistrationEnabled())
+ {
+ mLoginData->username = mUserField->getText();
+ mLoginData->password = mPassField->getText();
+ Client::setState(STATE_REGISTER_PREP);
+ }
+ else
+ {
+ new OkDialog(_("Registration disabled"), _("You need to use the "
+ "website to register an account for this server."));
+ }
}
}
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
index 1657c8d3..e377042a 100644
--- a/src/gui/serverdialog.cpp
+++ b/src/gui/serverdialog.cpp
@@ -199,13 +199,18 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir):
mDownloadStatus(DOWNLOADING_PREPARING),
mDownloadProgress(-1.0f),
mServers(ServerInfos()),
+#ifndef MANASERV_SUPPORT
+ mManaservServers(ServerInfos()),
+#endif
mServerInfo(serverInfo)
{
setWindowName("ServerDialog");
Label *serverLabel = new Label(_("Server:"));
Label *portLabel = new Label(_("Port:"));
+#ifdef MANASERV_SUPPORT
Label *typeLabel = new Label(_("Server type:"));
+#endif
mServerNameField = new TextField(mServerInfo->hostname);
mPortField = new TextField(toString(mServerInfo->port));
@@ -214,7 +219,6 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir):
mServersListModel = new ServersListModel(&mServers, this);
mServersList = new ServersListBox(mServersListModel);
- mServersList->addMouseListener(this);
ScrollArea *usedScroll = new ScrollArea(mServersList);
usedScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
@@ -244,6 +248,7 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir):
place(1, 0, mServerNameField, 4).setPadding(3);
place(0, 1, portLabel);
place(1, 1, mPortField, 4).setPadding(3);
+#ifdef MANASERV_SUPPORT
place(0, 2, typeLabel);
place(1, 2, mTypeField, 4).setPadding(3);
place(0, 3, usedScroll, 5, 5).setPadding(3);
@@ -252,6 +257,14 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir):
place(1, 9, mDeleteButton);
place(3, 9, mQuitButton);
place(4, 9, mConnectButton);
+#else
+ place(0, 2, usedScroll, 5, 5).setPadding(3);
+ place(0, 7, mDescription, 5);
+ place(0, 8, mManualEntryButton);
+ place(1, 8, mDeleteButton);
+ place(3, 8, mQuitButton);
+ place(4, 8, mConnectButton);
+#endif
// Make sure the list has enough height
getLayout().setRowHeight(3, 80);
@@ -417,16 +430,6 @@ void ServerDialog::valueChanged(const gcn::SelectionEvent &)
mDeleteButton->setEnabled(myServer.save);
}
-void ServerDialog::mouseClicked(gcn::MouseEvent &mouseEvent)
-{
- if (mouseEvent.getClickCount() == 2 &&
- mouseEvent.getSource() == mServersList)
- {
- action(gcn::ActionEvent(mConnectButton,
- mConnectButton->getActionEventId()));
- }
-}
-
void ServerDialog::logic()
{
{
@@ -468,7 +471,11 @@ void ServerDialog::setFieldsReadOnly(bool readOnly)
mServersList->setSelected(-1);
mServerNameField->setText(std::string());
+#ifdef MANASERV_SUPPORT
mPortField->setText(std::string());
+#else
+ mPortField->setText(std::string("6901"));
+#endif
mServerNameField->requestFocus();
}
@@ -590,7 +597,11 @@ void ServerDialog::loadServers()
}
}
+#ifdef MANASERV_SUPPORT
if (!found)
+#else
+ if (!found && server.type != ServerInfo::MANASERV)
+#endif
mServers.push_back(server);
}
}
@@ -616,7 +627,15 @@ void ServerDialog::loadCustomServers()
break;
server.save = true;
+
+#ifdef MANASERV_SUPPORT
mServers.push_back(server);
+#else
+ if (server.type == ServerInfo::MANASERV)
+ mManaservServers.push_back(server);
+ else
+ mServers.push_back(server);
+#endif
}
}
@@ -659,6 +678,27 @@ void ServerDialog::saveCustomServers(const ServerInfo &currentServer)
++savedServerCount;
}
+#ifndef MANASERV_SUPPORT
+ for (unsigned i = 0;
+ i < mManaservServers.size() && savedServerCount < MAX_SERVERLIST; ++i)
+ {
+ const ServerInfo &server = mManaservServers.at(i);
+
+ // Only save servers that were loaded from settings
+ if (!(server.save && server.isValid()))
+ continue;
+
+ const std::string index = toString(savedServerCount);
+ const std::string nameKey = "MostUsedServerName" + index;
+ const std::string typeKey = "MostUsedServerType" + index;
+ const std::string portKey = "MostUsedServerPort" + index;
+
+ config.setValue(nameKey, toString(server.hostname));
+ config.setValue(typeKey, serverTypeToString(server.type));
+ config.setValue(portKey, toString(server.port));
+ ++savedServerCount;
+ }
+#endif
// Insert an invalid entry at the end to make the loading stop there
if (savedServerCount < MAX_SERVERLIST)
config.setValue("MostUsedServerName" + toString(savedServerCount), "");
diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h
index 03ed0f7a..aae8b2e0 100644
--- a/src/gui/serverdialog.h
+++ b/src/gui/serverdialog.h
@@ -32,7 +32,6 @@
#include <guichan/actionlistener.hpp>
#include <guichan/keylistener.hpp>
#include <guichan/listmodel.hpp>
-#include <guichan/mouselistener.hpp>
#include <guichan/selectionlistener.hpp>
#include <string>
@@ -136,8 +135,6 @@ class ServerDialog : public Window,
*/
void valueChanged(const gcn::SelectionEvent &event);
- void mouseClicked(gcn::MouseEvent &mouseEvent);
-
void logic();
protected:
@@ -194,6 +191,9 @@ class ServerDialog : public Window,
float mDownloadProgress;
ServerInfos mServers;
+#ifndef MANASERV_SUPPORT
+ ServerInfos mManaservServers;
+#endif
ServerInfo *mServerInfo;
};
diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp
index cbe0e264..e1948bb0 100644
--- a/src/gui/setup_players.cpp
+++ b/src/gui/setup_players.cpp
@@ -298,9 +298,9 @@ Setup_Players::Setup_Players():
place(0, 7, mEnableChatLogCheckBox, 2).setPadding(2);
place(2, 5, ignore_action_label);
place(2, 6, mIgnoreActionChoicesBox, 2).setPadding(2);
- place(2, 7, mDefaultTrading);
- place(2, 8, mDefaultWhisper);
- place(0, 9, mWhisperTabCheckBox, 4).setPadding(4);
+ place(0, 8, mDefaultTrading);
+ place(0, 9, mDefaultWhisper);
+ place(0, 10, mWhisperTabCheckBox, 4).setPadding(4);
player_relations.addListener(this);
diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp
index ae921d2f..c8af218f 100644
--- a/src/gui/setup_video.cpp
+++ b/src/gui/setup_video.cpp
@@ -210,6 +210,7 @@ Setup_Video::Setup_Video():
mPickupParticleEnabled(config.getBoolValue("showpickupparticle")),
mOpacity(config.getFloatValue("guialpha")),
mFps(config.getIntValue("fpslimit")),
+ mSDLTransparencyDisabled(config.getBoolValue("disableTransparency")),
mSpeechMode(static_cast<Being::Speech>(config.getIntValue("speech"))),
mModeListModel(new ModeListModel),
mModeList(new ListBox(mModeListModel)),
@@ -222,7 +223,7 @@ Setup_Video::Setup_Video():
mParticleEffectsCheckBox(new CheckBox(_("Particle effects"),
mParticleEffectsEnabled)),
mNameCheckBox(new CheckBox(_("Show own name"), mNameEnabled)),
- mNPCLogCheckBox(new CheckBox(_("Log NPC interactions"), mNPCLogEnabled)),
+ mNPCLogCheckBox(new CheckBox(_("Log NPC dialogue"), mNPCLogEnabled)),
mPickupNotifyLabel(new Label(_("Show pickup notification"))),
// TRANSLATORS: Refers to "Show pickup notification"
mPickupChatCheckBox(new CheckBox(_("in chat"), mPickupChatEnabled)),
@@ -241,11 +242,14 @@ Setup_Video::Setup_Video():
mParticleDetail(3 - config.getIntValue("particleEmitterSkip")),
mParticleDetailSlider(new Slider(0, 3)),
mParticleDetailField(new Label),
- mFontSize(config.getIntValue("fontSize"))
+ mFontSize(config.getIntValue("fontSize")),
+ mDisableSDLTransparencyCheckBox(
+ new CheckBox(_("Disable transparency (Low CPU mode)"),
+ mSDLTransparencyDisabled))
{
setName(_("Video"));
- mShowMonsterDamageCheckBox = new CheckBox(_("Show monster damage"),
+ mShowMonsterDamageCheckBox = new CheckBox(_("Show damage"),
mShowMonsterDamageEnabled);
ScrollArea *scrollArea = new ScrollArea(mModeList);
@@ -268,6 +272,7 @@ Setup_Video::Setup_Video():
mAlphaSlider->setValue(mOpacity);
mAlphaSlider->setWidth(90);
+ mAlphaSlider->setEnabled(!mSDLTransparencyDisabled);
mFpsLabel->setCaption(mFps > 0 ? toString(mFps) : _("None"));
mFpsLabel->setWidth(60);
@@ -275,6 +280,10 @@ Setup_Video::Setup_Video():
mFpsSlider->setEnabled(mFps > 0);
mFpsCheckBox->setSelected(mFps > 0);
+ // If the openGL Mode is enabled, disabling the transaprency
+ // is irrelevant.
+ mDisableSDLTransparencyCheckBox->setEnabled(!mOpenGLEnabled);
+
// Pre-select the current video mode.
std::string videoMode = toString(graphics->getWidth()) + "x"
+ toString(graphics->getHeight());
@@ -295,13 +304,16 @@ Setup_Video::Setup_Video():
mFpsSlider->setActionEventId("fpslimitslider");
mOverlayDetailSlider->setActionEventId("overlaydetailslider");
mOverlayDetailField->setActionEventId("overlaydetailfield");
+ mOpenGLCheckBox->setActionEventId("opengl");
mParticleDetailSlider->setActionEventId("particledetailslider");
mParticleDetailField->setActionEventId("particledetailfield");
+ mDisableSDLTransparencyCheckBox->setActionEventId("disableTransparency");
mModeList->addActionListener(this);
mCustomCursorCheckBox->addActionListener(this);
mShowMonsterDamageCheckBox->addActionListener(this);
mVisibleNamesCheckBox->addActionListener(this);
+ mOpenGLCheckBox->addActionListener(this);
mParticleEffectsCheckBox->addActionListener(this);
mPickupChatCheckBox->addActionListener(this);
mPickupParticleCheckBox->addActionListener(this);
@@ -315,6 +327,7 @@ Setup_Video::Setup_Video():
mOverlayDetailField->addKeyListener(this);
mParticleDetailSlider->addActionListener(this);
mParticleDetailField->addKeyListener(this);
+ mDisableSDLTransparencyCheckBox->addActionListener(this);
mSpeechLabel->setCaption(speechModeToString(mSpeechMode));
mSpeechSlider->setValue(mSpeechMode);
@@ -372,6 +385,8 @@ Setup_Video::Setup_Video():
place(1, 11, particleDetailLabel);
place(2, 11, mParticleDetailField, 3).setPadding(2);
+ place(0, 12, mDisableSDLTransparencyCheckBox, 4);
+
setDimension(gcn::Rectangle(0, 0, 365, 300));
}
@@ -442,8 +457,9 @@ void Setup_Video::apply()
{
new OkDialog(_("Changing to OpenGL"),
_("Applying change to OpenGL requires restart. "
- "In case OpenGL messes up your game graphics, restart "
- "the game with the command line option \"--no-opengl\"."));
+ "In case OpenGL messes up your game graphics, "
+ "restart the game with the command line option "
+ "\"--no-opengl\"."));
}
else
{
@@ -451,6 +467,25 @@ void Setup_Video::apply()
_("Applying change to OpenGL requires restart."));
}
}
+ // If LowCPU is enabled from a disabled state we warn the user
+ else if (mDisableSDLTransparencyCheckBox->isSelected())
+ {
+ if (config.getValue("disableTransparency", true) == false)
+ {
+ new OkDialog(_("Transparency disabled"),
+ _("You must restart to apply changes."));
+ }
+ }
+ else
+ {
+ if (config.getValue("disableTransparency", true) == true)
+ {
+ new OkDialog(_("Transparency enabled"),
+ _("You must restart to apply changes."));
+ }
+ }
+ config.setValue("disableTransparency",
+ mDisableSDLTransparencyCheckBox->isSelected());
mFps = mFpsCheckBox->isSelected() ? (int) mFpsSlider->getValue() : 0;
mFpsSlider->setEnabled(mFps > 0);
@@ -467,13 +502,13 @@ void Setup_Video::apply()
mParticleEffectsEnabled = config.getBoolValue("particleeffects");
mNameEnabled = config.getBoolValue("showownname");
mNPCLogEnabled = config.getBoolValue("logNpcInGui");
- mSpeechMode = static_cast<Being::Speech>(
- config.getIntValue("speech"));
+ mSpeechMode = static_cast<Being::Speech>(config.getIntValue("speech"));
mOpacity = config.getFloatValue("guialpha");
mOverlayDetail = config.getIntValue("OverlayDetail");
mOpenGLEnabled = config.getBoolValue("opengl");
mPickupChatEnabled = config.getBoolValue("showpickupchat");
mPickupParticleEnabled = config.getBoolValue("showpickupparticle");
+ mSDLTransparencyDisabled = config.getBoolValue("disableTransparency");
}
void Setup_Video::cancel()
@@ -491,10 +526,13 @@ void Setup_Video::cancel()
mNameCheckBox->setSelected(mNameEnabled);
mNPCLogCheckBox->setSelected(mNPCLogEnabled);
mAlphaSlider->setValue(mOpacity);
+ mAlphaSlider->setEnabled(!mSDLTransparencyDisabled);
mOverlayDetailSlider->setValue(mOverlayDetail);
mParticleDetailSlider->setValue(mParticleDetail);
std::string text = mFpsCheckBox->isSelected() ? toString(mFps) : _("None");
mFpsLabel->setCaption(text);
+ mDisableSDLTransparencyCheckBox->setSelected(mSDLTransparencyDisabled);
+ mDisableSDLTransparencyCheckBox->setEnabled(!mOpenGLEnabled);
config.setValue("screen", mFullScreenEnabled);
@@ -518,6 +556,7 @@ void Setup_Video::cancel()
config.setValue("opengl", mOpenGLEnabled);
config.setValue("showpickupchat", mPickupChatEnabled);
config.setValue("showpickupparticle", mPickupParticleEnabled);
+ config.setValue("disableTransparency", mSDLTransparencyDisabled);
}
void Setup_Video::action(const gcn::ActionEvent &event)
@@ -626,4 +665,24 @@ void Setup_Video::action(const gcn::ActionEvent &event)
mFpsSlider->setValue(mFps);
mFpsSlider->setEnabled(mFps > 0);
}
+ else if (id == "opengl" || id == "disableTransparency")
+ {
+ // Disable transparency disabling when in OpenGL.
+ if (mOpenGLCheckBox->isSelected())
+ {
+ mDisableSDLTransparencyCheckBox->setSelected(false);
+ mDisableSDLTransparencyCheckBox->setEnabled(false);
+ }
+ else
+ {
+ mDisableSDLTransparencyCheckBox->setEnabled(true);
+ }
+
+ // Disable gui opacity slider when disabling transparency.
+ if (mDisableSDLTransparencyCheckBox->isEnabled())
+ mAlphaSlider->setEnabled(
+ !mDisableSDLTransparencyCheckBox->isSelected());
+ else
+ mAlphaSlider->setEnabled(true);
+ }
}
diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h
index ae0786b1..d0e2c492 100644
--- a/src/gui/setup_video.h
+++ b/src/gui/setup_video.h
@@ -62,6 +62,7 @@ class Setup_Video : public SetupTab, public gcn::ActionListener,
bool mPickupParticleEnabled;
double mOpacity;
int mFps;
+ bool mSDLTransparencyDisabled;
Being::Speech mSpeechMode;
ModeListModel *mModeListModel;
@@ -106,6 +107,8 @@ class Setup_Video : public SetupTab, public gcn::ActionListener,
int mFontSize;
gcn::DropDown *mFontSizeDropDown;
+
+ gcn::CheckBox *mDisableSDLTransparencyCheckBox;
};
#endif
diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp
index 588ce5e7..b4321b25 100644
--- a/src/gui/socialwindow.cpp
+++ b/src/gui/socialwindow.cpp
@@ -140,7 +140,7 @@ public:
mGuild->getName().c_str()))
mConfirmDialog = NULL;
}
- else if (event.getId() == "~yes")
+ else if (event.getId() == "no")
{
mConfirmDialog = NULL;
}
@@ -180,7 +180,7 @@ public:
{
setCaption(party->getName());
- setTabColor(&Theme::getThemeColor(Theme::PARTY));
+ setTabColor(&Theme::getThemeColor(Theme::PARTY_SOCIAL_TAB));
mList = new AvatarListBox(party);
mScroll = new ScrollArea(mList);
@@ -219,7 +219,7 @@ public:
mParty->getName().c_str()))
mConfirmDialog = NULL;
}
- else if (event.getId() == "~yes")
+ else if (event.getId() == "no")
{
mConfirmDialog = NULL;
}
@@ -498,10 +498,12 @@ void SocialWindow::action(const gcn::ActionEvent &event)
"shorter name."));
return;
}
-
- Net::getGuildHandler()->create(name);
- SERVER_NOTICE(strprintf(_("Creating guild called %s."),
- name.c_str()))
+ else if (!name.empty())
+ {
+ Net::getGuildHandler()->create(name);
+ SERVER_NOTICE(strprintf(_("Creating guild called %s."),
+ name.c_str()));
+ }
mGuildCreateDialog = NULL;
}
@@ -519,10 +521,12 @@ void SocialWindow::action(const gcn::ActionEvent &event)
"shorter name."));
return;
}
-
- Net::getPartyHandler()->create(name);
- SERVER_NOTICE(strprintf(_("Creating party called %s."),
- name.c_str()));
+ else if (!name.empty())
+ {
+ Net::getPartyHandler()->create(name);
+ SERVER_NOTICE(strprintf(_("Creating party called %s."),
+ name.c_str()));
+ }
mPartyCreateDialog = NULL;
}
diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp
index e2ae5b93..ebc01ec7 100644
--- a/src/gui/truetypefont.cpp
+++ b/src/gui/truetypefont.cpp
@@ -64,8 +64,8 @@ class TextChunk
if (!surface)
{
- throw "Rendering font to surface failed: " +
- std::string(TTF_GetError());
+ img = 0;
+ return;
}
img = Image::load(surface);
@@ -108,9 +108,7 @@ TrueTypeFont::~TrueTypeFont()
--fontCounter;
if (fontCounter == 0)
- {
TTF_Quit();
- }
}
void TrueTypeFont::drawString(gcn::Graphics *graphics,
@@ -123,9 +121,7 @@ void TrueTypeFont::drawString(gcn::Graphics *graphics,
Graphics *g = dynamic_cast<Graphics *>(graphics);
if (!g)
- {
throw "Not a valid graphics object!";
- }
gcn::Color col = g->getColor();
const float alpha = col.a / 255.0f;
@@ -154,15 +150,16 @@ void TrueTypeFont::drawString(gcn::Graphics *graphics,
if (!found)
{
if (mCache.size() >= CACHE_SIZE)
- {
mCache.pop_back();
- }
mCache.push_front(chunk);
mCache.front().generate(mFont);
}
- mCache.front().img->setAlpha(alpha);
- g->drawImage(mCache.front().img, x, y);
+ if (mCache.front().img)
+ {
+ mCache.front().img->setAlpha(alpha);
+ g->drawImage(mCache.front().img, x, y);
+ }
}
int TrueTypeFont::getWidth(const std::string &text) const
@@ -174,7 +171,10 @@ int TrueTypeFont::getWidth(const std::string &text) const
// Raise priority: move it to front
// Assumption is that TTF::draw will be called next
mCache.splice(mCache.begin(), mCache, i);
- return i->img->getWidth();
+ if (i->img)
+ return i->img->getWidth();
+ else
+ return 0;
}
}
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 0209b13f..368eef17 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -352,10 +352,17 @@ void Viewport::mousePressed(gcn::MouseEvent &event)
return;
mPlayerFollowMouse = false;
+ mBeingPopup->setVisible(false);
const int pixelX = event.getX() + (int) mPixelViewX;
const int pixelY = event.getY() + (int) mPixelViewY;
+ mHoverBeing = actorSpriteManager->findBeingByPixel(pixelX, pixelY);
+ mHoverItem = actorSpriteManager->findItem(pixelX / mMap->getTileWidth(),
+ pixelY / mMap->getTileHeight());
+
+ updateCursorType();
+
// Right click might open a popup
if (event.getButton() == gcn::MouseEvent::RIGHT)
{
@@ -452,10 +459,8 @@ void Viewport::mouseDragged(gcn::MouseEvent &event)
if (mLocalWalkTime != player_node->getActionTime())
{
mLocalWalkTime = player_node->getActionTime();
- int destX = (event.getX() + mPixelViewX + 16) /
- mMap->getTileWidth();
- int destY = (event.getY() + mPixelViewY + 16) /
- mMap->getTileHeight();
+ int destX = (event.getX() + mPixelViewX) / mMap->getTileWidth();
+ int destY = (event.getY() + mPixelViewY) / mMap->getTileHeight();
player_node->setDestination(destX, destY);
}
}
@@ -502,6 +507,11 @@ void Viewport::mouseMoved(gcn::MouseEvent &event)
mHoverItem = actorSpriteManager->findItem(x / mMap->getTileWidth(),
y / mMap->getTileHeight());
+ updateCursorType();
+}
+
+void Viewport::updateCursorType()
+{
if (mHoverBeing)
{
switch (mHoverBeing->getType())
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index c54b9860..55db3676 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -180,6 +180,11 @@ class Viewport : public WindowContainer, public gcn::MouseListener,
*/
void _followMouse();
+ /**
+ * Updates the cursor type
+ */
+ void updateCursorType();
+
Map *mMap; /**< The current map. */
int mScrollRadius;
diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp
index 6551aa04..60837ea1 100644
--- a/src/gui/widgets/avatarlistbox.cpp
+++ b/src/gui/widgets/avatarlistbox.cpp
@@ -22,7 +22,6 @@
#include "graphics.h"
-#include "gui/chat.h"
#include "gui/gui.h"
#include "gui/palette.h"
@@ -139,14 +138,6 @@ void AvatarListBox::mousePressed(gcn::MouseEvent &event)
int y = event.getY();
setSelected(y / getFont()->getHeight());
distributeActionEvent();
-
- if (event.getClickCount() == 2 && mListModel)
- {
- int selected = getSelected();
- AvatarListModel *model = static_cast<AvatarListModel*>(mListModel);
- chatWindow->addWhisperTab(model->getAvatarAt(selected)->getName(),
- true);
- }
}
// TODO: Add support for context menu
else if (event.getButton() == gcn::MouseEvent::RIGHT)
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
index d890f138..314429fa 100644
--- a/src/gui/widgets/browserbox.cpp
+++ b/src/gui/widgets/browserbox.cpp
@@ -2,6 +2,7 @@
* The Mana Client
* Copyright (C) 2004-2009 The Mana World Development Team
* Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2009 Aethyra Development Team
*
* This file is part of The Mana Client.
*
@@ -21,6 +22,8 @@
#include "gui/widgets/browserbox.h"
+#include "client.h"
+
#include "gui/widgets/linkhandler.h"
#include "resources/theme.h"
@@ -40,7 +43,9 @@ BrowserBox::BrowserBox(unsigned int mode, bool opaque):
mMaxRows(0),
mHeight(0),
mWidth(0),
- mYStart(0)
+ mYStart(0),
+ mUpdateTime(-1),
+ mAlwaysUpdate(true)
{
setFocusable(true);
addMouseListener(this);
@@ -74,13 +79,14 @@ void BrowserBox::addRow(const std::string &row)
{
std::string tmp = row;
std::string newRow;
- BROWSER_LINK bLink;
std::string::size_type idx1, idx2, idx3;
gcn::Font *font = getFont();
// Use links and user defined colors
if (mUseLinksAndUserColors)
{
+ BROWSER_LINK bLink;
+
// Check for links in format "@@link|Caption@@"
idx1 = tmp.find("@@");
while (idx1 != std::string::npos)
@@ -92,7 +98,7 @@ void BrowserBox::addRow(const std::string &row)
break;
bLink.link = tmp.substr(idx1 + 2, idx2 - (idx1 + 2));
bLink.caption = tmp.substr(idx2 + 1, idx3 - (idx2 + 1));
- bLink.y1 = mTextRows.size() * font->getHeight();
+ bLink.y1 = static_cast<int>(mTextRows.size()) * font->getHeight();
bLink.y2 = bLink.y1 + font->getHeight();
newRow += tmp.substr(0, idx1);
@@ -150,7 +156,7 @@ void BrowserBox::addRow(const std::string &row)
if (mMode == AUTO_SIZE)
{
std::string plain = newRow;
- for (idx1 = plain.find("##"); idx1 != std::string::npos; idx1 = plain.find("##"))
+ while ((idx1 = plain.find("##")) != std::string::npos)
plain.erase(idx1, 3);
// Adjust the BrowserBox size
@@ -179,11 +185,11 @@ void BrowserBox::addRow(const std::string &row)
// Wraping between words (at blank spaces)
if ((nextChar < row.size()) && (row.at(nextChar) == ' '))
{
- int nextSpacePos = row.find(" ", (nextChar + 1));
+ int nextSpacePos = static_cast<int>(
+ row.find(" ", (nextChar + 1)));
if (nextSpacePos <= 0)
- {
- nextSpacePos = row.size() - 1;
- }
+ nextSpacePos = static_cast<int>(row.size()) - 1;
+
int nextWordWidth = font->getWidth(
row.substr(nextChar,
(nextSpacePos - nextChar)));
@@ -204,12 +210,14 @@ void BrowserBox::addRow(const std::string &row)
}
}
- setHeight(font->getHeight() * (mTextRows.size() + y));
+ setHeight(font->getHeight() * (static_cast<int>(
+ mTextRows.size()) + y));
}
else
{
- setHeight(font->getHeight() * mTextRows.size());
+ setHeight(font->getHeight() * static_cast<int>(mTextRows.size()));
}
+ mUpdateTime = 0;
updateHeight();
}
@@ -225,7 +233,9 @@ void BrowserBox::clearRows()
struct MouseOverLink
{
- MouseOverLink(int x, int y) : mX(x),mY(y) { }
+ MouseOverLink(int x, int y) : mX(x), mY(y)
+ { }
+
bool operator() (BROWSER_LINK &link)
{
return (mX >= link.x1 && mX < link.x2 &&
@@ -249,7 +259,8 @@ void BrowserBox::mouseMoved(gcn::MouseEvent &event)
LinkIterator i = find_if(mLinks.begin(), mLinks.end(),
MouseOverLink(event.getX(), event.getY()));
- mSelectedLink = (i != mLinks.end()) ? (i - mLinks.begin()) : -1;
+ mSelectedLink = (i != mLinks.end())
+ ? static_cast<int>(i - mLinks.begin()) : -1;
}
void BrowserBox::draw(gcn::Graphics *graphics)
@@ -261,10 +272,7 @@ void BrowserBox::draw(gcn::Graphics *graphics)
mYStart = 0;
if (getWidth() != mWidth)
- {
- mWidth = getWidth();
updateHeight();
- }
if (mOpaque)
{
@@ -296,7 +304,28 @@ void BrowserBox::draw(gcn::Graphics *graphics)
}
}
+ gcn::Font *font = getFont();
+
+ for (LinePartIterator i = mLineParts.begin();
+ i != mLineParts.end();
+ i ++)
+ {
+ const LinePart &part = *i;
+ if (part.getY() + 50 < mYStart)
+ continue;
+ if (part.getY() > yEnd)
+ break;
+ graphics->setColor(part.getColor());
+ font->drawString(graphics, part.getText(), part.getX(), part.getY());
+ }
+
+ return;
+}
+
+int BrowserBox::calcHeight()
+{
int x = 0, y = 0;
+ int wrappedLines = 0;
int link = 0;
gcn::Font *font = getFont();
@@ -305,27 +334,13 @@ void BrowserBox::draw(gcn::Graphics *graphics)
char const *hyphen = "~";
int hyphenWidth = font->getWidth(hyphen);
- graphics->setColor(Theme::getThemeColor(Theme::TEXT));
+ gcn::Color selColor = Theme::getThemeColor(Theme::TEXT);
const gcn::Color textColor = Theme::getThemeColor(Theme::TEXT);
- TextRowsHeightIterator h = mTextRowsHeights.begin();
- for (TextRowIterator i = mTextRows.begin();
- i != mTextRows.end();
- i++, h++)
- {
- bool hidden = false;
- if (y + 50 < mYStart)
- {
- y += *(h);
- continue;
- }
- else if (y > yEnd)
- {
- break;
- }
+ mLineParts.clear();
- gcn::Color selColor = textColor;
- gcn::Color prevColor = selColor;
+ for (TextRowIterator i = mTextRows.begin(); i != mTextRows.end(); i++)
+ {
const std::string row = *(i);
bool wrapped = false;
x = 0;
@@ -333,19 +348,19 @@ void BrowserBox::draw(gcn::Graphics *graphics)
// Check for separator lines
if (row.find("---", 0) == 0)
{
- if (!hidden)
+ const int dashWidth = fontWidthMinus;
+ for (x = 0; x < getWidth(); x++)
{
- const int dashWidth = fontWidthMinus;
- for (x = 0; x < getWidth(); x++)
- {
- font->drawString(graphics, "-", x, y);
- x += dashWidth - 2;
- }
+ mLineParts.push_back(LinePart(x, y, selColor, "-"));
+ x += dashWidth - 2;
}
+
y += fontHeight;
continue;
}
+ gcn::Color prevColor = selColor;
+
// TODO: Check if we must take texture size limits into account here
// TODO: Check if some of the O(n) calls can be removed
for (std::string::size_type start = 0, end = std::string::npos;
@@ -364,14 +379,14 @@ void BrowserBox::draw(gcn::Graphics *graphics)
if (mUseLinksAndUserColors)
end = row.find("##", start + 1);
- if (!hidden
- && (mUseLinksAndUserColors ||
- (!mUseLinksAndUserColors && (start == 0))))
+ if (mUseLinksAndUserColors ||
+ (!mUseLinksAndUserColors && (start == 0)))
{
// Check for color change in format "##x", x = [L,P,0..9]
if (row.find("##", start) == start && row.size() > start + 2)
{
const char c = row.at(start + 2);
+
bool valid;
const gcn::Color col = Theme::getThemeColor(c, valid);
@@ -381,7 +396,6 @@ void BrowserBox::draw(gcn::Graphics *graphics)
}
else if (c == '<')
{
- link++;
prevColor = selColor;
selColor = col;
}
@@ -408,144 +422,12 @@ void BrowserBox::draw(gcn::Graphics *graphics)
selColor = textColor;
}
}
- start += 3;
-
- if (start == row.size())
- break;
- }
- graphics->setColor(selColor);
- }
-
- std::string::size_type len =
- end == std::string::npos ? end : end - start;
- std::string part = row.substr(start, len);
-
- // Auto wrap mode
- if (mMode == AUTO_WRAP && getWidth() > 0
- && font->getWidth(part) > 0
- && (x + font->getWidth(part) + 10) > getWidth())
- {
- bool forced = false;
-
- /* FIXME: This code layout makes it easy to crash remote
- clients by talking garbage. Forged long utf-8 characters
- will cause either a buffer underflow in substr or an
- infinite loop in the main loop. */
- do
- {
- if (!forced)
- end = row.rfind(' ', end);
-
- // Check if we have to (stupidly) force-wrap
- if (end == std::string::npos || end <= start)
- {
- forced = true;
- end = row.size();
- x += hyphenWidth; // Account for the wrap-notifier
- continue;
- }
-
- // Skip to the start of the current character
- while ((row[end] & 192) == 128)
- end--;
- end--; // And then to the last byte of the previous one
-
- part = row.substr(start, end - start + 1);
- }
- while (end > start && font->getWidth(part) > 0
- && (x + font->getWidth(part) + 10) > getWidth());
-
- if (forced)
- {
- x -= hyphenWidth; // Remove the wrap-notifier accounting
- if (y >= mYStart)
- {
- font->drawString(graphics, hyphen,
- getWidth() - hyphenWidth, y);
- }
- end++; // Skip to the next character
- }
- else
- {
- end += 2; // Skip to after the space
- }
-
- wrapped = true;
- }
-
- font->drawString(graphics, part, x, y);
-
- if (mMode == AUTO_WRAP && font->getWidth(part) == 0)
- break;
-
- x += font->getWidth(part);
- }
- y += fontHeight;
- }
- setHeight(mHeight);
-}
-
-int BrowserBox::calcHeight()
-{
- int x = 0, y = 0;
- int wrappedLines = 0;
- int link = 0;
- gcn::Font *font = getFont();
-
- int fontHeight = font->getHeight();
- int fontWidthMinus = font->getWidth("-");
- char const *hyphen = "~";
- int hyphenWidth = font->getWidth(hyphen);
-
- mTextRowsHeights.clear();
-
- for (TextRowIterator i = mTextRows.begin(); i != mTextRows.end(); i++)
- {
- const std::string row = *(i);
- bool wrapped = false;
- int yStart = y;
- x = 0;
-
- // Check for separator lines
- if (row.find("---", 0) == 0)
- {
- const int dashWidth = fontWidthMinus;
- for (x = 0; x < getWidth(); x++)
- x += dashWidth - 2;
-
- y += fontHeight;
- continue;
- }
-
- // TODO: Check if we must take texture size limits into account here
- // TODO: Check if some of the O(n) calls can be removed
- for (std::string::size_type start = 0, end = std::string::npos;
- start != std::string::npos;
- start = end, end = std::string::npos)
- {
- // Wrapped line continuation shall be indented
- if (wrapped)
- {
- y += fontHeight;
- x = 15;
- wrapped = false;
- }
-
- // "Tokenize" the string at control sequences
- if (mUseLinksAndUserColors)
- end = row.find("##", start + 1);
-
- if (mUseLinksAndUserColors ||
- (!mUseLinksAndUserColors && (start == 0)))
- {
- // Check for color change in format "##x", x = [L,P,0..9]
- if (row.find("##", start) == start && row.size() > start + 2)
- {
- const char c = row.at(start + 2);
if (c == '<')
{
- const int size = font->getWidth(mLinks[link].caption) + 1;
+ const int size =
+ font->getWidth(mLinks[link].caption) + 1;
+
mLinks[link].x1 = x;
mLinks[link].y1 = y;
mLinks[link].x2 = mLinks[link].x1 + size;
@@ -605,6 +487,8 @@ int BrowserBox::calcHeight()
if (forced)
{
x -= hyphenWidth; // Remove the wrap-notifier accounting
+ mLineParts.push_back(LinePart(getWidth() - hyphenWidth,
+ y, selColor, hyphen));
end++; // Skip to the next character
}
else
@@ -616,19 +500,26 @@ int BrowserBox::calcHeight()
wrappedLines++;
}
+ mLineParts.push_back(LinePart(x, y, selColor, part.c_str()));
+
if (mMode == AUTO_WRAP && font->getWidth(part) == 0)
break;
x += font->getWidth(part);
}
y += fontHeight;
- mTextRowsHeights.push_back(y - yStart);
}
- return (mTextRows.size() + wrappedLines) * fontHeight;
+ return (static_cast<int>(mTextRows.size()) + wrappedLines) * fontHeight;
}
void BrowserBox::updateHeight()
{
- mHeight = calcHeight();
- setHeight(mHeight);
+ if (mAlwaysUpdate || !mUpdateTime || std::abs(mUpdateTime - tick_time) > 10
+ || mTextRows.size() < 3)
+ {
+ mWidth = getWidth();
+ mHeight = calcHeight();
+ setHeight(mHeight);
+ mUpdateTime = tick_time;
+ }
}
diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h
index b71f30d7..54a2a8cc 100644
--- a/src/gui/widgets/browserbox.h
+++ b/src/gui/widgets/browserbox.h
@@ -2,6 +2,7 @@
* The Mana Client
* Copyright (C) 2004-2009 The Mana World Development Team
* Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2009 Aethyra Development Team
*
* This file is part of The Mana Client.
*
@@ -30,12 +31,39 @@
class LinkHandler;
-struct BROWSER_LINK {
+struct BROWSER_LINK
+{
int x1, x2, y1, y2; /**< Where link is placed */
std::string link;
std::string caption;
};
+class LinePart
+{
+ public:
+ LinePart(int x, int y, gcn::Color color, std::string text) :
+ mX(x), mY(y), mColor(color), mText(text)
+ {
+ }
+
+ int getX() const
+ { return mX; }
+
+ int getY() const
+ { return mY; }
+
+ const std::string &getText() const
+ { return mText; }
+
+ const gcn::Color &getColor() const
+ { return mColor; }
+
+ private:
+ int mX, mY;
+ gcn::Color mColor;
+ std::string mText;
+};
+
/**
* A simple browser box able to handle links and forward events to the
* parent conteiner.
@@ -72,7 +100,7 @@ class BrowserBox : public gcn::Widget,
/**
* Sets the maximum numbers of rows in the browser box. 0 = no limit.
*/
- void setMaxRow(int max) {mMaxRows = max; };
+ void setMaxRow(unsigned max) {mMaxRows = max; };
/**
* Disable links & user defined colors to be used in chat input.
@@ -111,8 +139,9 @@ class BrowserBox : public gcn::Widget,
/**
* BrowserBox modes.
*/
- enum {
- AUTO_SIZE,
+ enum
+ {
+ AUTO_SIZE = 0,
AUTO_WRAP /**< Maybe it needs a fix or to be redone. */
};
@@ -126,7 +155,8 @@ class BrowserBox : public gcn::Widget,
* windows and widgets. So, I think it's better keep BrowserBox
* opaque (white background) by default.
*/
- enum {
+ enum
+ {
RED = 0xff0000, /**< Color 1 */
GREEN = 0x009000, /**< Color 2 */
BLUE = 0x0000ff, /**< Color 3 */
@@ -142,21 +172,29 @@ class BrowserBox : public gcn::Widget,
* Highlight modes for links.
* This can be used for a bitmask.
*/
- enum {
+ enum
+ {
UNDERLINE = 1,
BACKGROUND = 2
};
+ typedef std::list<std::string> TextRows;
+
+ TextRows &getRows()
+ { return mTextRows; }
+
+ void setAlwaysUpdate(bool n)
+ { mAlwaysUpdate = n; }
+
private:
int calcHeight();
- typedef std::list<std::string> TextRows;
typedef TextRows::iterator TextRowIterator;
TextRows mTextRows;
- typedef std::list<int> TextRowsHeights;
- typedef TextRowsHeights::iterator TextRowsHeightIterator;
- TextRowsHeights mTextRowsHeights;
+ typedef std::list<LinePart> LinePartList;
+ typedef LinePartList::iterator LinePartIterator;
+ LinePartList mLineParts;
typedef std::vector<BROWSER_LINK> Links;
typedef Links::iterator LinkIterator;
@@ -172,6 +210,8 @@ class BrowserBox : public gcn::Widget,
int mHeight;
int mWidth;
int mYStart;
+ int mUpdateTime;
+ bool mAlwaysUpdate;
};
#endif
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index e9162ab6..c86eb2ea 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -54,6 +54,7 @@ ChatTab::ChatTab(const std::string &name) : Tab()
mTextOutput->setOpaque(false);
mTextOutput->setMaxRow((int) config.getIntValue("ChatLogLength"));
mTextOutput->setLinkHandler(chatWindow->mItemLinkHandler);
+ mTextOutput->setAlwaysUpdate(false);
mScrollArea = new ScrollArea(mTextOutput);
mScrollArea->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER,
diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp
index 2a80cc11..23dd3eb5 100644
--- a/src/gui/widgets/desktop.cpp
+++ b/src/gui/widgets/desktop.cpp
@@ -85,7 +85,7 @@ void Desktop::draw(gcn::Graphics *graphics)
if (mWallpaper)
{
- if (!mWallpaper->isAnOpenGLOne())
+ if (!mWallpaper->useOpenGL())
g->drawImage(mWallpaper,
(getWidth() - mWallpaper->getWidth()) / 2,
(getHeight() - mWallpaper->getHeight()) / 2);
@@ -114,7 +114,7 @@ void Desktop::setBestFittingWallpaper()
if (mWallpaper)
mWallpaper->decRef();
- if (!nWallPaper->isAnOpenGLOne() && (nWallPaper->getWidth() != getWidth()
+ if (!nWallPaper->useOpenGL() && (nWallPaper->getWidth() != getWidth()
|| nWallPaper->getHeight() != getHeight()))
{
// We rescale to obtain a fullscreen wallpaper...
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index c8c98d0a..d448c3c2 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -255,47 +255,13 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
if (mSelectedIndex == index)
{
- if(event.getClickCount() == 2)
- {
- if (item->getInfo().getEquippable())
- {
- if (item->isEquipped())
- item->doEvent("doUnequip");
- else
- item->doEvent("doEquip");
- }
- else
- item->doEvent("doUse");
-
- }
- else
- {
- mSelectionStatus = SEL_DESELECTING;
- }
+ mSelectionStatus = SEL_DESELECTING;
}
else if (item && item->getId())
{
- if(event.getClickCount() == 2)
- {
- if (item->getInfo().getEquippable())
- {
- if (item->isEquipped())
- item->doEvent("doUnequip");
- else
- item->doEvent("doEquip");
- }
- else
- {
- item->doEvent("doUse");
- }
- }
- else
- {
- setSelectedIndex(index);
- mSelectionStatus = SEL_SELECTING;
-
- itemShortcut->setItemSelected(item->getId());
- }
+ setSelectedIndex(index);
+ mSelectionStatus = SEL_SELECTING;
+ itemShortcut->setItemSelected(item->getId());
if (item->getInfo().getEquippable())
outfitWindow->setItemSelected(item->getId());
diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp
index f2982de9..fb4f558f 100644
--- a/src/gui/widgets/itemshortcutcontainer.cpp
+++ b/src/gui/widgets/itemshortcutcontainer.cpp
@@ -109,6 +109,7 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics)
else if (item->isEquipped())
caption = "Eq.";
+ image->setAlpha(1.0f);
g->drawImage(image, itemX, itemY);
if (item->isEquipped())
g->setColor(Theme::getThemeColor(Theme::ITEM_EQUIPPED));