📄 gsg_selectplayer.cpp
字号:
// GSG_SelectPlayer.cpp: implementation of the GSG_SelectPlayer class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "GSG_SelectPlayer.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
GSG_SelectPlayer::GSG_SelectPlayer(CGsEngine* pEngine)
:CGsGame(pEngine),
m_world(pEngine)
{
for( WORD ix=0; ix<2; ix++ )
{
for( WORD iy=0; iy<2; iy++ )
{
// FLOAT tu = ix;
// FLOAT tv = iy;
float fx = m_world.GetViewWidthPix()*ix;
float fy = m_world.GetViewHeightPix()*iy;
m_aVertex[ix+iy*2] = D3DTLVERTEX( D3DVECTOR(fx,fy,0.0f),
0.5f,
0xffffffff,
0,
0, 0 );
}
}
m_index_select = -1;
}
GSG_SelectPlayer::~GSG_SelectPlayer()
{
}
VOID GSG_SelectPlayer::OnUICmd(CGsUIPanel* pUI, UINT msg, LONG param)
{
switch(msg)
{
case UI_CMD_CLICK:
{
const char* str = pUI->GetName();
if(KEY("left")==str)
{
}
else if(KEY("right")==str)
{
}
else if(KEY("connect")==str)
{
CGsUIPanel* pPanel = m_pEngine->FindUIFromName("input_ip");
if(pPanel)
{
g_ptr_main_game->m_server_ip = ntohl(inet_addr(pPanel->GetCaption()));
g_ptr_main_game->Connect();
}
}
else if(KEY("connect_state")==str)
{
pUI->SetChecked(g_ptr_main_game->IsReady());
}
else if(KEY("select_ok")==str)
{
CGsUIPanel* pPanel = m_pEngine->FindUIFromName("input_name");
if(pPanel)
{
m_pEngine->SetGame(g_ptr_main_game);
g_ptr_main_game->m_account = pPanel->GetCaption();
g_ptr_main_game->m_unit_type = m_array_select_player[m_index_select].type;
Cleanup();
g_ptr_main_game->InitGame();
g_ptr_main_game->Login();
}
}
}
break;
default:
break;
}
}
LRESULT GSG_SelectPlayer::MsgProc( UINT uMsg, WPARAM wParam, LPARAM lParam )
{
return CGsGame::MsgProc( uMsg, wParam, lParam );
}
ID GSG_SelectPlayer::OnMouseMove(UINT nFlags, GPOINT point)
{
ID id_ret = CGsGame::OnMouseMove( nFlags, point );
if(id_ret>0)
return id_ret;
return id_ret;
}
ID GSG_SelectPlayer::OnLButtonDown( UINT nFlags, GPOINT point )
{
ID id_ret = CGsGame::OnLButtonDown( nFlags, point );
if(id_ret>0)
{
return id_ret;
}
return id_ret;
}
ID GSG_SelectPlayer::OnLButtonUp( UINT nFlags, GPOINT point )
{
ID id_ret = CGsGame::OnLButtonUp( nFlags, point );
if(id_ret>0)
return id_ret;
for(int i=0; i<m_array_select_player.size(); i++)
{
if( is_point_in_rect(m_pEngine->m_Pos, m_array_select_player[i].rc))
{
m_index_select = i;
}
else
{
}
}
update_ui();
return id_ret;
}
ID GSG_SelectPlayer::OnLButtonDbClk( UINT nFlags, GPOINT point )
{
ID id_ret = CGsGame::OnLButtonDbClk( nFlags, point );
if(id_ret>0)
return id_ret;
return id_ret;
}
ID GSG_SelectPlayer::OnRButtonDown( UINT nFlags, GPOINT point )
{
ID id_ret = CGsGame::OnRButtonDown( nFlags, point );
if(id_ret>0)
return id_ret;
return id_ret;
}
ID GSG_SelectPlayer::OnRButtonUp( UINT nFlags, GPOINT point )
{
ID id_ret = CGsGame::OnRButtonUp( nFlags, point );
if(id_ret>0)
return id_ret;
return id_ret;
}
ID GSG_SelectPlayer::OnRButtonDbClk( UINT nFlags, GPOINT point )
{
ID id_ret = CGsGame::OnRButtonDbClk( nFlags, point );
if(id_ret>0)
return id_ret;
return id_ret;
}
ID GSG_SelectPlayer::OnMouseWheel(UINT nFlags, short zDelta, GPOINT point)
{
ID id_ret = CGsGame::OnMouseWheel(nFlags, zDelta, point);
if(id_ret>0)
return id_ret;
return id_ret;
}
ID GSG_SelectPlayer::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
ID id_ret = CGsGame::OnChar(nChar, nRepCnt, nFlags);
if(id_ret>0)
return id_ret;
return id_ret;
}
ID GSG_SelectPlayer::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
ID id_ret = CGsGame::OnKeyDown(nChar, nRepCnt, nFlags);
if(id_ret>0)
return id_ret;
CGsUIPanel* pPanel = m_pEngine->FindUIFromName("input_name");
if(pPanel)
{
pPanel->SetFocus();
}
return id_ret;
}
ID GSG_SelectPlayer::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
ID id_ret = CGsGame::OnKeyUp(nChar, nRepCnt, nFlags);
update_ui();
if(id_ret>0)
return id_ret;
return id_ret;
}
VOID GSG_SelectPlayer::ReleaseSource()
{
m_world.ReleaseSource();
// m_ani_dreamland.ReleaseSource();
CGsGame::ReleaseSource();
}
HRESULT GSG_SelectPlayer::RestoreSource()
{
m_world.RestoreSource();
// m_ani_dreamland.RestoreSource();
return CGsGame::RestoreSource();
}
BOOL GSG_SelectPlayer::InitGame()
{
std::string str = CGsFunc::GetGsApp()->GetAppPath(NULL);
str += "\\server.ini";
m_ani_dreamland.SetGsEngine(m_pEngine);
// m_ani_dreamland.Create("land.jpg");//"animation\\effect\\caust");
m_ani_dreamland.Create("bk.jpg");//"animation\\effect\\caust");
m_ani_dreamland.Play();
GetMainUI()->Create("ui\\select_player.ini");
CGsUIPanel* pPanel = m_pEngine->FindUIFromName("locate_ip");
if(pPanel)
{
in_addr ia;
ia.S_un.S_addr = NET_GetLocalIP();
pPanel->SetCaption(inet_ntoa(ia));
}
pPanel = m_pEngine->FindUIFromName("input_ip");
if(pPanel)
{
in_addr ia;
ia.S_un.S_addr = ntohl(g_ptr_main_game->m_server_ip);
pPanel->SetCaption(inet_ntoa(ia));
}
int w = m_pEngine->GetRenderWidth();
int h = m_pEngine->GetRenderHeight();
BOOL bRet = m_world.CreateWorld(w,h);
_SELECT_PLAYER sp;
sp.type = g_config.GetLong("ROLES", "select_1");
GM_Unit* pUnit;
pUnit = new GM_Unit(&m_world);
GPOINT pt = GPOINT(w/6, h/2+50);
pUnit->Create(1, g_get_unit_res(sp.type).c_str(), pt.x, pt.y,0);
if(FALSE==m_world.AddObject(pUnit))
{
delete pUnit;
}
sp.rc = GRECT(pt.x-110, pt.y-250, pt.x+110, pt.y+60);
m_array_select_player.push_back(sp);
pUnit = new GM_Unit(&m_world);
sp.type = g_config.GetLong("ROLES", "select_2");
pt = GPOINT(w/2, h/2+50);
pUnit->Create(2, g_get_unit_res(sp.type).c_str(), pt.x, pt.y, 0);
if(FALSE==m_world.AddObject(pUnit))
{
delete pUnit;
}
sp.rc = GRECT(pt.x-110, pt.y-250, pt.x+110, pt.y+60);
m_array_select_player.push_back(sp);
pUnit = new GM_Unit(&m_world);
sp.type = g_config.GetLong("ROLES", "select_3");
pt = GPOINT(w*5/6, h/2+50);
pUnit->Create(3, g_get_unit_res(sp.type).c_str(), pt.x, pt.y,0);
if(FALSE==m_world.AddObject(pUnit))
{
delete pUnit;
}
sp.rc = GRECT(pt.x-110, pt.y-250, pt.x+110, pt.y+60);
m_array_select_player.push_back(sp);
return TRUE;
}
FLAG GSG_SelectPlayer::Update(DWORD dwPassTime)
{
m_ani_dreamland.Update();
m_world.Update();
if(g_ptr_main_game)
g_ptr_main_game->DoUpdate();
CGsUIPanel* pPanel = m_pEngine->FindUIFromName("connect_state");
if(pPanel)
{
if(pPanel->IsChecked()!=g_ptr_main_game->IsReady())
{
update_ui();
pPanel->SetChecked(g_ptr_main_game->IsReady());
}
}
return 0;
}
HRESULT GSG_SelectPlayer::Render()
{
HRESULT hr = S_OK;
m_pEngine->PreparePaint();
{
m_pEngine->DarkenScene(0.5);
m_pEngine->PreparePaint();
//幻境
LONG ox,oy;
//m_world.GetOriginal(ox, oy);
ox=m_pEngine->ValueLoop(0,1024,0,15000);
oy=ox;
CGsTexture* pTexture = m_ani_dreamland.GetCurrentFrame();
//if(pTexture==NULL)
// goto exit;
int w = pTexture->GetWidth();
int h = pTexture->GetHeight();
float scale = 1.0f;
float left = ox/scale/w;
//if(left>1.0f)goto exit;
float top = oy/scale/h;
//if(top>1.0f)goto exit;
float right = (ox+m_world.GetViewWidthPix())/scale/w;
// if(right>1.0f)
// {
// m_aVertex[1].sx = w*scale - ox;
// m_aVertex[3].sx = m_aVertex[1].sx;
// right=1.0f;
// }
// else
// {
m_aVertex[1].sx = m_world.GetViewWidthPix();
m_aVertex[3].sx = m_world.GetViewWidthPix();
// }
float bottom = (oy+m_world.GetViewHeightPix())/scale/h;
// if(bottom>1.0f)
// {
// m_aVertex[2].sy = h*scale - oy;
// m_aVertex[3].sy = m_aVertex[2].sy;
// bottom=1.0f;
// }
// else
// {
m_aVertex[2].sy = m_world.GetViewHeightPix();
m_aVertex[3].sy = m_world.GetViewHeightPix();
// }
D3DCOLOR color = RGBA_MAKE(32,32,32,255);
m_aVertex[0].tu = left;
m_aVertex[0].tv = top;
m_aVertex[0].color = color;
m_aVertex[1].tu = right;
m_aVertex[1].tv = top;
m_aVertex[1].color = color;
m_aVertex[2].tu = left;
m_aVertex[2].tv = bottom;
m_aVertex[2].color = color;
m_aVertex[3].tu = right;
m_aVertex[3].tv = bottom;
m_aVertex[3].color = color;
LPDIRECT3DDEVICE7 pDevice = m_pEngine->GetD3dDevice();
pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE);
pDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, false);
pDevice->SetTexture( 0, pTexture->GetDDrawSurface() );
{
pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,
D3DFVF_TLVERTEX,
(LPVOID)m_aVertex,
4,
0 );
}
}
//画选择框
m_pEngine->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
for(int i=0; i<m_array_select_player.size(); i++)
{
if(m_index_select==i)
{
float fcr = m_pEngine->ValueCycle(0.5, 1.0, 0, 500);
m_pEngine->Render_DrawRect(&m_array_select_player[i].rc, FALSE, D3DRGBA(fcr, fcr, fcr, 1.0f));
}
if( is_point_in_rect(m_pEngine->m_Pos, m_array_select_player[i].rc))
{
float fcr = m_pEngine->ValueCycle(0.5, 1.0, 0, 1000);
GRECT rc = m_array_select_player[i].rc;
rc.expand(m_pEngine->ValueCycle(15, 0, 0, 500));
m_pEngine->Render_DrawRect(&rc, FALSE, D3DRGBA(1.0f, 1.0f, 1.0f, 1.0f));
}
else
{
//m_pEngine->Render_DrawRect(&m_array_select_player[i], FALSE, RGBA_MAKE(0, 0, 255, 100));
}
}
m_world.Render();
m_pEngine->PreparePaint();
hr = RenderUI();
return hr;
}
HRESULT GSG_SelectPlayer::Draw(CGsSurface *pSurface)
{
Sys_Log(NULL, "begin draw time = %d", Sys_GetTime());
char strMouse[100];
LONG x = m_pEngine->m_Pos.x + m_world.m_rcOriginalPix.left;
LONG y = m_pEngine->m_Pos.y + m_world.m_rcOriginalPix.top;
m_world.PickFlatGrid(x,y);
sprintf(strMouse, "格子坐标X: %5d", x);
pSurface->DrawTextDirect(NULL, strMouse, 20, m_pEngine->GetRenderHeight() - 50, RGB(255,255,255), RGB(1,1,1));
sprintf(strMouse, "格子坐标Y: %5d", y);
pSurface->DrawTextDirect(NULL, strMouse, 20, m_pEngine->GetRenderHeight() - 30, RGB(255,255,255), RGB(1,1,1));
// pSurface->DrawTextDirect(NULL, g_strInfo, 20, 50, RGB(255,255,255), RGB(1,1,1));
return S_OK;
}
VOID GSG_SelectPlayer::Cleanup()
{
m_world.Cleanup();
m_ani_dreamland.Cleanup();
m_array_select_player.clear();
CGsGame::Cleanup();
}
void GSG_SelectPlayer::update_ui()
{
CGsUIPanel* pPanel = m_pEngine->FindUIFromName("input_name");
CGsUIPanel* pPanel_btn_ok = m_pEngine->FindUIFromName("select_ok");
if(pPanel && pPanel_btn_ok)
{
const char* str = pPanel->GetCaption();
if(str[0]!=0 && m_index_select>=0 && g_ptr_main_game->IsReady())
{
pPanel_btn_ok->SetEnable(TRUE);
}
else
{
pPanel_btn_ok->SetEnable(FALSE);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -