Exemple #1
0
/**
 * Menu interaction (enter/space/click to continue)
 */
void MenuTalker::logic() {

	if (!visible || !npc)
		return;

	tablist.logic();

	if (advanceButton->checkClick() || closeButton->checkClick()) {
		// button was clicked
		nextDialog();
	}
	else if	((advanceButton->enabled || closeButton->enabled) && inpt->pressing[Input::ACCEPT] && !inpt->lock[Input::ACCEPT]) {
		// pressed next/more
		inpt->lock[Input::ACCEPT] = true;
		nextDialog();
	}
	else {
		textbox->logic();

		Point mouse = textbox->input_assist(inpt->mouse);
		for (size_t i = 0; i < actions.size(); ++i) {
			if (actions[i].btn->checkClickAt(mouse.x, mouse.y)) {
				executeAction(i);
				break;
			}
		}

		Rect lock_area = dialog_pos;
		lock_area.x += window_area.x;
		lock_area.y += window_area.y;
		if (inpt->pressing[Input::MAIN1] && !inpt->lock[Input::MAIN1] && Utils::isWithinRect(lock_area, inpt->mouse)) {
			inpt->lock[Input::MAIN1] = true;
		}
	}
}
Exemple #2
0
BeingId NpcHandler::getNpc(Net::MessageIn &msg)
{
    if (msg.getId() == SMSG_NPC_CHOICE
        || msg.getId() == SMSG_NPC_MESSAGE
        || msg.getId() == SMSG_NPC_CHANGETITLE)
    {
        msg.readInt16("len");
    }

    const BeingId npcId = msg.readBeingId("npc id");

    const NpcDialogs::const_iterator diag = NpcDialog::mNpcDialogs.find(npcId);
    mDialog = nullptr;

    if (msg.getId() == SMSG_NPC_VIEWPOINT)
        return npcId;

    if (diag == NpcDialog::mNpcDialogs.end())
    {
        // Empty dialogs don't help
        if (msg.getId() == SMSG_NPC_CLOSE)
        {
            closeDialog(npcId);
            return npcId;
        }
        else if (msg.getId() == SMSG_NPC_NEXT)
        {
            nextDialog(npcId);
            return npcId;
        }
        else
        {
            CREATEWIDGETV(mDialog, NpcDialog, npcId);
            mDialog->saveCamera();
            if (localPlayer)
                localPlayer->stopWalking(false);
            NpcDialog::mNpcDialogs[npcId] = mDialog;
        }
    }
    else
    {
        NpcDialog *const dialog = diag->second;
        if (mDialog && mDialog != dialog)
            mDialog->restoreCamera();
        mDialog = dialog;
        if (mDialog)
            mDialog->saveCamera();
    }
    return npcId;
}
Exemple #3
0
void NpcDialog::action(const ActionEvent &event)
{
    const std::string &eventId = event.getId();
    if (eventId == "ok")
    {
        if (mActionState == NPC_ACTION_NEXT)
        {
            if (!PacketLimiter::limitPackets(PacketType::PACKET_NPC_NEXT))
                return;

            nextDialog();
            addText(std::string(), false);
        }
        else if (mActionState == NPC_ACTION_CLOSE
                 || mActionState == NPC_ACTION_WAIT)
        {
            closeDialog();
        }
        else if (mActionState == NPC_ACTION_INPUT)
        {
            std::string printText;  // Text that will get printed
                                    // in the textbox
            switch (mInputState)
            {
                case NPC_INPUT_LIST:
                {
                    if (gui)
                        gui->resetClickCount();
                    const int selectedIndex = mItemList->getSelected();

                    if (selectedIndex >= static_cast<int>(mItems.size())
                        || selectedIndex < 0
                        || !PacketLimiter::limitPackets(
                        PacketType::PACKET_NPC_INPUT))
                    {
                        return;
                    }
                    unsigned char choice = static_cast<unsigned char>(
                        selectedIndex + 1);
                    printText = mItems[selectedIndex];

                    npcHandler->listInput(mNpcId, choice);
                    break;
                }
                case NPC_INPUT_STRING:
                {
                    if (!PacketLimiter::limitPackets(
                        PacketType::PACKET_NPC_INPUT))
                    {
                        return;
                    }
                    printText = mTextField->getText();
                    npcHandler->stringInput(mNpcId, printText);
                    break;
                }
                case NPC_INPUT_INTEGER:
                {
                    if (!PacketLimiter::limitPackets(
                        PacketType::PACKET_NPC_INPUT))
                    {
                        return;
                    }
                    printText = strprintf("%d", mIntField->getValue());
                    npcHandler->integerInput(
                        mNpcId, mIntField->getValue());
                    break;
                }
                case NPC_INPUT_ITEM:
                {
                    if (!PacketLimiter::limitPackets(
                        PacketType::PACKET_NPC_INPUT))
                    {
                        return;
                    }

                    std::string str;
                    const int sz = mInventory->getNumberOfSlotsUsed();
                    if (sz == 0)
                    {
                        str = "0,0";
                    }
                    else
                    {
                        const Item *item = mInventory->getItem(0);
                        if (item)
                        {
                            str = strprintf("%d,%d", item->getId(),
                                item->getColor());
                        }
                        else
                        {
                            str = "0,0";
                        }
                        for (int f = 1; f < sz; f ++)
                        {
                            str.append(";");
                            item = mInventory->getItem(f);
                            if (item)
                            {
                                str.append(strprintf("%d,%d", item->getId(),
                                    item->getColor()));
                            }
                            else
                            {
                                str.append("0,0");
                            }
                        }
                    }

                    // need send selected item
                    npcHandler->stringInput(mNpcId, str);
                    mInventory->clear();
                    break;
                }

                case NPC_INPUT_NONE:
                default:
                    break;
            }
            if (mInputState != NPC_INPUT_ITEM)
            {
                // addText will auto remove the input layout
                addText(strprintf("> \"%s\"", printText.c_str()), false);
            }
            mNewText.clear();
        }

        if (!mLogInteraction)
            mTextBox->clearRows();
    }
    else if (eventId == "reset")
    {
        switch (mInputState)
        {
            case NPC_INPUT_STRING:
                mTextField->setText(mDefaultString);
                break;
            case NPC_INPUT_INTEGER:
                mIntField->setValue(mDefaultInt);
                break;
            case NPC_INPUT_ITEM:
                mInventory->clear();
                break;
            case NPC_INPUT_NONE:
            case NPC_INPUT_LIST:
            default:
                break;
        }
    }
    else if (eventId == "inc")
    {
        mIntField->setValue(mIntField->getValue() + 1);
    }
    else if (eventId == "dec")
    {
        mIntField->setValue(mIntField->getValue() - 1);
    }
    else if (eventId == "clear")
    {
        switch (mInputState)
        {
            case NPC_INPUT_ITEM:
                mInventory->clear();
                break;
            case NPC_INPUT_STRING:
            case NPC_INPUT_INTEGER:
            case NPC_INPUT_LIST:
            case NPC_INPUT_NONE:
            default:
                clearRows();
                break;
        }
    }
    else if (eventId == "close")
    {
        if (mActionState == NPC_ACTION_INPUT)
        {
            switch (mInputState)
            {
                case NPC_INPUT_ITEM:
                    npcHandler->stringInput(mNpcId, "0,0");
                    break;
                case NPC_INPUT_STRING:
                case NPC_INPUT_INTEGER:
                case NPC_INPUT_NONE:
                case NPC_INPUT_LIST:
                default:
                    npcHandler->listInput(mNpcId, 255);
                    break;
            }
            closeDialog();
        }
    }
    else if (eventId == "add")
    {
        if (inventoryWindow)
        {
            const Item *const item = inventoryWindow->getSelectedItem();
            if (item)
            {
                mInventory->addItem(item->getId(),
                    item->getType(),
                    1,
                    1,
                    item->getColor(),
                    item->getIdentified(),
                    item->getDamaged(),
                    item->getFavorite(),
                    Equipm_false,
                    Equipped_false);
            }
        }
    }
}
Exemple #4
0
void NpcDialog::action(const gcn::ActionEvent &event)
{
    if (event.getId() == "ok")
    {
        if (mActionState == NPC_ACTION_NEXT)
        {
            nextDialog();
            // TRANSLATORS: Please leave the \n sequences intact.
            addText(_("\n> Next\n"), false);
        }
        else if (mActionState == NPC_ACTION_CLOSE)
        {
            closeDialog();
        }
        else if (mActionState == NPC_ACTION_INPUT)
        {
            std::string printText = "";  // Text that will get printed in the textbox

            if (mInputState == NPC_INPUT_LIST)
            {
                int selectedIndex = mItemList->getSelected();

                if (selectedIndex >= (int) mItems.size() || selectedIndex < 0)
                    return;

                printText = mItems[selectedIndex];

                Net::getNpcHandler()->menuSelect(mNpcId, selectedIndex + 1);
            }
            else if (mInputState == NPC_INPUT_STRING)
            {
                printText = mTextField->getText();

                Net::getNpcHandler()->stringInput(mNpcId, printText);
            }
            else if (mInputState == NPC_INPUT_INTEGER)
            {
                printText = strprintf("%d", mIntField->getValue());

                Net::getNpcHandler()->integerInput(mNpcId, mIntField->getValue());
            }
            // addText will auto remove the input layout
            addText(strprintf("\n> \"%s\"\n", printText.c_str()), false);

            mNewText.clear();
        }

        if (!mLogInteraction)
            setText("");
    }
    else if (event.getId() == "reset")
    {
        if (mInputState == NPC_INPUT_STRING)
        {
            mTextField->setText(mDefaultString);
        }
        else if (mInputState == NPC_INPUT_INTEGER)
        {
            mIntField->setValue(mDefaultInt);
        }
    }
    else if (event.getId() == "inc")
    {
        mIntField->setValue(mIntField->getValue() + 1);
    }
    else if (event.getId() == "dec")
    {
        mIntField->setValue(mIntField->getValue() - 1);
    }
    else if (event.getId() == "clear")
    {
        setText(mNewText);
    }
}