~ubuntu-branches/ubuntu/trusty/manaplus/trusty-proposed

« back to all changes in this revision

Viewing changes to src/gui/npcdialog.cpp

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi, Andrei Karas, Patrick Matthäi
  • Date: 2013-05-27 09:14:03 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130527091403-4b1jceqok7g2v5on
Tags: 1.3.5.26-1
[ Andrei Karas ]
* Add new files to copyright file.
* Update homepage URL.

[ Patrick Matthäi ]
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
#include "gui/widgets/scrollarea.h"
44
44
#include "gui/widgets/textbox.h"
45
45
 
 
46
#include "resources/avatardb.h"
46
47
#include "resources/npcdb.h"
47
48
#include "resources/resourcemanager.h"
48
49
 
73
74
    Window(_("NPC"), false, nullptr, "npc.xml"),
74
75
    gcn::ActionListener(),
75
76
    mNpcId(npcId),
76
 
    mLogInteraction(config.getBoolValue("logNpcInGui")),
77
77
    mDefaultInt(0),
78
78
    mDefaultString(),
79
79
    mTextBox(new BrowserBox(this, BrowserBox::AUTO_WRAP)),
108
108
    mCameraY(0),
109
109
    mPlayerBox(new PlayerBox(nullptr)),
110
110
    mAvatarBeing(nullptr),
111
 
    mShowAvatar(false)
 
111
    mShowAvatar(false),
 
112
    mLogInteraction(config.getBoolValue("logNpcInGui"))
112
113
{
113
114
    // Basic Window Setup
114
115
    setWindowName("NpcText");
155
156
        fnt->getWidth(CAPTION_NEXT));
156
157
    width = std::max(width, fnt->getWidth(CAPTION_CLOSE));
157
158
    width = std::max(width, fnt->getWidth(CAPTION_SUBMIT));
158
 
 
159
159
    mButton->setWidth(8 + width);
160
160
 
161
161
    // Place widgets
182
182
 
183
183
NpcDialog::~NpcDialog()
184
184
{
185
 
    config.removeListener("logNpcInGui", this);
186
 
 
 
185
    config.removeListeners(this);
187
186
    clearLayout();
188
187
 
189
188
    if (mPlayerBox)
233
232
    instances.remove(this);
234
233
}
235
234
 
236
 
/*
237
 
void NpcDialog::setText(const std::string &text)
238
 
{
239
 
    mText = text;
240
 
 
241
 
    mTextBox->setTextWrapped(mText, mScrollArea->getWidth() - 15);
242
 
}
243
 
*/
244
 
 
245
235
void NpcDialog::addText(const std::string &text, const bool save)
246
236
{
247
237
    if (save || mLogInteraction)
251
241
 
252
242
        mNewText.append(text);
253
243
        mTextBox->addRow(text);
254
 
//        setText(mText + text + "\n");
255
244
    }
256
245
    mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll());
257
246
    mActionState = NPC_ACTION_WAIT;
290
279
        }
291
280
        else if (mActionState == NPC_ACTION_INPUT)
292
281
        {
293
 
            std::string printText("");  // Text that will get printed
294
 
                                        // in the textbox
 
282
            std::string printText;  // Text that will get printed
 
283
                                    // in the textbox
295
284
 
296
285
            if (mInputState == NPC_INPUT_LIST)
297
286
            {
328
317
            }
329
318
            // addText will auto remove the input layout
330
319
            addText(strprintf("> \"%s\"", printText.c_str()), false);
331
 
 
332
320
            mNewText.clear();
333
321
        }
334
322
 
416
404
    ResourceManager *const resman = ResourceManager::getInstance();
417
405
 
418
406
    std::string tmp;
 
407
    const std::string path = paths.getStringValue("guiIcons");
419
408
    while (getline(iss, tmp, ':'))
420
409
    {
421
410
        const size_t pos = tmp.find("|");
427
416
        else
428
417
        {
429
418
            mItems.push_back(tmp.substr(pos + 1));
430
 
            Image *const img = resman->getImage(
431
 
                paths.getStringValue("guiIcons")
432
 
                .append(tmp.substr(0, pos)).append(".png"));
 
419
            Image *const img = resman->getImage(std::string(
 
420
                path).append(tmp.substr(0, pos)).append(".png"));
433
421
            mImages.push_back(img);
434
422
        }
435
423
    }
668
656
 
669
657
    Layout &layout = getLayout();
670
658
    layout.setRowHeight(1, Layout::AUTO_SET);
671
 
 
672
659
    redraw();
673
 
 
674
660
    mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll());
675
661
}
676
662
 
710
696
    if (needShow)
711
697
    {
712
698
        delete mAvatarBeing;
713
 
        mAvatarBeing = new Being(0, ActorSprite::NPC, avatarId, nullptr);
 
699
        mAvatarBeing = new Being(0, ActorSprite::AVATAR, avatarId, nullptr);
714
700
        mPlayerBox->setPlayer(mAvatarBeing);
715
701
        if (!mAvatarBeing->empty())
716
702
        {
717
703
            mAvatarBeing->logic();
 
704
            const BeingInfo *const info = AvatarDB::get(avatarId);
 
705
            const int pad2 = 2 * mPadding;
 
706
            int width = 0;
 
707
            if (info)
 
708
            {
 
709
                width = info->getWidth();
 
710
                mPlayerBox->setWidth(width + pad2);
 
711
                mPlayerBox->setHeight(info->getHeight() + pad2);
 
712
            }
718
713
            const Sprite *const sprite = mAvatarBeing->getSprite(0);
719
 
            if (sprite)
 
714
            if (sprite && !width)
720
715
            {
721
 
                mPlayerBox->setWidth(sprite->getWidth() + 2 * getPadding());
722
 
                mPlayerBox->setHeight(sprite->getHeight() + 2 * getPadding());
 
716
                mPlayerBox->setWidth(sprite->getWidth() + pad2);
 
717
                mPlayerBox->setHeight(sprite->getHeight() + pad2);
723
718
            }
724
719
        }
725
720
    }