⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guitreeviewctrl.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
📖 第 1 页 / 共 5 页
字号:
                  // our current item is script data. but it may have children who
                  // is inspector data who need an updated set
                  if (item->mChild)
                     inspectorSearch(item->mChild, item, parentSet, newParentSet);

               }

               // And update everything hurrah.
               buildVisibleTree();
               scrollVisible(item);
            }
         }
         return true;

      case KEY_RIGHT:
         if ( item->mPrevious )
         {
            // Make the item the last child of its previous sibling.

            // First, unlink from the current position in the list
            item->mPrevious->mNext = item->mNext;

            if ( item->mNext )
               item->mNext->mPrevious = item->mPrevious;

            // Get the object we're poking with.
            SimObject *simObj = NULL;
            SimSet *parentSet = NULL;
            if(item->isInspectorData())
               simObj = item->getObject();
            if(item->mParent->isInspectorData())
               parentSet = dynamic_cast<SimSet*>(item->mParent->getObject());
            else {
               // parent is probably script data so we search up the tree for a
               // set to put our object in
               Item * temp = item->mParent;
               while (!temp->isInspectorData())
                  temp = temp->mParent;
               // found an ancestor who is an inspectorData
               if (temp->isInspectorData())
                  parentSet = dynamic_cast<SimSet*>(temp->getObject());
            }

            // If appropriate, remove from the current SimSet.
            if(parentSet && simObj) {
               if (parentSet->size()>0)
               {
                  SimObject *lastObject = parentSet->last();
                  parentSet->removeObject(simObj);
                  parentSet->reOrder(lastObject);
               } else
                  parentSet->removeObject(simObj);
            }


            // Now, make our previous sibling our parent...
            item->mParent = item->mPrevious;
            item->mNext = NULL;

            // And sink us down to the end of its siblings, if appropriate.
            if ( item->mParent->mChild )
            {
               Item* temp = item->mParent->mChild;
               while ( temp->mNext )
                  temp = temp->mNext;

               temp->mNext = item;
               item->mPrevious = temp;
            }
            else
            {
               // only child...<sniff>
               item->mParent->mChild = item;
               item->mPrevious = NULL;
            }

            // Make sure the new parent is expanded:
            if ( !item->mParent->mState.test( Item::Expanded ) )
               setItemExpanded( item->mParent->mId, true );

            // Snag the new parent simset if any.
            SimSet *newParentSet = NULL;

            // new parent might be script. so figure out what set we need to add it to.
            if(item->mParent->isInspectorData())
               newParentSet = dynamic_cast<SimSet*>(item->mParent->getObject());
            else
            {
               // parent is probably script data so we search up the tree for a
               // set to put our object in
               if (mDebug) Con::printf("oh nos my parent is script!");
               Item * temp = item->mParent;
               while (!temp->isInspectorData())
                  temp = temp->mParent;
               // found a ancestor who is an inspectorData
               if (temp->isInspectorData())
                  newParentSet = dynamic_cast<SimSet*>(temp->getObject());
               else newParentSet = NULL;
            }
            // Add the item's SimObject to the new parent simset, at the end.
            if(newParentSet && simObj)
               newParentSet->addObject(simObj);
            else if (!simObj&&newParentSet&&parentSet) {
               // our current item is script data. but it may have children who
               // is inspector data who need an updated set

               if (item->mChild) {
                  inspectorSearch(item->mChild, item, parentSet, newParentSet);
               }

            }
            scrollVisible(item);
         }
         return true;
      }
   }

   // Explorer-esque navigation...
   switch( event.keyCode )
   {
   case KEY_UP:
      // Select previous visible item:
      if ( item->mPrevious )
      {
         item = item->mPrevious;
         while ( item->isParent() && item->isExpanded() )
         {
            item = item->mChild;
            while ( item->mNext )
               item = item->mNext;
         }
         setItemSelected(mSelectedItems.first()->mId,false);
         setItemSelected( item->mId, true );
         scrollVisible(item);
         return true;
      }

      // or select parent:
      if ( item->mParent )
      {
         setItemSelected(mSelectedItems.first()->mId,false);
         setItemSelected( item->mParent->mId, true );
         scrollVisible(item->mParent);
         return true;
      }

      return false;
      break;

   case KEY_DOWN:
      // Selected child if it is visible:
      if ( item->isParent() && item->isExpanded() )
      {
         setItemSelected(mSelectedItems.first()->mId,false);
         setItemSelected( item->mChild->mId, true );
         scrollVisible(item->mChild);
         return true;
      }
      // or select next sibling (recursively):
      do
      {
         if ( item->mNext )
         {
            setItemSelected(mSelectedItems.first()->mId,false);
            setItemSelected(item->mNext->mId, true );
            scrollVisible(item->mNext);
            return true;
         }

         item = item->mParent;
      } while ( item );

      return false;
      break;

   case KEY_LEFT:
      // Contract current menu:
      if ( item->isExpanded() )
      {
         setItemExpanded( item->mId, false );
         scrollVisible(item);
         return true;
      }
      // or select parent:
      if ( item->mParent )
      {
         setItemSelected(mSelectedItems.first()->mId,false);
         setItemSelected( item->mParent->mId, true );
         scrollVisible(item->mParent);
         return true;
      }

      return false;
      break;

   case KEY_RIGHT:
      // Expand selected item:
      if ( item->isParent() )
      {
         if ( !item->isExpanded() )
         {
            setItemExpanded( item->mId, true );
            scrollVisible(item);
            return true;
         }

         // or select child:
         setItemSelected(mSelectedItems.first()->mId,false);
         setItemSelected( item->mChild->mId, true );
         scrollVisible(item->mChild);
         return true;
      }

      return false;
      break;
   }

   // Not processed, so pass the event on:
   return Parent::onKeyDown( event );
}



//------------------------------------------------------------------------------
// on mouse up look at the current item and check to see if it is valid
// to move the selected item(s) to it.
void GuiTreeViewCtrl::onMouseUp(const GuiEvent &event)
{
   if( !mActive || !mAwake || !mVisible )
      return;

   mouseUnlock();

   if ( mSelectedItems.empty())
   {
      mDragMidPoint = NomDragMidPoint;
      return;
   }
   
   if (!mMouseDragged) 
      return;
   else
      mMouseDragged = false;

   Item* newItem = NULL;
   Item* newItem2 = NULL;

   if (mFlags.test(IsEditable))
   {
      Parent::onMouseMove( event );
      if (mOldDragY != mMouseOverCell.y)
      {

         mOldDragY = mMouseOverCell.y;
         BitSet32 hitFlags = 0;
         if ( !hitTest( event.mousePoint, newItem2, hitFlags ) )
         {
            mDragMidPoint = NomDragMidPoint;
            return;
         }

         newItem2->mState.clear(Item::MouseOverBmp | Item::MouseOverText );
         
         // if the newItem isn't in the mSelectedItemList then continue.

         Vector<Item *>::iterator k;
         for(k = mSelectedItems.begin(); k != mSelectedItems.end(); k++) 
         {
            newItem = newItem2;
            
            if (*(k) == newItem) 
            {
               mDragMidPoint = NomDragMidPoint;
               return;
            }

            Item * temp = *(k);
            Item * grandpaTemp = newItem->mParent;
            
            // grandpa check, kick out if an item would be its own ancestor
            while (grandpaTemp)
            {
               if (temp == grandpaTemp)
               {
                  if (mDebug)
                  {
                     Con::printf("grandpa check");

                     if (temp->isInspectorData())
                        Con::printf("temp's name: %s",temp->getObject()->getName());

                     if (grandpaTemp->isInspectorData())
                        Con::printf("grandpa's name: %s",grandpaTemp->getObject()->getName());
                  }

                  mDragMidPoint = NomDragMidPoint;
                  return;
               }

               grandpaTemp = grandpaTemp->mParent;
            }
         }


         for (S32 i = 0; i <mSelectedItems.size();i++) 
         {
            newItem = newItem2;
            Item * item = mSelectedItems[i];
            char bufs[2][32];

            if (mDebug) Con::printf("----------------------------");
         
            // clear old highlighting of the item
            item->mState.clear(Item::MouseOverBmp | Item::MouseOverText );

            // move the selected item to the newItem
            Item* oldParent = item->mParent;
            // Snag the current parent set if any for future reference
            SimSet *parentSet = NULL;

            if(oldParent->isInspectorData())
               parentSet = dynamic_cast<SimSet*>(oldParent->getObject());
            else 
            {
               // parent is probably script data so we search up the tree for a
               // set to put our object in
               Item * temp = oldParent;
               while (temp) 
               {
                  if (temp->isInspectorData())
                     break;
                  temp = temp->mParent;
               }
               // found an ancestor who is an inspectorData
               if (temp) 
               {
                  if (temp->isInspectorData())
                     parentSet = dynamic_cast<SimSet*>(temp->getObject());
               }
            }

            // unlink from the current position in the list
            unlinkItem(item);

            // update the parent's children

            // check if we an only child
            if (item->mParent->mChild == item)
            {
               if (item->mNext)
                  item->mParent->mChild = item->mNext;
               else
                  item->mParent->mChild = NULL;
            }

            if (mDragMidPoint != NomDragMidPoint)
            {

               //if it is below an expanded tree, place as last item in the tree
               //if it is below a parent who isn't expanded put below it

               // position the item above or below another item
               if (mDragMidPoint == AbovemDragMidPoint)
               {
                  // easier to treat everything as "Below the mDragMidPoint" so make some adjustments
                  if (mDebug) Con::printf("adding item above mDragMidPoint");

                  // above the mid point of an item, so grab either the parent
                  // or the previous sibling

                  // does the item have a previous sibling?
                  if (newItem->mPrevious)
                  {
                     newItem = newItem->mPrevious;

                     if (mDebug) Con::printf("treating as if below an item that isn't expanded");

                     // otherwise add below that item as a sibling
                     item->mParent = newItem->mParent;
                     item->mPrevious = newItem;
                     item->mNext = newItem->mNext;
                     if (newItem->mNext)
                        newItem->mNext->mPrevious = item;
                     newItem->mNext = item;
                  } 
                  else
                  {
                     if (mDebug) Con::printf("treating as if adding below the parent of the item");

                     // instead we add as the first item below the newItem's parent
                     item->mParent = newItem->mParent;
                     item->mNext = newItem;
                     item->mPrevious = NULL;
                     newItem->mPrevious = item;
                     item->mParent->mChild = item;

                  }
               }
               else if (mDragMidPoint == BelowmDragMidPoint)
               {
                  if ((newItem->isParent())&&(newItem->isExpanded()))
                  {
                     if (mDebug) Con::printf("adding item to an expanded parent below the mDragMidPoint");

                     item->mParent = newItem;

                     // then add the new item as a child
                     item->mNext = newItem->mChild;
                     if (newItem->mChild)
                        newItem->mChild->mPrevious = item;
                     item->mParent->mChild = item;
                     item->mPrevious = NULL;
                  }
                  else if ((!newItem->mNext)&&(newItem->mParent)&&(newItem->mParent->mParent)) 
                  {
                     // add below it's parent.
                     if (mDebug) Con::printf("adding below a tree");

                     item->mParent = newItem->mParent->mParent;
                     item->mNext = newItem->mParent->mNext;
                     item->mPrevious = newItem->mParent;

                     if (newItem->mParent->mNext)
                        newItem->mParent->mNext->mPrevious = item;

                     newItem->mParent->mNext = item;
                  }
                  else 
                  {
                     // adding below item not as a child
                     if (mDebug) Con::printf("adding item below the mDragMidPoint of an item");

                     item->mParent = newItem->mParent;
                     // otherwise the item is a sibling
                     if (newItem->mNext)
                        newItem->mNext->mPrevious = item;
                     item->mNext = newItem->mNext;
                     item->mPrevious = newItem;
                     newItem->mNext = item;
                  }
               }
            }
            else 
            {
               if (mDebug) 
               {
                  if (item->isInspectorData())
                     Con::printf("Item: %s",item->getObject()->getName());
                  if (newItem->isInspectorData())
                     Con::printf("Parent: %s",newItem->getObject()->getName());
                  Con::printf("dragged onto an item");
               }

               // just dragging on an item, so just put the item into it.

               // new parent is the item in the current cell
               item->mParen

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -