Пример #1
0
void
dmz::ObjectModuleGridBasic::_init (Config &local) {

   _xCoordMax = config_to_int32 ("grid.cell.x", local, _xCoordMax);
   _yCoordMax = config_to_int32 ("grid.cell.y", local, _yCoordMax);
   _minGrid = config_to_vector ("grid.min", local, _minGrid);
   _maxGrid = config_to_vector ("grid.max", local, _maxGrid);

   _log.info << "grid: " << _xCoordMax << "x" << _yCoordMax << endl;
   _log.info << "extents:" << endl
      << "\t" << _minGrid << endl
      << "\t" << _maxGrid << endl;

   Vector vec (_maxGrid - _minGrid);
   _xCellSize = vec.get (_primaryAxis) / (Float64)(_xCoordMax);
   _yCellSize = vec.get (_secondaryAxis) / (Float64)(_yCoordMax);

   _log.info << "cell count: " << _xCoordMax * _yCoordMax << endl;

   if (is_zero64 (_xCellSize)) { _xCellSize = 1.0; }
   if (is_zero64 (_yCellSize)) { _yCellSize = 1.0; }

   _grid = new GridStruct[_xCoordMax * _yCoordMax];

   activate_default_object_attribute (
      ObjectCreateMask | ObjectDestroyMask | ObjectPositionMask);
}
QGraphicsPixmapItem *
dmz::QtPluginCanvasObjectBasic::_create_pixmap_item (
      ObjectStruct &os,
      QGraphicsItem *parent,
      const Config &Data,
      HashTableStringTemplate<String> &table) {

   QGraphicsPixmapItem *item (new QGraphicsPixmapItem (parent));

   Boolean center (True);

   if (_file_request (item, Data, table)) {

      item->setTransformationMode (Qt::SmoothTransformation);

      ConfigIterator it;
      Config cd;

      while (Data.get_next_config (it, cd)) {

         const String DataName (cd.get_name ().to_lower ());

         if (DataName == "offset") {

            Vector vec (config_to_vector (cd));
            item->setOffset (vec.get_x (), vec.get_y ());
         }
         else if (DataName == "translate") {

            Vector vec (config_to_vector (cd));
            item->translate (vec.get_x (), vec.get_y ());
            center = False;
         }
         else if (DataName == "scale") {

            Vector vec (config_to_vector (cd));

            if (vec.get_x () && vec.get_y ()) {

               item->scale (vec.get_x (), vec.get_y ());
            }
         }
      }
   }
   else { delete item; item = 0; }

   if (item && center) {

      QRectF bound = item->boundingRect ();

      item->translate (bound.width () * -0.5f, bound.height () * -0.5f);
   }

   return item;
}
void
dmz::EntityPluginPortalFollow3D::_init (Config &local) {

   Definitions defs (get_plugin_runtime_context (), &_log);

   _defaultHandle = defs.create_named_handle (ObjectAttributeDefaultName);

   _hilAttrHandle = activate_object_attribute (
      ObjectAttributeHumanInTheLoopName,
      ObjectFlagMask);

   Boolean foundOffset (False);

   Config cameraParams;

   if (local.lookup_config ("offset", cameraParams)) {

      foundOffset = True;

      _offset = config_to_vector (cameraParams, _offset);
   }

   init_input_channels (local, InputEventChannelStateMask, &_log);

   _log.info << "Using " << (foundOffset ? "" : "default ") << "camera offset: "
      << _offset << endl;
}
Пример #4
0
void
dmz::WeaponPluginFixedLauncher::_init (Config &local) {

   RuntimeContext *context (get_plugin_runtime_context ());

   Definitions defs (context, &_log);

   _defaultHandle = activate_default_object_attribute (
      ObjectStateMask);

   _hilAttrHandle = activate_object_attribute (
      ObjectAttributeHumanInTheLoopName,
      ObjectFlagMask);

   _deadState = config_to_state (
      "state.dead.value",
      local,
      DefaultStateNameDead,
      context);

   _delay = config_to_float64 ("delay.value", local, _delay);
   _launcherOffset = config_to_vector ("offset", local);
   const Vector HPR = config_to_vector ("rotation", local);

   _launcherRotation.roll_in_place (HPR.get_z ());
   _launcherRotation.pitch_in_place (HPR.get_x ());
   _launcherRotation.yaw_in_place (HPR.get_y ());

   _launchButton = config_to_uint32 ("button.value", local, _launchButton);

   init_input_channels (
      local,
      InputEventButtonMask | InputEventChannelStateMask,
      &_log);

}
dmz::QtCanvasObjectText *
dmz::QtPluginCanvasObjectBasic::_create_text_item (
      ObjectStruct &os,
      QGraphicsItem *parent,
      const Config &Data) {

   QtCanvasObjectText *item (new QtCanvasObjectText (parent));

   ConfigIterator it;
   Config cd;

   while (Data.get_next_config (it, cd)) {

      const String DataName (cd.get_name ().to_lower ());

      if (DataName == "text") {

         String text (config_to_string (cd));
         item->set_text (text.get_buffer ());
      }
      else if (DataName == "textcolor") {

         item->set_text_color (config_to_qcolor (cd));
      }
      else if (DataName == "outlinecolor") {

         item->set_outline_color (config_to_qcolor (cd));
      }
      else if (DataName == "backgroundcolor") {

         item->set_background_color (config_to_qcolor (cd));
      }
      else if (DataName == "enablebackground") {

         item->enable_background (config_to_boolean ("value", cd, true));
      }
      else if (DataName == "alignment") {

         String alignmentName (config_to_string (cd).to_lower ());
         if (alignmentName == "center") {  item->set_alignment (Qt::AlignCenter); }
         else if (alignmentName == "right") {  item->set_alignment (Qt::AlignRight); }
         else {  item->set_alignment (Qt::AlignLeft); }
      }
      else if (DataName == "max-length") {

         item->set_max_length (config_to_int32 ("value", cd));
      }
      else if (DataName == "translate") {

         Vector vec (config_to_vector (cd));
         String itemName = config_to_string ("name", cd);

         if (itemName) {

            QGraphicsItem *img = os.itemTable.lookup (itemName);
            if (img) {

               QRectF rect = img->boundingRect ();
               Vector rectVec;
               if (vec.get_x () == 0) { rectVec.set_x (0); }
               else if (vec.get_x() > 0) { rectVec.set_x (rect.center ().x ()); }
               else { rectVec.set_x (-rect.center ().x ()); }

               if (vec.get_y () == 0) { rectVec.set_y (0); }
               else if (vec.get_y () > 0) { rectVec.set_y (rect.center ().y ()); }
               else { rectVec.set_y (-rect.center ().y ()); }

               vec += rectVec;
               item->setPos (vec.get_x (), vec.get_y ());
            }
         }
         else { item->translate (vec.get_x (), vec.get_y ()); }
      }
      else if (DataName == "scale") {

         Vector vec (config_to_vector (cd));

         if (vec.get_x () && vec.get_y ()) {

            item->scale (vec.get_x (), vec.get_y ());
         }
      }
   }

   return item;
}
QGraphicsSvgItem *
dmz::QtPluginCanvasObjectBasic::_create_svg_item (
      ObjectStruct &os,
      QGraphicsItem *parent,
      const Config &Data,
      HashTableStringTemplate<String> &table) {

   QGraphicsSvgItem *item (new QGraphicsSvgItem (parent));

   Boolean center (True);

   if (_file_request (item, Data, table)) {

      ConfigIterator it;
      Config cd;

      while (Data.get_next_config (it, cd)) {

         const String DataName (cd.get_name ().to_lower ());

         if (DataName == "translate") {

            Vector vec (config_to_vector (cd));
            String itemName = config_to_string ("name", cd);

            if (itemName) {

               QGraphicsItem *img = os.itemTable.lookup (itemName);
               if (img) {

                  QRectF rect = img->boundingRect ();
                  Vector rectVec;
                  if (vec.get_x () == 0) { rectVec.set_x (0); }
                  else if (vec.get_x() > 0) { rectVec.set_x (rect.center ().x ()); }
                  else { rectVec.set_x (-rect.center ().x ()); }

                  if (vec.get_y () == 0) { rectVec.set_y (0); }
                  else if (vec.get_y () > 0) { rectVec.set_y (rect.center ().y ()); }
                  else { rectVec.set_y (-rect.center ().y ()); }

                  QPointF center = item->boundingRect ().center ();
                  rectVec.set_x (rectVec.get_x () - center.x ());
                  rectVec.set_y (rectVec.get_y () - center.y ());
                  vec += rectVec;
                  item->setPos (vec.get_x (), vec.get_y ());
               }
            }
            else { item->translate (vec.get_x (), vec.get_y ()); }

            center = False;
         }
         else if (DataName == "scale") {

            Vector vec (config_to_vector (cd));

            if (vec.get_x () && vec.get_y ()) {

               item->scale (vec.get_x (), vec.get_y ());
            }
         }
      }
   }
   else { delete item; item = 0; }

   if (item && center) {

      QRectF bound = item->boundingRect ();

      item->translate (bound.width () * -0.5f, bound.height () * -0.5f);
   }

   return item;
}