Mercurial > mm7
diff GUIWindow.cpp @ 1268:2929c4406d2c
guiwindow funcs cleanup
author | Gloval |
---|---|
date | Sat, 15 Jun 2013 01:22:17 +0400 |
parents | 746f7ef994cb |
children | 86a83e12d795 dcc52e17b517 |
line wrap: on
line diff
--- a/GUIWindow.cpp Thu Jun 13 23:41:42 2013 +0400 +++ b/GUIWindow.cpp Sat Jun 15 01:22:17 2013 +0400 @@ -29,8 +29,36 @@ #include "mm7_data.h" +typedef struct _RGBColor + { + unsigned char R; + unsigned char B; + unsigned char G; + }RGBColor; +std::array<RGBColor, 20> spell_tooltip_colors={{ + {0x96, 0xD4, 0xFF}, + {0xFF, 0x80, 0x00}, + {0xFF, 0xFF, 0x9B}, + {0xE1, 0xE1, 0xE1}, + {0x80, 0x80, 0x80}, + {0x96, 0xD4, 0xFF}, + {0xFF, 0x55, 0x00}, + {0x96, 0xD4, 0xFF}, + {0xFF, 0x55, 0x00}, + {0xE1, 0xE1, 0xE1}, + {0xFF, 0x55, 0x00}, + {0x96, 0xD4, 0xFF}, + {0xEB, 0x0F, 0xFF}, + {0xFF, 0x80, 0x00}, + {0x96, 0xD4, 0xFF}, + {0x80, 0x80, 0x80}, + {0xFF, 0x55, 0x00}, + {0x00, 0x80, 0xFF}, + {0x00, 0x80, 0xFF}, + {0x96, 0xD4, 0xFF}}}; + int pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[1]; // idb struct GUIWindow *pWindow_MainMenu; @@ -46,11 +74,11 @@ //----- (004141CA) -------------------------------------------------------- -void ModalWindow(const char *pStr, int a4) -{ +void ModalWindow( const char *pStrHint, int a4 ) + { pEventTimer->Pause(); dword_506F0C[0] = pCurrentScreen; - ptr_507BDC = GUIWindow::Create(0, 0, 640, 480, WINDOW_FinalWindow, a4, (int)pStr); + ptr_507BDC = GUIWindow::Create(0, 0, 640, 480, WINDOW_FinalWindow, a4, pStrHint); pCurrentScreen = SCREEN_PRESS_ESCAPE_MESSAGE; } // 4E28F8: using guessed type int pCurrentScreen; @@ -180,79 +208,41 @@ //----- (0041D73D) -------------------------------------------------------- void GUIWindow::_41D73D_draw_buff_tooltip() { - GUIFont *v1; // esi@1 - GUIWindow *v2; // edi@1 - SpellBuff *v3; // eax@1 - unsigned int v4; // eax@5 - int v5; // ecx@5 - unsigned int v6; // eax@5 - unsigned int v7; // ecx@5 - char *v8; // ebx@7 - unsigned int v9; // eax@8 - unsigned int v10; // ecx@8 - __int64 v11; // ST28_8@11 - int v12; // esi@11 - const char *v13; // ST0C_4@11 - unsigned int v14; // eax@11 - char **v16; // [sp+14h] [bp-10h]@7 - GUIFont *a2; // [sp+18h] [bp-Ch]@1 - SpellBuff *v18; // [sp+1Ch] [bp-8h]@7 - int v19; // [sp+20h] [bp-4h]@1 - int v20; // [sp+20h] [bp-4h]@7 + + __int64 remaing_time; // ST28_8@11 + unsigned short text_color; + int Y_pos; // esi@11 + int string_count; // [sp+20h] [bp-4h]@7 + + + string_count = 0; + for (int i=0; i<20; ++i) + if ( pParty->pPartyBuffs[i].uExpireTime > 0i64 ) + ++string_count; - v1 = pFontComic; - v2 = this; - a2 = pFontComic; - v19 = 0; - v3 = pParty->pPartyBuffs; - do + uFrameHeight = pFontArrus->uFontHeight + 72; + uFrameHeight += (string_count - 1) * pFontArrus->uFontHeight; + uFrameZ = uFrameWidth + uFrameX - 1; + uFrameW = uFrameY + uFrameHeight - 1; + DrawMessageBox(0); + DrawTitleText(pFontArrus, 0, 12, 0, pGlobalTXT_LocalizationStrings[451], 3u); + if ( !string_count ) + DrawTitleText(pFontComic, 0, 40, 0, pGlobalTXT_LocalizationStrings[153], 3u); + + GetTickCount(); + string_count = 0; + for (int i=0; i<20; ++i) { - if ( (signed __int64)v3->uExpireTime > 0 ) - ++v19; - ++v3; + if ( pParty->pPartyBuffs[i].uExpireTime>0i64 )//!!! + { + remaing_time = pParty->pPartyBuffs[i].uExpireTime- pParty->uTimePlayed;//!!! + Y_pos = string_count * pFontComic->uFontHeight + 40; + text_color = TargetColor(spell_tooltip_colors[i].R, spell_tooltip_colors[i].G, spell_tooltip_colors[i].B); + DrawText(pFontComic, 52, Y_pos, text_color, aSpellNames[i], 0, 0, 0); + sub_41D20D_buff_remaining_time_string(Y_pos, this, remaing_time, pFontComic); + ++string_count; + } } - while ( (signed int)v3 < (signed int)pParty->pPlayers ); - v4 = LOBYTE(pFontArrus->uFontHeight) + 72; - this->uFrameHeight = v4; - v5 = v4 + (v19 - 1) * LOBYTE(pFontArrus->uFontHeight); - v6 = v2->uFrameWidth; - v2->uFrameHeight = v5; - v7 = v2->uFrameHeight; - v2->uFrameZ = v6 + v2->uFrameX - 1; - v2->uFrameW = v2->uFrameY + v7 - 1; - v2->DrawMessageBox(0); - v2->DrawTitleText(pFontArrus, 0, 0xCu, 0, pGlobalTXT_LocalizationStrings[451], 3u); - if ( !v19 ) - v2->DrawTitleText(v1, 0, 0x28u, 0, pGlobalTXT_LocalizationStrings[153], 3u); - v20 = 0; - GetTickCount(); - v8 = &_4E2B21_buff_spell_tooltip_colors[1]; - v16 = aSpellNames.data(); - v18 = pParty->pPartyBuffs; - do - { - v9 = LODWORD(v18->uExpireTime); - v10 = HIDWORD(v18->uExpireTime); - if ( (v10 & 0x80000000u) == 0 && ((signed int)v10 > 0 || v9) )//!!! - { - v11 = __PAIR__(v10, v9) - pParty->uTimePlayed;//!!! - v12 = v20 * LOBYTE(v1->uFontHeight) + 40; - v13 = *v16; - ++v20; - v14 = TargetColor( - (unsigned __int8)*(v8 - 1), - (unsigned __int8)*v8, - (unsigned __int8)v8[1]); - v2->DrawText(a2, 52, v12, v14, v13, 0, 0, 0); - sub_41D20D_buff_remaining_time_string(v12, v2, v11, a2); - v1 = a2; - } - ++v18; - ++v16; - v8 += 3; - } - while ( (signed int)v18 < (signed int)pParty->pPlayers ); - } @@ -1206,7 +1196,8 @@ //----- (0044D406) -------------------------------------------------------- -void GUIWindow::DrawTitleText( GUIFont *a2, signed int uHorizontalMargin, unsigned int uVerticalMargin, unsigned __int16 uDefaultColor, const char *pInString, unsigned int uLineSpacing ) +void GUIWindow::DrawTitleText( GUIFont *a2, signed int uHorizontalMargin, unsigned int uVerticalMargin, unsigned __int16 uDefaultColor, + const char *pInString, unsigned int uLineSpacing ) { GUIWindow *pWindow; // esi@1 unsigned int v8; // ebx@1 @@ -1383,7 +1374,7 @@ pRenderer->DrawTextPalette( v12, v13, - v17, + (unsigned char*)v17, v16, LOBYTE(v10->uFontHeight), v10->pFontPalettes[0], @@ -1409,11 +1400,11 @@ //----- (0044CB4F) -------------------------------------------------------- -int GUIWindow::DrawTextInRect(GUIFont *a2, unsigned int uX, unsigned int uY, unsigned int uColor, const char *Str1, int Source, int a8) -{ - GUIFont *pFont; // edi@1 +int GUIWindow::DrawTextInRect( GUIFont *pFont, unsigned int uX, unsigned int uY, unsigned int uColor, const char *text, int rect_width, int reverse_text ) + { + int pLineWidth; // ebx@1 - int v11; // esi@3 + int text_width; // esi@3 unsigned __int8 v12; // cl@7 signed int v13; // esi@19 signed int v14; // ebx@19 @@ -1423,11 +1414,11 @@ int v18; // ecx@23 int v19; // ecx@24 unsigned int v20; // ecx@26 - int v21; // eax@28 + unsigned char* v21; // eax@28 int v22; // ebx@34 int v23; // eax@34 int v24; // ebx@36 - char Str; // [sp+Ch] [bp-20h]@34 + char Str[6]; // [sp+Ch] [bp-20h]@34 char v26; // [sp+Fh] [bp-1Dh]@34 char v27; // [sp+11h] [bp-1Bh]@35 int v28; // [sp+20h] [bp-Ch]@17 @@ -1437,144 +1428,114 @@ size_t Str1b; // [sp+40h] [bp+14h]@19 const char *Sourcea; // [sp+44h] [bp+18h]@20 int v34; // [sp+48h] [bp+1Ch]@26 + int i; - pFont = a2; + pWindow = this; - pNumLen = strlen(Str1); - pLineWidth = pFont->GetLineWidth(Str1); - if ( pLineWidth < Source ) + pNumLen = strlen(text); + pLineWidth = pFont->GetLineWidth(text); + if ( pLineWidth < rect_width ) { - pWindow->DrawText(pFont, uX, uY, uColor, Str1, 0, 0, 0); + pWindow->DrawText(pFont, uX, uY, uColor, text, 0, 0, 0); return pLineWidth; } - strcpy(pTmpBuf2.data(), Str1); - v11 = 0; - if ( a8 ) + strcpy(pTmpBuf2.data(), text); + text_width = 0; + if ( reverse_text ) _strrev(pTmpBuf2.data()); Str1a = 0; - if ( (signed int)pNumLen > 0 ) - { - do + for (i=0; i<pNumLen; ++i) { - if ( v11 >= Source ) + if ( text_width >= rect_width ) break; - if ( pFont->IsCharValid(v12 = pTmpBuf2[Str1a]) ) + v12 = pTmpBuf2[i]; + if ( pFont->IsCharValid(v12) ) { - if ( v12 < 9u ) - { - if ( (signed int)Str1a > 0 ) - v11 += pFont->pMetrics[v12].uLeftSpacing; - v11 += *((int *)&pFont->cFirstChar + 3 * v12 + 9); - if ( (signed int)Str1a < (signed int)pNumLen ) - v11 += pFont->pMetrics[v12].uRightSpacing; - goto LABEL_16; - } - if ( v12 > 0xAu )//10 - { - if ( v12 == 12 ) + switch (v12) { - Str1a += 5; - } - else - { - if ( v12 != 13 ) - { - if ( (signed int)Str1a > 0 ) - v11 += pFont->pMetrics[v12].uLeftSpacing; - v11 += *((int *)&pFont->cFirstChar + 3 * v12 + 9); - if ( (signed int)Str1a < (signed int)pNumLen ) - v11 += pFont->pMetrics[v12].uRightSpacing; - } - } - } + case '\t':// Horizontal tab 09 + case '\n': //Line Feed 0A 10 + case '\r': //Form Feed, page eject 0C 12 + break; + case '\f': //Carriage Return 0D 13 + i += 5; + break; + default: + if ( i > 0 ) + text_width += pFont->pMetrics[v12].uLeftSpacing; + text_width += pFont->pMetrics[v12].uWidth; + if ( i < pNumLen ) + text_width += pFont->pMetrics[v12].uRightSpacing; + } } -LABEL_16: - ++Str1a; } - while ( (signed int)Str1a < (signed int)pNumLen ); - } - pTmpBuf2[Str1a - 1] = 0; + pTmpBuf2[i - 1] = 0; + + pNumLen = strlen(pTmpBuf2.data()); v28 = pFont->GetLineWidth(pTmpBuf2.data()); - if ( a8 ) + if ( reverse_text ) _strrev(pTmpBuf2.data()); - Str1b = 0; + v13 = uX + pWindow->uFrameX; v14 = uY + pWindow->uFrameY; - if ( (signed int)pNumLen > 0 ) + for (i=0; i<pNumLen; ++i) { - Sourcea = &pTmpBuf2[1]; - do - { - if ( pFont->IsCharValid(v15 = pTmpBuf2[Str1b]) ) + v15 = pTmpBuf2[i]; + if ( pFont->IsCharValid(v15) ) { - v16 = v15; - v17 = v15 - 9; - if ( v17 )//>0 - { - v18 = v17 - 1; - if ( v18 )//>0 + switch (v12) + { + case '\t':// Horizontal tab 09 + { + strncpy(Str, &pTmpBuf2[i+1], 3); + Str[3] = 0; + // atoi(Str); + i += 3; + break; + } + case '\n': //Line Feed 0A 10 + { + v24 = pFont->uFontHeight; + v13 = uX; + uY = uY + pFont->uFontHeight - 3; + v14 = uY+pFont->uFontHeight - 3; + break; + } + case '\r': //Form Feed, page eject 0C 12 { - v19 = v18 - 2; - if ( v19 )//>0 - { - if ( v19 == 1 )//v15 == 13 - { - strncpy(&Str, Sourcea, 3u); - v26 = 0; - Str1b += 3; - Sourcea += 3; - v22 = atoi(&Str); - v23 = pFont->GetLineWidth(&pTmpBuf2[Str1b]); - v13 = pWindow->uFrameZ - v23 - v22; - v14 = uY; - } - else//v15 > 13 - { - v20 = *((int *)&pFont->cFirstChar + 3 * v16 + 9); - v34 = *((int *)&pFont->cFirstChar + 3 * v16 + 9); - if ( (signed int)Str1b > 0 ) - v13 += pFont->pMetrics[v16].uLeftSpacing; - v21 = (int)((char *)&pFont[1] + pFont->font_pixels_offset[v16]); - if ( (short)uColor ) - pRenderer->DrawText(v13, v14, (unsigned __int8 *)v21, v20, LOBYTE(pFont->uFontHeight), pFont->pFontPalettes[0], uColor, 0); - else - pRenderer->DrawTextPalette(v13, v14, v21, v20, LOBYTE(pFont->uFontHeight), pFont->pFontPalettes[0], 0); - v13 += v34; - if ( (signed int)Str1b < (signed int)pNumLen ) - v13 += pFont->pMetrics[(unsigned __int8)pTmpBuf2[Str1b]].uRightSpacing; - } - } - else//v15 == 12 - { - strncpy(&Str, Sourcea, 5u); - v27 = 0; - Str1b += 5; - Sourcea += 5; - uColor = atoi(&Str); - } + strncpy(Str, &pTmpBuf2[i+1], 5); + Str[5] = 0; + i += 5; + uColor = atoi(Str); + break; + } + case '\f': //Carriage Return 0D 13 + { + strncpy(Str, &pTmpBuf2[i+1], 3); + Str[3] = 0; + i += 3; + v23 = pFont->GetLineWidth(&pTmpBuf2[i]); + v13 = pWindow->uFrameZ - v23 - atoi(Str); + v14 = uY; + break; } - else//v15 == 10 - { - v24 = LOBYTE(pFont->uFontHeight); - v13 = uX; - uY = uY + v24 - 3; - v14 = v24 + uY - 3; - } - } - else//v15 == 9 - { - strncpy(&Str, Sourcea, 3u); - v26 = 0; - atoi(&Str); - Str1b += 3; - Sourcea += 3; - } + default: + v20 = pFont->pMetrics[v15].uWidth; + if ( i > 0 ) + v13 += pFont->pMetrics[v15].uLeftSpacing; + v21 = &pFont->pFontData[pFont->font_pixels_offset[v15]]; + if ( uColor ) + pRenderer->DrawText(v13, v14, v21, v20, pFont->uFontHeight, pFont->pFontPalettes[0], uColor, 0); + else + pRenderer->DrawTextPalette(v13, v14, v21, v20, pFont->uFontHeight, pFont->pFontPalettes[0], 0); + v13 += v20; + if ( i < (signed int)pNumLen ) + v13 += pFont->pMetrics[v15].uRightSpacing; + } } - ++Str1b; - ++Sourcea; - } - while ( (signed int)Str1b < (signed int)pNumLen ); + + } return v28; } @@ -1597,25 +1558,23 @@ pButton = (GUIButton *)pAllocator->AllocNamedChunk(0, 0xBCu, "BUTTON"); pButton->pParent = this; - pButton->uX = uX + this->uFrameX; - v13 = uY + this->uFrameY; + pButton->uWidth = uWidth; pButton->uHeight = uHeight; - pButton->uY = v13; - pButton->uWidth = uWidth; + if ( a6 == 2 && !uHeight ) pButton->uHeight = uWidth; - v14 = pButton->uX; + pButton->uButtonType = a6; - v15 = v14 + uWidth - 1; - pButton->uZ = v15; - v17 = pButton->uY; + pButton->uX = uX + this->uFrameX; + pButton->uY = uY + this->uFrameY; + pButton->uZ = pButton->uX + uWidth - 1; + pButton->uW = pButton->uY + uHeight - 1; pButton->field_2C_is_pushed = 0; - pButton->uW = v17 + uHeight - 1; pButton->field_1C = a7; pButton->msg = msg; pButton->msg_param = msg_param; pButton->uHotkey = uHotkey; - strlen(pName); + //strlen(pName); strcpy(pButton->pButtonName, pName); va_start(texturs_ptr, pName); while (NULL!=(pTextures=va_arg(texturs_ptr, Texture *))) @@ -1637,20 +1596,15 @@ } //----- (00459C2B) -------------------------------------------------------- -void GUIWindow::DrawFlashingInputCursor(signed int a3, int a4, GUIFont *a2) -{ - signed int v4; // esi@1 - GUIWindow *v5; // edi@1 - - v4 = a3; - v5 = this; +void GUIWindow::DrawFlashingInputCursor( signed int uX, int uY, struct GUIFont *a2 ) + { if ( GetTickCount() % 1000 > 500 ) - DrawText(a2, v4, a4, 0, "_", 0, 0, 0); + DrawText(a2, uX, uY, 0, "_", 0, 0, 0); } //----- (0041C432) -------------------------------------------------------- -GUIWindow *GUIWindow::Create(unsigned int uX, unsigned int uY, unsigned int uWidth, unsigned int uHeight, WindowType eWindowType, int pButton, int a5) -{ +GUIWindow * GUIWindow::Create( unsigned int uX, unsigned int uY, unsigned int uWidth, unsigned int uHeight, enum WindowType eWindowType, int pButton, const char* hint ) + { unsigned int uNextFreeWindowID; // ebp@1 //int *v8; // eax@1 //GUIWindow *pWindow; // esi@4 @@ -1679,15 +1633,16 @@ auto pWindow = &pWindowList[uNextFreeWindowID]; pWindow->uFrameWidth = uWidth; + pWindow->uFrameHeight = uHeight; + + pWindow->uFrameX = uX; + pWindow->uFrameY = uY; pWindow->uFrameZ = uX + uWidth - 1; pWindow->uFrameW = uY + uHeight - 1; + pWindow->ptr_1C = (void *)pButton; - pWindow->Hint = (char *)a5; - //v10 = uNumVisibleWindows; - pWindow->uFrameX = uX; - //++v10; - pWindow->uFrameY = uY; - pWindow->uFrameHeight = uHeight; + pWindow->Hint = hint; + pWindow->eWindowType = eWindowType; pWindow->receives_keyboard_input = false; ++uNumVisibleWindows; @@ -1699,10 +1654,11 @@ { switch (eWindowType) { - case WINDOW_Book: + case WINDOW_Book: { pWindow->InitializeBookView(); break; - case WINDOW_Dialogue: + } + case WINDOW_Dialogue: { pMainScreenNum = pCurrentScreen; pCurrentScreen = SCREEN_NPC_DIALOGUE; pBtn_ExitCancel = pWindow->CreateButton(0x1D7u, 0x1BDu, 0xA9u, 0x23u, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], //"Exit" @@ -1794,8 +1750,8 @@ pWindow->_41D08F_set_keyboard_control_group(num_menu_buttons, 1, 0, 1); } break; - - case WINDOW_ChangeLocation: + } + case WINDOW_ChangeLocation: { pMainScreenNum = pCurrentScreen; pCurrentScreen = SCREEN_CHANGE_LOCATION; pBtn_ExitCancel = pWindow->CreateButton( 566, 445, 75, 33, 1, 0, UIMSG_CHANGE_LOCATION_ClickCencelBtn, 0, 'N', pGlobalTXT_LocalizationStrings[156], pIcons_LOD->GetTexture(uTextureID_BUTTDESC2), 0);//Остаться в этой области @@ -1803,16 +1759,19 @@ pWindow->CreateButton(pNPCPortraits_x[0][0], pNPCPortraits_y[0][0], 63, 73, 1, 0, UIMSG_OnTravelByFoot, 1, ' ', pWindow->Hint, 0, 0, 0); pWindow->CreateButton( 8, 8, 460, 344, 1, 0, UIMSG_OnTravelByFoot, 1, 0, pWindow->Hint, 0); break; - - case WINDOW_SpellBook: // окно книги заклов + } + case WINDOW_SpellBook: {// окно книги заклов InitializeBookTextures(); pWindow->OpenSpellBook(); break; - case WINDOW_GreetingNPC: // окно приветствия НПС + } + case WINDOW_GreetingNPC: {// окно приветствия НПС pMainScreenNum = pCurrentScreen; pKeyActionMap->EnterText(0, 15, pWindow); pCurrentScreen = SCREEN_BRANCHLESS_NPC_DIALOG; break; + } + } return pWindow; } @@ -1842,7 +1801,7 @@ if ( v26 || !dword_591080 ) v27 = HouseNPCData[v26 +1 - (dword_591080 != 0)]->pName; else - v27 = (char *)p2DEvents[pButton - 1].pProprieterName; + v27 = (char*)p2DEvents[pButton - 1].pProprieterName; v30 = v27; v29 = (char*)pGlobalTXT_LocalizationStrings[435]; } @@ -1879,7 +1838,6 @@ return pWindow; } if (eWindowType == WINDOW_Scroll) - //goto LABEL_62; { pWindow->CreateButton(0x3Du, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 1u, '1', "", 0); pWindow->CreateButton(0xB1u, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 2u, '2', "", 0);