diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/buy.cpp | 57 | ||||
-rw-r--r-- | src/gui/chargedialog.cpp | 1 | ||||
-rw-r--r-- | src/gui/listbox.cpp | 7 | ||||
-rw-r--r-- | src/gui/listbox.h | 4 | ||||
-rw-r--r-- | src/gui/sell.cpp | 3 | ||||
-rw-r--r-- | src/gui/shop.cpp | 2 | ||||
-rw-r--r-- | src/gui/shoplistbox.cpp | 142 | ||||
-rw-r--r-- | src/gui/shoplistbox.h | 20 | ||||
-rw-r--r-- | src/gui/updatewindow.cpp | 175 | ||||
-rw-r--r-- | src/gui/updatewindow.h | 9 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 4 |
11 files changed, 212 insertions, 212 deletions
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 9fcf752b..102dd49e 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -85,7 +85,6 @@ BuyDialog::BuyDialog(): mShopItemList->setEventId("item"); mSlider->setEventId("slider"); - mShopItemList->addActionListener(this); mShopItemList->addSelectionListener(this); mSlider->addActionListener(this); @@ -112,7 +111,7 @@ void BuyDialog::setMoney(int amount) { mMoney = amount; mShopItemList->setPlayersMoney(amount); - mMoneyLabel->setCaption("Price : 0 GP / " + toString(mMoney) + " GP"); + mMoneyLabel->setCaption("Price: 0 GP / " + toString(mMoney) + " GP"); mMoneyLabel->adjustSize(); } @@ -129,7 +128,7 @@ void BuyDialog::reset() mDecreaseButton->setEnabled(false); mQuantityLabel->setCaption("0"); mQuantityLabel->adjustSize(); - mMoneyLabel->setCaption("Price : 0 GP / " + toString(mMoney) + " GP"); + mMoneyLabel->setCaption("Price: 0 GP / " + toString(mMoney) + " GP"); mMoneyLabel->adjustSize(); mItemDescLabel->setCaption(""); mItemEffectLabel->setCaption(""); @@ -145,31 +144,7 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) { int selectedItem = mShopItemList->getSelected(); - if (eventId == "item") - { - // Reset amount of items and update labels - mAmountItems = 0; - mSlider->setValue(0); - mQuantityLabel->setCaption("0"); - mQuantityLabel->adjustSize(); - mMoneyLabel->setCaption("Price : 0 GP / " + toString(mMoney) + " GP"); - mMoneyLabel->adjustSize(); - - // Disable buttons for buying and decreasing - mBuyButton->setEnabled(false); - mDecreaseButton->setEnabled(false); - - // If no item was selected, none can be bought, otherwise - // calculate how many the player can afford - mMaxItems = (mShopItemList->getSelected() == -1) ? 0 : - mMoney / mShopItems->at(selectedItem).price; - - // When at least one item can be bought, enable the slider and the - // increase button - mIncreaseButton->setEnabled(mMaxItems > 0); - mSlider->setEnabled(mMaxItems > 0); - } - else if (eventId == "quit") + if (eventId == "quit") { setVisible(false); current_npc = 0; @@ -253,7 +228,7 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) mQuantityLabel->adjustSize(); int price = mAmountItems * mShopItems->at(selectedItem).price; - mMoneyLabel->setCaption("Price : " + toString(price) + " GP / " + mMoneyLabel->setCaption("Price: " + toString(price) + " GP / " + toString(mMoney) + " GP" ); mMoneyLabel->adjustSize(); } @@ -261,19 +236,39 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) void BuyDialog::selectionChanged(const SelectionEvent &event) { + // Reset amount of items and update labels + mAmountItems = 0; + mSlider->setValue(0); + mQuantityLabel->setCaption("0"); + mQuantityLabel->adjustSize(); + mMoneyLabel->setCaption("Price: 0 GP / " + toString(mMoney) + " GP"); + mMoneyLabel->adjustSize(); + + // Disable buttons for buying and decreasing + mBuyButton->setEnabled(false); + mDecreaseButton->setEnabled(false); + int selectedItem = mShopItemList->getSelected(); if (selectedItem > -1) { - const ItemInfo &info = - ItemDB::get(mShopItems->at(selectedItem).id); + const ItemInfo &info = ItemDB::get(mShopItems->at(selectedItem).id); mItemDescLabel->setCaption("Description: " + info.getDescription()); mItemEffectLabel->setCaption("Effect: " + info.getEffect()); + + // Calculate how many the player can afford + mMaxItems = mMoney / mShopItems->at(selectedItem).price; } else { mItemDescLabel->setCaption("Description:"); mItemEffectLabel->setCaption("Effect:"); + mMaxItems = 0; } + + // When at least one item can be bought, enable the slider and the + // increase button + mIncreaseButton->setEnabled(mMaxItems > 0); + mSlider->setEnabled(mMaxItems > 0); } diff --git a/src/gui/chargedialog.cpp b/src/gui/chargedialog.cpp index 349ca223..862378ae 100644 --- a/src/gui/chargedialog.cpp +++ b/src/gui/chargedialog.cpp @@ -37,6 +37,7 @@ ChargeDialog::ChargeDialog(): mProgBar = new ProgressBar(0.0f, 140, 25, 128, 128, 128); mProgBar->setPosition(20, 40); add(mProgBar); + setVisible(true); } // update the dialog diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index 14626d06..d4a2c6cb 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -38,9 +38,8 @@ ListBox::ListBox(gcn::ListModel *listModel): void ListBox::draw(gcn::Graphics *graphics) { - if (mListModel == NULL) { + if (!mListModel) return; - } graphics->setColor(gcn::Color(110, 160, 255)); graphics->setFont(getFont()); @@ -54,7 +53,9 @@ void ListBox::draw(gcn::Graphics *graphics) } // Draw the list elements - for (int i = 0, y = 0; i < mListModel->getNumberOfElements(); ++i, y += fontHeight) + for (int i = 0, y = 0; + i < mListModel->getNumberOfElements(); + ++i, y += fontHeight) { graphics->drawText(mListModel->getElementAt(i), 1, y); } diff --git a/src/gui/listbox.h b/src/gui/listbox.h index c1932f54..deca07cf 100644 --- a/src/gui/listbox.h +++ b/src/gui/listbox.h @@ -73,9 +73,9 @@ class ListBox : public gcn::ListBox /** * Sets the index of the selected element. */ - void setSelected(int selected); + virtual void setSelected(int selected); - private: + protected: /** * Sends out selection events to the list of selection listeners. */ diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 499bbd05..b0957f9e 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -142,7 +142,8 @@ void SellDialog::addItem(Item *item, int price) ITEM_SHOP item_shop; - item_shop.name = item->getInfo().getName() + " " + toString(price) + " GP"; + item_shop.name = item->getInfo().getName() + + " (" + toString(price) + " GP)"; item_shop.price = price; item_shop.index = item->getInvIndex(); item_shop.id = item->getId(); diff --git a/src/gui/shop.cpp b/src/gui/shop.cpp index 2d33e8a8..3d972bc2 100644 --- a/src/gui/shop.cpp +++ b/src/gui/shop.cpp @@ -45,7 +45,7 @@ void ShopItems::addItem(short id, int price) ITEM_SHOP item_shop; item_shop.name = ItemDB::get(id).getName() - + " " + toString(price) + " GP"; + + " (" + toString(price) + " GP)"; item_shop.price = price; item_shop.id = id; item_shop.image = ItemDB::get(id).getImage(); diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp index 61abff35..4821067c 100644 --- a/src/gui/shoplistbox.cpp +++ b/src/gui/shoplistbox.cpp @@ -34,11 +34,10 @@ #include "../graphics.h" -const int ITEM_SPRITE_HEIGHT = 32; +const int ITEM_ICON_SIZE = 32; ShopListBox::ShopListBox(gcn::ListModel *listModel): - gcn::ListBox(listModel), - mMousePressed(false), + ListBox(listModel), mPlayerMoney(0) { mRowHeight = getFont()->getHeight(); @@ -46,105 +45,101 @@ ShopListBox::ShopListBox(gcn::ListModel *listModel): } ShopListBox::ShopListBox(gcn::ListModel *listModel, ShopItems *shopListModel): - gcn::ListBox(listModel), - mMousePressed(false), + ListBox(listModel), mPlayerMoney(0), mShopItems(shopListModel) { - mRowHeight = (getFont()->getHeight() > ITEM_SPRITE_HEIGHT ? - getFont()->getHeight() : ITEM_SPRITE_HEIGHT); + mRowHeight = std::max(getFont()->getHeight(), ITEM_ICON_SIZE); mPriceCheck = true; } - void ShopListBox::setPlayersMoney(int money) { mPlayerMoney = money; } -void ShopListBox::draw(gcn::Graphics *graphics) +void ShopListBox::draw(gcn::Graphics *gcnGraphics) { - if (mListModel == NULL) { + if (!mListModel) return; - } + + Graphics *graphics = static_cast<Graphics*>(gcnGraphics); graphics->setFont(getFont()); // Draw the list elements - for (int i = 0, y = 0; i < mListModel->getNumberOfElements(); ++i, y += mRowHeight) + for (int i = 0, y = 0; + i < mListModel->getNumberOfElements(); + ++i, y += mRowHeight) { - graphics->setColor(gcn::Color(0xffffff)); - if (mShopItems != NULL) + gcn::Color backgroundColor = gcn::Color(0xffffff); + + if (i == mSelected) { - if(mPlayerMoney < mShopItems->at(i).price && mPriceCheck) - { - graphics->setColor(gcn::Color(0x919191)); - } + backgroundColor = gcn::Color(110, 160, 255); } + else if (mShopItems && + mPlayerMoney < mShopItems->at(i).price && mPriceCheck) + { + backgroundColor = gcn::Color(0x919191); + } + + graphics->setColor(backgroundColor); graphics->fillRectangle(gcn::Rectangle(0, y, getWidth(), mRowHeight)); - if (mShopItems) - dynamic_cast<Graphics*>(graphics)->drawImage(mShopItems->at(i).image, 1, y); - graphics->drawText(mListModel->getElementAt(i), ITEM_SPRITE_HEIGHT, y); - } - // Draw rectangle below the selected list element and the list element - // not shown. - if (mSelected >= 0) { - graphics->setColor(gcn::Color(110, 160, 255)); - graphics->fillRectangle(gcn::Rectangle(0, mRowHeight * mSelected, - getWidth(), mRowHeight)); if (mShopItems) - dynamic_cast<Graphics*>(graphics)->drawImage( - mShopItems->at(mSelected).image, 1, mRowHeight * mSelected); - graphics->drawText(mListModel->getElementAt(mSelected), - ITEM_SPRITE_HEIGHT, mRowHeight * mSelected); + { + Image *icon = mShopItems->at(i).image; + if (icon) + { + graphics->drawImage(icon, 1, y); + } + } + graphics->drawText(mListModel->getElementAt(i), ITEM_ICON_SIZE + 5, + y + (ITEM_ICON_SIZE - getFont()->getHeight()) / 2); } } void ShopListBox::setSelected(int selected) { - gcn::ListBox::setSelected(selected); - if (mListModel != NULL) + if (!mListModel) { - gcn::BasicContainer *par = getParent(); - if (par == NULL) - { - return; - } - - gcn::Rectangle scroll; + mSelected = -1; + } + else + { + // Update mSelected with bounds checking + mSelected = std::min(mListModel->getNumberOfElements() - 1, + std::max(-1, selected)); - if (mSelected < 0) + gcn::BasicContainer *parent = getParent(); + if (parent) { - scroll.y = 0; + gcn::Rectangle scroll; + scroll.y = (mSelected < 0) ? 0 : mRowHeight * mSelected; + scroll.height = mRowHeight; + parent->showWidgetPart(this, scroll); } - else - { - scroll.y = mRowHeight * mSelected; - } - - scroll.height = mRowHeight; - par->showWidgetPart(this, scroll); } + fireSelectionChangedEvent(); } void ShopListBox::mousePress(int x, int y, int button) { - - bool enoughMoney = false; if (button == gcn::MouseInput::LEFT && hasMouse()) { - if (mShopItems) + bool enoughMoney = false; + + if (mShopItems && mPriceCheck) { - if(mPlayerMoney >= mShopItems->at(y / mRowHeight).price) + if (mPlayerMoney >= mShopItems->at(y / mRowHeight).price) enoughMoney = true; } else // Old Behaviour + { enoughMoney = true; - - if (!mPriceCheck) - enoughMoney = true; + } if (enoughMoney) { @@ -155,40 +150,9 @@ void ShopListBox::mousePress(int x, int y, int button) } } -void ShopListBox::mouseRelease(int x, int y, int button) -{ - gcn::ListBox::mouseRelease(x, y, button); - - mMousePressed = false; -} - -void ShopListBox::mouseMotion(int x, int y) -{ - gcn::ListBox::mouseMotion(x, y); - - // Pretend mouse is pressed continuously while dragged. Causes list - // selection to be updated as is default in many GUIs. - if (mMousePressed) - { - mousePress(x, y, gcn::MouseInput::LEFT); - } -} - -void ShopListBox::fireSelectionChangedEvent() -{ - SelectionEvent event(this); - SelectionListeners::iterator i_end = mListeners.end(); - SelectionListeners::iterator i; - - for (i = mListeners.begin(); i != i_end; ++i) - { - (*i)->selectionChanged(event); - } -} - void ShopListBox::adjustSize() { - if (mListModel != NULL) + if (mListModel) { setHeight(mRowHeight * mListModel->getNumberOfElements()); } diff --git a/src/gui/shoplistbox.h b/src/gui/shoplistbox.h index 2dff8977..476564b2 100644 --- a/src/gui/shoplistbox.h +++ b/src/gui/shoplistbox.h @@ -21,10 +21,10 @@ * $Id: listbox.h 2655 2006-09-03 21:25:02Z b_lindeijer $ */ -#ifndef _TMW_LISTBOX_H -#define _TMW_LISTBOX_H +#ifndef _TMW_SHOPLISTBOX_H +#define _TMW_SHOPLISTBOX_H -#include <guichan/widgets/listbox.hpp> +#include "listbox.h" #include "shop.h" class SelectionListener; @@ -36,7 +36,7 @@ class SelectionListener; * * \ingroup GUI */ -class ShopListBox : public gcn::ListBox +class ShopListBox : public ListBox { public: /** @@ -55,8 +55,6 @@ class ShopListBox : public gcn::ListBox void draw(gcn::Graphics *graphics); void mousePress(int x, int y, int button); - void mouseRelease(int x, int y, int button); - void mouseMotion(int x, int y); /** * Adds a listener to the list that's notified each time a change to @@ -98,15 +96,6 @@ class ShopListBox : public gcn::ListBox void setPriceCheck(bool check); private: - /** - * Sends out selection events to the list of selection listeners. - */ - void fireSelectionChangedEvent(); - - bool mMousePressed; /**< Keeps track of mouse pressed status. */ - - std::list<SelectionListener*> mListeners; - int mPlayerMoney; /** @@ -118,7 +107,6 @@ class ShopListBox : public gcn::ListBox int mRowHeight; /**< Row Height */ bool mPriceCheck; - }; #endif diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 73343483..73e4489e 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -26,6 +26,7 @@ #include <iostream> #include <SDL.h> #include <SDL_thread.h> +#include <zlib.h> #include <curl/curl.h> @@ -48,9 +49,9 @@ UpdaterWindow::UpdaterWindow(): Window("Updating..."), mThread(NULL), mMutex(NULL), mDownloadStatus(UPDATE_NEWS), mUpdateHost(""), mCurrentFile("news.txt"), mBasePath(""), - mStoreInMemory(true), mDownloadComplete(true), mUserCancel(false), - mDownloadedBytes(0), mMemoryBuffer(NULL), - mCurlError(new char[CURL_ERROR_SIZE]), mFileIndex(0) + mStoreInMemory(true), mDownloadComplete(true), mUserCancel(false), + mDownloadedBytes(0), mMemoryBuffer(NULL), + mCurlError(new char[CURL_ERROR_SIZE]), mLineIndex(0) { mCurlError[0] = 0; @@ -83,8 +84,9 @@ UpdaterWindow::UpdaterWindow(): add(mCancelButton); add(mPlayButton); - mCancelButton->requestFocus(); setLocationRelativeTo(getParent()); + setVisible(true); + mCancelButton->requestFocus(); mUpdateHost = config.getValue("updatehost", "http://updates.themanaworld.org"); @@ -179,7 +181,6 @@ void UpdaterWindow::loadNews() mMemoryBuffer = NULL; mScrollArea->setVerticalScrollAmount(0); - setVisible(true); } int UpdaterWindow::updateProgress(void *ptr, @@ -227,78 +228,116 @@ size_t UpdaterWindow::memoryWrite(void *ptr, int UpdaterWindow::downloadThread(void *ptr) { + int attempts = 0; + UpdaterWindow *uw = reinterpret_cast<UpdaterWindow *>(ptr); CURL *curl; CURLcode res; - FILE *outfile = NULL; - UpdaterWindow *uw = reinterpret_cast<UpdaterWindow *>(ptr); std::string outFilename; std::string url(uw->mUpdateHost + "/" + uw->mCurrentFile); - uw->setLabel(uw->mCurrentFile + " (0%)"); - curl = curl_easy_init(); + while (attempts < 3 && !uw->mDownloadComplete) { + FILE *outfile = NULL; + uw->setLabel(uw->mCurrentFile + " (0%)"); - if (curl) - { - logger->log("Downloading: %s", url.c_str()); + curl = curl_easy_init(); - if (uw->mStoreInMemory) + if (curl) { - uw->mDownloadedBytes = 0; - curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, - UpdaterWindow::memoryWrite); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, ptr); - } - else - { - // Download in the proper folder : ./updates under win, - // /home/user/.tmw/updates for unices - outFilename = uw->mBasePath + "/updates/download.temp"; - outfile = fopen(outFilename.c_str(), "wb"); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile); - } + logger->log("Downloading: %s", url.c_str()); - curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, uw->mCurlError); - curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); - curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, - UpdaterWindow::updateProgress); - curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, ptr); - curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15); + if (uw->mStoreInMemory) + { + uw->mDownloadedBytes = 0; + curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, + UpdaterWindow::memoryWrite); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, ptr); + } + else + { + // Download in the proper folder : ./updates under win, + // /home/user/.tmw/updates for unices + outFilename = uw->mBasePath + "/updates/download.temp"; + outfile = fopen(outFilename.c_str(), "w+b"); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile); + } - if ((res = curl_easy_perform(curl)) != 0) - { - uw->mDownloadStatus = UPDATE_ERROR; - switch (res) + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, uw->mCurlError); + curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); + curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, + UpdaterWindow::updateProgress); + curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, ptr); + curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15); + + if ((res = curl_easy_perform(curl)) != 0) { - case CURLE_COULDNT_CONNECT: // give more debug info on that error - std::cerr << "curl error " << res << " : " << uw->mCurlError << " " << url.c_str() - << std::endl; - break; - - default: - std::cerr << "curl error " << res << " : " << uw->mCurlError << " host: " << url.c_str() - << std::endl; + uw->mDownloadStatus = UPDATE_ERROR; + switch (res) + { + case CURLE_COULDNT_CONNECT: // give more debug info on that error + std::cerr << "curl error " << res << " : " << uw->mCurlError << " " << url.c_str() + << std::endl; + break; + + default: + std::cerr << "curl error " << res << " : " << uw->mCurlError << " host: " << url.c_str() + << std::endl; + } } - } - curl_easy_cleanup(curl); - uw->mDownloadComplete = true; + curl_easy_cleanup(curl); - if (!uw->mStoreInMemory) - { - fclose(outfile); + uw->mDownloadComplete = true; - // Give the file the proper name - std::string newName(uw->mBasePath + "/updates/" + - uw->mCurrentFile.c_str()); + if (!uw->mStoreInMemory) + { + long fileSize; + char *buffer; + // Obtain file size. + fseek(outfile, 0, SEEK_END); + fileSize = ftell(outfile); + rewind(outfile); + buffer = (char*)malloc(fileSize); + fread(buffer, 1, fileSize, outfile); + fclose(outfile); + + // Give the file the proper name + std::string newName(uw->mBasePath + "/updates/" + + uw->mCurrentFile.c_str()); + + // Any existing file with this name is deleted first, otherwise the + // rename will fail on Windows. + ::remove(newName.c_str()); + ::rename(outFilename.c_str(), newName.c_str()); + + // Don't check resources2.txt checksum + if (uw->mDownloadStatus == UPDATE_RESOURCES) + { + // Calculate Adler-32 checksum + unsigned long adler = adler32(0L, Z_NULL, 0); + adler = adler32(adler, (Bytef *)buffer, fileSize); + free(buffer); + + if (uw->mCurrentChecksum != adler) { + uw->mDownloadComplete = false; + // Remove the corrupted file + ::remove(newName.c_str()); + logger->log( + "Checksum for file %s failed: (%lx/%lx)", + uw->mCurrentFile.c_str(), + adler, uw->mCurrentChecksum); + } + } - // Any existing file with this name is deleted first, otherwise the - // rename will fail on Windows. - ::remove(newName.c_str()); - ::rename(outFilename.c_str(), newName.c_str()); + } } + attempts++; + } + + if (!uw->mDownloadComplete) { + uw->mDownloadStatus = UPDATE_ERROR; } return 0; @@ -351,7 +390,7 @@ void UpdaterWindow::logic() // Parse current memory buffer as news and dispose of the data loadNews(); - mCurrentFile = "resources.txt"; + mCurrentFile = "resources2.txt"; mStoreInMemory = false; download(); mDownloadStatus = UPDATE_LIST; @@ -361,7 +400,7 @@ void UpdaterWindow::logic() if (mDownloadComplete) { ResourceManager *resman = ResourceManager::getInstance(); - mFiles = resman->loadTextFile("updates/resources.txt"); + mLines = resman->loadTextFile("updates/resources2.txt"); mStoreInMemory = false; mDownloadStatus = UPDATE_RESOURCES; } @@ -375,9 +414,15 @@ void UpdaterWindow::logic() mThread = NULL; } - if (mFileIndex < mFiles.size()) + if (mLineIndex < mLines.size()) { - mCurrentFile = mFiles[mFileIndex]; + std::stringstream line(mLines[mLineIndex]); + line >> mCurrentFile; + std::string checksum; + line >> checksum; + std::stringstream ss(checksum); + ss >> std::hex >> mCurrentChecksum; + std::ifstream temp( (mBasePath + "/updates/" + mCurrentFile).c_str()); if (!temp.is_open()) @@ -389,7 +434,7 @@ void UpdaterWindow::logic() { logger->log("%s already here", mCurrentFile.c_str()); } - mFileIndex++; + mLineIndex++; } else { diff --git a/src/gui/updatewindow.h b/src/gui/updatewindow.h index 16442656..0d1493ee 100644 --- a/src/gui/updatewindow.h +++ b/src/gui/updatewindow.h @@ -141,6 +141,11 @@ class UpdaterWindow : public Window, public gcn::ActionListener std::string mCurrentFile; /** + * The Adler32 checksum of the file currently downloading. + */ + unsigned long mCurrentChecksum; + + /** * Absolute path to locally save downloaded files. */ std::string mBasePath; @@ -179,12 +184,12 @@ class UpdaterWindow : public Window, public gcn::ActionListener /** * List of files to download */ - std::vector<std::string> mFiles; + std::vector<std::string> mLines; /** * Index of the file to be downloaded */ - unsigned int mFileIndex; + unsigned int mLineIndex; gcn::Label *mLabel; /**< Progress bar caption. */ Button *mCancelButton; /**< Button to stop the update process. */ diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 3346c07a..75a16865 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -197,8 +197,8 @@ Viewport::draw(gcn::Graphics *gcnGraphics) } // Draw target marker if needed - Being *target; - if ((target = player_node->getTarget())) + Being *target = player_node->getTarget(); + if (target) { graphics->setFont(speechFont); graphics->setColor(gcn::Color(255, 32, 32)); |