Change inventory text rendering

This commit is contained in:
Kaehvaman 2024-10-28 20:27:37 +04:00
parent f89b7120bd
commit 260e17e609
2 changed files with 39 additions and 25 deletions

View File

@ -88,6 +88,7 @@ ATOM MyRegisterClass(HINSTANCE hInstance)
#define N 15 #define N 15
#define WIDTH 50 #define WIDTH 50
#define HEIGHT 50 #define HEIGHT 50
#define VOFFSET 50
// //
// ФУНКЦИЯ: InitInstance(HINSTANCE, int) // ФУНКЦИЯ: InitInstance(HINSTANCE, int)
@ -106,7 +107,7 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
// стиль окна без кнопки разворачивания на весь экран и без возможности измения размера // стиль окна без кнопки разворачивания на весь экран и без возможности измения размера
int wstyle = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX); int wstyle = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
RECT wnd = { 0, 0, N * WIDTH, M * HEIGHT }; // желаемый размер клиентской области окна RECT wnd = { 0, 0, N * WIDTH, M * HEIGHT + VOFFSET}; // желаемый размер клиентской области окна
AdjustWindowRectEx(&wnd, wstyle, 1, WS_EX_COMPOSITED); AdjustWindowRectEx(&wnd, wstyle, 1, WS_EX_COMPOSITED);
int width = wnd.right - wnd.left; int width = wnd.right - wnd.left;
@ -278,6 +279,12 @@ void drawMap(HDC hdc) {
} }
} }
void drawBottomBar(HDC hdc) {
HBRUSH hBrush = CreateSolidBrush(RGB(30, 30, 30));
RECT r = { 0, HEIGHT * M, WIDTH * N, HEIGHT * M + VOFFSET };
FillRect(hdc, &r, hBrush);
}
void drawPlayer(HDC hdc) { void drawPlayer(HDC hdc) {
HBRUSH hBrushMan = CreateSolidBrush(RGB(0, 0, 255)); // синий HBRUSH hBrushMan = CreateSolidBrush(RGB(0, 0, 255)); // синий
int x1 = player_x * WIDTH; int x1 = player_x * WIDTH;
@ -344,8 +351,6 @@ int clip(int n, int lower, int upper) {
return max(lower, min(n, upper)); return max(lower, min(n, upper));
} }
char count_string[50];
bool netToggle = false; bool netToggle = false;
enum keyboard { enum keyboard {
@ -399,20 +404,29 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
drawMap(hdc); drawMap(hdc);
drawPlayer(hdc); drawPlayer(hdc);
drawBottomBar(hdc);
if (netToggle) drawNet(hdc); if (netToggle) drawNet(hdc);
if (selected_element == gold) sprintf(count_string, "gold = %d", inventory[gold]); char gold_string[50];
else if (selected_element == wall) sprintf(count_string, "wall = %d", inventory[wall]); char wall_string[50];
else sprintf(count_string, "not selected");
sprintf(gold_string, " gold = %d", inventory[gold]);
RECT textrect = { 0, 0, 150, 50 }; sprintf(wall_string, " wall = %d", inventory[wall]);
HFONT hFont = CreateFontW(23, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS, PROOF_QUALITY, VARIABLE_PITCH, TEXT("SegoeUI")); if (selected_element == gold) gold_string[0] = '>';
else if (selected_element == wall) wall_string[0] = '>';
RECT textrect = { WIDTH / 4, HEIGHT * M, 150, HEIGHT * M + VOFFSET };
HFONT hFont = CreateFontW(24, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS, PROOF_QUALITY, VARIABLE_PITCH, TEXT("Consolas"));
SelectObject(hdc, hFont); SelectObject(hdc, hFont);
SetTextColor(hdc, RGB(78, 201, 176));
//SetBkColor(hdc, RGB(255, 0, 0)); //SetBkColor(hdc, RGB(255, 0, 0));
//SetBkMode(hdc, TRANSPARENT); SetBkMode(hdc, TRANSPARENT);
DrawTextA(hdc, count_string, -1, &textrect, (DT_SINGLELINE | DT_TOP | DT_CENTER)); DrawTextA(hdc, gold_string, -1, &textrect, (DT_SINGLELINE | DT_TOP | DT_LEFT));
DrawTextA(hdc, wall_string, -1, &textrect, (DT_SINGLELINE | DT_BOTTOM | DT_LEFT));
DeleteObject(hFont); DeleteObject(hFont);

View File

@ -1,13 +1,13 @@
10 15 10 15
3 0 0 0 0 0 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 0 0 0 3 3 2 2
3 0 0 0 0 0 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 0 0 0 3 2 2 2
3 0 0 0 0 0 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 0 0 0 0 3 2 2 2
3 0 0 0 0 0 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 0 0 0 0 3 2 2 2
3 0 0 0 0 0 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 0 0 0 3 3 2 2 2
3 3 0 0 0 0 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 0 0 0 3 3 2 2 2
3 3 0 0 0 0 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 0 0 0 0 3 2 2 2
3 3 0 0 0 0 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 0 0 0 0 3 2 2 2
3 3 0 0 0 0 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 0 0 0 0 3 2 2 2
3 3 0 0 0 0 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 0 0 0 0 3 3 2 2
0 0 0 0 0 0 0 1
5 4 2 3 4 3