#include "SunClientPrecompiledHeader.h" #ifdef _NA_000000_20140120_SMART_NPC_SYSTEM #include "uiSmartNpcDialogMan/uiSmartNpcDialogMan.h" #include "uiSmartNpcDialogMan/uiSmartNpcDialogMenu.h" #include "uiSmartNpcDialogMan/uiSmartNpcDialog.h" #include "InterfaceManager.h" #include "ObjectManager.h" #include "PacketStruct_CG_SmartNPC.h" #include "Hero.h" #include "GlobalFunc.h" uiSmartNpcDialogMenu::uiSmartNpcDialogMenu(InterfaceManager* ui_manager) : uiSmartNpcDialog(ui_manager), scroll_control_(NULL), list_control_(NULL), button_count_(0) { dialog_type_ = SmartDialogType_Menu; RegisterControlPosition(StrToWzID("B999"), kControl_Button_B999); RegisterControlPosition(StrToWzID("T999"), kControl_Text_T999); RegisterControlPosition(StrToWzID("L000"), kControl_List_L000); RegisterControlPosition(StrToWzID("V001"), kControl_VScroll_V001); RegisterControlPosition(StrToWzID("B001"), kControl_Button_B001); RegisterControlPosition(StrToWzID("B002"), kControl_Button_B002); RegisterControlPosition(StrToWzID("B003"), kControl_Button_B003); RegisterControlPosition(StrToWzID("B004"), kControl_Button_B004); RegisterControlPosition(StrToWzID("B005"), kControl_Button_B005); RegisterControlPosition(StrToWzID("B006"), kControl_Button_B006); for (int i = 0; i < uiSmartNpcDialogMan::MaxMenuButton; ++i) { button_event_id[i].event_id = 0; button_event_id[i].step = 0; } } uiSmartNpcDialogMenu::~uiSmartNpcDialogMenu() { } VOID uiSmartNpcDialogMenu::Init(CDrawBase* pDrawBase) { draw_ = pDrawBase; uiBase::Init(pDrawBase); } BOOL uiSmartNpcDialogMenu::CreateControls(BYTE sub_type) { CDialogWZ* dialog_ = GetDialogWZ(); // ¾ÆÁ÷ sub_type ¹Ì±¸Çö. 1°¡Áö ¸ð¸ÒÀÓ // ui ¹«´Ì - Áß¾Ó»ó´Ü CCtrlPictureWZ* picture_control = CreateContorlPicture(IM_SMARTNPCDIALOG_MANAGER::SMARTNPCDIALOG_MENU, StrToWzID("P000")); if (picture_control == NULL) { return FALSE; } else { picture_control->MoveWindowWZ(dialog_->GetDlgX() + 115, dialog_->GetDlgY(), 100, 20); SI_TSUBINFO image_sub_info; image_sub_info.Initialize(); image_sub_info.m_blIs = true; image_sub_info.m_sImageName = "Common_bg01.tga"; image_sub_info.m_blUseGradation = false; image_sub_info.m_fTileCornerX = 0; image_sub_info.m_fTileCornerY = 0; image_sub_info.m_nType = SI_TSUBINFO::DrawType_Whole; image_sub_info.m_sFRect.fTopX = 430; image_sub_info.m_sFRect.fTopY = 940; image_sub_info.m_sFRect.fWidth = 100; image_sub_info.m_sFRect.fHeight = 20; image_sub_info.m_color = 0xffffffff; //RGBA(255,255,255,255); picture_control->SetCtrlDetailImageFormat(E_BASE, &image_sub_info); picture_control->SetDiscardMessage(true); } // ui ¹«´Ì - ÁÂÃø»ó´Ü picture_control = CreateContorlPicture(IM_SMARTNPCDIALOG_MANAGER::SMARTNPCDIALOG_MENU, StrToWzID("P001")); if (picture_control == NULL) { return FALSE; } else { picture_control->MoveWindowWZ(dialog_->GetDlgX() + 12, dialog_->GetDlgY() + 11, 100, 20); SI_TSUBINFO image_sub_info; image_sub_info.Initialize(); image_sub_info.m_blIs = true; image_sub_info.m_sImageName = "Common_bg01.tga"; image_sub_info.m_blUseGradation = false; image_sub_info.m_fTileCornerX = 0; image_sub_info.m_fTileCornerY = 0; image_sub_info.m_nType = SI_TSUBINFO::DrawType_Whole; image_sub_info.m_sFRect.fTopX = 430; image_sub_info.m_sFRect.fTopY = 960; image_sub_info.m_sFRect.fWidth = 100; image_sub_info.m_sFRect.fHeight = 20; image_sub_info.m_color = 0xffffffff; //RGBA(255,255,255,255); picture_control->SetCtrlDetailImageFormat(E_BASE, &image_sub_info); picture_control->SetDiscardMessage(true); } // ui ¹«´Ì - ¿ìÃø»ó´Ü picture_control = CreateContorlPicture(IM_SMARTNPCDIALOG_MANAGER::SMARTNPCDIALOG_MENU, StrToWzID("P002")); if (picture_control == NULL) { return FALSE; } else { picture_control->MoveWindowWZ(dialog_->GetDlgX() + 198, dialog_->GetDlgY() + 11, 100, 20); SI_TSUBINFO image_sub_info; image_sub_info.Initialize(); image_sub_info.m_blIs = true; image_sub_info.m_sImageName = "Common_bg01.tga"; image_sub_info.m_blUseGradation = false; image_sub_info.m_fTileCornerX = 0; image_sub_info.m_fTileCornerY = 0; image_sub_info.m_nType = SI_TSUBINFO::DrawType_Whole; image_sub_info.m_sFRect.fTopX = 430; image_sub_info.m_sFRect.fTopY = 980; image_sub_info.m_sFRect.fWidth = 100; image_sub_info.m_sFRect.fHeight = 20; image_sub_info.m_color = 0xffffffff; //RGBA(255,255,255,255); picture_control->SetCtrlDetailImageFormat(E_BASE, &image_sub_info); picture_control->SetDiscardMessage(true); } // â À̸§ CCtrlStaticWZ* static_control = CreateContorlStatic(IM_SMARTNPCDIALOG_MANAGER::SMARTNPCDIALOG_MENU, StrToWzID("T999")); if (static_control == NULL) { return FALSE; } else { static_control->MoveWindowWZ(dialog_->GetDlgX() + 39, dialog_->GetDlgY() + 12, 233, 17); } // ¸®½ºÆ® CCtrlListWZ* list_control = CreateContorlList(IM_SMARTNPCDIALOG_MANAGER::SMARTNPCDIALOG_MENU, StrToWzID("L000")); if (list_control == NULL) { return FALSE; } else { list_control->MoveWindowWZ(dialog_->GetDlgX() + 27, dialog_->GetDlgY() + 49, 241, 192); list_control_ = list_control; RECT list_rect = list_control_->GetSizeRect(); ftext_render_.Init(draw_, list_rect); ftext_render_.SetMargin(0,0,0,-5); ftext_render_.SetGap(0,0); ftext_render_.convertLineInfo(); } // ¸®½ºÆ® µÚ¿¡ À̹ÌÁö1 picture_control = CreateContorlPicture(IM_SMARTNPCDIALOG_MANAGER::SMARTNPCDIALOG_MENU, StrToWzID("P003")); if (picture_control == NULL) { return FALSE; } else { picture_control->MoveWindowWZ(dialog_->GetDlgX() + 21, dialog_->GetDlgY() + 41, 268, 207); SI_TSUBINFO image_sub_info; image_sub_info.Initialize(); image_sub_info.m_blIs = true; image_sub_info.m_sImageName = "Common_bg01.tga"; image_sub_info.m_blUseGradation = false; image_sub_info.m_fTileCornerX = 5; image_sub_info.m_fTileCornerY = 5; image_sub_info.m_nType = SI_TSUBINFO::DrawType_TileExpand; image_sub_info.m_sFRect.fTopX = 398; image_sub_info.m_sFRect.fTopY = 147; image_sub_info.m_sFRect.fWidth = 17; image_sub_info.m_sFRect.fHeight = 17; image_sub_info.m_color = 0xffffffff; //RGBA(255,255,255,255); picture_control->SetCtrlDetailImageFormat(E_BASE, &image_sub_info); } // ¸®½ºÆ® µÚ¿¡ À̹ÌÁö2 picture_control = CreateContorlPicture(IM_SMARTNPCDIALOG_MANAGER::SMARTNPCDIALOG_MENU, StrToWzID("P004")); if (picture_control == NULL) { return FALSE; } else { picture_control->MoveWindowWZ(dialog_->GetDlgX() + 13, dialog_->GetDlgY() + 33, 284, 223); SI_TSUBINFO image_sub_info; image_sub_info.Initialize(); image_sub_info.m_blIs = true; image_sub_info.m_sImageName = "Common_bg01.tga"; image_sub_info.m_blUseGradation = false; image_sub_info.m_fTileCornerX = 12; image_sub_info.m_fTileCornerY = 12; image_sub_info.m_nType = SI_TSUBINFO::DrawType_TileExpand; image_sub_info.m_sFRect.fTopX = 390; image_sub_info.m_sFRect.fTopY = 0; image_sub_info.m_sFRect.fWidth = 26; image_sub_info.m_sFRect.fHeight = 26; image_sub_info.m_color = 0xffffffff; //RGBA(255,255,255,255); picture_control->SetCtrlDetailImageFormat(E_BASE, &image_sub_info); } // ½ºÅ©·Ñ µÚ¿¡ À̹ÌÁö picture_control = CreateContorlPicture(IM_SMARTNPCDIALOG_MANAGER::SMARTNPCDIALOG_MENU, StrToWzID("P005")); if (picture_control == NULL) { return FALSE; } else { picture_control->MoveWindowWZ(dialog_->GetDlgX() + 271, dialog_->GetDlgY() + 45, 14, 199); SI_TSUBINFO image_sub_info; image_sub_info.Initialize(); image_sub_info.m_blIs = true; image_sub_info.m_sImageName = "all_butten4.tga"; image_sub_info.m_blUseGradation = false; image_sub_info.m_fTileCornerX = 7; image_sub_info.m_fTileCornerY = 20; image_sub_info.m_nType = SI_TSUBINFO::DrawType_TileExpand; image_sub_info.m_sFRect.fTopX = 117; image_sub_info.m_sFRect.fTopY = 30; image_sub_info.m_sFRect.fWidth = 16; image_sub_info.m_sFRect.fHeight = 42; image_sub_info.m_color = 0xffffffff; //RGBA(255,255,255,255); picture_control->SetCtrlDetailImageFormat(E_BASE, &image_sub_info); } // ½ºÅ©·Ñ CCtrlVScrollWZ* scroll_control = CreateContorlVScroll(IM_SMARTNPCDIALOG_MANAGER::SMARTNPCDIALOG_MENU, StrToWzID("V001")); if (scroll_control == NULL) { return FALSE; } else { scroll_control->MoveWindowWZ(dialog_->GetDlgX() + 273, dialog_->GetDlgY() + 47, 10, 195); scroll_control_ = scroll_control; scroll_control_->SetScrollPosWZ(0); scroll_control_->SetScrollRangeWZ(0,1); } // x ¹öư CCtrlButtonWZ* button_control = CreateContorlCloseButton(IM_SMARTNPCDIALOG_MANAGER::SMARTNPCDIALOG_MENU, StrToWzID("B999")); if (button_control == NULL) { return FALSE; } else { button_control->MoveWindowWZ(dialog_->GetDlgX() + 278, dialog_->GetDlgY() + 13, 17, 17); } // ¹öư µÚ¿¡ À̹ÌÁö1 picture_control = CreateContorlPicture(IM_SMARTNPCDIALOG_MANAGER::SMARTNPCDIALOG_MENU, StrToWzID("P006")); if (picture_control == NULL) { return FALSE; } else { picture_control->MoveWindowWZ( dialog_->GetDlgX() + 21, dialog_->GetDlgY() + 259, 268, button_count_ * 30.0f); SI_TSUBINFO image_sub_info; image_sub_info.Initialize(); image_sub_info.m_blIs = true; image_sub_info.m_sImageName = "Common_bg01.tga"; image_sub_info.m_blUseGradation = false; image_sub_info.m_fTileCornerX = 5; image_sub_info.m_fTileCornerY = 5; image_sub_info.m_nType = SI_TSUBINFO::DrawType_TileExpand; image_sub_info.m_sFRect.fTopX = 398; image_sub_info.m_sFRect.fTopY = 147; image_sub_info.m_sFRect.fWidth = 17; image_sub_info.m_sFRect.fHeight = 17; image_sub_info.m_color = 0xffffffff; //RGBA(255,255,255,255); picture_control->SetCtrlDetailImageFormat(E_BASE, &image_sub_info); } // ¹öư µÚ¿¡ À̹ÌÁö2 picture_control = CreateContorlPicture(IM_SMARTNPCDIALOG_MANAGER::SMARTNPCDIALOG_MENU, StrToWzID("P007")); if (picture_control == NULL) { return FALSE; } else { picture_control->MoveWindowWZ( dialog_->GetDlgX() + 13, dialog_->GetDlgY() + 251, 284, 15.0f + (button_count_ * 30)); SI_TSUBINFO image_sub_info; image_sub_info.Initialize(); image_sub_info.m_blIs = true; image_sub_info.m_sImageName = "Common_bg01.tga"; image_sub_info.m_blUseGradation = false; image_sub_info.m_fTileCornerX = 12; image_sub_info.m_fTileCornerY = 12; image_sub_info.m_nType = SI_TSUBINFO::DrawType_TileExpand; image_sub_info.m_sFRect.fTopX = 390; image_sub_info.m_sFRect.fTopY = 0; image_sub_info.m_sFRect.fWidth = 26; image_sub_info.m_sFRect.fHeight = 26; image_sub_info.m_color = 0xffffffff; //RGBA(255,255,255,255); picture_control->SetCtrlDetailImageFormat(E_BASE, &image_sub_info); } // ¹öư for (int i = 0; i < button_count_; ++i) { button_control = CreateContorlButton(IM_SMARTNPCDIALOG_MANAGER::SMARTNPCDIALOG_MENU, GetControlID_byPosition(i + kControl_Button_B001)); if (button_control == NULL) { return FALSE; } else { button_control->MoveWindowWZ(dialog_->GetDlgX() + 23, dialog_->GetDlgY() + 440.0f - ((6-i)*30), 264, 29); } } return TRUE; } void uiSmartNpcDialogMenu::MessageProc(SI_MESSAGE* message) { if (IsLock()) return; switch (message->eResultMsg) { case RT_MSG_LBUTTONCLICK: OnLButtonClick(message); break; case RT_MSG_SB_PAGETOP: //. À­ÂÊ ¸öÅëÀ» ´­·¶´Ù. case RT_MSG_SB_LINETOP: //.À­ÂÊ È­»ìÇ¥¸¦ ´­·¶´Ù. { if(scroll_control_) { int pos = scroll_control_->GetScrollPosWZ(); // ÇöÀç ½ºÅ©·Ñ °ªÀ» ¹Þ¾Æ ¿Â´Ù. int mmin = 0 , mmax = 0; scroll_control_->GetScrollRangeWZ( &mmin, &mmax ); // ½ºÅ©·Ñ °ªÀÇ ÃÖ´ë ÃÖ¼Ò¸¦ ¾ò¾î ¿Â´Ù. if(pos>mmin) // ÇöÀç ÀÔ·ÂµÈ ¶óÀμö º¸´Ù ÀÛÀ¸¸é { --pos; // ÇÑÁÙ °¨¼Ò ½Ã۰í scroll_control_->SetScrollPosWZ(pos); ftext_render_.SetBeginLineIndex(pos); } } } break; case RT_MSG_SB_PAGEBOTTOM: //. ¾Æ·¡ÂÊ ¸öÅëÀ» ´­·¶´Ù. case RT_MSG_SB_LINEBOTTOM: //.¾Æ·§ÂÊ È­»ìÇ¥¸¦ ´­·¶´Ù { if(scroll_control_) { int pos = scroll_control_->GetScrollPosWZ(); // ÇöÀç ½ºÅ©·Ñ °ªÀ» ¹Þ¾Æ ¿Â´Ù. int mmin = 0 , mmax = 0; scroll_control_->GetScrollRangeWZ( &mmin, &mmax ); // ½ºÅ©·Ñ °ªÀÇ ÃÖ´ë ÃÖ¼Ò¸¦ ¾ò¾î ¿Â´Ù. if(posSetScrollPosWZ(pos); ftext_render_.SetBeginLineIndex(pos); } } } break; case RT_MSG_SB_THUMBTRACK: //. ½æÀ» µå·¡±× Çϰí ÀÖ´Ù. case RT_MSG_SB_THUMBPOSITION: //. ½æÀ» µå·¡±×ÇÑÈÄ ¸¶¿ì½º¸¦ ³õ¾Ò´Ù. case RT_MSG_SB_ENDSCROLL: //. ½ºÅ©·ÑÀÌ Á¾·á µÇ¾ú´Ù. { if(scroll_control_) { int pos = scroll_control_->GetScrollPosWZ(); // ÇöÀç ½ºÅ©·Ñ °ªÀ» ¹Þ¾Æ ¿Â´Ù. ftext_render_.SetBeginLineIndex(pos); } } break; break; default: SolarDialog::MessageProc(message); break; } } bool uiSmartNpcDialogMenu::OnLButtonClick(SI_MESSAGE* message) { switch (GetControlPosition_byID(message->dwCtrlID)) { case kControl_Button_B999: { g_InterfaceManager.DeleteInterface(IM_SMARTNPCDIALOG_MANAGER::SMARTNPCDIALOG_MENU); } break; case kControl_Button_B001: case kControl_Button_B002: case kControl_Button_B003: case kControl_Button_B004: case kControl_Button_B005: case kControl_Button_B006: { DWORD index = GetControlPosition_byID(message->dwCtrlID); EVENT_IDSTEP& event_id = button_event_id[index - kControl_Button_B001]; MSG_CG_NPCDIALOG_ON_CLICK_MENU_CMD send_packet( g_pHero->GetObjectKey(), GetOwnerKey(), event_id.event_id, event_id.step); GlobalFunc::SendPacket(CI_GAMESERVERIDX, &send_packet, sizeof(send_packet)); g_InterfaceManager.DeleteInterface(IM_SMARTNPCDIALOG_MANAGER::SMARTNPCDIALOG_MENU); } break; default: { } break; } return true; } void uiSmartNpcDialogMenu::OnRenderSolarDialog() { ftext_render_.Render(); } void uiSmartNpcDialogMenu::OnUpdateSolarDialog() { UpdateMouseWheel(); if (GetOwnerKey() != 0) { Object* object = (g_ObjectManager.GetObject(GetOwnerKey())); if (object && g_pHero) { WzVector vDiff = object->GetPosition() - g_pHero->GetVisiblePos(); float distance = VectorLength2(&vDiff); if (distance > (DISTANCE_NPC_MEET * DISTANCE_NPC_MEET)) { //g_InterfaceManager.DeleteInterface(IM_SMARTNPCDIALOG_MANAGER::SMARTNPCDIALOG_MENU); SetDestroyWindow(TRUE); return; } } } } void uiSmartNpcDialogMenu::OnShowWindow(BOOL val) { if (val) { keyMsg msg; ZeroMemory(&msg,sizeof(msg)); msg.dwType=eDoType_SmartMenu_Dialog; msg.wParam=IM_SMARTNPCDIALOG_MANAGER::SMARTNPCDIALOG_MENU; msg.DoSomething=GlobalFunc::DoSmartNpcMenuDialog; g_KeyQueueManager.PushBack(msg); } else { g_KeyQueueManager.DeleteMsg(eDoType_SmartMenu_Dialog); } } void uiSmartNpcDialogMenu::UpdateMouseWheel() { if(list_control_ == NULL || scroll_control_ == NULL) { return; } int scroll_max_line = 0; size_t list_max_line = ftext_render_.GetDrawLineInRect(); if (ftext_render_.GetMaxLine() > list_max_line) { scroll_max_line = ftext_render_.GetMaxLine() - list_max_line; } scroll_control_->SetScrollRangeWZ(0, scroll_max_line); RECT list_rect = list_control_->GetSizeRect(); ftext_render_.SetRect(list_rect); switch (GetMouseWheelStatus(&list_rect)) { case MOUSE_WHEEL_UP: { int index = scroll_control_->GetScrollPosWZ(); int scroll_min = 0; int scroll_max = 0; scroll_control_->GetScrollRangeWZ(&scroll_min, &scroll_max); if (index > scroll_min) { --index; ftext_render_.SetBeginLineIndex(index); scroll_control_->SetScrollPosWZ(index); } } break; case MOUSE_WHEEL_DOWN: { int index = scroll_control_->GetScrollPosWZ(); int scroll_min = 0; int scroll_max = 0; scroll_control_->GetScrollRangeWZ(&scroll_min, &scroll_max); if (index < scroll_max) { ++index; ftext_render_.SetBeginLineIndex(index); scroll_control_->SetScrollPosWZ(index); } } break; default: break; } } void uiSmartNpcDialogMenu::SetControlText(BYTE contorl_index, const TCHAR *text_massage) { if (contorl_index >= kControl_Size) { return; } switch (contorl_index) { case kControl_Text_T999: { CCtrlStaticWZ* control = static_cast(GetControlWZ_byPosition(contorl_index)); if (control) { control->SetTextWZ(text_massage); } } break; case kControl_Button_B001: case kControl_Button_B002: case kControl_Button_B003: case kControl_Button_B004: case kControl_Button_B005: case kControl_Button_B006: { CCtrlButtonWZ* control = static_cast(GetControlWZ_byPosition(contorl_index)); if (control) { control->SetTextWZ(text_massage); } } break; case kControl_List_L000: { SetTextMessage(text_massage); } break; } } void uiSmartNpcDialogMenu::SetControlEventID(BYTE contorl_index, DWORD event_id, DWORD step) { if (contorl_index >= kControl_Size) { return; } switch (contorl_index) { case kControl_Button_B001: case kControl_Button_B002: case kControl_Button_B003: case kControl_Button_B004: case kControl_Button_B005: case kControl_Button_B006: { CCtrlButtonWZ* control = static_cast(GetControlWZ_byPosition(contorl_index)); if (control) { int index = contorl_index - kControl_Button_B001; button_event_id[index].event_id = event_id; button_event_id[index].step = step; } } break; } } void uiSmartNpcDialogMenu::SetTextMessage(const TCHAR *text_massage) { if (list_control_ == NULL || scroll_control_ == NULL) { return; } ftext_render_.ClearSentence(); ftext_render_.SetBeginLineIndex(0); FTextParser parser; FTextSentence sentence; TCHAR str_format[INTERFACE_STRING_LENGTH]={0,}; BOOL result = parser.Parser(text_massage, sentence); if (result == TRUE) { ftext_render_.Append(sentence); ftext_render_.convertLineInfo(); } int scroll_range = ftext_render_.GetMaxLine() - ftext_render_.GetDrawLineInRect(); scroll_control_->SetScrollRangeWZ(0,scroll_range); scroll_control_->SetScrollPosWZ(0); } #endif //_NA_000000_20140120_SMART_NPC_SYSTEM*