summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-02-26 21:29:49 +0100
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-02-26 21:29:49 +0100
commit3008805eea4b972265597ba196ab05ce64c69965 (patch)
treed3195600e956e496b6b21f200fc04e5b08cab368
parent3ad6ac47d4967870a54fddd66aa9996724115b94 (diff)
parent6b0cff837b7adae56dc90d12e9c0e256e6aab134 (diff)
downloadmana-client-3008805eea4b972265597ba196ab05ce64c69965.tar.gz
mana-client-3008805eea4b972265597ba196ab05ce64c69965.tar.bz2
mana-client-3008805eea4b972265597ba196ab05ce64c69965.tar.xz
mana-client-3008805eea4b972265597ba196ab05ce64c69965.zip
Merge branch 'aethyra/master'
Conflicts: data/graphics/images/login_wallpaper.png src/being.cpp src/beingmanager.cpp src/engine.cpp src/game.cpp src/gui/buysell.cpp src/gui/buysell.h src/gui/gui.h src/gui/npc_text.cpp src/gui/npc_text.h src/gui/npcintegerdialog.cpp src/gui/npclistdialog.cpp src/gui/npclistdialog.h src/gui/npcstringdialog.cpp src/gui/sell.cpp src/gui/shop.cpp src/gui/table.cpp src/net/beinghandler.cpp src/net/npchandler.cpp src/net/playerhandler.cpp src/npc.cpp src/npc.h src/shopitem.cpp src/shopitem.h src/utils/stringutils.cpp src/utils/stringutils.h src/utils/trim.h
-rw-r--r--data/graphics/gui/CMakeLists.txt3
-rw-r--r--data/graphics/gui/Makefile.am3
-rw-r--r--data/graphics/gui/hits_blue.pngbin884 -> 0 bytes
-rw-r--r--data/graphics/gui/hits_red.pngbin813 -> 0 bytes
-rw-r--r--data/graphics/gui/hits_yellow.pngbin907 -> 0 bytes
-rw-r--r--src/being.cpp26
-rw-r--r--src/beingmanager.cpp8
-rw-r--r--src/engine.cpp2
-rw-r--r--src/game.cpp32
-rw-r--r--src/gui/buy.cpp2
-rw-r--r--src/gui/buy.h2
-rw-r--r--src/gui/buysell.cpp16
-rw-r--r--src/gui/gui.cpp22
-rw-r--r--src/gui/gui.h9
-rw-r--r--src/gui/listbox.cpp88
-rw-r--r--src/gui/listbox.h19
-rw-r--r--src/gui/npc_text.cpp11
-rw-r--r--src/gui/npc_text.h2
-rw-r--r--src/gui/npcintegerdialog.cpp13
-rw-r--r--src/gui/npcintegerdialog.h7
-rw-r--r--src/gui/npclistdialog.cpp14
-rw-r--r--src/gui/npclistdialog.h7
-rw-r--r--src/gui/npcstringdialog.cpp4
-rw-r--r--src/gui/npcstringdialog.h4
-rw-r--r--src/gui/sell.cpp2
-rw-r--r--src/gui/setup_video.cpp8
-rw-r--r--src/gui/shop.cpp3
-rw-r--r--src/gui/shoplistbox.cpp9
-rw-r--r--src/gui/shoplistbox.h2
-rw-r--r--src/gui/table.cpp6
-rw-r--r--src/gui/textbox.cpp32
-rw-r--r--src/gui/viewport.cpp29
-rw-r--r--src/localplayer.cpp6
-rw-r--r--src/net/beinghandler.cpp7
-rw-r--r--src/net/buysellhandler.cpp23
-rw-r--r--src/net/npchandler.cpp11
-rw-r--r--src/net/playerhandler.cpp7
-rw-r--r--src/npc.cpp11
-rw-r--r--src/npc.h2
-rw-r--r--src/shopitem.cpp6
-rw-r--r--src/shopitem.h2
-rw-r--r--tmw.cbp4
42 files changed, 295 insertions, 169 deletions
diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt
index f564253a..5ecadede 100644
--- a/data/graphics/gui/CMakeLists.txt
+++ b/data/graphics/gui/CMakeLists.txt
@@ -10,9 +10,6 @@ SET (FILES
deepbox.png
default.png
gui.xml
- hits_blue.png
- hits_red.png
- hits_yellow.png
hscroll_left_default.png
hscroll_left_highlight.png
hscroll_left_pressed.png
diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am
index e78018b7..2d68a20c 100644
--- a/data/graphics/gui/Makefile.am
+++ b/data/graphics/gui/Makefile.am
@@ -13,9 +13,6 @@ gui_DATA = \
deepbox.png \
default.png \
gui.xml \
- hits_blue.png \
- hits_red.png \
- hits_yellow.png \
hscroll_left_default.png \
hscroll_left_highlight.png \
hscroll_left_pressed.png \
diff --git a/data/graphics/gui/hits_blue.png b/data/graphics/gui/hits_blue.png
deleted file mode 100644
index cfb04ab8..00000000
--- a/data/graphics/gui/hits_blue.png
+++ /dev/null
Binary files differ
diff --git a/data/graphics/gui/hits_red.png b/data/graphics/gui/hits_red.png
deleted file mode 100644
index 150f1c1e..00000000
--- a/data/graphics/gui/hits_red.png
+++ /dev/null
Binary files differ
diff --git a/data/graphics/gui/hits_yellow.png b/data/graphics/gui/hits_yellow.png
deleted file mode 100644
index 6975dfd5..00000000
--- a/data/graphics/gui/hits_yellow.png
+++ /dev/null
Binary files differ
diff --git a/src/being.cpp b/src/being.cpp
index 43480eba..902bd4e1 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -232,20 +232,36 @@ void Being::takeDamage(int amount)
gcn::Font *font;
std::string damage = amount ? toString(amount) : "miss";
+ int red, green, blue;
+
+ font = gui->getInfoParticleFont();
+
// Selecting the right color
if (damage == "miss")
- font = hitYellowFont;
+ {
+ red = 255;
+ green = 255;
+ blue = 0;
+ }
else
{
if (getType() == MONSTER)
- font = hitBlueFont;
+ {
+ red = 0;
+ green = 100;
+ blue = 255;
+ }
else
- font = hitRedFont;
+ {
+ red = 255;
+ green = 50;
+ blue = 50;
+ }
}
// Show damage number
- particleEngine->addTextSplashEffect(damage, 255, 255, 255, font,
- mPx + 16, mPy + 16);
+ particleEngine->addTextSplashEffect(damage, red, green, blue, font,
+ mPx + 16, mPy + 16, true);
effectManager->trigger(26, this);
}
diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp
index 273436bf..15f683af 100644
--- a/src/beingmanager.cpp
+++ b/src/beingmanager.cpp
@@ -71,17 +71,17 @@ Being* BeingManager::createBeing(Uint32 id, Uint16 job)
{
Being *being;
- if (job < 10)
+ if (job <= 25 || (job >= 4001 && job <= 4049))
being = new Player(id, job, mMap);
- else if (job >= 50 && job < 1002)
+ else if (job >= 46 && job <= 1000)
being = new NPC(id, job, mMap, mNetwork);
- else if (job >= 1002 && job < 1500)
+ else if (job > 1000 && job <= 2000)
being = new Monster(id, job, mMap);
else
being = new Being(id, job, mMap);
// Player or NPC
- if (job < 1002)
+ if (job <= 1000 || (job >= 4001 && job <= 4049))
{
MessageOut outMsg(mNetwork);
outMsg.writeInt16(0x0094);
diff --git a/src/engine.cpp b/src/engine.cpp
index a67d379f..84a734d1 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -41,8 +41,6 @@
#include "utils/stringutils.h"
-char itemCurrenyQ[10] = "0";
-
Engine::Engine(Network *network):
mCurrentMap(NULL),
mNetwork(network)
diff --git a/src/game.cpp b/src/game.cpp
index 6f9dbb88..6bff0025 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -144,9 +144,9 @@ namespace {
{
void action(const gcn::ActionEvent &event)
{
- if (event.getId() == "yes" || event.getId() == "ok") {
+ if (event.getId() == "yes" || event.getId() == "ok")
done = true;
- }
+
exitConfirm = NULL;
disconnectedDialog = NULL;
}
@@ -177,13 +177,9 @@ Uint32 nextSecond(Uint32 interval, void *param)
int get_elapsed_time(int start_time)
{
if (start_time <= tick_time)
- {
return (tick_time - start_time) * 10;
- }
else
- {
return (tick_time + (MAX_TIME - start_time)) * 10;
- }
}
/**
@@ -212,8 +208,10 @@ void createGuiWindows(Network *network)
tradeWindow = new TradeWindow(network);
helpWindow = new HelpWindow;
debugWindow = new DebugWindow;
- itemShortcutWindow = new ShortcutWindow("ItemShortcut",new ItemShortcutContainer);
- emoteShortcutWindow = new ShortcutWindow("emoteShortcut",new EmoteShortcutContainer);
+ itemShortcutWindow = new ShortcutWindow("ItemShortcut",
+ new ItemShortcutContainer);
+ emoteShortcutWindow = new ShortcutWindow("emoteShortcut",
+ new EmoteShortcutContainer);
// Set initial window visibility
chatWindow->setVisible((bool) config.getValue(
@@ -467,8 +465,9 @@ void Game::logic()
if (!disconnectedDialog)
{
disconnectedDialog = new OkDialog(_("Network Error"),
- _("The connection to the server was lost, "
- "the program will now quit"));
+ _("The connection to the "
+ "server was lost, the "
+ "program will now quit"));
disconnectedDialog->addActionListener(&exitListener);
disconnectedDialog->requestMoveToTop();
}
@@ -493,7 +492,7 @@ void Game::handleInput()
gcn::Window *requestedWindow = NULL;
if (setupWindow->isVisible() &&
- keyboard.getNewKeyIndex() > keyboard.KEY_NO_VALUE)
+ keyboard.getNewKeyIndex() > keyboard.KEY_NO_VALUE)
{
keyboard.setNewKey((int) event.key.keysym.sym);
keyboard.callbackNewKey();
@@ -857,9 +856,11 @@ void Game::handleInput()
}
// Attack priorioty is: Monster, Player, auto target
- target = beingManager->findBeing(targetX, targetY, Being::MONSTER);
+ target = beingManager->findBeing(targetX, targetY,
+ Being::MONSTER);
if (!target)
- target = beingManager->findBeing(targetX, targetY, Being::PLAYER);
+ target = beingManager->findBeing(targetX, targetY,
+ Being::PLAYER);
}
player_node->attack(target, newTarget);
@@ -895,14 +896,15 @@ void Game::handleInput()
// Talk to the nearest NPC if 't' pressed
if ( keyboard.isKeyActive(keyboard.KEY_TALK) )
{
- if (!npcTextDialog->isVisible() && !npcListDialog->isVisible())
+ if (!npcTextDialog->isVisible() && !npcListDialog->isVisible() &&
+ !npcStringDialog->isVisible() && !npcIntegerDialog->isVisible())
{
Being *target = player_node->getTarget();
if (!target)
{
target = beingManager->findNearestLivingBeing(
- x, y, 20, Being::NPC);
+ x, y, 20, Being::NPC);
}
if (target)
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp
index cad21ab5..768dab4d 100644
--- a/src/gui/buy.cpp
+++ b/src/gui/buy.cpp
@@ -119,7 +119,7 @@ void BuyDialog::reset()
setMoney(0);
}
-void BuyDialog::addItem(short id, int price)
+void BuyDialog::addItem(int id, int price)
{
mShopItems->addItem(id, price);
mShopItemList->adjustSize();
diff --git a/src/gui/buy.h b/src/gui/buy.h
index 55a1898c..2555e139 100644
--- a/src/gui/buy.h
+++ b/src/gui/buy.h
@@ -68,7 +68,7 @@ class BuyDialog : public Window, public gcn::ActionListener,
/**
* Adds an item to the shop inventory.
*/
- void addItem(short id, int price);
+ void addItem(int id, int price);
/**
* Called when receiving actions from the widgets.
diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp
index c1c934d1..818413c2 100644
--- a/src/gui/buysell.cpp
+++ b/src/gui/buysell.cpp
@@ -64,12 +64,20 @@ void BuySellDialog::logic()
void BuySellDialog::action(const gcn::ActionEvent &event)
{
setVisible(false);
- int action;
- if (event.getId() == "Buy") {
+ int action = 0;
+
+ NPC::isTalking = false;
+
+ if (event.getId() == "Buy")
+ {
action = 0;
- } else if (event.getId() == "Sell") {
+ }
+ else if (event.getId() == "Sell")
+ {
action = 1;
- } else if (event.getId() == "Cancel") {
+ }
+ else if (event.getId() == "Cancel")
+ {
current_npc = 0;
return;
}
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 26192e26..6d6ccbdf 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -135,22 +135,6 @@ Gui::Gui(Graphics *graphics):
gcn::Widget::setGlobalFont(mGuiFont);
- // Load hits' colorful fonts
- try
- {
- hitRedFont = new gcn::ImageFont("graphics/gui/hits_red.png",
- "0123456789crit! ");
- hitBlueFont = new gcn::ImageFont("graphics/gui/hits_blue.png",
- "0123456789crit! ");
- hitYellowFont = new gcn::ImageFont("graphics/gui/hits_yellow.png",
- "0123456789misxp ");
- }
- catch (gcn::Exception e)
- {
- logger->error(std::string("Unable to load colored hits' fonts: ")
- + e.getMessage());
- }
-
// Initialize mouse cursor and listen for changes to the option
setUseCustomCursor(config.getValue("customcursor", 1) == 1);
mConfigListener = new GuiConfigListener(this);
@@ -168,16 +152,12 @@ Gui::~Gui()
config.removeListener("customcursor", mConfigListener);
delete mConfigListener;
- // Fonts used in showing hits
- delete hitRedFont;
- delete hitBlueFont;
- delete hitYellowFont;
-
if (mMouseCursors)
mMouseCursors->decRef();
delete mGuiFont;
delete boldFont;
+ delete mInfoParticleFont;
delete viewport;
delete getTop();
diff --git a/src/gui/gui.h b/src/gui/gui.h
index 41df3dda..340eec09 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -114,7 +114,7 @@ class Gui : public gcn::Gui
private:
GuiConfigListener *mConfigListener;
gcn::Font *mGuiFont; /**< The global GUI font */
- gcn::Font *mInfoParticleFont; /**< Font for Info Particles*/
+ gcn::Font *mInfoParticleFont; /**< Font for Info Particles*/
bool mCustomCursor; /**< Show custom cursor */
ImageSet *mMouseCursors; /**< Mouse cursor images */
float mMouseCursorAlpha;
@@ -126,13 +126,6 @@ extern Gui *gui; /**< The GUI system */
extern SDLInput *guiInput; /**< GUI input */
/**
- * Fonts used in showing hits
- */
-extern gcn::Font *hitRedFont;
-extern gcn::Font *hitBlueFont;
-extern gcn::Font *hitYellowFont;
-
-/**
* Bolded text font
*/
extern gcn::Font *boldFont;
diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp
index 74d0b9ad..64c8be85 100644
--- a/src/gui/listbox.cpp
+++ b/src/gui/listbox.cpp
@@ -21,6 +21,7 @@
#include <guichan/font.hpp>
#include <guichan/graphics.hpp>
+#include <guichan/key.hpp>
#include <guichan/listmodel.hpp>
#include "color.h"
@@ -54,7 +55,7 @@ void ListBox::draw(gcn::Graphics *graphics)
const int fontHeight = getFont()->getHeight();
- // Draw rectangle below the selected list element
+ // Draw filled rectangle around the selected list element
if (mSelected >= 0)
graphics->fillRectangle(gcn::Rectangle(0, fontHeight * mSelected,
getWidth(), fontHeight));
@@ -68,6 +69,91 @@ void ListBox::draw(gcn::Graphics *graphics)
}
}
+void ListBox::setSelected(int selected)
+{
+ if (!mListModel)
+ {
+ mSelected = -1;
+ }
+ else
+ {
+ if (selected < 0 && !mWrappingEnabled)
+ {
+ mSelected = -1;
+ }
+ else if (selected >= mListModel->getNumberOfElements() &&
+ mWrappingEnabled)
+ {
+ mSelected = 0;
+ }
+ else if ((selected >= mListModel->getNumberOfElements() &&
+ !mWrappingEnabled) || (selected < 0 && mWrappingEnabled))
+ {
+ mSelected = mListModel->getNumberOfElements() - 1;
+ }
+ else
+ {
+ mSelected = selected;
+ }
+ }
+ gcn::ListBox::setSelected(mSelected);
+}
+
+// -- KeyListener notifications
+void ListBox::keyPressed(gcn::KeyEvent& keyEvent)
+{
+ gcn::Key key = keyEvent.getKey();
+
+ if (key.getValue() == gcn::Key::ENTER || key.getValue() == gcn::Key::SPACE)
+ {
+ distributeActionEvent();
+ keyEvent.consume();
+ }
+ else if (key.getValue() == gcn::Key::UP)
+ {
+ setSelected(mSelected - 1);
+ keyEvent.consume();
+ }
+ else if (key.getValue() == gcn::Key::DOWN)
+ {
+ setSelected(mSelected + 1);
+ keyEvent.consume();
+ }
+ else if (key.getValue() == gcn::Key::HOME)
+ {
+ setSelected(0);
+ keyEvent.consume();
+ }
+ else if (key.getValue() == gcn::Key::END)
+ {
+ setSelected(getListModel()->getNumberOfElements() - 1);
+ keyEvent.consume();
+ }
+}
+
+void ListBox::mouseWheelMovedUp(gcn::MouseEvent& mouseEvent)
+{
+ if (isFocused())
+ {
+ if (getSelected() > 0 || (getSelected() == 0 && mWrappingEnabled))
+ {
+ setSelected(getSelected() - 1);
+ }
+
+ mouseEvent.consume();
+ }
+}
+
+void ListBox::mouseWheelMovedDown(gcn::MouseEvent& mouseEvent)
+{
+ if (isFocused())
+ {
+ setSelected(getSelected() + 1);
+
+ mouseEvent.consume();
+ }
+}
+
void ListBox::mouseDragged(gcn::MouseEvent &event)
{
// Pretend mouse is pressed continuously while dragged. Causes list
diff --git a/src/gui/listbox.h b/src/gui/listbox.h
index 12fcb955..cfb58f15 100644
--- a/src/gui/listbox.h
+++ b/src/gui/listbox.h
@@ -46,8 +46,27 @@ class ListBox : public gcn::ListBox
*/
void draw(gcn::Graphics *graphics);
+ // Inherited from KeyListener
+
+ void keyPressed(gcn::KeyEvent& keyEvent);
+
+ // Inherited from MouseListener
+
+ void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent);
+
+ void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent);
+
void mouseDragged(gcn::MouseEvent &event);
+ /**
+ * Sets the selected item. The selected item is represented by
+ * an index from the list model.
+ *
+ * @param selected the selected item as an index from the list model.
+ * @see getSelected
+ */
+ void setSelected(int selected);
+
private:
static float mAlpha;
};
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp
index 520efad4..954f22d8 100644
--- a/src/gui/npc_text.cpp
+++ b/src/gui/npc_text.cpp
@@ -64,6 +64,12 @@ NpcTextDialog::NpcTextDialog(Network *network):
setLocationRelativeTo(getParent());
}
+void NpcTextDialog::clearText()
+{
+ NPC::isTalking = false;
+ setText("");
+}
+
void NpcTextDialog::setText(const std::string &text)
{
mText = text;
@@ -76,11 +82,6 @@ void NpcTextDialog::addText(const std::string &text)
mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll());
}
-void NpcTextDialog::clearText()
-{
- setText("");
-}
-
void NpcTextDialog::showNextButton()
{
mButton->setCaption(_("Next"));
diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h
index 62486fff..019c22a5 100644
--- a/src/gui/npc_text.h
+++ b/src/gui/npc_text.h
@@ -102,4 +102,6 @@ class NpcTextDialog : public Window, public gcn::ActionListener
NPCTextState mState;
};
+extern NpcTextDialog *npcTextDialog;
+
#endif // NPC_TEXT_H
diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp
index f6d788df..9dc3660b 100644
--- a/src/gui/npcintegerdialog.cpp
+++ b/src/gui/npcintegerdialog.cpp
@@ -76,18 +76,23 @@ int NpcIntegerDialog::getValue()
return mValueField->getValue();
}
+void NpcIntegerDialog::reset()
+{
+ mValueField->reset();
+}
+
void NpcIntegerDialog::action(const gcn::ActionEvent &event)
{
- int finish = 0;
+ bool finish = false;
if (event.getId() == "ok")
{
- finish = 1;
+ finish = true;
npcTextDialog->addText(strprintf("\n> %d\n", mValueField->getValue()));
}
else if (event.getId() == "cancel")
{
- finish = 1;
+ finish = true;
mValueField->reset();
npcTextDialog->addText(_("\n> Cancel\n"));
}
@@ -107,12 +112,14 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event)
if (finish)
{
setVisible(false);
+ NPC::isTalking = false;
MessageOut outMsg(mNetwork);
outMsg.writeInt16(CMSG_NPC_INT_RESPONSE);
outMsg.writeInt32(current_npc);
outMsg.writeInt32(mValueField->getValue());
+ current_npc = 0;
mValueField->reset();
}
}
diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h
index 80a21848..58f6970b 100644
--- a/src/gui/npcintegerdialog.h
+++ b/src/gui/npcintegerdialog.h
@@ -55,6 +55,11 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener
int getValue();
/**
+ * Resets the integer input field.
+ */
+ void reset();
+
+ /**
* Prepares the NPC dialog.
*
* @param min The minimum value to allow
@@ -88,4 +93,6 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener
IntTextField *mValueField;
};
+extern NpcIntegerDialog *npcIntegerDialog;
+
#endif // GUI_NPCINTEGERDIALOG_H
diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp
index fc7d2979..53d4f21f 100644
--- a/src/gui/npclistdialog.cpp
+++ b/src/gui/npclistdialog.cpp
@@ -51,7 +51,9 @@ NpcListDialog::NpcListDialog(Network *network):
mItemList = new ListBox(this);
mItemList->setWrappingEnabled(true);
+
gcn::ScrollArea *scrollArea = new ScrollArea(mItemList);
+
gcn::Button *okButton = new Button(_("OK"), "ok", this);
gcn::Button *cancelButton = new Button(_("Cancel"), "cancel", this);
@@ -90,6 +92,8 @@ void NpcListDialog::parseItems(const std::string &itemString)
void NpcListDialog::reset()
{
+ NPC::isTalking = false;
+ mItemList->setSelected(-1);
mItems.clear();
}
@@ -100,6 +104,7 @@ void NpcListDialog::action(const gcn::ActionEvent &event)
{
// Send the selected index back to the server
int selectedIndex = mItemList->getSelected();
+
if (selectedIndex > -1)
{
choice = selectedIndex + 1;
@@ -118,10 +123,13 @@ void NpcListDialog::action(const gcn::ActionEvent &event)
{
setVisible(false);
reset();
+
MessageOut outMsg(mNetwork);
outMsg.writeInt16(CMSG_NPC_LIST_CHOICE);
outMsg.writeInt32(current_npc);
outMsg.writeInt8(choice);
+
+ current_npc = 0;
}
}
@@ -131,3 +139,9 @@ void NpcListDialog::setVisible(bool visible)
Window::setVisible(visible);
}
+
+void NpcListDialog::requestFocus()
+{
+ mItemList->requestFocus();
+ mItemList->setSelected(0);
+}
diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h
index a7b49506..b5a62515 100644
--- a/src/gui/npclistdialog.h
+++ b/src/gui/npclistdialog.h
@@ -76,6 +76,11 @@ class NpcListDialog : public Window, public gcn::ActionListener,
void setVisible(bool visible);
+ /**
+ * Requests the listbox to take focus for input.
+ */
+ void requestFocus();
+
private:
Network *mNetwork;
gcn::ListBox *mItemList;
@@ -83,4 +88,6 @@ class NpcListDialog : public Window, public gcn::ActionListener,
std::vector<std::string> mItems;
};
+extern NpcListDialog *npcListDialog;
+
#endif // GUI_NPCLISTDIALOG_H
diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp
index 7ed05288..fb3b43db 100644
--- a/src/gui/npcstringdialog.cpp
+++ b/src/gui/npcstringdialog.cpp
@@ -77,6 +77,8 @@ void NpcStringDialog::action(const gcn::ActionEvent &event)
}
setVisible(false);
+ NPC::isTalking = false;
+
std::string text = mValueField->getText();
mValueField->setText("");
@@ -86,6 +88,8 @@ void NpcStringDialog::action(const gcn::ActionEvent &event)
outMsg.writeInt32(current_npc);
outMsg.writeString(text, text.length());
outMsg.writeInt8(0);
+
+ current_npc = 0;
}
bool NpcStringDialog::isInputFocused()
diff --git a/src/gui/npcstringdialog.h b/src/gui/npcstringdialog.h
index 43283219..0c552baa 100644
--- a/src/gui/npcstringdialog.h
+++ b/src/gui/npcstringdialog.h
@@ -28,6 +28,8 @@
class Network;
+class Network;
+
/**
* The npc integer input dialog.
*
@@ -78,4 +80,6 @@ class NpcStringDialog : public Window, public gcn::ActionListener
std::string mDefault;
};
+extern NpcStringDialog *npcStringDialog;
+
#endif // GUI_NPCSTRINGDIALOG_H
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp
index 51fc8f9f..1aa0e2d3 100644
--- a/src/gui/sell.cpp
+++ b/src/gui/sell.cpp
@@ -121,7 +121,7 @@ void SellDialog::addItem(const Item *item, int price)
}
mShopItems->addItem(item->getInvIndex(), item->getId(),
- item->getQuantity(), price);
+ item->getQuantity(), price);
mShopItemList->adjustSize();
}
diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp
index b019edb9..e89afd94 100644
--- a/src/gui/setup_video.cpp
+++ b/src/gui/setup_video.cpp
@@ -287,7 +287,7 @@ Setup_Video::Setup_Video():
place(0, 11, mOverlayDetailSlider);
place(0, 12, mParticleDetailSlider);
- place(1, 6, alphaLabel, 2);
+ place(1, 6, alphaLabel, 3);
place(1, 7, mFpsCheckBox).setPadding(3);
place(1, 8, scrollRadiusLabel);
place(1, 9, scrollLazinessLabel);
@@ -298,9 +298,9 @@ Setup_Video::Setup_Video():
place(2, 7, mFpsField).setPadding(1);
place(2, 8, mScrollRadiusField).setPadding(1);
place(2, 9, mScrollLazinessField).setPadding(1);
- place(2, 10, mSpeechLabel, 2).setPadding(2);
- place(2, 11, mOverlayDetailField, 2).setPadding(2);
- place(2, 12, mParticleDetailField, 2).setPadding(2);
+ place(2, 10, mSpeechLabel, 3).setPadding(2);
+ place(2, 11, mOverlayDetailField, 3).setPadding(2);
+ place(2, 12, mParticleDetailField, 3).setPadding(2);
setDimension(gcn::Rectangle(0, 0, 325, 280));
}
diff --git a/src/gui/shop.cpp b/src/gui/shop.cpp
index e13e218c..85f238c0 100644
--- a/src/gui/shop.cpp
+++ b/src/gui/shop.cpp
@@ -43,8 +43,7 @@ std::string ShopItems::getElementAt(int i)
return mShopItems.at(i)->getDisplayName();
}
-void ShopItems::addItem(int inventoryIndex, int id, int quantity,
- int price)
+void ShopItems::addItem(int inventoryIndex, int id, int quantity, int price)
{
ShopItem* item = 0;
if (mMergeDuplicates)
diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp
index b258c2d8..c0c8f7a1 100644
--- a/src/gui/shoplistbox.cpp
+++ b/src/gui/shoplistbox.cpp
@@ -106,15 +106,6 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics)
}
}
-void ShopListBox::mousePressed(gcn::MouseEvent &event)
-{
- if (event.getButton() == gcn::MouseEvent::LEFT)
- {
- setSelected(event.getY() / mRowHeight);
- distributeActionEvent();
- }
-}
-
void ShopListBox::adjustSize()
{
if (mListModel)
diff --git a/src/gui/shoplistbox.h b/src/gui/shoplistbox.h
index cde4786e..5d3378b1 100644
--- a/src/gui/shoplistbox.h
+++ b/src/gui/shoplistbox.h
@@ -56,8 +56,6 @@ class ShopListBox : public ListBox
*/
unsigned int getRowHeight() const { return mRowHeight; }
- void mousePressed(gcn::MouseEvent &event);
-
/**
* gives information about the current player's money
*/
diff --git a/src/gui/table.cpp b/src/gui/table.cpp
index 1fd088ce..68f36329 100644
--- a/src/gui/table.cpp
+++ b/src/gui/table.cpp
@@ -401,25 +401,21 @@ void GuiTable::keyPressed(gcn::KeyEvent& keyEvent)
else if (key.getValue() == gcn::Key::UP)
{
setSelectedRow(mSelectedRow - 1);
-
keyEvent.consume();
}
else if (key.getValue() == gcn::Key::DOWN)
{
setSelectedRow(mSelectedRow + 1);
-
keyEvent.consume();
}
else if (key.getValue() == gcn::Key::LEFT)
{
setSelectedColumn(mSelectedColumn - 1);
-
keyEvent.consume();
}
else if (key.getValue() == gcn::Key::RIGHT)
{
setSelectedColumn(mSelectedColumn + 1);
-
keyEvent.consume();
}
else if (key.getValue() == gcn::Key::HOME)
@@ -459,7 +455,7 @@ void GuiTable::mouseWheelMovedUp(gcn::MouseEvent& mouseEvent)
{
if (isFocused())
{
- if (getSelectedRow() >= 0 )
+ if (getSelectedRow() > 0 || (getSelectedRow() == 0 && mWrappingEnabled))
{
setSelectedRow(getSelectedRow() - 1);
}
diff --git a/src/gui/textbox.cpp b/src/gui/textbox.cpp
index 2a86d549..a4024de3 100644
--- a/src/gui/textbox.cpp
+++ b/src/gui/textbox.cpp
@@ -37,52 +37,46 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension)
{
// Make sure parent scroll area sets width of this widget
if (getParent())
- {
getParent()->logic();
- }
// Take the supplied minimum dimension as a starting point and try to beat it
mMinWidth = minDimension;
std::stringstream wrappedStream;
- std::string::size_type newlinePos, lastNewlinePos = 0;
+ std::string::size_type spacePos, newlinePos, lastNewlinePos = 0;
int minWidth = 0;
int xpos;
+ spacePos = text.rfind(" ", text.size());
+
+ if (spacePos != std::string::npos)
+ {
+ const std::string word = text.substr(spacePos + 1);
+ const int length = getFont()->getWidth(word);
+
+ if (length > mMinWidth)
+ mMinWidth = length;
+ }
+
do
{
// Determine next piece of string to wrap
newlinePos = text.find("\n", lastNewlinePos);
if (newlinePos == std::string::npos)
- {
newlinePos = text.size();
- }
std::string line =
text.substr(lastNewlinePos, newlinePos - lastNewlinePos);
- std::string::size_type spacePos, lastSpacePos = 0;
+ std::string::size_type lastSpacePos = 0;
xpos = 0;
- spacePos = text.rfind(" ", text.size());
-
- if (spacePos != std::string::npos)
- {
- const std::string word = text.substr(spacePos + 1);
- const int length = getFont()->getWidth(word);
-
- if (length > mMinWidth)
- mMinWidth = length;
- }
-
do
{
spacePos = line.find(" ", lastSpacePos);
if (spacePos == std::string::npos)
- {
spacePos = line.size();
- }
std::string word =
line.substr(lastSpacePos, spacePos - lastSpacePos);
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 1ac82281..cba52cf9 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -113,19 +113,23 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
{
if (player_x > mPixelViewX + mScrollRadius)
{
- mPixelViewX += (player_x - mPixelViewX - mScrollRadius) / mScrollLaziness;
+ mPixelViewX += (player_x - mPixelViewX - mScrollRadius) /
+ mScrollLaziness;
}
if (player_x < mPixelViewX - mScrollRadius)
{
- mPixelViewX += (player_x - mPixelViewX + mScrollRadius) / mScrollLaziness;
+ mPixelViewX += (player_x - mPixelViewX + mScrollRadius) /
+ mScrollLaziness;
}
if (player_y > mPixelViewY + mScrollRadius)
{
- mPixelViewY += (player_y - mPixelViewY - mScrollRadius) / mScrollLaziness;
+ mPixelViewY += (player_y - mPixelViewY - mScrollRadius) /
+ mScrollLaziness;
}
if (player_y < mPixelViewY - mScrollRadius)
{
- mPixelViewY += (player_y - mPixelViewY + mScrollRadius) / mScrollLaziness;
+ mPixelViewY += (player_y - mPixelViewY + mScrollRadius) /
+ mScrollLaziness;
}
lastTick++;
}
@@ -168,8 +172,8 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
{
mMap->draw(graphics, (int) mPixelViewX, (int) mPixelViewY);
- // Find a path from the player to the mouse, and draw it. This is for debug
- // purposes.
+ // Find a path from the player to the mouse, and draw it. This is for
+ // debug purposes.
if (mShowDebugPath)
{
// Get the current mouse position
@@ -179,7 +183,8 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
int mouseTileX = mouseX / 32 + mTileViewX;
int mouseTileY = mouseY / 32 + mTileViewY;
- Path debugPath = mMap->findPath(player_node->mX, player_node->mY, mouseTileX, mouseTileY);
+ Path debugPath = mMap->findPath(player_node->mX, player_node->mY,
+ mouseTileX, mouseTileY);
graphics->setColor(gcn::Color(255, 0, 0));
for (PathIterator i = debugPath.begin(); i != debugPath.end(); i++)
@@ -188,7 +193,9 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
int squareY = i->y * 32 - (int) mPixelViewY + 12;
graphics->fillRectangle(gcn::Rectangle(squareX, squareY, 8, 8));
- graphics->drawText(toString(mMap->getMetaTile(i->x, i->y)->Gcost), squareX + 4, squareY + 12, gcn::Graphics::CENTER);
+ graphics->drawText(toString(mMap->getMetaTile(i->x, i->y)->Gcost),
+ squareX + 4, squareY + 12,
+ gcn::Graphics::CENTER);
}
}
}
@@ -305,10 +312,12 @@ void Viewport::mousePressed(gcn::MouseEvent &event)
if (being->mAction == Being::DEAD)
break;
- if (player_node->withinAttackRange(being) || keyboard.isKeyActive(keyboard.KEY_ATTACK))
+ if (player_node->withinAttackRange(being) ||
+ keyboard.isKeyActive(keyboard.KEY_ATTACK))
{
player_node->setGotoTarget(being);
- player_node->attack(being, !keyboard.isKeyActive(keyboard.KEY_TARGET));
+ player_node->attack(being,
+ !keyboard.isKeyActive(keyboard.KEY_TARGET));
}
else
{
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index ea05bd7e..c3e3f87a 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -581,8 +581,10 @@ void LocalPlayer::setXp(int xp)
const std::string text = toString(xp - mXp) + " xp";
// Show XP number
- particleEngine->addTextRiseFadeOutEffect(text, hitYellowFont,
- mPx + 16, mPy - 16);
+ particleEngine->addTextRiseFadeOutEffect(text,
+ gui->getInfoParticleFont(),
+ mPx + 16, mPy - 16,
+ 255, 255, 0, true);
}
mXp = xp;
}
diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp
index 982667d1..b706b088 100644
--- a/src/net/beinghandler.cpp
+++ b/src/net/beinghandler.cpp
@@ -211,7 +211,7 @@ void BeingHandler::handleMessage(MessageIn *msg)
id = msg->readInt32();
if (id == current_npc)
- npcTextDialog->showCloseButton();
+ npcTextDialog->showCloseButton();
dstBeing = beingManager->findBeing(id);
@@ -456,11 +456,6 @@ void BeingHandler::handleMessage(MessageIn *msg)
{
switch (msg->readInt8())
{
- case 1:
- if (dstBeing->getType() != Being::NPC)
- dstBeing->setAction(Being::DEAD);
- break;
-
case 2:
dstBeing->setAction(Being::SIT);
break;
diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp
index 714bc0ea..65f8498a 100644
--- a/src/net/buysellhandler.cpp
+++ b/src/net/buysellhandler.cpp
@@ -88,7 +88,8 @@ void BuySellHandler::handleMessage(MessageIn *msg)
case SMSG_NPC_SELL:
msg->readInt16(); // length
n_items = (msg->getLength() - 4) / 10;
- if (n_items > 0) {
+ if (n_items > 0)
+ {
sellDialog->setMoney(player_node->mGp);
sellDialog->reset();
sellDialog->setVisible(true);
@@ -100,21 +101,25 @@ void BuySellHandler::handleMessage(MessageIn *msg)
msg->readInt32(); // OCvalue
Item *item = player_node->getInventory()->getItem(index);
- if (item && !(item->isEquipped())) {
+
+ if (item && !(item->isEquipped()))
sellDialog->addItem(item, value);
- }
}
}
- else {
+ else
+ {
chatWindow->chatLog(_("Nothing to sell"), BY_SERVER);
current_npc = 0;
}
break;
case SMSG_NPC_BUY_RESPONSE:
- if (msg->readInt8() == 0) {
+ if (msg->readInt8() == 0)
+ {
chatWindow->chatLog(_("Thanks for buying"), BY_SERVER);
- } else {
+ }
+ else
+ {
// Reset player money since buy dialog already assumed purchase
// would go fine
buyDialog->setMoney(player_node->mGp);
@@ -123,11 +128,11 @@ void BuySellHandler::handleMessage(MessageIn *msg)
break;
case SMSG_NPC_SELL_RESPONSE:
- if (msg->readInt8() == 0) {
+ if (msg->readInt8() == 0)
chatWindow->chatLog(_("Thanks for selling"), BY_SERVER);
- } else {
+ else
chatWindow->chatLog(_("Unable to sell"), BY_SERVER);
- }
+
break;
}
}
diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp
index 405217bb..2ecd4726 100644
--- a/src/net/npchandler.cpp
+++ b/src/net/npchandler.cpp
@@ -19,6 +19,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include <SDL_types.h>
+
#include "messagein.h"
#include "npchandler.h"
#include "protocol.h"
@@ -32,11 +34,6 @@
#include "../gui/npclistdialog.h"
#include "../gui/npcstringdialog.h"
-extern NpcIntegerDialog *npcIntegerDialog;
-extern NpcListDialog *npcListDialog;
-extern NpcTextDialog *npcTextDialog;
-extern NpcStringDialog *npcStringDialog;
-
NPCHandler::NPCHandler()
{
static const Uint16 _messages[] = {
@@ -53,7 +50,7 @@ NPCHandler::NPCHandler()
void NPCHandler::handleMessage(MessageIn *msg)
{
- int id;
+ Uint32 id;
switch (msg->getId())
{
@@ -63,6 +60,7 @@ void NPCHandler::handleMessage(MessageIn *msg)
player_node->setAction(LocalPlayer::STAND);
npcListDialog->parseItems(msg->readString(msg->getLength() - 8));
npcListDialog->setVisible(true);
+ npcListDialog->requestFocus();
break;
case SMSG_NPC_MESSAGE:
@@ -70,7 +68,6 @@ void NPCHandler::handleMessage(MessageIn *msg)
current_npc = msg->readInt32();
player_node->setAction(LocalPlayer::STAND);
npcTextDialog->addText(msg->readString(msg->getLength() - 8));
- npcListDialog->setVisible(false);
npcTextDialog->setVisible(true);
break;
diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp
index 550753b7..7790cdd0 100644
--- a/src/net/playerhandler.cpp
+++ b/src/net/playerhandler.cpp
@@ -48,10 +48,6 @@
OkDialog *weightNotice = NULL;
OkDialog *deathNotice = NULL;
-extern NpcIntegerDialog *npcIntegerDialog;
-extern NpcListDialog *npcListDialog;
-extern NpcStringDialog *npcStringDialog;
-extern NpcTextDialog *npcTextDialog;
extern BuyDialog *buyDialog;
extern SellDialog *sellDialog;
extern Window *buySellDialog;
@@ -85,8 +81,11 @@ namespace {
{
player_node->revive();
deathNotice = NULL;
+ npcIntegerDialog->reset();
npcIntegerDialog->setVisible(false);
+ npcListDialog->reset();
npcListDialog->setVisible(false);
+ npcStringDialog->setValue("");
npcStringDialog->setVisible(false);
npcTextDialog->clearText();
npcTextDialog->setVisible(false);
diff --git a/src/npc.cpp b/src/npc.cpp
index 5132e0dc..7ba25c08 100644
--- a/src/npc.cpp
+++ b/src/npc.cpp
@@ -32,10 +32,8 @@
#include "resources/npcdb.h"
-extern NpcTextDialog *npcTextDialog;
-
-int current_npc = 0;
bool NPC::isTalking = false;
+int current_npc = 0;
static const int NAME_X_OFFSET = 15;
static const int NAME_Y_OFFSET = 30;
@@ -51,7 +49,8 @@ NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network):
i != info.sprites.end();
i++)
{
- if (c == VECTOREND_SPRITE) break;
+ if (c == VECTOREND_SPRITE)
+ break;
std::string file = "graphics/sprites/" + (*i)->sprite;
int variant = (*i)->variant;
@@ -108,7 +107,7 @@ Being::Type NPC::getType() const
void NPC::talk()
{
- if (isTalking || !this || !mNetwork) return;
+ if (isTalking || !mNetwork) return;
isTalking = true;
MessageOut outMsg(mNetwork);
@@ -120,7 +119,5 @@ void NPC::talk()
void NPC::updateCoords()
{
if (mName)
- {
mName->adviseXY(mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET);
- }
}
diff --git a/src/npc.h b/src/npc.h
index 182da3e5..216fb2fe 100644
--- a/src/npc.h
+++ b/src/npc.h
@@ -22,6 +22,8 @@
#ifndef NPC_H
#define NPC_H
+#include <SDL_types.h>
+
#include "player.h"
class Network;
diff --git a/src/shopitem.cpp b/src/shopitem.cpp
index d6bb1d49..ee55799f 100644
--- a/src/shopitem.cpp
+++ b/src/shopitem.cpp
@@ -51,8 +51,7 @@ ShopItem::~ShopItem()
}
}
-void ShopItem::addDuplicate(int inventoryIndex,
- int quantity)
+void ShopItem::addDuplicate(int inventoryIndex, int quantity)
{
DuplicateItem* di = new DuplicateItem;
di->inventoryIndex = inventoryIndex;
@@ -76,7 +75,8 @@ int ShopItem::sellCurrentDuplicate(int quantity)
int sellCount = quantity <= dupl->quantity ? quantity : dupl->quantity;
dupl->quantity -= sellCount;
mQuantity -= sellCount;
- if (dupl->quantity == 0) {
+ if (dupl->quantity == 0)
+ {
delete dupl;
mDuplicates.pop();
}
diff --git a/src/shopitem.h b/src/shopitem.h
index 69bed334..3b00a3c8 100644
--- a/src/shopitem.h
+++ b/src/shopitem.h
@@ -88,7 +88,7 @@ class ShopItem : public Item
*/
int getCurrentInvIndex() {
return mDuplicates.empty() ? mInvIndex :
- mDuplicates.top()->inventoryIndex;
+ mDuplicates.top()->inventoryIndex;
}
/**
diff --git a/tmw.cbp b/tmw.cbp
index 9b0c54bc..4132dbf3 100644
--- a/tmw.cbp
+++ b/tmw.cbp
@@ -420,10 +420,10 @@
<Unit filename="src\utils\fastsqrt.h" />
<Unit filename="src\utils\gettext.h" />
<Unit filename="src\utils\mutex.h" />
+ <Unit filename="src\utils\stringutils.cpp" />
+ <Unit filename="src\utils\stringutils.h" />
<Unit filename="src\utils\strprintf.cpp" />
<Unit filename="src\utils\strprintf.h" />
- <Unit filename="src\utils\tostring.h" />
- <Unit filename="src\utils\trim.h" />
<Unit filename="src\utils\xml.cpp" />
<Unit filename="src\utils\xml.h" />
<Unit filename="src\vector.cpp" />