Files
2026-06-01 12:46:52 +02:00

264 lines
6.2 KiB
C++

#include "stdafx.h"
#include "SUIArenaReportDivewnd.h"
//#include "SGameMessageUI.h"
#include "KUIControlStatic.h"
#include "SGameManager.h"
#include "SGameInterface.h"
#include "KUIControlEdit.h"
#include "CommonUtil.h"
#include "SStringDB.h"
SUIArenaReportDiveWnd::SUIArenaReportDiveWnd(SGameManager* pGameManager) : SUIWnd(pGameManager)
{
}
SUIArenaReportDiveWnd::~SUIArenaReportDiveWnd()
{
}
bool SUIArenaReportDiveWnd::InitData( bool reload )
{
initFp();
getWndInfo();
return SUIWnd::InitData(reload);
}
void SUIArenaReportDiveWnd::initFp()
{
m_controlFp.add("button_help_01", &SUIArenaReportDiveWnd::help);
m_controlFp.add("button_arena_start_01", &SUIArenaReportDiveWnd::ok);
m_msgFp.add(MSG_BATTLE_ARENA_ABSENCE_CHECK, &SUIArenaReportDiveWnd::procMsgAbsenceCheck);
}
void SUIArenaReportDiveWnd::getWndInfo()
{
m_countControl = dynamicCast<KUIControlStatic*>(GetChild("text_warning_count_01"));
m_passControl = dynamicCast<KUIControlEdit*>(GetChild("edit_bg_01"));
m_passControl->SetOnlyNumber(true);
m_passControl->SetLimitation(4);
m_passControl->SetFontSize(10);
}
void SUIArenaReportDiveWnd::setPassword()
{
generatePassword();
std::string caption;
XStringUtil::Format(caption, "<font:font_01><size:10><#898989><hcenter>%d", m_password);
KUIControl* passControl = dynamicCast<KUIControl*>(GetChild("text_password_bg_01"));
passControl->SetCaption(caption.c_str());
}
void SUIArenaReportDiveWnd::generatePassword()
{
struct sPasswordGenerator
{
int generate() const
{
int a = getRand(10);
if (0 == a)
a = getRand(9); + 1;
int b = getRand(10);
int c = getRand(10);
int d = getRand(10);
int ret = a * 1000 + b * 100 + c * 10 + d;
return ret;
}
int getRand(int bound) const
{
return rand()%bound;
}
};
sPasswordGenerator generator;
m_password = generator.generate();
}
void SUIArenaReportDiveWnd::Process(DWORD dwTime)
{
SUIWnd::Process(dwTime);
DWORD elapsedTime = 0;
if (m_time)
elapsedTime = dwTime - m_time;
m_time = dwTime;
float e = (float)elapsedTime/1000.0f;
procState(e);
}
void SUIArenaReportDiveWnd::ProcMsgAtStatic( SGameMessage* msg )
{
m_msgFp.call(msg->nType, this, msg);
}
void SUIArenaReportDiveWnd::PumpUpMessage( LPCTSTR controlID, DWORD msg, DWORD lparam, DWORD wparam )
{
switch (msg)
{
case KUI_MESSAGE::KBUTTON_CLICK: m_controlFp.call(controlID, this); break;
}
SUIWnd::PumpUpMessage( controlID, msg, lparam, wparam );
}
void SUIArenaReportDiveWnd::OnNotifyUIWindowOpen( bool bOpen, bool bLimitWnd )
{
if (bOpen)
{
m_time = 0;
syncPos();
}
}
void SUIArenaReportDiveWnd::syncPos()
{
SUIWnd* menuWnd = m_pGameManager->GetSUI(SIMSG_TOGGLE_UIWINDOW::UIWINDOW_MAINMENU);
if (menuWnd)
MovePos(menuWnd->GetRect().left, menuWnd->GetRect().top - GetRect().GetHeight());
}
void SUIArenaReportDiveWnd::help()
{
}
void SUIArenaReportDiveWnd::ok()
{
if (isValidPassword())
{
sendResult(true);
m_pGameManager->PostMsgAtDynamic( new SIMSG_SHOW_UIWINDOW( SIMSG_TOGGLE_UIWINDOW::UIWINDOW_ARENA_REPORT_DIVE, false));
}
else
{
setPassword();
//m_pGameManager->GetGameInterface()->OpenMessageBox(SIMSG_REQ_OPEN_MSGBOX::MSGBOX_OK, SIMSG_REQ_OPEN_MSGBOX::MSGBOX_GENERAL, false, -1, "test 틀렸습니다.");
}
}
void SUIArenaReportDiveWnd::setState(int state)
{
m_state = state;
switch (state)
{
case STATE_WAITING_INPUT: setWaitingInputState(); break;
case STATE_READY_LEAVE: setReadyLeaveState(); break;
case STATE_LEAVE: setLeaveState(); break;
}
}
void SUIArenaReportDiveWnd::setStatus(float remainTime, char const* countColor, int warningStringId, bool enable)
{
m_remainTime = remainTime;
m_countColor = countColor;
updateCount(0.0);
KUIControl* warningControl = dynamicCast<KUIControl*>(GetChild("text_warning_01"));
std::string str;
str = "<font:font_01><size:9><#acacac><b><top><hcenter>";
str += S(warningStringId);
warningControl->SetCaption(str.c_str());
KUIControl* okControl = dynamicCast<KUIControl*>(GetChild("button_arena_start_01"));
KUIControl* inputControl = dynamicCast<KUIControl*>(GetChild("edit_bg_01"));
if (enable)
{
okControl->Enable();
inputControl->Enable();
}
else
{
okControl->Disable();
inputControl->Disable();
}
}
void SUIArenaReportDiveWnd::setWaitingInputState()
{
setStatus(m_remainTime, "<#843a17>", 2333, true);
setPassword();
m_passControl->SetText("");
}
void SUIArenaReportDiveWnd::setReadyLeaveState()
{
setStatus((float)LEAVE_WAITING_TIME, "<#9e0b0f>", 2334, false);
}
void SUIArenaReportDiveWnd::setLeaveState()
{
sendResult(false);
m_pGameManager->PostMsgAtDynamic( new SIMSG_SHOW_UIWINDOW( SIMSG_TOGGLE_UIWINDOW::UIWINDOW_ARENA_REPORT_DIVE, false));
}
void SUIArenaReportDiveWnd::procState(float elapsedTime)
{
bool needNextState = updateCount(elapsedTime);
switch (m_state)
{
case STATE_WAITING_INPUT: procWaitingInput(needNextState); break;
case STATE_READY_LEAVE: procReadyLeave(needNextState); break;
}
}
void SUIArenaReportDiveWnd::procWaitingInput(bool needNextState)
{
if (needNextState)
setState(STATE_READY_LEAVE);
}
void SUIArenaReportDiveWnd::procReadyLeave(bool needNextState)
{
if (needNextState)
setState(STATE_LEAVE);
}
bool SUIArenaReportDiveWnd::updateCount(float elapsedTime)
{
bool end = false;
m_remainTime -= elapsedTime;
if (0.0f >= m_remainTime)
{
end = true;
m_remainTime = 0.0f;
}
std::string str;
XStringUtil::Format(str, "<font:font_01><size:28><hcenter>%s%d", m_countColor.c_str(), (int)m_remainTime);
m_countControl->SetCaption(str.c_str());
return end;
}
bool SUIArenaReportDiveWnd::isValidPassword()
{
int inputPassword = atoi(m_passControl->GetText());
return m_password == inputPassword;
}
void SUIArenaReportDiveWnd::procMsgAbsenceCheck(SGameMessage *msg)
{
msg->bUse = true;
SMSG_BATTLE_ARENA_ABSENCE_CHECK* _msg = dynamicCast<SMSG_BATTLE_ARENA_ABSENCE_CHECK*>(msg);
AR_TIME lastTime = _msg->limitTime - GetArTime();
m_remainTime = (float)(lastTime)/100.0f - (float)LEAVE_WAITING_TIME;
m_pGameManager->ProcMsgAtStatic( &SIMSG_SHOW_UIWINDOW( SIMSG_TOGGLE_UIWINDOW::UIWINDOW_ARENA_REPORT_DIVE, true ) );
setState(STATE_WAITING_INPUT);
}
void SUIArenaReportDiveWnd::sendResult(bool success)
{
TS_CS_BATTLE_ARENA_ABSENCE_CHECK_ANSWER msg;
msg.bSuccess = success;
m_pGameManager->PendMessage(&msg);
}