📄 guicellbuttonctrl.cc
字号:
//guiCellButtonCtrl.cc
/*/////////////////////////////////////////////////////////////////
李亦
2006-7-7
/*/////////////////////////////////////////////////////////////////
#include "console/console.h"
#include "dgl/dgl.h"
#include "console/consoleTypes.h"
#include "platform/platformAudio.h"
#include "gui/core/guiCanvas.h"
#include "gui/core/guiDefaultControlRender.h"
#include "gui/controls/guiCellButtonCtrl.h"
#include "gui/containers/guiCellArrayCtrl.h"
#include "rpg/ui/gameIconDictionary.h"
#include "rpg/ui/gameIconMan.h"
#include "rpg/gobjects/GGoodsArray.h"
IMPLEMENT_CONOBJECT(GuiCellButtonCtrl);
//-------------------------------------
GuiCellButtonCtrl::GuiCellButtonCtrl(GuiCellArrayControl* pOwner)
{
m_pOwnerCtrl = pOwner;
//m_bDrawText = false;
//m_bDrawBorder = true;
m_texHandle = NULL;
m_nCellIndex = -1;
//m_pCursorCaret = 0;
m_pGameIcon = NULL;
//m_pIconName = StringTable->insert("");
}
//-------------------------------------
void GuiCellButtonCtrl::initPersistFields()
{
Parent::initPersistFields();
//addField("bitmap", TypeFilename, Offset(mBitmapName, GuiCellButtonCtrl));
//addField("fullDraw", TypeBool, Offset(m_bFullDraw, GuiCellButtonCtrl));
//removeField("");
//removeField("drawBorder");
}
//-------------------------------------
bool GuiCellButtonCtrl::onWake()
{
if (! Parent::onWake())
return false;
//AssertWarn(m_pGameIcon,"不能为空,默认应用为Blank空白格子...");
//if(m_pGameIcon == 0)
// return false;
//RPG::g_pGameIconMan->GetIconTexture(m_pGameIcon->uIcon,m_texHandle,m_iconRect);
updateGameIcon();
return true;
}
//-------------------------------------
void GuiCellButtonCtrl::onSleep()
{
m_texHandle = NULL;
Parent::onSleep();
}
//-------------------------------------
//-------------------------------------
void GuiCellButtonCtrl::inspectPostApply()
{
//// if the extent is set to (0,0) in the gui editor and appy hit, this control will
//// set it's extent to be exactly the size of the normal bitmap (if present)
Parent::inspectPostApply();
//if ((mBounds.extent.x == 0) && (mBounds.extent.y == 0) && mTextureNormal)
//{
// TextureObject *texture = (TextureObject *) mTextureNormal;
// mBounds.extent.x = texture->bitmapWidth;
// mBounds.extent.y = texture->bitmapHeight;
//}
}
void GuiCellButtonCtrl::onMouseDown(const GuiEvent &event)
{
//mouseLock();
if(m_pOwnerCtrl)
{
m_pOwnerCtrl->readyDragCell(this);
m_pOwnerCtrl->onMouseDown(event);
//m_pOwnerCtrl->hideToolTip();
}
Parent::onMouseDown(event);
}
void GuiCellButtonCtrl::onMouseEnter(const GuiEvent &event)
{
if(m_pOwnerCtrl)
{
if(m_pOwnerCtrl->showToolTip(this))
mTooltip = StringTable->getBlank();
}
Parent::onMouseEnter(event);
}
void GuiCellButtonCtrl::onMouseLeave(const GuiEvent &event)
{
if(m_pOwnerCtrl)
m_pOwnerCtrl->showToolTip(NULL);
Parent::onMouseLeave(event);
}
void GuiCellButtonCtrl::onMouseDragged(const GuiEvent &event)
{
//if( m_pGameIcon == 0
// || !m_pOwnerCtrl->m_bCanDragDrop
// || StringTable->isBlank(m_pOwnerCtrl->m_arCellNames[m_nCellIndex]) )
// return;
if(!m_pOwnerCtrl)
return;
if( m_pGameIcon == 0
|| !m_pOwnerCtrl->DragIsDRAG()
|| StringTable->isBlank(m_pOwnerCtrl->m_arCellNames[m_nCellIndex]) )
return;
if(!m_pOwnerCtrl->isCellDragged())
m_pOwnerCtrl->beginDragCell(this);
//m_pCursorCaret = Canvas->createDragCursor(this);
}
void GuiCellButtonCtrl::onRightMouseDown(const GuiEvent &event)
{
if(m_pOwnerCtrl)
{
m_pOwnerCtrl->onRightMouseDown(event);
//m_pOwnerCtrl->toggleShowToolTip();
// m_pOwnerCtrl->toggleHilightMode();
}
// m_pOwnerCtrl->onCellAction(this,true);
}
void GuiCellButtonCtrl::onMouseUp(const GuiEvent &event)
{
if(m_pOwnerCtrl && m_pOwnerCtrl->isCellDragged())
{
GuiCellButtonCtrl* pCellDrop = dynamic_cast<GuiCellButtonCtrl*>(Canvas->findHitControl(event.mousePoint));
if(pCellDrop)
{
GuiCellArrayControl* pOwnerDrop = pCellDrop->m_pOwnerCtrl;
if(pOwnerDrop)
{
//同一控件内交换图标
if(m_pOwnerCtrl == pOwnerDrop)
{
//if(m_pOwnerCtrl->DragIsMOVEDROP())
if(m_pOwnerCtrl->DragCheckCANMOVE() && m_pOwnerCtrl->DragCheckCANDROP())
m_pOwnerCtrl->swapCellTo(this,pCellDrop);
}
//控件间拖放图标
//else if(m_pOwnerCtrl && pOwnerDrop->DragIsDROP() && (m_pOwnerCtrl->m_bDataSupply || m_pOwnerCtrl->DragIsMOVE()))
else if( m_pOwnerCtrl
&& pOwnerDrop->DragIsDROP() && m_pOwnerCtrl->DragIsDRAG()/*DragIsMOVE()*/
&& (m_pOwnerCtrl->m_sSupplyKey[0] || m_pOwnerCtrl->m_sSupplyKey[0]==0 && pOwnerDrop->m_sSupplyKey[0]==0))
{
//条件:源控件须为supplyKey提供者
//结果:若目标为提供者,则图标转移,否则(或非Move模式)目标只Ghost图标
if(m_pOwnerCtrl->putCellTo(this,pCellDrop) == GuiCellArrayControl::GPS_OK)
{
//如果存在supplyKey,且与目标同样的key,将作Move移动处理
if(m_pOwnerCtrl->m_sSupplyKey[0])
{
if(m_pOwnerCtrl->m_sSupplyKey == pOwnerDrop->m_sSupplyKey)
{
if(m_pOwnerCtrl->DragCheckCANMOVE())
m_pOwnerCtrl->clearCell(this, false);
}
}//if
//否则,将直接Move移动处理
else
{
//if(m_pOwnerCtrl->DragIsMOVE() && pOwnerDrop->m_bDataSupply)
if(m_pOwnerCtrl->DragCheckCANMOVE())
m_pOwnerCtrl->clearCell(this, false);
}//else
}//if
}//else if
else
{
pCellDrop = NULL;
}
}//if(pOwnerDrop)
}//if(pCellDrop)
if(pCellDrop == NULL)
{
//去除图标
//if(m_pOwnerCtrl && m_pOwnerCtrl->DragIsMOVE())
if(m_pOwnerCtrl && m_pOwnerCtrl->DragCheckCANMOVE())
{
m_pOwnerCtrl->clearCell(this, true);
}
}
//Canvas->clearDragCursor();
//m_pCursorCaret = NULL;
}
//这里不调用Parent的onMouseUp,避免单击引起onAction事件
if (! mActive)
return;
mouseUnlock();
setUpdate();
//在非拖动情况下,或双击情况下,将引起onAction
//if(!m_pOwnerCtrl->m_bCanDragDrop || event.mouseClickCount == 2)
if(m_pOwnerCtrl->DragIsNONE() || event.mouseClickCount == 2)
{
if (mDepressed)
onAction();
}
mDepressed = false;
if(m_pOwnerCtrl)
{
m_pOwnerCtrl->onMouseUp(event);
}
//m_pOwnerCtrl->hideToolTip();
}
void GuiCellButtonCtrl::updateGameIcon()
{
//m_pIconName = pName;
if(bool(m_pOwnerCtrl->m_iconTextureHandle))
{
m_pGameIcon = NULL;
m_texHandle = m_pOwnerCtrl->m_iconTextureHandle;
U32 nIndex = m_pOwnerCtrl->m_nIconBase + m_nCellIndex;
//Point2I iconSize(m_pOwnerCtrl->m_cellSize);
//if(m_pOwnerCtrl->m_bCellBorder)
// iconSize += Point2I(2,2);
m_iconRect.set(Point2I(nIndex * m_pOwnerCtrl->m_cellSize.x,0),m_pOwnerCtrl->m_cellSize) ;
}
else
{
RPG::g_pGameIconMan->GetIconTexture(m_pGameIcon->uIcon,m_texHandle,m_iconRect);
setUpdate();
}
}
void GuiCellButtonCtrl::setGameIcon(StringTableEntry pName,bool bLoadNow)
{
//m_pIconName = pName;
if(bool(m_pOwnerCtrl->m_iconTextureHandle))
{
mTooltip = pName;
m_pGameIcon = NULL;
}
else
{
//pName = m_arCellNames[nIndex];
if(pName == NULL || StringTable->isBlank(pName) )
pName = m_pOwnerCtrl->m_arCellBlanks[m_nCellIndex];
m_pGameIcon = RPG::g_pGameIconMan->GetGameIcon(pName);
if(m_pGameIcon == NULL)
m_pGameIcon = RPG::g_pGameIconMan->GetGameIcon(StringTable->getBlank());
mTooltip = m_pGameIcon->pDesc;
}
if(m_pOwnerCtrl->m_pDataSource)
{
StringTableEntry pText = m_pOwnerCtrl->m_pDataSource->GetToolTip(m_nCellIndex + m_pOwnerCtrl->m_uBaseIndex);
if(pText && pText[0])
mTooltip = pText;
}
//if(m_pOwnerCtrl->m_pToolTipGui && m_pOwnerCtrl->m_pToolTipGui[0])
//{
//}
if(bLoadNow)
{
updateGameIcon();
}
}
void GuiCellButtonCtrl::setTipText(StringTableEntry pTip)
{
if(pTip == NULL || pTip[0] == 0)
{
if(m_pGameIcon)
mTooltip = m_pGameIcon->pDesc;
else
mTooltip = StringTable->getBlank();
}
else
{
mTooltip = pTip;
}
}
//void GuiCellButtonCtrl::clearCell()
//{
// setGameIcon(NULL, true);
//}
//
//
//void GuiCellButtonCtrl::swapCellTo(GuiCellButtonCtrl* pDest)
//{
//}
void GuiCellButtonCtrl::onAction()
{
if(m_pOwnerCtrl && mConsoleCommand[0] == 0)
m_pOwnerCtrl->onCellAction(this);
else
Parent::onAction();
}
void GuiCellButtonCtrl::drawDragCursor(const Point2I &pos)
{
RectI updateRect(pos - mBounds.extent/2,mBounds.extent);
onRender(updateRect.point,updateRect);
}
//-------------------------------------
void GuiCellButtonCtrl::onRender(Point2I offset, const RectI& updateRect)
{
if (!m_texHandle)
{
Parent::onRender(offset, updateRect);
return;
}
U32 state = NORMAL;
if (mActive)
{
if (mMouseOver)
state = HILIGHT;
if (mDepressed || mStateOn)
state = DEPRESSED;
}
else
state = INACTIVE;
//绘画加速键
if( m_pOwnerCtrl->m_uCellAlign != GuiCellArrayControl::ALIGN_NONE)
{
switch (state)
{
case HILIGHT:
dglSetBitmapModulation(mProfile->mFontColorHL);
break;
case INACTIVE:
dglSetBitmapModulation(mProfile->mFontColorNA);
break;
default:
dglSetBitmapModulation(mProfile->mFontColor);
break;
}
}
/////////////////////////////////////////////////////////////
//绘画边框线
RectI rect(offset, mBounds.extent);
if(m_pOwnerCtrl->m_bCellBorder)
{
switch (state)
{
case HILIGHT:
dglDrawRectFill(rect,mProfile->mFillColorHL);
dglDrawRect(rect,mProfile->mBorderColorHL);
break;
case INACTIVE:
dglDrawRectFill(rect,mProfile->mFillColorNA);
dglDrawRect(rect,mProfile->mBorderColorNA);
break;
default:
dglDrawRectFill(rect,mProfile->mFillColor);
dglDrawRect(rect,mProfile->mBorderColor);
break;
}
rect.point.x ++;
rect.point.y ++;
rect.extent.x -= 2;
rect.extent.y -= 2;
}
//绘画文字
if(m_pOwnerCtrl->m_uCellAlign != GuiCellArrayControl::ALIGN_NONE)
{
if(bool(m_pOwnerCtrl->m_iconTextureHandle))
dglDrawText(mProfile->mFont,offset + m_textOffset,m_pOwnerCtrl->m_arCellNames[m_nCellIndex]);
else if(m_pGameIcon->pIDName[0])
dglDrawText(mProfile->mFont,offset + m_textOffset,m_pGameIcon->pName);
rect.extent = m_pOwnerCtrl->m_cellSize;
rect.point = offset + m_iconOffset;
}
dglClearBitmapModulation();
dglDrawBitmapStretchSR(m_texHandle, rect,m_iconRect);
renderChildControls( offset, updateRect);
//绘画加速键
if(mAcceleratorKey && mAcceleratorKey[0])
{
dglSetBitmapModulation(mProfile->mBorderColorHL);
dglDrawText(mProfile->mFont,rect.point, mAcceleratorKey);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -