์์ :)
https://github.com/eazuooz/WindowAPI/commit/c76d9a833dc8bd2fdaf7feb3fbcac92c9ee2f813
TileMap Tool · eazuooz/WindowAPI@c76d9a8
Show file tree Showing 31 changed files with 891 additions and 170 deletions.
github.com
ํ์ผ๋งต์ด๋? ์ผ์ ํ ํฌ๊ธฐ์ ๋ชจ์์ ๊ฐ์ง ๊ทธ๋ฆผ ์กฐ๊ฐ๋ค์ ์๋ฏธํ๊ณ , ๊ฒ์์์๋ ์ด๋ค ์กฐ๊ฐ์ ๋ง์ถ์ด์ ๊ฒ์์ ๋ฐฐ๊ฒฝ์ ์์ฑ์ ํ๊ธฐ๋ ํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ ์ด๋ ๊ฒ ์์ฑ์ด ๋ ๋ฐฐ๊ฒฝ๋ค์ ๊ฐ๋ฆฌ์ผ์ 'ํ์ผ๋งต(TileMap)'์ด๋ผ๊ณ ๋ค ๋ถ๋ฆ ๋๋ค.

โถ ์ ์ด๋ฏธ์ง์ ๊ฐ์ด ๊ฒ์์์ ํ์ผ์ ์ด์ฉํด ๋ฐฐ๊ฒฝ๋งต์ ๋ง๋๋ ์ด์ ๋ ๊ฒ์์ ๋ฐฐ๊ฒฝ์ด ์ด์ ์ฑํฐ์์ ๊ณต๋ถ ํ๋ ํจ๋ด๋์ค๋
ธ๋์ ๊ฐ์ด ํฌ๊ณ ๋ํ ์ฅ๋ฉด(Scene)์ด ๋ง์ ๊ฒฝ์ฐ์ ๋ฐฐ๊ฒฝ์ด ๋๋ ๋นํธ๋งต์ ๋ชจ๋ ๋ฉ๋ชจ๋ฆฌ์ ์ฝ์ด๋ค์ฌ์ผ๋ง ํ๋ค๋ฉด ๋งค์ฐ ํฐ ๋ฉ๋ชจ๋ฆฌ๊ฐ ํ์ํ๊ธฐ ๋๋ฌธ์, ํ์ผ์ ์ฌ์ฉํด์ ๋ฐ๋ณตํ๊ฒ ๋๋ฉด์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ ๊ฒ ์ฌ์ฉํ๊ณ ๋ ๊ฒ์ํ๋ ์ด์ ํ์ํ ๋ฐฐ๊ฒฝ์ ๋ง๋ค ์ ์์ต๋๋ค.
๋ง์ฝ ์ ์ด๋ฏธ์ง๋ค์ ์ด์ฉํด์ ๊ฐ๋ก 20 ์ธ๋ก 10์ค๋ก ๊ตฌ์ฑ ๋ ๋ฐฐ๊ฒฝ์ ๊ตฌ์ฑํ๊ฒ ๋๋ค๋ฉด ํ์ผ์ด ์ด 200๊ฐ๋ก ๊ตฌ์ฑ์ด ๋๊ฒ์ธ๊ฐ์? ๋ต์ ๊ทธ๋ ์ง ์์ต๋๋ค. ์๋ํ๋ฉด ๊ฐ์ ์กฐ๊ฐ๋ค ์ฆ, ํ
์ค์ฒ๋ค์ ๊ทธ๋๋ก ๊ฐ๋ค ๋ถ์ฌ์ ์ฌ์ฉํ๋ฉด ๋๊ธฐ ๋๋ฌธ์ด์ง์. ๋งต์ด ์ปค์ง์๋ก ํ์ผ๋งต์ ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ์ ์์ฃผ ์ ์ฉํ๊ฒ ์ฌ์ฉ์ด ๋ฉ๋๋ค.
์ด๋ฒ์๊ฐ์๋ ์ด๋ฐ ํ์ผ๋งต์ ์ ์ํ๊ธฐ ์ํ Tool์ ์ ์ํด๋ณด๋ ค ํ๋ค.
์ด๋ค ํ์ผ๋ค์ ์ ํํด์ผํ ์ง ์ด๋ฏธ์ง๋ฅผ ๋์ธ ์๋ก์ด ์๋์ฐ๋ฅผ ์์ฑํด๋ณผ๊ฒ์ด๋ค.
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; // ์ธ์คํด์ค ํธ๋ค์ ์ ์ญ ๋ณ์์ ์ ์ฅํฉ๋๋ค.
HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
if (!hWnd)
return FALSE;
//์๋์ฐ ํฌ์ง์
๋ฐ ํฌ๊ธฐ ์ค์
ya::WindowData windowData;
windowData.hWnd = hWnd;
windowData.height = 900;
windowData.width = 1600;
SetWindowPos(hWnd, nullptr, 0, 0, windowData.width, windowData.height, 0);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
ya::Application::GetInstance().Initialize(windowData);
if (ya::SceneManager::GetSecneType() != eSceneType::Tool)
return TRUE;
//ATLAS
hWnd = CreateWindowW(L"AtlasWindow", L"Atlas", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
if (!hWnd)
return FALSE;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
์๋์ฐ๋ฅผ ์์ฑํด์ค๋ ์ด์ ๋ 1๊ฐ์ ์๋์ฐ๊ฐ ์๋ 2๊ฐ์ ์๋์ฐ๋ฅผ ์์ฑํด์ค๋ค.
๊ทธ๋ฆฌ๊ณ 2๋ฒ์จฐ ์๋์ฐ๋ ๋ค์๊ณผ ๊ฐ์ด ์ด๋ฏธ์ง ํฌ๊ธฐ์ ๋ง์ถ์ด ์๋์ฐ ํฌ๊ธฐ๋ฅผ ์ง์ ํด์ฃผ๊ณ
๋ง์ฐ์ค ํด๋ฆญ์ ํด๋น ์ด๋ฏธ์ง์ ์ธ๋ฑ์ค ๋ฒํธ๋ฅผ ๊ฐ์ ธ์ฌ์ ์๋๋ก ์ค์ ํด์ค ๊ฒ์ด๋ค.
LRESULT CALLBACK AtlasWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
{
DefWindowProc(hWnd, message, wParam, lParam);
ya::WindowData atlasWindowData;
atlasWindowData.hWnd = hWnd;
atlasWindowData.hdc = GetDC(hWnd);
atlasWindowData.height = 900;
atlasWindowData.width = 800;
ya::Application::GetInstance().SetAtlasWindow(atlasWindowData);
ya::Scene* pScene = ya::SceneManager::GetPlayScene();
ya::ToolScene* toolScene = dynamic_cast<ya::ToolScene*>(pScene);
ya::TilePalatte* atlas = toolScene->GetTilePalatte();
ya::Image* atlamsImg = atlas->GetImage();
RECT rect = { 0, 0, atlamsImg->GetWidth(), atlamsImg->GetHeight()};
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, false);
SetWindowPos(atlasWindowData.hWnd
, nullptr, 1600, 0
, rect.right - rect.left
, rect.bottom - rect.top
, 0);
ShowWindow(atlasWindowData.hWnd, true);
}
break;
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
// ๋ฉ๋ด ์ ํ์ ๊ตฌ๋ฌธ ๋ถ์ํฉ๋๋ค:
switch (wmId)
{
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
//Rectangle(GetDC(hWnd), 0, 0, 100, 100);
ya::Scene* pScene = ya::SceneManager::GetPlayScene();
ya::ToolScene* toolScene = dynamic_cast<ya::ToolScene*>(pScene);
ya::TilePalatte* atlas = toolScene->GetTilePalatte();
ya::Image* atlamsImg = atlas->GetImage();
ya::Vector2 pos(ya::Vector2::Zero);
TransparentBlt(hdc, (int)pos.x
, (int)pos.y
, atlamsImg->GetWidth(), atlamsImg->GetHeight()
, atlamsImg->GetHdc(), 0, 0, atlamsImg->GetWidth(), atlamsImg->GetHeight(), RGB(255, 0, 255));
// TODO: ์ฌ๊ธฐ์ hdc๋ฅผ ์ฌ์ฉํ๋ ๊ทธ๋ฆฌ๊ธฐ ์ฝ๋๋ฅผ ์ถ๊ฐํฉ๋๋ค...
EndPaint(hWnd, &ps);
}
break;
case WM_LBUTTONDOWN:
{
if (GetFocus())
{
POINT mousePos = {};
GetCursorPos(&mousePos);
ScreenToClient(hWnd, &mousePos);
// ๊ฐ๋ก 8 ์ธ๋ก 6
int x = mousePos.x / TILE_SIZE;
int y = mousePos.y / TILE_SIZE;
int index = (y * 8) + (x % 8);
ya::Scene* pScene = ya::SceneManager::GetPlayScene();
ya::ToolScene* toolScene = dynamic_cast<ya::ToolScene*>(pScene);
toolScene->SetTileIndex(index);
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
๊ทธ๋ผ ์ฐ์ธก ์๋จ์ ๋ค์๊ณผ ๊ฐ์ ์๋์ฐ๊ฐ ์๊ธฐ๊ฒ ๋ ๊ฒ์ด๋ค.
์ด์ ์ข์ธก ์๋์ฐ์ ์ค๋ฅธ์ชฝ์ผ๋ก ํด๋ฆญ๋ ํ์ผ์ ์ค์นํ ์ ์๋๋ก ํด์ฃผ๋ฉด ๋๋ค.
๊ทธ์์ ์ TilePalatte๋ผ๋ ํด๋์ค์์ ์งํํ ๊ฒ์ธ๋ฐ ํ์ผ์ ์์ฑ ๊ด๋ฆฌ ๋ฑ ๋ชจ๋ ๊ฒ๋ค์
๊ด๋ฆฌํด์ฃผ๋ ํด๋์ค์ด๋ค.
void TilePalatte::Tick()
{
if (KEY_PREESED(KEY_CODE::LBTN))
{
if (GetFocus())
{
POINT pos = GetTilePos();
Scene* pScene = SceneManager::GetPlayScene();
ToolScene* toolScene = dynamic_cast<ToolScene*>(pScene);
CreateTile(toolScene->GetTileIndex(), Vector2(pos.x, pos.y));
}
}
}
์ถ๊ฐ์ ์ผ๋ก ์์ฑ๋ ํ์ผ์ ์ ์ฅํ๊ณ ๋ถ๋ฌ์ฌ์ ์๋ ๊ธฐ๋ฅ๋ ์ถ๊ฐ ํด์ฃผ์๋ค.
void TilePalatte::Save()
{
// open a file name
OPENFILENAME ofn = {};
wchar_t szFilePath[256] = {};
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.lpstrFile = szFilePath;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = 256;
ofn.lpstrFilter = L"Tile\0*.tile\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (false == GetSaveFileName(&ofn))
return;
// ํ์ผ ์
์ถ๋ ฅ
FILE* pFile = nullptr;
// ์ฐ๊ธฐ ๋ชจ๋๋ก ์ด๊ธฐ
_wfopen_s(&pFile, szFilePath, L"wb");
if (nullptr == pFile)
return;
std::unordered_map<UINT64, Tile*>::iterator iter = mTiles.begin();
for (; iter != mTiles.end(); ++iter)
{
int index = (*iter).second->GetIndex();
fwrite(&index, sizeof(int), 1, pFile);
TileID id;
id.ID = (*iter).first;
fwrite(&id.ID, sizeof(UINT64), 1, pFile);
}
fclose(pFile);
}
void TilePalatte::Load()
{
OPENFILENAME ofn = {};
wchar_t szFilePath[256] = {};
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.lpstrFile = szFilePath;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = 256;
ofn.lpstrFilter = L"All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (false == GetOpenFileName(&ofn))
return;
FILE* pFile = nullptr;
_wfopen_s(&pFile, szFilePath, L"rb");
if (pFile == nullptr)
return;
while (true)
{
int index = 0;
TileID id;
if (fread(&index, sizeof(int), 1, pFile) == NULL)
break;
if (fread(&id, sizeof(UINT64), 1, pFile) == NULL)
break;
CreateTile(index, Vector2(id.left, id.right));
}
fclose(pFile);
}
'๐ Development Study > ๐ป Win32API' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Gravity (0) | 2022.11.09 |
---|---|
UIManager, UIBase (0) | 2022.11.09 |
Clone Object(๋ณต์ฌ ์์ฑ์) (0) | 2022.10.26 |
Rigidbody (0) | 2022.10.20 |
API Math (0) | 2022.10.20 |
๋๊ธ