Exemplo n.º 1
0
ButtonEditDialog::ButtonEditDialog(JoyButton *button, QWidget *parent) :
    QDialog(parent, Qt::Window),
    ui(new Ui::ButtonEditDialog)
{
    ui->setupUi(this);

#ifdef Q_OS_WIN
    setMinimumHeight(460);
#endif

    setAttribute(Qt::WA_DeleteOnClose);

    ignoreRelease = false;

    this->button = button;
    ui->virtualKeyMouseTabWidget->hide();
    ui->virtualKeyMouseTabWidget->deleteLater();
    ui->virtualKeyMouseTabWidget = new VirtualKeyboardMouseWidget(button, this);
    ui->virtualKeyMouseTabWidget->setFocus();

    ui->verticalLayout->insertWidget(1, ui->virtualKeyMouseTabWidget);
    ui->slotSummaryLabel->setText(button->getSlotsString());
    updateWindowTitleButtonName();

    ui->toggleCheckBox->setChecked(button->getToggleState());
    ui->turboCheckBox->setChecked(button->isUsingTurbo());

    if (!button->getActionName().isEmpty())
    {
        ui->actionNameLineEdit->setText(button->getActionName());
    }

    if (!button->getButtonName().isEmpty())
    {
        ui->buttonNameLineEdit->setText(button->getButtonName());
    }

    connect(ui->virtualKeyMouseTabWidget, SIGNAL(selectionCleared()), this, SLOT(refreshSlotSummaryLabel()));
    connect(ui->virtualKeyMouseTabWidget, SIGNAL(selectionFinished()), this, SLOT(close()));

    connect(this, SIGNAL(keyGrabbed(JoyButtonSlot*)), this, SLOT(processSlotAssignment(JoyButtonSlot*)));
    connect(this, SIGNAL(selectionCleared()), this, SLOT(clearButtonSlots()));
    connect(this, SIGNAL(selectionCleared()), this, SLOT(sendSelectionFinished()));
    connect(this, SIGNAL(selectionFinished()), this, SLOT(close()));

    connect(ui->toggleCheckBox, SIGNAL(clicked()), this, SLOT(changeToggleSetting()));
    connect(ui->turboCheckBox, SIGNAL(clicked()), this, SLOT(changeTurboSetting()));
    connect(ui->advancedPushButton, SIGNAL(clicked()), this, SLOT(openAdvancedDialog()));
    connect(this, SIGNAL(advancedDialogOpened()), ui->virtualKeyMouseTabWidget, SLOT(establishVirtualKeyboardAdvancedSignalConnections()));
    connect(this, SIGNAL(advancedDialogOpened()), ui->virtualKeyMouseTabWidget, SLOT(establishVirtualMouseAdvancedSignalConnections()));
    connect(ui->virtualKeyMouseTabWidget, SIGNAL(selectionMade(int)), this, SLOT(createTempSlot(int)));

    connect(ui->actionNameLineEdit, SIGNAL(textEdited(QString)), button, SLOT(setActionName(QString)));
    connect(ui->buttonNameLineEdit, SIGNAL(textEdited(QString)), button, SLOT(setButtonName(QString)));

    connect(button, SIGNAL(toggleChanged(bool)), ui->toggleCheckBox, SLOT(setChecked(bool)));
    connect(button, SIGNAL(turboChanged(bool)), this, SLOT(checkTurboSetting(bool)));
    connect(button, SIGNAL(slotsChanged()), this, SLOT(refreshSlotSummaryLabel()));
    connect(button, SIGNAL(buttonNameChanged()), this, SLOT(updateWindowTitleButtonName()));
}
Exemplo n.º 2
0
void InputDevice::updateSetButtonNames(int index)
{
    JoyButton *button = getActiveSetJoystick()->getJoyButton(index);
    if (button)
    {
        setButtonName(index, button->getButtonName());
    }
}
Exemplo n.º 3
0
void  LaunchPad::buttonContextMenu(const QPoint& /*pos*/)
{
  QAbstractButton* btn = static_cast<QAbstractButton*>(sender());
  int id = mButtons.id(btn);

  QDialog      dialog;
  QGridLayout  layout(&dialog);
  QLabel*      label;
  int          row = 0;            // Count layout rows

  label = new QLabel(tr("Name"));
  label->setAlignment(Qt::AlignRight);
  layout.addWidget(label, row, 0);
  QLineEdit name(btn->text());
  name.setToolTip(tr("Button caption"));
  layout.addWidget(&name, row++, 1);
  layout.setColumnStretch(1, 1);

  label = new QLabel(tr("Tip"));
  label->setAlignment(Qt::AlignRight);
  layout.addWidget(label, row, 0);
  QLineEdit tip(btn->toolTip());
  tip.setToolTip(tr("Button tool tip"));
  tip.setCursorPosition(0);
  layout.addWidget(&tip, row++, 1, 1, 2);
  layout.setColumnStretch(2, 3);

  label = new QLabel(tr("Command"));
  label->setAlignment(Qt::AlignRight);
  layout.addWidget(label, row, 0);
  QLineEdit command(mCommands.at(id));
  //QTextEdit command(mCommands.at(id));
  command.setCursorPosition(0);
  command.setToolTip(tr("Available Tags are: %1").arg("[Provider] [Symbol] [Market] "
                                                      "[FiId] [MarketId]"));
  layout.addWidget(&command, row++, 1, 1, 2); // Spawn over two colums...
//   layout.setColumnStretch(2, 2);              // ...and take more space

  label = new QLabel(tr("Symbol Type"));
  label->setAlignment(Qt::AlignRight);
  layout.addWidget(label, row, 0);
//   QLineEdit symbolType(mSymbolTypes.at(id));
  QComboBox symbolType;
  symbolType.setToolTip(tr("Witch type has to be [Symbol]. When empty is called once with any symbol\n"
                           "(You should not use [Symbol] in this case at the command)"));
  SymbolTypeTuple* st = mFilu->getSymbolTypes(Filu::eAllTypes);
  if(st)
  {
    while(st->next()) symbolType.addItem(st->caption());
  }

  symbolType.addItem("");
  symbolType.setCurrentIndex(symbolType.findText(mSymbolTypes.at(id)));

  layout.addWidget(&symbolType, row, 1);

  QCheckBox allMarkets(tr("All Markets"));
  allMarkets.setToolTip(tr("Call multiple times with all markets by 'Symbol Type'"));
  allMarkets.setChecked(mMultis.at(id));
  layout.addWidget(&allMarkets, row++, 2);

  // Add an empty row to take unused space
  layout.addWidget(new QWidget, row, 1);
  layout.setRowStretch(row++, 2);

  // Build the button line
  QDialogButtonBox dlgBtns(QDialogButtonBox::Save | QDialogButtonBox::Discard);
  QPushButton* db = dlgBtns.button(QDialogButtonBox::Discard);
  dlgBtns.addButton(db, QDialogButtonBox::RejectRole);
  connect(&dlgBtns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  connect(&dlgBtns, SIGNAL(rejected()), &dialog, SLOT(reject()));

  DialogButton* remove = new DialogButton(tr("&Remove"), -1);
  remove->setToolTip(tr("Remove button"));
  dlgBtns.addButton(remove, QDialogButtonBox::ActionRole);
  connect(remove, SIGNAL(clicked(int)), &dialog, SLOT(done(int)));

  DialogButton* add = new DialogButton(tr("&Add"), 2);
  add->setToolTip(tr("Copy to new button"));
  dlgBtns.addButton(add, QDialogButtonBox::ActionRole);
  connect(add, SIGNAL(clicked(int)), &dialog, SLOT(done(int)));

  layout.addWidget(&dlgBtns, row, 1, 1, 2);

  dialog.setWindowTitle(tr("LaunchPad - Edit button '%1'").arg(btn->text()));
  dialog.setMinimumWidth(350);

  switch (dialog.exec())
  {
    case 0:     // Discard
      return;
      break;
    case -1:    // Remove
    {
      int ret = QMessageBox::warning(&dialog
                  , tr("LaunchPad - Last chance to keep your data")
                  , tr("Are you sure to delete button <b>'%1'</b> with all your work<b>?</b>")
                      .arg(btn->text())
                  , QMessageBox::Yes | QMessageBox::No
                  , QMessageBox::No);

      if(ret == QMessageBox::No) return;

      deleteButton(btn);

      mCommands.removeAt(id);
      mSymbolTypes.removeAt(id);
      mMultis.removeAt(id);
      break;
    }
    case  1:    // Save
      setButtonName(btn, name.text());
      btn->setToolTip(tip.text());

      mCommands[id] = command.text();
      //mCommands[id] = command.toPlainText();
//       mSymbolTypes[id] = symbolType.text();
      mSymbolTypes[id] = symbolType.currentText();
      mMultis[id] = allMarkets.isChecked();
      break;
    case  2:    // Add
      btn = newButton(name.text());
      btn->setToolTip(tip.text());

      mCommands.append(command.text());
      //mCommands.append(command.toPlainText());
//       mSymbolTypes.append(symbolType.text());
      mSymbolTypes.append(symbolType.currentText());
      mMultis.append(allMarkets.isChecked());
      mButtons.setId(btn, mCommands.size() - 1);
      break;
  }

  saveSettings();
}
Exemplo n.º 4
0
void InputDevice::readConfig(QXmlStreamReader *xml)
{
    if (xml->isStartElement() && xml->name() == getXmlName())
    {
        reset();

        xml->readNextStartElement();
        while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != getXmlName()))
        {
            if (xml->name() == "sets" && xml->isStartElement())
            {
                xml->readNextStartElement();

                while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "sets"))
                {
                    if (xml->name() == "set" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        index = index - 1;
                        if (index >= 0 && index < joystick_sets.size())
                        {
                            joystick_sets.value(index)->readConfig(xml);
                        }
                    }
                    else
                    {
                        // If none of the above, skip the element
                        xml->skipCurrentElement();
                    }

                    xml->readNextStartElement();
                }
            }
            else if (xml->name() == "stickAxisAssociation" && xml->isStartElement())
            {
                int stickIndex = xml->attributes().value("index").toString().toInt();
                int xAxis = xml->attributes().value("xAxis").toString().toInt();
                int yAxis = xml->attributes().value("yAxis").toString().toInt();

                if (stickIndex > 0 && xAxis > 0 && yAxis > 0)
                {
                    xAxis -= 1;
                    yAxis -= 1;
                    stickIndex -= 1;

                    for (int i=0; i <joystick_sets.size(); i++)
                    {
                        SetJoystick *currentset = joystick_sets.value(i);
                        JoyAxis *axis1 = currentset->getJoyAxis(xAxis);
                        JoyAxis *axis2 = currentset->getJoyAxis(yAxis);
                        if (axis1 && axis2)
                        {
                            JoyControlStick *stick = new JoyControlStick(axis1, axis2, stickIndex, i, this);
                            currentset->addControlStick(stickIndex, stick);
                        }
                    }

                    xml->readNext();
                }
                else
                {
                    xml->skipCurrentElement();
                }
            }
            else if (xml->name() == "vdpadButtonAssociations" && xml->isStartElement())
            {
                int vdpadIndex = xml->attributes().value("index").toString().toInt();
                if (vdpadIndex > 0)
                {
                    for (int i=0; i <joystick_sets.size(); i++)
                    {
                        SetJoystick *currentset = joystick_sets.value(i);
                        VDPad *vdpad = currentset->getVDPad(vdpadIndex-1);
                        if (!vdpad)
                        {
                            vdpad = new VDPad(vdpadIndex-1, i, currentset);
                            currentset->addVDPad(vdpadIndex-1, vdpad);
                        }
                    }

                    xml->readNextStartElement();
                    while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "vdpadButtonAssociations"))
                    {
                        if (xml->name() == "vdpadButtonAssociation" && xml->isStartElement())
                        {
                            int vdpadAxisIndex = xml->attributes().value("axis").toString().toInt();
                            int vdpadButtonIndex = xml->attributes().value("button").toString().toInt();
                            int vdpadDirection = xml->attributes().value("direction").toString().toInt();

                            if (vdpadAxisIndex > 0 && vdpadDirection > 0)
                            {
                                vdpadAxisIndex -= 1;
                                for (int i=0; i < joystick_sets.size(); i++)
                                {
                                    SetJoystick *currentset = joystick_sets.value(i);
                                    VDPad *vdpad = currentset->getVDPad(vdpadIndex-1);
                                    if (vdpad)
                                    {
                                        JoyAxis *axis = currentset->getJoyAxis(vdpadAxisIndex);
                                        if (axis)
                                        {
                                            JoyButton *button = 0;
                                            if (vdpadButtonIndex == 0)
                                            {
                                                button = axis->getNAxisButton();
                                            }
                                            else if (vdpadButtonIndex == 1)
                                            {
                                                button = axis->getPAxisButton();
                                            }

                                            if (button)
                                            {
                                                vdpad->addVButton((JoyDPadButton::JoyDPadDirections)vdpadDirection, button);
                                            }
                                        }
                                    }
                                }
                            }
                            else if (vdpadButtonIndex > 0 && vdpadDirection > 0)
                            {
                                vdpadButtonIndex -= 1;

                                for (int i=0; i < joystick_sets.size(); i++)
                                {
                                    SetJoystick *currentset = joystick_sets.value(i);
                                    VDPad *vdpad = currentset->getVDPad(vdpadIndex-1);
                                    if (vdpad)
                                    {
                                        JoyButton *button = currentset->getJoyButton(vdpadButtonIndex);
                                        if (button)
                                        {
                                            vdpad->addVButton((JoyDPadButton::JoyDPadDirections)vdpadDirection, button);
                                        }
                                    }
                                }
                            }
                            xml->readNext();
                        }
                        else
                        {
                            xml->skipCurrentElement();
                        }

                        xml->readNextStartElement();
                    }
                }

                for (int i=0; i < joystick_sets.size(); i++)
                {
                    SetJoystick *currentset = joystick_sets.value(i);
                    for (int j=0; j < currentset->getNumberVDPads(); j++)
                    {
                        VDPad *vdpad = currentset->getVDPad(j);
                        if (vdpad && vdpad->isEmpty())
                        {
                            currentset->removeVDPad(j);
                        }
                    }
                }
            }
            else if (xml->name() == "names" && xml->isStartElement())
            {
                xml->readNextStartElement();
                while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "names"))
                {
                    if (xml->name() == "buttonname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            setButtonName(index, temp);
                        }
                    }
                    else if (xml->name() == "axisbuttonname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        int buttonIndex = xml->attributes().value("button").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        buttonIndex = buttonIndex - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            setAxisButtonName(index, buttonIndex, temp);
                        }
                    }
                    else if (xml->name() == "controlstickbuttonname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        int buttonIndex = xml->attributes().value("button").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            setStickButtonName(index, buttonIndex, temp);
                        }
                    }
                    else if (xml->name() == "dpadbuttonname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        int buttonIndex = xml->attributes().value("button").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            setDPadButtonName(index, buttonIndex, temp);
                        }
                    }
                    else if (xml->name() == "vdpadbuttonname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        int buttonIndex = xml->attributes().value("button").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            setVDPadButtonName(index, buttonIndex, temp);
                        }
                    }
                    else if (xml->name() == "axisname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            setAxisName(index, temp);
                        }
                    }
                    else if (xml->name() == "controlstickname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            setStickName(index, temp);
                        }
                    }
                    else if (xml->name() == "dpadname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            setDPadName(index, temp);
                        }
                    }
                    else if (xml->name() == "vdpadname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            setVDPadName(index, temp);
                        }
                    }
                    else
                    {
                        // If none of the above, skip the element
                        xml->skipCurrentElement();
                    }

                    xml->readNextStartElement();
                }
            }
            else if (xml->name() == "keyPressTime" && xml->isStartElement())
            {
                QString temptext = xml->readElementText();
                int tempchoice = temptext.toInt();
                if (tempchoice >= 10)
                {
                    this->setDeviceKeyDelay(tempchoice);
                }
            }
            else
            {
                // If none of the above, skip the element
                xml->skipCurrentElement();
            }

            xml->readNextStartElement();
        }
    }
}
Exemplo n.º 5
0
void GameController::readConfig(QXmlStreamReader *xml)
{
    if (xml->isStartElement() && xml->name() == getXmlName())
    {
        reset();

        xml->readNextStartElement();
        while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != getXmlName()))
        {
            if (xml->name() == "sets" && xml->isStartElement())
            {
                xml->readNextStartElement();

                while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "sets"))
                {
                    if (xml->name() == "set" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        index = index - 1;
                        if (index >= 0 && index < joystick_sets.size())
                        {
                            joystick_sets.value(index)->readConfig(xml);
                        }
                    }
                    else
                    {
                        // If none of the above, skip the element
                        xml->skipCurrentElement();
                    }

                    xml->readNextStartElement();
                }
            }
            else if (xml->name() == "names" && xml->isStartElement())
            {
                xml->readNextStartElement();
                while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "names"))
                {
                    if (xml->name() == "buttonname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            setButtonName(index, temp);
                        }
                    }
                    else if (xml->name() == "triggerbuttonname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        int buttonIndex = xml->attributes().value("button").toString().toInt();
                        QString temp = xml->readElementText();
                        index = (index - 1) + SDL_CONTROLLER_AXIS_TRIGGERLEFT;
                        buttonIndex = buttonIndex - 1;
                        if ((index == SDL_CONTROLLER_AXIS_TRIGGERLEFT ||
                             index == SDL_CONTROLLER_AXIS_TRIGGERRIGHT) && !temp.isEmpty())
                        {
                            setAxisButtonName(index, buttonIndex, temp);
                        }
                    }
                    else if (xml->name() == "controlstickbuttonname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        int buttonIndex = xml->attributes().value("button").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            setStickButtonName(index, buttonIndex, temp);
                        }
                    }
                    else if (xml->name() == "dpadbuttonname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        int buttonIndex = xml->attributes().value("button").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            setVDPadButtonName(index, buttonIndex, temp);
                        }
                    }
                    else if (xml->name() == "triggername" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        QString temp = xml->readElementText();
                        index = (index - 1) + SDL_CONTROLLER_AXIS_TRIGGERLEFT;
                        if ((index == SDL_CONTROLLER_AXIS_TRIGGERLEFT ||
                             index == SDL_CONTROLLER_AXIS_TRIGGERRIGHT) && !temp.isEmpty())
                        {
                            setAxisName(index, temp);
                        }
                    }
                    else if (xml->name() == "controlstickname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            setStickName(index, temp);
                        }
                    }
                    else if (xml->name() == "dpadname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            setVDPadName(index, temp);
                        }
                    }
                    else
                    {
                        // If none of the above, skip the element
                        xml->skipCurrentElement();
                    }

                    xml->readNextStartElement();
                }
            }
            else if (xml->name() == "keyPressTime" && xml->isStartElement())
            {
                QString temptext = xml->readElementText();
                int tempchoice = temptext.toInt();
                if (tempchoice >= 10)
                {
                    this->setDeviceKeyDelay(tempchoice);
                }
            }
            else
            {
                // If none of the above, skip the element
                xml->skipCurrentElement();
            }

            xml->readNextStartElement();
        }
    }
}
Exemplo n.º 6
0
bool BlankTile::init() {
    NewBaseTileInfo::init();
    m_title->setString(_lang(m_cityInfo.cityName).c_str());
    
    if(!WorldController::isInSelfServer(m_cityInfo.tileServerId)){
        auto &tool = ToolController::getInstance()->getToolInfoById(getNewBeginnerMoveItemId());
        bool is_teleport_limit_open = GlobalData::shared()->teleport_limit_open;
        bool isGm = GlobalData::shared()->playerInfo.gmFlag == 1;
        bool haveBtn = true;
        if(is_teleport_limit_open && !isGm)//限制功能开启
        {
            double closeTime = GlobalData::shared()->playerInfo.regTime + GlobalData::shared()->teleport_limit_time * 3600;
            double currentTime = GlobalData::shared()->getTimeStamp();
            if(currentTime >= closeTime)
            {
                haveBtn = false;
            }
        }
        
            
        if (haveBtn && tool.getCNT()>0 && FunBuildController::getInstance()->getMainCityLv() < GlobalData::shared()->new_trans_kingdom_level&&!CCCommonUtils::isInSimulator()) {
            setButtonCount(2);
            setButtonName(2,_lang("108719")); // teleport
            setButtonState(2, ButtonTeleport);
            setButtonCallback(2,cccontrol_selector(BlankTile::onClickTeleport));
            setButtonName(3,_lang("E100184")); // teleport
            setButtonState(3, ButtonTransKingdom);
            setButtonCallback(3,cccontrol_selector(BlankTile::onClickTransKingdom));
        }
        else {
            setButtonCount(1);
            setButtonName(1,_lang("108719")); // teleport
            setButtonState(1, ButtonTeleport);
            setButtonCallback(1,cccontrol_selector(BlankTile::onClickTeleport));
        }
    }else{
//        setButtonCount(2);
//        setButtonName(3,_lang("108720")); // occupy
//        setButtonName(2,_lang("108719")); // teleport
//        setButtonState(3, ButtonOccupy);
//        setButtonState(2, ButtonTeleport);
//        setButtonCallback(3,cccontrol_selector(BlankTile::onClickOccupy));
//        setButtonCallback(2,cccontrol_selector(BlankTile::onClickTeleport));
        int rank = GlobalData::shared()->playerInfo.allianceInfo.rank;
        if (rank >= 4) {
            if ((GlobalData::shared()->serverType==SERVER_BATTLE_FIELD || GlobalData::shared()->serverType==SERVER_DRAGON_BATTLE) && WorldController::getInstance()->isInCrossMap()) {
                setButtonCount(3);
                setButtonName(3, _lang("108720")); // occupy
                setButtonName(2, _lang("108719")); // teleport
                setButtonName(1, _lang("115285")); // invite teleport
                setButtonState(3, ButtonOccupy);
                setButtonState(2, ButtonTeleport);
                setButtonState(1, ButtonWorldInviteTeleport);
                setButtonCallback(3, cccontrol_selector(BlankTile::onClickOccupy));
                setButtonCallback(2,cccontrol_selector(BlankTile::onClickTeleport));
                setButtonCallback(1,cccontrol_selector(BlankTile::onClickInviteTeleport));
                if(GlobalData::shared()->serverType==SERVER_DRAGON_BATTLE && ActivityController::getInstance()->wa_switch_k3==0){
                    setButtonCount(2);
                    setButtonName(3, _lang("108720")); // occupy
                    setButtonName(2, _lang("108719")); // teleport
                    setButtonState(3, ButtonOccupy);
                    setButtonState(2, ButtonTeleport);
                    setButtonCallback(3, cccontrol_selector(BlankTile::onClickOccupy));
                    setButtonCallback(2,cccontrol_selector(BlankTile::onClickTeleport));
                }else{
                    setButtonCount(3);
                    setButtonName(3, _lang("108720")); // occupy
                    setButtonName(2, _lang("108719")); // teleport
                    setButtonName(1, _lang("115285")); // invite teleport
                    setButtonState(3, ButtonOccupy);
                    setButtonState(2, ButtonTeleport);
                    setButtonState(1, ButtonWorldInviteTeleport);
                    setButtonCallback(3, cccontrol_selector(BlankTile::onClickOccupy));
                    setButtonCallback(2,cccontrol_selector(BlankTile::onClickTeleport));
                    setButtonCallback(1,cccontrol_selector(BlankTile::onClickInviteTeleport));
                }
            }else{
                setButtonCount(4);
                setButtonName(3, _lang("108720")); // occupy
                setButtonName(2, _lang("108719")); // teleport
                setButtonName(4, _lang("115285")); // invite teleport
                setButtonName(5, _lang("115302"));// territory
                setButtonState(3, ButtonOccupy);
                setButtonState(2, ButtonTeleport);
                setButtonState(4, ButtonWorldInviteTeleport);
                setButtonState(5, ButtonPlace);
                setButtonCallback(3, cccontrol_selector(BlankTile::onClickOccupy));
                setButtonCallback(2,cccontrol_selector(BlankTile::onClickTeleport));
                setButtonCallback(4,cccontrol_selector(BlankTile::onClickInviteTeleport));
                setButtonCallback(5,cccontrol_selector(BlankTile::onClickPlace));
            }
        }else if (rank >= 3){
            setButtonCount(3);
            setButtonName(3, _lang("108720")); // occupy
            setButtonName(2, _lang("108719")); // teleport
            setButtonName(1, _lang("115285")); // invite teleport
            setButtonState(3, ButtonOccupy);
            setButtonState(2, ButtonTeleport);
            setButtonState(1, ButtonWorldInviteTeleport);
            setButtonCallback(3, cccontrol_selector(BlankTile::onClickOccupy));
            setButtonCallback(2,cccontrol_selector(BlankTile::onClickTeleport));
            setButtonCallback(1,cccontrol_selector(BlankTile::onClickInviteTeleport));
        }
        else {
            setButtonCount(2);
            setButtonName(3, _lang("108720")); // occupy
            setButtonName(2, _lang("108719")); // teleport
            setButtonState(3, ButtonOccupy);
            setButtonState(2, ButtonTeleport);
            setButtonCallback(3, cccontrol_selector(BlankTile::onClickOccupy));
            setButtonCallback(2,cccontrol_selector(BlankTile::onClickTeleport));
        }
    }
    setBtnState();
    
    std::string str = "";
    if(m_cityInfo.tileGid < 98){
        int index = m_cityInfo.tileGid % 98;
        if(index < 10){
            str = CCString::createWithFormat("00%s.png", CC_ITOA(index))->getCString();
        }else{
            str = CCString::createWithFormat("0%s.png", CC_ITOA(index))->getCString();
        }
    }else{
        int index = m_cityInfo.tileGid % 98;
        if(index < 10){
            str = CCString::createWithFormat("000%s.png", CC_ITOA(index))->getCString();
        }else{
            str = CCString::createWithFormat("00%s.png", CC_ITOA(index))->getCString();
        }
    };

    addToParent();
    return true;
}
Exemplo n.º 7
0
void GameController::readJoystickConfig(QXmlStreamReader *xml)
{
    if (xml->isStartElement() && xml->name() == "joystick")
    {
        //reset();
        transferReset();

        QHash<unsigned int, SDL_GameControllerButton> buttons;
        QHash<unsigned int, SDL_GameControllerAxis> axes;
        QList<SDL_GameControllerButtonBind> hatButtons;

        for (int i=(int)SDL_CONTROLLER_BUTTON_A; i < (int)SDL_CONTROLLER_BUTTON_MAX; i++)
        {
            SDL_GameControllerButton currentButton = (SDL_GameControllerButton)i;
            SDL_GameControllerButtonBind bound = SDL_GameControllerGetBindForButton(this->controller, currentButton);
            if (bound.bindType == SDL_CONTROLLER_BINDTYPE_BUTTON)
            {
                buttons.insert(bound.value.button, currentButton);
            }
            else if (bound.bindType == SDL_CONTROLLER_BINDTYPE_HAT)
            {
                hatButtons.append(bound);
            }
        }

        for (int i=(int)SDL_CONTROLLER_AXIS_LEFTX; i < (int)SDL_CONTROLLER_AXIS_MAX; i++)
        {
            SDL_GameControllerAxis currentAxis = (SDL_GameControllerAxis)i;
            SDL_GameControllerButtonBind bound = SDL_GameControllerGetBindForAxis(this->controller, currentAxis);
            if (bound.bindType == SDL_CONTROLLER_BINDTYPE_AXIS)
            {
                axes.insert(bound.value.axis, currentAxis);
            }
        }

        xml->readNextStartElement();
        while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "joystick"))
        {
            if (xml->name() == "sets" && xml->isStartElement())
            {
                xml->readNextStartElement();

                while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "sets"))
                {
                    if (xml->name() == "set" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        index = index - 1;
                        if (index >= 0 && index < joystick_sets.size())
                        {
                            GameControllerSet *currentSet = static_cast<GameControllerSet*>(joystick_sets.value(index));
                            currentSet->readJoystickConfig(xml, buttons, axes, hatButtons);
                        }
                    }
                    else
                    {
                        // If none of the above, skip the element
                        xml->skipCurrentElement();
                    }

                    xml->readNextStartElement();
                }
            }
            else if (xml->name() == "names" && xml->isStartElement())
            {
                bool dpadNameExists = false;
                bool vdpadNameExists = false;

                xml->readNextStartElement();
                while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "names"))
                {
                    if (xml->name() == "buttonname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            SDL_GameControllerButton current = buttons.value(index);
                            if (current)
                            {
                                setButtonName(current, temp);
                            }
                        }
                    }
                    else if (xml->name() == "axisbuttonname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        int buttonIndex = xml->attributes().value("button").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        buttonIndex = buttonIndex - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            SDL_GameControllerAxis current = axes.value(index);
                            if (current)
                            {
                                if (current == SDL_CONTROLLER_AXIS_LEFTX)
                                {
                                    setStickButtonName(0, buttonIndex, temp);
                                }
                                else if (current == SDL_CONTROLLER_AXIS_LEFTY)
                                {
                                    setStickButtonName(0, buttonIndex, temp);
                                }
                                else if (current == SDL_CONTROLLER_AXIS_RIGHTX)
                                {
                                    setStickButtonName(1, buttonIndex, temp);
                                }
                                else if (current == SDL_CONTROLLER_AXIS_RIGHTY)
                                {
                                    setStickButtonName(1, buttonIndex, temp);
                                }
                                else if (current == SDL_CONTROLLER_AXIS_TRIGGERLEFT)
                                {
                                    setAxisName(current, temp);
                                }
                                else if (current == SDL_CONTROLLER_AXIS_TRIGGERRIGHT)
                                {
                                    setAxisName(current, temp);
                                }
                            }
                        }
                    }
                    else if (xml->name() == "controlstickbuttonname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        int buttonIndex = xml->attributes().value("button").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            setStickButtonName(index, buttonIndex, temp);
                        }
                    }
                    else if (xml->name() == "dpadbuttonname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        int buttonIndex = xml->attributes().value("button").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            bool found = false;
                            QListIterator<SDL_GameControllerButtonBind> iter(hatButtons);
                            SDL_GameControllerButtonBind current;
                            while (iter.hasNext())
                            {
                                current = iter.next();
                                if (current.value.hat.hat == index)
                                {
                                    found = true;
                                    iter.toBack();
                                }
                            }

                            if (found)
                            {
                                VDPad *dpad = getActiveSetJoystick()->getVDPad(0);
                                if (dpad)
                                {
                                    JoyDPadButton *dpadbutton = dpad->getJoyButton(buttonIndex);
                                    if (dpad && dpadbutton->getActionName().isEmpty())
                                    {
                                        setVDPadButtonName(index, buttonIndex, temp);
                                    }
                                }
                            }
                        }
                    }
                    else if (xml->name() == "vdpadbuttonname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        int buttonIndex = xml->attributes().value("button").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            bool found = false;
                            QListIterator<SDL_GameControllerButtonBind> iter(hatButtons);
                            SDL_GameControllerButtonBind current;
                            while (iter.hasNext())
                            {
                                current = iter.next();
                                if (current.value.hat.hat == index)
                                {
                                    found = true;
                                    iter.toBack();
                                }
                            }

                            if (found)
                            {
                                VDPad *dpad = getActiveSetJoystick()->getVDPad(0);
                                if (dpad)
                                {
                                    JoyDPadButton *dpadbutton = dpad->getJoyButton(buttonIndex);
                                    if (dpad && dpadbutton->getActionName().isEmpty())
                                    {
                                        setVDPadButtonName(index, buttonIndex, temp);
                                    }
                                }
                            }
                        }
                    }
                    else if (xml->name() == "axisname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            if (axes.contains(index))
                            {
                                SDL_GameControllerAxis current = axes.value(index);
                                setAxisName((int)current, temp);
                            }
                        }
                    }
                    else if (xml->name() == "controlstickname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty())
                        {
                            setStickName(index, temp);
                        }
                    }
                    else if (xml->name() == "dpadname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty() && !vdpadNameExists)
                        {
                            bool found = false;
                            QListIterator<SDL_GameControllerButtonBind> iter(hatButtons);
                            SDL_GameControllerButtonBind current;
                            while (iter.hasNext())
                            {
                                current = iter.next();
                                if (current.value.hat.hat == index)
                                {
                                    found = true;
                                    iter.toBack();
                                }
                            }

                            if (found)
                            {
                                dpadNameExists = true;

                                VDPad *dpad = getActiveSetJoystick()->getVDPad(0);
                                if (dpad)
                                {
                                    if (dpad->getDpadName().isEmpty())
                                    {
                                        setVDPadName(index, temp);
                                    }
                                }
                            }
                        }
                    }
                    else if (xml->name() == "vdpadname" && xml->isStartElement())
                    {
                        int index = xml->attributes().value("index").toString().toInt();
                        QString temp = xml->readElementText();
                        index = index - 1;
                        if (index >= 0 && !temp.isEmpty() && !dpadNameExists)
                        {
                            bool found = false;
                            QListIterator<SDL_GameControllerButtonBind> iter(hatButtons);
                            SDL_GameControllerButtonBind current;
                            while (iter.hasNext())
                            {
                                current = iter.next();
                                if (current.value.hat.hat == index)
                                {
                                    found = true;
                                    iter.toBack();
                                }
                            }

                            if (found)
                            {
                                vdpadNameExists = true;

                                VDPad *dpad = getActiveSetJoystick()->getVDPad(0);
                                if (dpad)
                                {
                                    if (dpad->getDpadName().isEmpty())
                                    {
                                        setVDPadName(index, temp);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        // If none of the above, skip the element
                        xml->skipCurrentElement();
                    }

                    xml->readNextStartElement();
                }
            }
            else if (xml->name() == "keyPressTime" && xml->isStartElement())
            {
                QString temptext = xml->readElementText();
                int tempchoice = temptext.toInt();
                if (tempchoice >= 10)
                {
                    this->setDeviceKeyPressTime(tempchoice);
                }
            }
            else if (xml->name() == "profilename" && xml->isStartElement())
            {
                QString temptext = xml->readElementText();
                this->setProfileName(temptext);
            }
            else
            {
                // If none of the above, skip the element
                xml->skipCurrentElement();
            }

            xml->readNextStartElement();
        }

        reInitButtons();
    }
}
Exemplo n.º 8
0
bool TroopInfoPanel::init() {
    NewBaseTileInfo::init(false, true);
    this->setModelLayerTouchPriority(3);
    auto &marchInfos = WorldController::getInstance()->m_marchInfo;
    auto it = marchInfos.find(m_marchId);
    if (it == marchInfos.end()) {
        return false;
    }
    SoundController::sharedSound()->playEffects(Music_Sfx_world_click_march);
    auto &info = it->second;
    
    double remainTime = info.endStamp - WorldController::getInstance()->getTime();
    if (remainTime <= 0) {
        return false;
    }

    std::string nameStr = info.playerName;
    if(info.asn != ""){
        nameStr = CCString::createWithFormat("(%s)%s", info.asn.c_str(), info.playerName.c_str())->getCString();
    }
    this->m_nameAndAlliance->setString(nameStr.c_str());
    m_nameAndAlliance->setPositionX(0);
    m_infoBG->setScaleY(1.05);
    this->m_nameAndAlliance->setPositionY(m_nameAndAlliance->getPositionY() - 2);
    if (info.ownerType != PlayerSelf) {
        m_tilePoint->setPositionY(m_tilePoint->getPositionY() - 14);
    }
//    m_tilePoint->setPositionY(m_tilePoint->getPositionY() - 14);
    m_tilePoint->setPositionX(-5);
    m_faveIcon->setVisible(false);
    m_addNode->setVisible(false);
    // organise state str
    CCLabelIF* stateLabel = nullptr;
    switch (info.stateType) {
        case StateMarch:{
            stateLabel = CCLabelIF::create(_lang(MarchStateName.at("depart")).c_str());
        }
            break;
        case StateReturn:{
            stateLabel = CCLabelIF::create(_lang(MarchStateName.at("return")).c_str());
        }
            break;
        default:
            break;
    }
    
    CCSize size = this->getContentSize();
    this->setPosition(ccp(0, size.height/8));
    if (CCCommonUtils::isIosAndroidPad() && CCCommonUtils::getIsHDViewPort())
    {
        this->setPosition(ccp(0, size.height/60));
    }
    
    bool isSelf = info.ownerType == PlayerSelf;
    if(info.marchType == MethodRally && !isSelf){
        for (auto it = WorldController::getInstance()->m_marchInfo.begin(); it != WorldController::getInstance()->m_marchInfo.end(); it++) {
            if(it->second.teamUid == info.uuid && it->second.uuid != info.uuid){
                isSelf = (it->second.ownerType == PlayerSelf);
                break;
            }
        }
    }
    if (isSelf && info.marchType != MethodHeiqishi) {
        if(info.stateType == StateReturn){
            if (info.marchType == MethodDeal || info.marchType == MethodWarehouse) {
                setButtonCount(1);
                setButtonName(1, _lang("108558"));
                setButtonCallback(1, cccontrol_selector(TroopInfoPanel::clickSpeedUp));
                setButtonState(1, ButtonSpeedUp);
                getButton(1)->setTouchPriority(Touch_Default);
            }
            else {
                setButtonCount(2);
                setButtonName(3, _lang("108558"));
                setButtonCallback(3, cccontrol_selector(TroopInfoPanel::clickSpeedUp));
                setButtonState(3, ButtonSpeedUp);
                getButton(3)->setTouchPriority(Touch_Default);
                setButtonName(2, _lang("108557"));
                setButtonCallback(2, cccontrol_selector(TroopInfoPanel::onMarchInfoClick));
                setButtonState(2, ButtonViewTroop);
                getButton(2)->setTouchPriority(Touch_Default);
            }
        }else{
            setButtonCount(3);
            setButtonName(3, _lang("108558"));
            setButtonCallback(3, cccontrol_selector(TroopInfoPanel::clickSpeedUp));
            setButtonState(3, ButtonSpeedUp);
            
            if (info.marchType == MethodDeal || info.marchType == MethodScout || info.marchType == MethodWarehouse){
                setButtonName(2, _lang("108556"));
                setButtonCallback(2, cccontrol_selector(TroopInfoPanel::onCallBackClick));
                setButtonState(2, ButtonRecall);
            }
            else
            {
                setButtonName(2, _lang("108557"));
                setButtonCallback(2, cccontrol_selector(TroopInfoPanel::onMarchInfoClick));
                setButtonState(2, ButtonViewTroop);
                
                if(info.marchType == MethodRally){//添加组队行军召回
                    setButtonName(1, _lang("115191"));//解散
                    setButtonCallback(1, cccontrol_selector(TroopInfoPanel::onCallBackClick));
                    setButtonState(1, ButtonRecall);
                }else if(info.marchType != MethodUnion){// && info.marchType != MethodRally
                    setButtonName(1, _lang("108556"));
                    setButtonCallback(1, cccontrol_selector(TroopInfoPanel::onCallBackClick));
                    setButtonState(1, ButtonRecall);
                }
            }
            
            getButton(1)->setTouchPriority(Touch_Default);
            getButton(2)->setTouchPriority(Touch_Default);
            getButton(3)->setTouchPriority(Touch_Default);
        }
    }
    else {
        if(GlobalData::shared()->playerInfo.isInAlliance() && info.marchType == MethodHeiqishi && info.marchToIndexLeague == GlobalData::shared()->playerInfo.allianceInfo.uid){
            setButtonCount(1);
            setButtonName(1, _lang("108557"));
            setButtonCallback(1, cccontrol_selector(TroopInfoPanel::onMarchInfoClick));
            setButtonState(1, ButtonAllianceAct);
        }
        else{
            setButtonCount(0);
        }
    }

    CCPoint endPt = WorldController::getPointByIndex(info.endPointIndex);
    std::string ptStr =  "To X:";
    ptStr.append(CC_ITOA(endPt.x));
    ptStr.append(", Y:");
    ptStr.append(CC_ITOA(endPt.y));
    if (info.ownerType == PlayerSelf) {
        m_pointLabel->setFontSize(m_tilePoint->getFontSize());
        m_pointLabel->setString(ptStr);
        m_pointLabel->setPosition(m_tilePoint->getPosition() - ccp(0, 20));
        m_underLine->setContentSize(Size(m_pointLabel->getContentSize().width * m_pointLabel->getOriginScaleX(), 1));
        m_underLine->setPosition(m_pointLabel->getPosition() - ccp(0, 10));
        m_pointLabel->setVisible(true);
        if (info.stateType == StateMarch) {
            m_underLine->setVisible(true);
        }
    }
    
    schedule(schedule_selector(TroopInfoPanel::timeCount), 0.2f);
    
    return true;
}