📄 gsg_selectplayer.cpp
字号:
// GSG_SelectPlayer.cpp: implementation of the GSG_SelectPlayer class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "GSG_SelectPlayer.h"
#define NUM_SELECT_PLAYER 14
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
GSG_SelectPlayer::GSG_SelectPlayer(CGsEngine* pEngine)
:CGsGame(pEngine)
,m_bk_music(pEngine)
{
for( WORD ix=0; ix<2; ix++ )
{
for( WORD iy=0; iy<2; iy++ )
{
// FLOAT tu = ix;
// FLOAT tv = iy;
float fx = 800*ix;
float fy = 600*iy;
m_aVertex[ix+iy*2] = D3DTLVERTEX( D3DVECTOR(fx,fy,0.0f),
0.5f,
0xffffffff,
0,
0, 0 );
}
}
m_index_select = 0;
m_index_start = 0;
m_index_select_list_head = 0;
m_fscale_select_list = 1.0f;
memset(&m_control_pointer, 0, sizeof(m_control_pointer));
}
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)
{
PageSelected(FALSE);
}
else if(KEY("right")==str)
{
PageSelected(TRUE);
}
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");
CGsUIPanel* pPanel_face = m_pEngine->FindUIFromName("face");
if(pPanel && pPanel_face)
{
m_bk_music.Stop();
m_pEngine->SetGame(g_ptr_main_game);
g_ptr_main_game->m_account = pPanel->GetCaption();
g_ptr_main_game->m_unit_type = m_index_select;
g_ptr_main_game->m_register = pPanel_face->IsChecked();
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 = m_array_select_player[i]->type;
}
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;
switch(nChar)
{
case VK_SPACE:
case VK_UP:
m_bubble_scene.Shoot();
break;
case VK_LEFT:
if(m_pEngine && (m_control_pointer.key&1)!=1)
{
m_control_pointer.angle_base = m_bubble_scene.m_angle;
m_control_pointer.key |= 1;
m_control_pointer.tick_base = m_pEngine->m_dwEngineTime;
}
// if(m_bubble_scene.m_angle<const_PI - const_PI_DIV_2/4)
// m_bubble_scene.m_angle += const_PI_DIV_4/16;
break;
case VK_RIGHT:
if(m_pEngine && (m_control_pointer.key&2)!=2)
{
m_control_pointer.angle_base = m_bubble_scene.m_angle;
m_control_pointer.key |= 2;
m_control_pointer.tick_base = m_pEngine->m_dwEngineTime;
}
// if(m_bubble_scene.m_angle>const_PI_DIV_2/4)
// m_bubble_scene.m_angle -= const_PI_DIV_4/16;
break;
}
// 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;
switch(nChar)
{
case VK_LEFT:
if(m_pEngine)
{
m_control_pointer.key &= !1;
}
break;
case VK_RIGHT:
if(m_pEngine)
{
m_control_pointer.key &= !2;
}
break;
}
return id_ret;
}
VOID GSG_SelectPlayer::ReleaseSource()
{
// m_ani_dreamland.ReleaseSource();
CGsGame::ReleaseSource();
}
HRESULT GSG_SelectPlayer::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();
m_ani_test.SetGsEngine(m_pEngine);
m_ani_test.Create("shows\\test.gif");//"test.gif");
m_ani_test.Play();
m_SP_select.type = g_get_num_shows_res()*rand()/(RAND_MAX+1);
m_index_select = m_SP_select.type;
m_SP_select.ani.SetGsEngine(m_pEngine);
m_SP_select.ani.Create(g_get_str_shows_res(m_SP_select.type));//"test.gif");
m_SP_select.ani.Play();
m_SP_select.rc = GRECT(560, 120, 560+140, 120+226);
//m_bk_music.SetStreamSource(g_get_str_musics_res(0));
//m_bk_music.Play();
//m_bk_music.SetLooping();
if (m_pEngine)
{
m_pEngine->SetMediaVolume(DSBVOLUME_MIN/8);
}
m_index_start = g_get_num_shows_res()*rand()/(RAND_MAX+1);
for (int i=0; i<NUM_SELECT_PLAYER; i++)
{
_SELECT_PLAYER* pSP = new _SELECT_PLAYER;
pSP->type = (m_index_start+i)%g_get_num_shows_res();
pSP->ani.SetGsEngine(m_pEngine);
pSP->ani.Create(g_get_str_shows_res(pSP->type));
pSP->ani.Play();
int left = -108 + 73*i;
pSP->rc = GRECT(left, 350, left + 73, 350 + 113);
m_array_select_player.push_back(pSP);
}
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();
m_bubble_scene.SetGsEngine(m_pEngine);
m_bubble_scene.Create(8,14);
m_bubble_scene.m_scale = 20;
return TRUE;
}
FLAG GSG_SelectPlayer::Update(DWORD dwPassTime)
{
static int face = 0;
int i = m_pEngine->ValueLoop(0, g_get_num_shows_res(), 0, 1000000);
if (face!=i)
{
//face=i;
//m_ani_test.Create(g_get_str_shows_res(face));
}
m_SP_select.ani.Update();
if (m_SP_select.type!=m_index_select)
{
m_SP_select.rc += GPOINT(35, 0);
if (m_SP_select.rc.left>800)
{
m_SP_select.type = m_index_select;
m_SP_select.ani.Create(g_get_str_shows_res(m_SP_select.type));
m_SP_select.ani.Play();
}
}
else if (m_SP_select.rc.left!=560)
{
int s = sign(m_SP_select.rc.left-560);
m_SP_select.rc -= GPOINT(35*s, 0);
if (s!=sign(m_SP_select.rc.left-560))
{
m_SP_select.rc.left = 560;
m_SP_select.rc.right = 560 + 140;
}
}
for (i=0; i<NUM_SELECT_PLAYER; i++)
{
int x = m_array_select_player[i]->rc.left + 108 - 73*i;
if (x!=0)
{
m_array_select_player[i]->rc -= GPOINT(sign(x)*10, 0);
if (sign(m_array_select_player[i]->rc.left + 108 - 73*i)!=sign(x))
{
m_array_select_player[i]->rc.left = -108 + 73*i;
m_array_select_player[i]->rc.right = -108 + 73*i + 73;
}
}
if (m_array_select_player[i] && m_array_select_player[i]->ani.IsReady())
{
m_array_select_player[i]->ani.Update();
}
}
m_ani_dreamland.Update();
m_bubble_scene.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());
}
}
if(!m_bk_music.IsPlaying())
{
m_bk_music.SetStreamSource(g_get_str_musics_res((int)(rnd()*g_get_num_musics_res())));
m_bk_music.Play();
}
return 0;
}
HRESULT GSG_SelectPlayer::Render()
{
HRESULT hr = S_OK;
m_pEngine->GetD3dDevice()->Clear(0UL, NULL, D3DCLEAR_TARGET ,
RGBA_MAKE(0,0,50,255),
1.0f, 0L );
//做些简单的背景特效
g_render_background(m_pEngine);
m_pEngine->PreparePaint();
m_bubble_scene.Render(400, 500);
m_ani_test.Draw(100, 100);
m_SP_select.ani.Draw(m_SP_select.rc.left, m_SP_select.rc.top);
//翻转效果
if (m_array_select_player[0]->type!=m_index_start)
{
m_fscale_select_list -= 0.2f;
if (m_fscale_select_list<0)
{
m_fscale_select_list =0;
for (int i=0; i<NUM_SELECT_PLAYER; i++)
{
m_array_select_player[i]->type = (m_index_start+i)%g_get_num_shows_res();
m_array_select_player[i]->ani.Create(g_get_str_shows_res(m_array_select_player[i]->type));
m_array_select_player[i]->ani.Play();
}
}
}
else if(m_fscale_select_list<1.0f)
{
m_fscale_select_list += 0.2f;
if (m_fscale_select_list>1.0f)
{
m_fscale_select_list = 1.0f;
}
}
for (int i=0; i<NUM_SELECT_PLAYER; i++)
{
if (m_array_select_player[i] && m_array_select_player[i]->ani.IsReady())
{
GRECT rc = m_array_select_player[i]->rc;
if (m_fscale_select_list!=1.0f)
{
float fs = (rc.width() - rc.width()*m_fscale_select_list)/2;
rc.left += fs;
rc.right -= fs;
}
if (is_point_in_rect(m_pEngine->m_Pos, m_array_select_player[i]->rc))
{
if ((i<2 || i>= NUM_SELECT_PLAYER-2)
&& m_array_select_player[i]->rc.left == -108 + 73*i)
{
MoveSelected(i<2);
m_pEngine->Render_DrawRect(&rc, true, RGBA_MAKE(20, 30, 50, 150));
}
else
{
float fcr = m_pEngine->ValueCycle(0.2f, 0.5f, 0, 1000);
m_pEngine->Render_DrawRect(&rc, true, D3DRGBA(fcr, fcr, fcr, 180));
}
}
else
{
m_pEngine->Render_DrawRect(&rc, true, RGBA_MAKE(20, 30, 50, 150));
}
m_pEngine->Render_DrawRect(&rc, FALSE, D3DRGBA(1.0f, 0.7f, 0.2f, 0.3f));
m_array_select_player[i]->ani.Draw(rc.left, rc.top, 0.0f, 0.5f*m_fscale_select_list, 0.5f);
}
}
//画选择框
m_pEngine->PreparePaint();
hr = RenderUI();
return hr;
}
HRESULT GSG_SelectPlayer::Draw(CGsSurface *pSurface)
{
Sys_Log(NULL, "begin draw time = %d", Sys_GetTime());
return S_OK;
}
VOID GSG_SelectPlayer::Cleanup()
{
m_ani_dreamland.Cleanup();
for (int i=0; i<m_array_select_player.size(); i++)
{
if (m_array_select_player[i])
{
delete(m_array_select_player[i]);
}
}
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 && g_ptr_main_game->IsReady())
{
pPanel_btn_ok->SetEnable(TRUE);
}
else
{
pPanel_btn_ok->SetEnable(FALSE);
}
}
}
void GSG_SelectPlayer::MoveSelected(BOOL bRight)
{
_SELECT_PLAYER* pSP;
if (bRight)
{
pSP = m_array_select_player[NUM_SELECT_PLAYER-1];
pSP->type = (pSP->type-NUM_SELECT_PLAYER + g_get_num_shows_res())%g_get_num_shows_res();
pSP->ani.Create(g_get_str_shows_res(pSP->type));
pSP->ani.Play();
pSP->rc = m_array_select_player[0]->rc - GPOINT(73, 0);
m_array_select_player.pop_back();
m_array_select_player.push_front(pSP);
}
else
{
pSP = m_array_select_player[0];
pSP->type = (pSP->type+NUM_SELECT_PLAYER)%g_get_num_shows_res();
pSP->ani.Create(g_get_str_shows_res(pSP->type));
pSP->ani.Play();
pSP->rc = m_array_select_player[NUM_SELECT_PLAYER-1]->rc + GPOINT(73, 0);
m_array_select_player.pop_front();
m_array_select_player.push_back(pSP);
}
m_index_start = m_array_select_player[0]->type;
}
void GSG_SelectPlayer::PageSelected(BOOL bRight)
{
if (bRight)
{
m_index_start = (m_index_start + NUM_SELECT_PLAYER-4 + g_get_num_shows_res())%g_get_num_shows_res();
}
else
{
m_index_start = (m_index_start - (NUM_SELECT_PLAYER-4) + g_get_num_shows_res())%g_get_num_shows_res();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -