Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement in game command list #222

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/engine/N3Base/N3UIBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ class CN3UIBase : public CN3BaseFileAccess {
#endif

public:
std::string m_szID; // UI id
std::string m_szToolTip; // tooltip text
std::string m_szID; // UI id
std::string m_szToolTip; // tooltip text
D3DCOLOR m_crToolTipColor; // tooltip text color
void SetID(LPCTSTR pszID) { m_szID = pszID; }
const std::string GetID() const { return m_szID; }
void SetTooltipText(LPCTSTR pszTT) { m_szToolTip = pszTT; }
Expand Down
93 changes: 67 additions & 26 deletions src/engine/N3Base/N3UIList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "N3UIList.h"
#include "N3UIString.h"
#include "N3UIScrollBar.h"
#include "N3UITooltip.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
Expand All @@ -14,7 +15,7 @@
CN3UIList::CN3UIList() {
m_eType = UI_TYPE_LIST;

m_iCurSel = 0; // 현재 선택..
m_iCurSel = 0; // Current selection..
m_pScrollBarRef = NULL;

m_szFontName = "굴림체";
Expand All @@ -35,7 +36,8 @@ void CN3UIList::Release() {
// delete (*it);
// }

m_ListString.clear(); // 어차피 자식은 다지우니까... 리스트의 포인터를 Delete 할 필요 없다..
// Since all the children will be deleted anyway... there is no need to delete the pointer to the list..
m_ListString.clear();
m_iCurSel = 0;
m_pScrollBarRef = NULL;

Expand All @@ -46,6 +48,13 @@ void CN3UIList::Release() {
m_crFont = 0xffffffff;
}

void CN3UIList::SetScrollBarRef(CN3UIScrollBar * pScrollBarRef) {
m_pScrollBarRef = pScrollBarRef;
if (m_pScrollBarRef) {
m_pScrollBarRef->SetCurrentPos(0);
}
}

void CN3UIList::SetFont(const std::string & szFontName, DWORD dwHeight, BOOL bBold, BOOL bItalic) {
m_szFontName = szFontName;
m_dwFontHeight = dwHeight;
Expand Down Expand Up @@ -96,6 +105,23 @@ int CN3UIList::AddStrings(const std::string * pszStrings, int iStringCount) {
return m_ListString.size() - 1;
}

int CN3UIList::AddStringTooltip(const std::string & szString, const D3DCOLOR szStringColor,
const std::string & szStringToolTip, const D3DCOLOR szStringToolTipColor) {
CN3UIString * pString = new CN3UIString();
pString->Init(this);
pString->SetFont(m_szFontName, m_dwFontHeight, m_bFontBold, m_bFontItalic);
pString->SetColor(szStringColor);
pString->SetString(szString);

pString->SetTooltipText(szStringToolTip.c_str());
pString->m_crToolTipColor = szStringToolTipColor;

m_ListString.push_back(pString);
this->UpdateChildRegions();

return m_ListString.size() - 1;
}

int CN3UIList::AddString(const std::string & szString) {
CN3UIString * pString = new CN3UIString();
pString->Init(this);
Expand Down Expand Up @@ -137,11 +163,9 @@ bool CN3UIList::DeleteString(int iIndex) {
}

it_pString it = m_ListString.begin();
for (int i = 0; i < iIndex; it++) {
;
}
std::advance(it, iIndex);

delete (*it);
delete *it;
m_ListString.erase(it);

int iSC = m_ListString.size();
Expand Down Expand Up @@ -195,14 +219,24 @@ bool CN3UIList::SetString(int iIndex, const std::string & szString) {
return false;
}

CN3UIString * CN3UIList::GetChildStrFromList(const std::string str) {
for (CN3UIString * pString : m_ListString) {
if (pString->GetString() == str) {
return pString;
}
}

return NULL;
}

void CN3UIList::UpdateChildRegions() {
RECT rc = this->GetRegion();
RECT rcThis = rc;
POINT pt;
SIZE size;
int iScrollPos = 0;
if (m_pScrollBarRef) {
m_pScrollBarRef->GetCurrentPos();
iScrollPos = m_pScrollBarRef->GetCurrentPos();
RECT rcTmp = m_pScrollBarRef->GetRegion();
rc.right = rcTmp.left;
}
Expand Down Expand Up @@ -230,14 +264,13 @@ void CN3UIList::UpdateChildRegions() {
}

if (m_pScrollBarRef) {
if (rc.bottom <= rcThis.bottom) {
m_pScrollBarRef->SetCurrentPos(0);
m_pScrollBarRef->SetVisibleWithNoSound(false);
if (rc.top <= rcThis.bottom) {
//m_pScrollBarRef->SetCurrentPos(0);
//m_pScrollBarRef->SetVisibleWithNoSound(false);
} else {
m_pScrollBarRef->SetVisibleWithNoSound(true);
}

m_pScrollBarRef->SetRange(0, m_ListString.size());
//m_pScrollBarRef->SetRange(0, m_ListString.size());
}
}

Expand All @@ -262,10 +295,10 @@ bool CN3UIList::SetScrollPos(int iScrollPos) {
bool CN3UIList::Load(HANDLE hFile) {
bool bSuccess = CN3UIBase::Load(hFile);

// font 정보
// font information
DWORD dwNum;
int iStrLen = 0;
ReadFile(hFile, &iStrLen, sizeof(iStrLen), &dwNum, NULL); // font 이름 길이
ReadFile(hFile, &iStrLen, sizeof(iStrLen), &dwNum, NULL); // font name length
__ASSERT(iStrLen > 0, "No font name");
if (iStrLen > 0) {
m_szFontName.assign(iStrLen, ' ');
Expand All @@ -276,7 +309,7 @@ bool CN3UIList::Load(HANDLE hFile) {
ReadFile(hFile, &m_bFontItalic, 4, &dwNum, NULL); // font flag (bold, italic)
}

// Child 중에 Scroll Bar 가 있는지 찾아본다.
// Check if any of the children have a scroll bar.
for (UIListItor itor = m_Children.begin(); m_Children.end() != itor; ++itor) {
CN3UIBase * pUI = *itor;
if (pUI->UIType() == UI_TYPE_SCROLLBAR) {
Expand All @@ -288,7 +321,7 @@ bool CN3UIList::Load(HANDLE hFile) {
// if( pString->GetFontName != m_szFontName ||
// pString->GetFontHeight() != m_dwFontHeight ||
// m_bFontBold != (pString->GetFontFlags() & D3DFONT_BOLD) ||
// m_bFontItalic != (pString->GetFontFlags() & D3DFONT_ITALIC) ) // 폰트가 다르면.. 적용
// m_bFontItalic != (pString->GetFontFlags() & D3DFONT_ITALIC) ) // If the font is different.. apply
// {
// pString->SetFont(m_szFontName, m_dwFontHeight, m_bFontBold, m_bFontItalic);
// }
Expand All @@ -306,10 +339,10 @@ bool CN3UIList::Save(HANDLE hFile) {

DWORD dwNum;

// font 정보
// font information
int iStrLen = m_szFontName.size();
__ASSERT(iStrLen > 0, "No font name");
WriteFile(hFile, &iStrLen, sizeof(iStrLen), &dwNum, NULL); // font 이름 길이
WriteFile(hFile, &iStrLen, sizeof(iStrLen), &dwNum, NULL); // font name length
if (iStrLen > 0) {
WriteFile(hFile, m_szFontName.c_str(), iStrLen, &dwNum, NULL); // string
WriteFile(hFile, &m_dwFontHeight, 4, &dwNum, NULL); // font height
Expand Down Expand Up @@ -341,14 +374,14 @@ DWORD CN3UIList::MouseProc(DWORD dwFlags, const POINT & ptCur, const POINT & ptO
}

// 특정 이벤트에 대해 메시지 전송..
if (IsIn(ptCur.x, ptCur.y) && ((dwFlags & UI_MOUSE_LBCLICK) || (dwFlags & UI_MOUSE_LBDBLCLK))) {
if (IsIn(ptCur.x, ptCur.y)) {
RECT rc = this->GetRegion(), rcStr;
SIZE size;

it_pString it = m_ListString.begin(), itEnd = m_ListString.end();
for (int i = 0; it != itEnd; it++, i++) {
CN3UIString * pStr = (*it);
if (false == pStr->IsVisible()) {
if (!pStr->IsVisible()) {
continue;
}

Expand All @@ -359,20 +392,28 @@ DWORD CN3UIList::MouseProc(DWORD dwFlags, const POINT & ptCur, const POINT & ptO
rc.bottom += size.cy;

if (::PtInRect(&rcStr, ptCur)) {
m_iCurSel = i;
if (!pStr->m_szToolTip.empty()) {
pStr->GetTooltipCtrl()->SetSingleLineText(pStr->m_szToolTip);
pStr->GetTooltipCtrl()->SetColor(pStr->m_crToolTipColor);
}

if (dwFlags & UI_MOUSE_LBCLICK) {
m_iCurSel = i;
if (m_pParent) {
m_pParent->ReceiveMessage(this, UIMSG_LIST_SELCHANGE); // 부모에게 버튼 클릭 통지..
}
dwRet |= UIMSG_LIST_SELCHANGE;
} else {
dwRet |= UI_MOUSEPROC_DONESOMETHING;
return dwRet;
} else if (dwFlags & UI_MOUSE_LBDBLCLK) {
m_iCurSel = i;
if (m_pParent) {
m_pParent->ReceiveMessage(this, UIMSG_LIST_DBLCLK); // 부모에게 버튼 클릭 통지..
}
dwRet |= UIMSG_LIST_DBLCLK;
dwRet |= UI_MOUSEPROC_DONESOMETHING;
return dwRet;
}
dwRet |= UI_MOUSEPROC_DONESOMETHING;
return dwRet;
}
}
}
Expand All @@ -391,7 +432,7 @@ void CN3UIList::Render() {
}
CN3UIString * pStr = *it;
if (pStr) {
RECT rc = pStr->GetRegion(); // 선택 표시
RECT rc = pStr->GetRegion(); // Selection indicator

__VertexTransformedColor vLines[5];
vLines[0].Set(rc.left, rc.top, UI_DEFAULT_Z, UI_DEFAULT_RHW, 0xff00ff00);
Expand Down Expand Up @@ -443,7 +484,7 @@ bool CN3UIList::ReceiveMessage(CN3UIBase * pSender, DWORD dwMsg) {
if (UIMSG_SCROLLBAR_POS == dwMsg) {
if (pSender == m_pScrollBarRef) {
this->SetScrollPos(m_pScrollBarRef->GetCurrentPos());
// return m_pParent->ReceiveMessage(this, UIMSG_SCROLLBAR_POS);
return m_pParent->ReceiveMessage(this, UIMSG_SCROLLBAR_POS);
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/engine/N3Base/N3UIList.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ typedef typename std::list<CN3UIString *>::iterator it_pString;

class CN3UIList : public CN3UIBase {
protected:
int m_iCurSel; // 현재 선택..
int m_iCurSel; // Current selection..
std::list<CN3UIString *> m_ListString; // String List
class CN3UIScrollBar * m_pScrollBarRef;

Expand All @@ -28,6 +28,8 @@ class CN3UIList : public CN3UIBase {
D3DCOLOR FontColor() { return m_crFont; }
BOOL FontIsBold() { return m_bFontBold; }
BOOL FontIsItalic() { return m_bFontItalic; }
CN3UIString * GetChildStrFromList(const std::string str);
void SetScrollBarRef(CN3UIScrollBar * pScrollBarRef);

void SetFont(const std::string & szFontName, DWORD dwHeight, BOOL bBold, BOOL bItalic);
void SetFontColor(D3DCOLOR color);
Expand All @@ -37,6 +39,9 @@ class CN3UIList : public CN3UIBase {
void UpdateChildRegions();
int AddStrings(const std::string * pszStrings, int iStringCount);
int AddString(const std::string & szString);
int AddStringTooltip(const std::string & szString, const D3DCOLOR szStringColor = 0x00000000,
const std::string & szStringToolTip = nullptr,
const D3DCOLOR szStringToolTipColor = 0x00000000);
bool InsertString(int iIndex, const std::string & szString);
bool DeleteString(int iIndex);
bool GetString(int iIndex, std::string & szString);
Expand Down
57 changes: 57 additions & 0 deletions src/engine/N3Base/N3UITooltip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,63 @@ void CN3UITooltip::Render() {
CN3UIStatic::Render();
}
}
// I've added this function to fix long single line tooltip. I left old function too.
void CN3UITooltip::SetSingleLineText(const std::string & szText) {
if (!m_bVisible || m_bSetText) {
return;
}

int iStrLen = szText.size();
if (iStrLen == 0 || m_pBuffOutRef == NULL) {
return;
}

m_pBuffOutRef->ClearOnlyStringBuffer();

SIZE size;
if (m_pBuffOutRef->GetTextExtent(szText, iStrLen, &size)) {
m_pBuffOutRef->SetStyle(UISTYLE_STRING_SINGLELINE | UISTYLE_STRING_ALIGNCENTER | UISTYLE_STRING_ALIGNVCENTER);

size.cx += 12;
size.cy += 12;
SetSize(size.cx, size.cy);
}

m_pBuffOutRef->SetString(szText);
m_pBuffOutRef->SetColor(m_crToolTipColor);

POINT ptNew = m_ptCursor;
ptNew.x -= (m_rcRegion.right - m_rcRegion.left) / 2;
ptNew.y -= (m_rcRegion.bottom - m_rcRegion.top) + 10;

D3DVIEWPORT9 & vp = s_CameraData.vp;

int vpWidth = vp.Width;
int vpHeight = vp.Height;

int tooltipWidth = m_rcRegion.right - m_rcRegion.left;
int tooltipHeight = m_rcRegion.bottom - m_rcRegion.top;

int horizontalMargin = 15;
int verticalMargin = 10;

if (ptNew.x + tooltipWidth > vp.X + vpWidth) {
ptNew.x = vp.X + vpWidth - tooltipWidth - horizontalMargin;
}
if (ptNew.x < vp.X) {
ptNew.x = vp.X + horizontalMargin;
}

if (ptNew.y + tooltipHeight > vp.Y + vpHeight) {
ptNew.y = vp.Y + vpHeight - tooltipHeight - verticalMargin;
}
if (ptNew.y < vp.Y) {
ptNew.y = vp.Y + verticalMargin;
}
SetPos(ptNew.x, ptNew.y);

m_bSetText = true;
}

void CN3UITooltip::SetText(const std::string & szText) {
if (!m_bVisible || m_bSetText) {
Expand Down
9 changes: 6 additions & 3 deletions src/engine/N3Base/N3UITooltip.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ class CN3UITooltip : public CN3UIStatic {
// Attributes
public:
protected:
float m_fHoverTime; // 마우스가 한곳에서 정지하여 있는 시간(누적)
bool m_bSetText; // 이미 text가 설정되었는가?
POINT m_ptCursor; // 커서의 위치
float m_fHoverTime; // 마우스가 한곳에서 정지하여 있는 시간(누적)
bool m_bSetText; // 이미 text가 설정되었는가?
POINT m_ptCursor; // 커서의 위치
D3DCOLOR m_crToolTipColor;

// Operations
public:
void SetText(const std::string & szText);
void SetSingleLineText(const std::string & szText);
void SetColor(const D3DCOLOR & crToolTipColor) { m_crToolTipColor = crToolTipColor; };
virtual void Release();
virtual void Tick();
virtual void Render();
Expand Down
1 change: 1 addition & 0 deletions src/game/GameDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum eKeyMap {
KM_TOGGLE_SKILL = DIK_K,
KM_TOGGLE_STATE = DIK_U,
KM_TOGGLE_MINIMAP = DIK_M,
KM_TOGGLE_COMMAND_LIST = DIK_H,
KM_TOGGLE_HELP = DIK_F1,
KM_CAMERA_CHANGE = DIK_F9,
KM_DROPPED_ITEM_OPEN = DIK_F,
Expand Down
Loading