void MainWindow::sellTicketDialog()
{
    int rowNum = trainTable->currentRow();
    if(rowNum >= 0)
    {
        QString trainID_ = trainTable->item(rowNum, 0)->text();
        QString departureTime_ = trainTable->item(rowNum, 3)->text();
        QString price_ = trainTable->item(rowNum, 5)->text();
        QStringList routesWithSeats;
        QComboBox *comboBox = (QComboBox*)trainTable->cellWidget(rowNum, 8);
        for(int i = 0 ; i < comboBox->count(); ++i)
        {
            routesWithSeats << comboBox->itemText(i);
        }

        SellDialog *sellDialog = new SellDialog(this);
        sellDialog->setTicketData(trainID_, departureTime_, price_, routesWithSeats);
        connect(sellDialog, &SellDialog::buyTicket, this, &MainWindow::sellTicket);
        sellDialog->exec();
    }
    else
    {
        QMessageBox::warning(this, QString::fromLocal8Bit("购票失败"), QString::fromLocal8Bit("请选择要购买的车次"));
    }
}
示例#2
0
void BuySellHandler::processNpcSell(Net::MessageIn &msg, int offset)
{
    msg.readInt16();  // length
    int n_items = (msg.getLength() - 4) / 10;
    if (n_items > 0)
    {
        SellDialog *dialog = new SellDialog(mNpcId);
        dialog->setMoney(PlayerInfo::getAttribute(MONEY));

        for (int k = 0; k < n_items; k++)
        {
            int index = msg.readInt16() - offset;
            int value = msg.readInt32();
            msg.readInt32();  // OCvalue

            Item *item = PlayerInfo::getInventory()->getItem(index);

            if (item && !(item->isEquipped()))
                dialog->addItem(item, value);
        }
    }
    else
    {
        SERVER_NOTICE(_("Nothing to sell."))
    }
}
示例#3
0
void BuySellHandler::handleMessage(Net::MessageIn &msg)
{
    Being *being = actorSpriteManager->findBeing(msg.readInt16());
    if (!being || being->getType() != ActorSprite::NPC)
    {
        return;
    }

    int npcId = being->getId();

    switch (msg.getId())
    {
        case GPMSG_NPC_BUY:
        {
            BuyDialog* dialog = new BuyDialog(npcId);

            dialog->reset();
            dialog->setMoney(PlayerInfo::getAttribute(MONEY));

            while (msg.getUnreadLength())
            {
                int itemId = msg.readInt16();
                int amount = msg.readInt16();
                int value = msg.readInt16();
                dialog->addItem(itemId, amount, value);
            }
            break;
        }

        case GPMSG_NPC_SELL:
        {
            SellDialog* dialog = new SellDialog(npcId);

            dialog->reset();
            dialog->setMoney(PlayerInfo::getAttribute(MONEY));

            while (msg.getUnreadLength())
            {
                int itemId = msg.readInt16();
                int amount = msg.readInt16();
                int value = msg.readInt16();
                dialog->addItem(new Item(itemId, amount, false), value);
            }
            break;
        }
    }
}