本文整理汇总了C++中Action类的典型用法代码示例。如果您正苦于以下问题:C++ Action类的具体用法?C++ Action怎么用?C++ Action使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Action类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setupKeymapper
static void setupKeymapper(OSystem &system) {
#ifdef ENABLE_KEYMAPPER
using namespace Common;
Keymapper *mapper = system.getEventManager()->getKeymapper();
Keymap *globalMap = new Keymap("global");
Action *act;
HardwareKeySet *keySet;
keySet = system.getHardwareKeySet();
// Query backend for hardware keys and register them
mapper->registerHardwareKeySet(keySet);
// Now create the global keymap
act = new Action(globalMap, "MENU", _("Menu"), kGenericActionType, kSelectKeyType);
act->addKeyEvent(KeyState(KEYCODE_F5, ASCII_F5, 0));
act = new Action(globalMap, "SKCT", _("Skip"), kGenericActionType, kActionKeyType);
act->addKeyEvent(KeyState(KEYCODE_ESCAPE, ASCII_ESCAPE, 0));
act = new Action(globalMap, "PAUS", _("Pause"), kGenericActionType, kStartKeyType);
act->addKeyEvent(KeyState(KEYCODE_SPACE, ' ', 0));
act = new Action(globalMap, "SKLI", _("Skip line"), kGenericActionType, kActionKeyType);
act->addKeyEvent(KeyState(KEYCODE_PERIOD, '.', 0));
act = new Action(globalMap, "VIRT", _("Display keyboard"), kVirtualKeyboardActionType);
act->addKeyEvent(KeyState(KEYCODE_F7, ASCII_F7, 0));
act = new Action(globalMap, "REMP", _("Remap keys"), kKeyRemapActionType);
act->addKeyEvent(KeyState(KEYCODE_F8, ASCII_F8, 0));
mapper->addGlobalKeymap(globalMap);
mapper->pushKeymap("global");
#endif
}
示例2: Action
Action *ActionManagerPrivate::overridableAction(Id id)
{
Action *a = m_idCmdMap.value(id, 0);
if (!a) {
a = new Action(id);
m_idCmdMap.insert(id, a);
readUserSettings(id, a);
ICore::mainWindow()->addAction(a->action());
a->action()->setObjectName(id.toString());
a->action()->setShortcutContext(Qt::ApplicationShortcut);
a->setCurrentContext(m_context);
if (ActionManager::isPresentationModeEnabled())
connect(a->action(), &QAction::triggered, this, &ActionManagerPrivate::actionTriggered);
}
return a;
}
示例3: qfLogFuncFrame
Action* MenuBar::actionForPath(const QString &path, bool create_if_not_exists)
{
qfLogFuncFrame() << path;
QWidget *parent_w = this;
Action *ret = nullptr;
QStringList path_list = qf::core::String(path).splitAndTrim('/');
Q_FOREACH(auto id, path_list) {
qfDebug() << id << "of path:" << path;
if(!parent_w) {
/// recent action was not a menu one
qfWarning() << "Attempt to traverse through not menu action before:" << id << "in:" << path_list.join("/");
break;
}
ret = nullptr;
Q_FOREACH(auto a, parent_w->actions()) {
qfDebug() << a;
Action *act = qobject_cast<Action*>(a);
//if(!ret) continue;
QF_ASSERT(act!=nullptr, "bad action", return ret);
if(act->oid() == id) {
qfDebug() << "\t found action" << a;
ret = act;
break;
}
}
if(!ret) {
if(!create_if_not_exists) {
break;
}
QMenu *m = new QMenu(parent_w);
ret = new Action(parent_w);
ret->setMenu(m);
ret->setOid(id);
ret->setText(id);
qfDebug() << "\t created menu" << ret;
parent_w->addAction(ret);
}
parent_w = ret->menu();
}
示例4: handle_between
void ButtonIO::handle_between(Action &action, int value) {
if ( action.startTime > 0 ) {
if (action.lastState == HIGH && value == LOW) {
long time = millis();
long time_down = time - action.startTime;
int duration = action.duration;
int least = action.least;
bool is_between = time_down > least && time_down < duration;
if (is_between) {
action.callback(action.pin);
}
action.startTime = -1;
}
}
else {
if (action.lastState == LOW && value == HIGH) {
action.startTime = millis();
}
}
}
示例5: Action
Action * StdCmdDownloadOnlineHelp::createAction(void)
{
Action *pcAction;
QString exe = QString::fromAscii(App::GetApplication().getExecutableName());
pcAction = new Action(this,getMainWindow());
pcAction->setText(QCoreApplication::translate(
this->className(), sMenuText, 0,
QCoreApplication::CodecForTr));
pcAction->setToolTip(QCoreApplication::translate(
this->className(), sToolTipText, 0,
QCoreApplication::CodecForTr).arg(exe));
pcAction->setStatusTip(QCoreApplication::translate(
this->className(), sStatusTip, 0,
QCoreApplication::CodecForTr).arg(exe));
pcAction->setWhatsThis(QCoreApplication::translate(
this->className(), sWhatsThis, 0,
QCoreApplication::CodecForTr).arg(exe));
pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap));
pcAction->setShortcut(QString::fromAscii(sAccel));
return pcAction;
}
示例6: b
// Send Messages
void Network::SendActionToAll(const Action& a, bool lock) const
{
if (0) {
if (a.GetType() == Action::ACTION_GAME_CALCULATE_FRAME) {
frames++;
if (frames == Action::MAX_FRAMES) {
Action b(Action::ACTION_GAME_PACK_CALCULATED_FRAMES, Action::MAX_FRAMES);
SendAction(b, NULL, false, lock);
printf("Sending pack for %u frames\n", Action::MAX_FRAMES);
frames = 0;
}
return;
}
if (frames>0 && !a.IsFrameLess()) {
// This should have arrived here
assert(a.GetType()!=Action::ACTION_TIME_VERIFY_SYNC ||
a.GetType()!=Action::ACTION_NETWORK_VERIFY_RANDOM_SYNC);
// The clients must have seen all previous frames for this to occur
Action b(Action::ACTION_GAME_PACK_CALCULATED_FRAMES, frames);
SendAction(b, NULL, false, lock);
printf("Sending pack for %u frames because of action '%s'\n",
frames, ActionHandler::GetActionName(a.GetType()).c_str());
frames = 0;
}
if (a.GetType()==Action::ACTION_TIME_VERIFY_SYNC ||
a.GetType()==Action::ACTION_NETWORK_VERIFY_RANDOM_SYNC)
printf("Sending %u\n", (uint)a.GetType());
}
MSG_DEBUG("network.traffic", "Send action %s to all remote computers",
ActionHandler::GetActionName(a.GetType()).c_str());
SendAction(a, NULL, false, lock);
}
示例7: Failure
Future<uint64_t> CoordinatorProcess::append(const string& bytes)
{
if (state == INITIAL) {
return Failure("Coordinator is not elected");
} else if (state == ELECTING) {
return Failure("Coordinator is being elected");
} else if (state == WRITING) {
return Failure("Coordinator is currently writing");
}
Action action;
action.set_position(index);
action.set_promised(proposal);
action.set_performed(proposal);
action.set_type(Action::APPEND);
Action::Append* append = action.mutable_append();
append->set_bytes(bytes);
return write(action);
}
示例8: SYNTAX_ERROR
RobotInterface::Action RobotInterface::XMLReader::Private::readActionTag(TiXmlElement* actionElem)
{
if (actionElem->ValueStr().compare("action") != 0) {
SYNTAX_ERROR(actionElem->Row()) << "Expected \"action\". Found" << actionElem->ValueStr();
}
Action action;
if (actionElem->QueryValueAttribute<ActionPhase>("phase", &action.phase()) != TIXML_SUCCESS || action.phase() == ActionPhaseUnknown) {
SYNTAX_ERROR(actionElem->Row()) << "\"action\" element should contain the \"phase\" attribute [startup|interrupt{1,2,3}|shutdown]";
}
if (actionElem->QueryValueAttribute<ActionType>("type", &action.type()) != TIXML_SUCCESS || action.type() == ActionTypeUnknown) {
SYNTAX_ERROR(actionElem->Row()) << "\"action\" element should contain the \"type\" attribute [configure|calibrate|attach|abort|detach|park|custom]";
}
// yDebug() << "Found action [ ]";
#if TINYXML_UNSIGNED_INT_BUG
if (actionElem->QueryUnsignedAttribute("level", &action.level()) != TIXML_SUCCESS) {
SYNTAX_ERROR(actionElem->Row()) << "\"action\" element should contain the \"level\" attribute [unsigned int]";
}
#else
int tmp;
if (actionElem->QueryIntAttribute("level", &tmp) != TIXML_SUCCESS || tmp < 0) {
SYNTAX_ERROR(actionElem->Row()) << "\"action\" element should contain the \"level\" attribute [unsigned int]";
}
action.level() = (unsigned)tmp;
#endif
for (TiXmlElement* childElem = actionElem->FirstChildElement(); childElem != 0; childElem = childElem->NextSiblingElement()) {
ParamList childParams = readParams(childElem);
for (ParamList::const_iterator it = childParams.begin(); it != childParams.end(); ++it) {
action.params().push_back(*it);
}
}
// yDebug() << action;
return action;
}
示例9: qWarning
Action *ActionManagerPrivate::overridableAction(Id id)
{
Action *a = 0;
if (CommandPrivate *c = m_idCmdMap.value(id, 0)) {
a = qobject_cast<Action *>(c);
if (!a) {
qWarning() << "registerAction: id" << id.name()
<< "is registered with a different command type.";
return 0;
}
} else {
a = new Action(id);
m_idCmdMap.insert(id, a);
ICore::mainWindow()->addAction(a->action());
a->action()->setObjectName(id.toString());
a->action()->setShortcutContext(Qt::ApplicationShortcut);
a->setCurrentContext(m_context);
if (ActionManager::isPresentationModeEnabled())
connect(a->action(), SIGNAL(triggered()), this, SLOT(actionTriggered()));
}
return a;
}
示例10: Action
Action * MacroCommand::createAction(void)
{
Action *pcAction;
pcAction = new Action(this,getMainWindow());
pcAction->setText(QString::fromUtf8(sMenuText));
pcAction->setToolTip(QString::fromUtf8(sToolTipText));
pcAction->setStatusTip(QString::fromUtf8(sStatusTip));
if (pcAction->statusTip().isEmpty())
pcAction->setStatusTip(pcAction->toolTip());
pcAction->setWhatsThis(QString::fromUtf8(sWhatsThis));
if (sPixmap)
pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap));
pcAction->setShortcut(QString::fromAscii(sAccel));
QString accel = pcAction->shortcut().toString(QKeySequence::NativeText);
if (!accel.isEmpty()) {
// show shortcut inside tooltip
QString ttip = QString::fromLatin1("%1 (%2)")
.arg(pcAction->toolTip()).arg(accel);
pcAction->setToolTip(ttip);
// show shortcut inside status tip
QString stip = QString::fromLatin1("(%1)\t%2")
.arg(accel).arg(pcAction->statusTip());
pcAction->setStatusTip(stip);
}
return pcAction;
}
示例11: Error
Try<Nothing> LevelDBStorage::persist(const Action& action)
{
Stopwatch stopwatch;
stopwatch.start();
Record record;
record.set_type(Record::ACTION);
record.mutable_action()->MergeFrom(action);
string value;
if (!record.SerializeToString(&value)) {
return Error("Failed to serialize record");
}
leveldb::WriteOptions options;
options.sync = true;
leveldb::Status status = db->Put(options, encode(action.position()), value);
if (!status.ok()) {
return Error(status.ToString());
}
// Updated the first position. Notice that we use 'min' here instead
// of checking 'isNone()' because it's likely that log entries are
// written out of order during catch-up (e.g. if a random bulk
// catch-up policy is used).
first = min(first, action.position());
LOG(INFO) << "Persisting action (" << value.size()
<< " bytes) to leveldb took " << stopwatch.elapsed();
// Delete positions if a truncate action has been *learned*. Note
// that we do this in a best-effort fashion (i.e., we ignore any
// failures to the database since we can always try again).
if (action.has_type() && action.type() == Action::TRUNCATE &&
action.has_learned() && action.learned()) {
CHECK(action.has_truncate());
stopwatch.start(); // Restart the stopwatch.
// To actually perform the truncation in leveldb we need to remove
// all the keys that represent positions no longer in the log. We
// do this by attempting to delete all keys that represent the
// first position we know is still in leveldb up to (but
// excluding) the truncate position. Note that this works because
// the semantics of WriteBatch are such that even if the position
// doesn't exist (which is possible because this replica has some
// holes), we can attempt to delete the key that represents it and
// it will just ignore that key. This is *much* cheaper than
// actually iterating through the entire database instead (which
// was, for posterity, the original implementation). In addition,
// caching the "first" position we know is in the database is
// cheaper than using an iterator to determine the first position
// (which was, for posterity, the second implementation).
leveldb::WriteBatch batch;
CHECK_SOME(first);
// Add positions up to (but excluding) the truncate position to
// the batch starting at the first position still in leveldb. It's
// likely that the first position is greater than the truncate
// position (e.g., during catch-up). In that case, we do nothing
// because there is nothing we can truncate.
// TODO(jieyu): We might miss a truncation if we do random (i.e.,
// out of order) bulk catch-up and the truncate operation is
// caught up first.
uint64_t index = 0;
while ((first.get() + index) < action.truncate().to()) {
batch.Delete(encode(first.get() + index));
index++;
}
// If we added any positions, attempt to delete them!
if (index > 0) {
// We do this write asynchronously (e.g., using default options).
leveldb::Status status = db->Write(leveldb::WriteOptions(), &batch);
if (!status.ok()) {
LOG(WARNING) << "Ignoring leveldb batch delete failure: "
<< status.ToString();
} else {
// Save the new first position!
CHECK_LT(first.get(), action.truncate().to());
first = action.truncate().to();
LOG(INFO) << "Deleting ~" << index
<< " keys from leveldb took " << stopwatch.elapsed();
}
}
}
return Nothing();
}
示例12: getAction
ReturnValue Actions::internalUseItem(Player* player, const Position& pos, uint8_t index, Item* item, bool isHotkey)
{
if (Door* door = item->getDoor()) {
if (!door->canUse(player)) {
return RETURNVALUE_CANNOTUSETHISOBJECT;
}
}
Action* action = getAction(item);
if (action) {
int32_t stack = item->getParent()->__getIndexOfThing(item);
PositionEx posEx(pos, stack);
if (action->isScripted()) {
if (action->executeUse(player, item, posEx, posEx, false, 0, isHotkey)) {
return RETURNVALUE_NOERROR;
}
} else if (action->function) {
if (action->function(player, item, posEx, posEx, false, isHotkey)) {
return RETURNVALUE_NOERROR;
}
}
}
if (BedItem* bed = item->getBed()) {
if (!bed->canUse(player)) {
return RETURNVALUE_CANNOTUSETHISOBJECT;
}
if (bed->trySleep(player)) {
player->setBedItem(bed);
g_game.sendOfflineTrainingDialog(player);
}
return RETURNVALUE_NOERROR;
}
if (Container* container = item->getContainer()) {
Container* openContainer;
//depot container
if (DepotLocker* depot = container->getDepotLocker()) {
DepotLocker* myDepotLocker = player->getDepotLocker(depot->getDepotId());
myDepotLocker->setParent(depot->getParent()->getTile());
openContainer = myDepotLocker;
player->setLastDepotId(depot->getDepotId());
} else {
openContainer = container;
}
uint32_t corpseOwner = container->getCorpseOwner();
if (corpseOwner != 0 && !player->canOpenCorpse(corpseOwner)) {
return RETURNVALUE_YOUARENOTTHEOWNER;
}
//open/close container
int32_t oldContainerId = player->getContainerID(openContainer);
if (oldContainerId != -1) {
player->onCloseContainer(openContainer);
player->closeContainer(oldContainerId);
} else {
player->addContainer(index, openContainer);
player->onSendContainer(openContainer);
}
return RETURNVALUE_NOERROR;
}
if (item->isReadable()) {
if (item->canWriteText()) {
player->setWriteItem(item, item->getMaxWriteLength());
player->sendTextWindow(item, item->getMaxWriteLength(), true);
} else {
player->setWriteItem(nullptr);
player->sendTextWindow(item, 0, false);
}
return RETURNVALUE_NOERROR;
}
return RETURNVALUE_CANNOTUSETHISOBJECT;
}
示例13: debug
void RemapDialog::loadKeymap() {
_currentActions.clear();
const Stack<Keymapper::MapRecord> &activeKeymaps = _keymapper->getActiveStack();
debug(3, "RemapDialog::loadKeymap active keymaps: %u", activeKeymaps.size());
if (!activeKeymaps.empty() && _kmPopUp->getSelected() == 0) {
// This is the "effective" view which shows all effective actions:
// - all of the topmost keymap action
// - all mapped actions that are reachable
List<const HardwareInput *> freeInputs(_keymapper->getHardwareInputs());
int topIndex = activeKeymaps.size() - 1;
// This is a WORKAROUND for changing the popup list selected item and changing it back
// to the top entry. Upon changing it back, the top keymap is always "gui".
if (!_topKeymapIsGui && activeKeymaps[topIndex].keymap->getName() == kGuiKeymapName)
--topIndex;
// add most active keymap's keys
Keymapper::MapRecord top = activeKeymaps[topIndex];
List<Action *>::iterator actIt;
debug(3, "RemapDialog::loadKeymap top keymap: %s", top.keymap->getName().c_str());
for (actIt = top.keymap->getActions().begin(); actIt != top.keymap->getActions().end(); ++actIt) {
Action *act = *actIt;
ActionInfo info = {act, false, act->description};
_currentActions.push_back(info);
if (act->getMappedInput())
freeInputs.remove(act->getMappedInput());
}
// loop through remaining finding mappings for unmapped keys
if (top.transparent && topIndex >= 0) {
for (int i = topIndex - 1; i >= 0; --i) {
Keymapper::MapRecord mr = activeKeymaps[i];
debug(3, "RemapDialog::loadKeymap keymap: %s", mr.keymap->getName().c_str());
List<const HardwareInput *>::iterator inputIt = freeInputs.begin();
const HardwareInput *input = *inputIt;
while (inputIt != freeInputs.end()) {
Action *act = 0;
if (input->type == kHardwareInputTypeKeyboard)
act = mr.keymap->getMappedAction(input->key);
else if (input->type == kHardwareInputTypeGeneric)
act = mr.keymap->getMappedAction(input->inputCode);
if (act) {
ActionInfo info = {act, true, act->description + " (" + mr.keymap->getName() + ")"};
_currentActions.push_back(info);
freeInputs.erase(inputIt);
} else {
++inputIt;
}
}
if (mr.transparent == false || freeInputs.empty())
break;
}
}
} else if (_kmPopUp->getSelected() != -1) {
// This is the regular view of a keymap that isn't the topmost one.
// It shows all of that keymap's actions
Keymap *km = _keymapTable[_kmPopUp->getSelectedTag()];
List<Action *>::iterator it;
for (it = km->getActions().begin(); it != km->getActions().end(); ++it) {
ActionInfo info = {*it, false, (*it)->description};
_currentActions.push_back(info);
}
}
// refresh scroll bar
_scrollBar->_currentPos = 0;
_scrollBar->_numEntries = _currentActions.size();
_scrollBar->recalc();
// force refresh
_topAction = -1;
refreshKeymap();
}
示例14: MEASURE
void Player::makeMove() {
vector<Vec2> squareDirs = creature->getConstSquare()->getTravelDir();
const vector<Creature*>& creatures = creature->getLevel()->getAllCreatures();
if (creature->isAffected(Creature::HALLU))
ViewObject::setHallu(true);
else
ViewObject::setHallu(false);
MEASURE(
model->getView()->refreshView(creature),
"level render time");
if (Options::getValue(OptionId::HINTS) && displayTravelInfo && creature->getConstSquare()->getName() == "road") {
model->getView()->presentText("", "Use ctrl + arrows to travel quickly on roads and corridors.");
displayTravelInfo = false;
}
static bool greeting = false;
if (Options::getValue(OptionId::HINTS) && displayGreeting) {
CHECK(creature->getFirstName());
model->getView()->presentText("", "Dear " + *creature->getFirstName() + ",\n \n \tIf you are reading this letter, then you have arrived in the valley of " + NameGenerator::worldNames.getNext() + ". There is a band of dwarves dwelling in caves under a mountain. Find them, talk to them, they will help you. Let your sword guide you.\n \n \nYours, " + NameGenerator::firstNames.getNext() + "\n \nPS.: Beware the goblins!");
model->getView()->presentText("", "Every settlement that you find has a leader, and they may have quests for you."
"\n \nYou can turn these messages off in the options (press F2).");
displayGreeting = false;
model->getView()->refreshView(creature);
}
for (const Creature* c : creature->getVisibleEnemies()) {
if (c->isSpecialMonster() && !contains(specialCreatures, c)) {
privateMessage(MessageBuffer::important(c->getDescription()));
model->getView()->refreshView(creature);
specialCreatures.push_back(c);
}
}
if (travelling)
travelAction();
else if (target)
targetAction();
else {
Action action = model->getView()->getAction();
vector<Vec2> direction;
bool travel = false;
switch (action.getId()) {
case ActionId::FIRE: fireAction(action.getDirection()); break;
case ActionId::TRAVEL: travel = true;
case ActionId::MOVE: direction.push_back(action.getDirection()); break;
case ActionId::MOVE_TO: if (action.getDirection().dist8(creature->getPosition()) == 1) {
Vec2 dir = action.getDirection() - creature->getPosition();
if (const Creature* c = creature->getConstSquare(dir)->getCreature()) {
if (!creature->isEnemy(c)) {
chatAction(dir);
break;
}
}
direction.push_back(dir);
} else
if (action.getDirection() != creature->getPosition()) {
target = action.getDirection();
target = Vec2(min(creature->getLevel()->getBounds().getKX() - 1, max(0, target->x)),
min(creature->getLevel()->getBounds().getKY() - 1, max(0, target->y)));
// Just in case
if (!target->inRectangle(creature->getLevel()->getBounds()))
target = Nothing();
}
else
pickUpAction(false);
break;
case ActionId::SHOW_INVENTORY: displayInventory(); break;
case ActionId::PICK_UP: pickUpAction(false); break;
case ActionId::EXT_PICK_UP: pickUpAction(true); break;
case ActionId::DROP: dropAction(false); break;
case ActionId::EXT_DROP: dropAction(true); break;
case ActionId::WAIT: creature->wait(); break;
case ActionId::APPLY_ITEM: applyAction(); break;
case ActionId::THROW: throwAction(); break;
case ActionId::THROW_DIR: throwAction(action.getDirection()); break;
case ActionId::EQUIPMENT: equipmentAction(); break;
case ActionId::HIDE: hideAction(); break;
case ActionId::PAY_DEBT: payDebtAction(); break;
case ActionId::CHAT: chatAction(); break;
case ActionId::SHOW_HISTORY: messageBuffer.showHistory(); break;
case ActionId::UNPOSSESS: if (creature->canPopController()) {
creature->popController();
return;
} break;
case ActionId::CAST_SPELL: spellAction(); break;
case ActionId::DRAW_LEVEL_MAP: model->getView()->drawLevelMap(creature); break;
case ActionId::EXIT: model->exitAction(); break;
case ActionId::IDLE: break;
}
if (creature->isAffected(Creature::SLEEP) && creature->canPopController()) {
if (model->getView()->yesOrNoPrompt("You fell asleep. Do you want to leave your minion?"))
creature->popController();
return;
}
for (Vec2 dir : direction)
if (travel) {
vector<Vec2> squareDirs = creature->getConstSquare()->getTravelDir();
if (findElement(squareDirs, dir)) {
travelDir = dir;
lastLocation = creature->getLevel()->getLocation(creature->getPosition());
travelling = true;
travelAction();
}
//.........这里部分代码省略.........
示例15: remove
void MenuAdapter::remove(Action& action)
{
::RemoveMenu(HMENU(_handle), (UINT) uptrint_t(action.getId()), MF_BYCOMMAND);
}