Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
265 lines
6.2 KiB
C++
265 lines
6.2 KiB
C++
// GUIButton.cpp: implementation of the CGUIButton class.
|
||
//
|
||
//////////////////////////////////////////////////////////////////////
|
||
|
||
#include "ClientMain.h"
|
||
#include "SoundBuffer.h"
|
||
#include "SoundManager.h"
|
||
#include "WinInput.h"
|
||
#include "GUIButton.h"
|
||
|
||
//////////////////////////////////////////////////////////////////////
|
||
// Construction/Destruction
|
||
//////////////////////////////////////////////////////////////////////
|
||
|
||
CGUIButton::CGUIButton()
|
||
{
|
||
m_lpNormalButton = NULL;
|
||
m_lpOnMouseButton = NULL;
|
||
m_lpClickMouseButton = NULL;
|
||
|
||
m_lpTooltip = NULL;
|
||
|
||
m_bExistItemPress = FALSE;
|
||
m_bShow = TRUE;
|
||
m_bPress = FALSE;
|
||
m_nState = BUTTON_NONE;
|
||
m_nMethod = BUTTON_NORMAL;
|
||
|
||
m_lMoveX = 0;
|
||
m_lMoveY = 0;
|
||
}
|
||
|
||
CGUIButton::~CGUIButton()
|
||
{
|
||
if(m_lpNormalButton) { delete m_lpNormalButton; m_lpNormalButton = NULL; }
|
||
if(m_lpOnMouseButton) { delete m_lpOnMouseButton; m_lpOnMouseButton = NULL; }
|
||
if(m_lpClickMouseButton) { delete m_lpClickMouseButton; m_lpClickMouseButton = NULL; }
|
||
}
|
||
|
||
void CGUIButton::Render(LPDIRECT3DDEVICE8 lpD3DDevice, unsigned char cAlpha, long x, long y)
|
||
{
|
||
if(m_bShow)
|
||
{
|
||
switch(m_nState)
|
||
{
|
||
case BUTTON_OFF:
|
||
case BUTTON_NONE:
|
||
m_lpNormalButton->Render(lpD3DDevice, cAlpha, m_lMoveX + x, m_lMoveY + y);
|
||
break;
|
||
|
||
case BUTTON_OVER:
|
||
m_lpOnMouseButton->Render(lpD3DDevice, cAlpha, m_lMoveX + x, m_lMoveY + y);
|
||
break;
|
||
|
||
case BUTTON_PRESS:
|
||
case BUTTON_CLICK:
|
||
case BUTTON_ON:
|
||
case BUTTON_HOLD:
|
||
m_lpClickMouseButton->Render(lpD3DDevice, cAlpha, m_lMoveX + x, m_lMoveY + y);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
void CGUIButton::SetTooltip(CGUITooltipManager *lpTooltipManager, const char *strTooltip)
|
||
{
|
||
if(!m_lpTooltip)
|
||
{
|
||
m_lpTooltip = new CGUITooltipButton;
|
||
m_lpTooltip->InitTooltip(strTooltip);
|
||
m_lpTooltip->SetRect( m_lpNormalButton->m_nPutX + m_lMoveX, m_lpNormalButton->m_nPutY + m_lMoveY,
|
||
m_lpNormalButton->m_nPutX + m_lMoveX + m_lpNormalButton->GetSizeX(),
|
||
m_lpNormalButton->m_nPutY + m_lMoveY + m_lpNormalButton->GetSizeY() );
|
||
lpTooltipManager->AddTooltip(m_lpTooltip);
|
||
} else
|
||
{
|
||
m_lpTooltip->InitTooltip(strTooltip);
|
||
}
|
||
}
|
||
|
||
void CGUIButton::Update()
|
||
{
|
||
if(!m_bShow || (!m_bExistItemPress && g_ClientMain.m_lpPickItem))
|
||
{
|
||
m_nState = BUTTON_NONE;
|
||
|
||
return;
|
||
}
|
||
|
||
RECT rc;
|
||
rc.left = m_lpNormalButton->m_nPutX + m_lMoveX;
|
||
rc.right = m_lpNormalButton->m_nPutX + m_lMoveX + m_lpNormalButton->GetSizeX() - 1;
|
||
rc.top = m_lpNormalButton->m_nPutY + m_lMoveY;
|
||
rc.bottom = m_lpNormalButton->m_nPutY + m_lMoveY + m_lpNormalButton->GetSizeY() - 1;
|
||
|
||
if(m_nMethod == BUTTON_NORMAL)
|
||
{
|
||
if(g_DeviceInput.InRect(rc.left, rc.top, rc.right, rc.bottom))
|
||
{
|
||
m_nState = BUTTON_OVER;
|
||
|
||
if(g_DeviceInput.GetIsLeftMouseDown())
|
||
{
|
||
m_bPress = TRUE;
|
||
CSoundManager &sm = CSoundManager::GetInstance();
|
||
char Temp[MAX_PATH];
|
||
sprintf(Temp, "%s\\Sound\\Interface\\click.mnd", g_ClientMain.m_strClientPath);
|
||
ISoundObject &sb = sm.GetBuffer(Temp, false);
|
||
sb.Play(false);
|
||
}
|
||
|
||
if(m_bPress)
|
||
{
|
||
if(g_DeviceInput.GetIsLeftMousePress())
|
||
{
|
||
m_nState = BUTTON_PRESS;
|
||
} else if(g_DeviceInput.GetIsLeftMouseUp())
|
||
{
|
||
m_nState = BUTTON_CLICK;
|
||
m_bPress = FALSE;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(m_bPress && g_DeviceInput.GetIsLeftMousePress())
|
||
m_nState = BUTTON_PRESS;
|
||
else
|
||
m_nState = BUTTON_NONE;
|
||
|
||
if(g_DeviceInput.GetIsLeftMouseUp())
|
||
{
|
||
m_bPress = FALSE;
|
||
}
|
||
}
|
||
} else if(m_nMethod == BUTTON_SIMPLE)
|
||
{
|
||
if(g_DeviceInput.InRect(rc.left, rc.top, rc.right, rc.bottom))
|
||
{
|
||
if(g_DeviceInput.GetIsLeftMouseDown())
|
||
{
|
||
m_bPress = TRUE;
|
||
CSoundManager &sm = CSoundManager::GetInstance();
|
||
char Temp[MAX_PATH];
|
||
sprintf(Temp, "%s\\Sound\\Interface\\click.mnd", g_ClientMain.m_strClientPath);
|
||
ISoundObject &sb = sm.GetBuffer(Temp, false);
|
||
sb.Play(false);
|
||
}
|
||
|
||
if(m_bPress)
|
||
{
|
||
if(g_DeviceInput.GetIsLeftMousePress())
|
||
{
|
||
m_nState = BUTTON_PRESS;
|
||
} else if(g_DeviceInput.GetIsLeftMouseUp())
|
||
{
|
||
m_nState = BUTTON_CLICK;
|
||
m_bPress = FALSE;
|
||
}
|
||
} else
|
||
{
|
||
m_nState = BUTTON_NONE;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(m_bPress && g_DeviceInput.GetIsLeftMousePress())
|
||
m_nState = BUTTON_PRESS;
|
||
else
|
||
m_nState = BUTTON_NONE;
|
||
|
||
if(g_DeviceInput.GetIsLeftMouseUp())
|
||
{
|
||
m_bPress = FALSE;
|
||
}
|
||
}
|
||
} else if(m_nMethod == BUTTON_SIMPLECHECK)
|
||
{
|
||
if(m_nState == BUTTON_OFF)
|
||
{
|
||
m_nState = BUTTON_NONE;
|
||
} else if(m_nState == BUTTON_ON)
|
||
{
|
||
m_nState = BUTTON_HOLD;
|
||
}
|
||
|
||
if(g_DeviceInput.InRect(rc.left, rc.top, rc.right, rc.bottom) && g_DeviceInput.GetIsLeftMouseUp())
|
||
{
|
||
if(g_DeviceInput.GetIsLeftMouseDown())
|
||
{
|
||
CSoundManager &sm = CSoundManager::GetInstance();
|
||
char Temp[MAX_PATH];
|
||
sprintf(Temp, "%s\\Sound\\Interface\\click.mnd", g_ClientMain.m_strClientPath);
|
||
ISoundObject &sb = sm.GetBuffer(Temp, false);
|
||
sb.Play(false);
|
||
}/**/
|
||
// CZ3DSound::QuickPlay("\\Interface\\click.mnd");
|
||
if(m_nState == BUTTON_NONE)
|
||
{
|
||
m_nState = BUTTON_ON;
|
||
}
|
||
else
|
||
{
|
||
m_nState = BUTTON_OFF;
|
||
}
|
||
}
|
||
} else if(m_nMethod == BUTTON_CHECK)
|
||
{
|
||
if(m_nState == BUTTON_OFF)
|
||
{
|
||
m_nState = BUTTON_NONE;
|
||
}
|
||
|
||
if(g_DeviceInput.InRect(rc.left, rc.top, rc.right, rc.bottom))
|
||
{
|
||
if(g_DeviceInput.GetIsLeftMouseDown())
|
||
{
|
||
CSoundManager &sm = CSoundManager::GetInstance();
|
||
char Temp[MAX_PATH];
|
||
sprintf(Temp, "%s\\Sound\\Interface\\click.mnd", g_ClientMain.m_strClientPath);
|
||
ISoundObject &sb = sm.GetBuffer(Temp, false);
|
||
sb.Play(false);
|
||
}/**/
|
||
if(m_nState == BUTTON_NONE || m_nState == BUTTON_OVER || m_nState == BUTTON_PRESS)
|
||
{
|
||
m_nState = BUTTON_OVER;
|
||
if(g_DeviceInput.GetIsLeftMousePress())
|
||
{
|
||
m_nState = BUTTON_PRESS;
|
||
}
|
||
if(g_DeviceInput.GetIsLeftMouseUp())
|
||
{
|
||
// CZ3DSound::QuickPlay("\\Interface\\click.mnd");
|
||
m_nState = BUTTON_CLICK;//<2F><><EFBFBD><EFBFBD>
|
||
}
|
||
}
|
||
else
|
||
{
|
||
m_nState = BUTTON_ON;
|
||
if(g_DeviceInput.GetIsLeftMousePress())
|
||
{
|
||
m_nState = BUTTON_HOLD;
|
||
}
|
||
if(g_DeviceInput.GetIsLeftMouseUp())
|
||
{
|
||
// CZ3DSound::QuickPlay("\\Interface\\click.mnd");
|
||
m_nState = BUTTON_OFF;//<2F><><EFBFBD><EFBFBD>
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(m_nState == BUTTON_NONE || m_nState == BUTTON_OVER || m_nState == BUTTON_PRESS)
|
||
m_nState = BUTTON_NONE;
|
||
else
|
||
m_nState = BUTTON_ON;
|
||
|
||
if(g_DeviceInput.GetIsLeftMouseUp())
|
||
{
|
||
m_bPress = FALSE;
|
||
}
|
||
}
|
||
}
|
||
}
|