TileSetBrowserView.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  1. /*
  2. FinalSun/FinalAlert 2 Mission Editor
  3. Copyright (C) 1999-2024 Electronic Arts, Inc.
  4. Authored by Matthias Wagner
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. */
  16. // TileSetBrowserView.cpp: Implementierungsdatei
  17. //
  18. #include "stdafx.h"
  19. #include "finalsun.h"
  20. #include "TileSetBrowserView.h"
  21. #include "FinalSunDlg.h"
  22. #include "mapdata.h"
  23. #include "variables.h"
  24. #include "functions.h"
  25. extern ACTIONDATA AD;
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CTileSetBrowserView
  33. IMPLEMENT_DYNCREATE(CTileSetBrowserView, CScrollView)
  34. CTileSetBrowserView::CTileSetBrowserView()
  35. {
  36. m_lpDDS = NULL;
  37. m_bottom_needed = 1000;
  38. m_CurrentMode = 0;
  39. }
  40. CTileSetBrowserView::~CTileSetBrowserView()
  41. {
  42. if (m_lpDDS)
  43. {
  44. int i;
  45. for (i = 0;i < m_tilecount;i++)
  46. {
  47. if (m_lpDDS[i]) m_lpDDS[i]->Release();
  48. }
  49. delete[] m_lpDDS;
  50. }
  51. m_lpDDS = NULL;
  52. }
  53. BEGIN_MESSAGE_MAP(CTileSetBrowserView, CScrollView)
  54. //{{AFX_MSG_MAP(CTileSetBrowserView)
  55. ON_WM_LBUTTONDOWN()
  56. ON_WM_VSCROLL()
  57. //}}AFX_MSG_MAP
  58. END_MESSAGE_MAP()
  59. /////////////////////////////////////////////////////////////////////////////
  60. // Zeichnung CTileSetBrowserView
  61. void CTileSetBrowserView::OnInitialUpdate()
  62. {
  63. CScrollView::OnInitialUpdate();
  64. }
  65. // for fast overlay drawing use IsoView´s overlay table
  66. extern PICDATA* ovrlpics[0xFF][max_ovrl_img];
  67. void CTileSetBrowserView::OnDraw(CDC* pDC)
  68. {
  69. //ReleaseDC(pDC);
  70. if (((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->b_IsLoading || ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->lpds == NULL || ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->lpds->IsLost() != DD_OK)
  71. return;
  72. RECT r;
  73. GetClientRect(&r);
  74. if (tiledata == NULL || (*tiledata) == NULL)
  75. return;
  76. if (m_tilecount == 0)
  77. return;
  78. if (m_tile_width == 0)
  79. return; // just to make sure I never divide through 0 here...
  80. int max_r = r.right / m_tile_width;
  81. int cur_y = 0;
  82. int cur_x = 0;
  83. if (m_CurrentMode == 1)
  84. {
  85. DWORD dwID = GetTileID(m_currentTileSet, 0);
  86. int i;
  87. for (i = 0;i < m_tilecount;i++)
  88. {
  89. char c[50];
  90. itoa(i, c, 10);
  91. int curwidth = (*tiledata)[dwID].rect.right - (*tiledata)[dwID].rect.left;
  92. int curheight = GetAddedHeight(dwID) + (*tiledata)[dwID].rect.bottom - (*tiledata)[dwID].rect.top;
  93. //pDC.TextOut(cur_x, cur_y, c);
  94. #ifdef RA2_MODE
  95. if ((m_currentTileSet == 80 && Map->GetTheater() == "TEMPERATE") || (m_currentTileSet == 73 && Map->GetTheater() == "SNOW") || (m_currentTileSet == 101 && Map->GetTheater() == "URBAN"))
  96. {
  97. if (i == 10 || i == 15)
  98. {
  99. dwID++; // don´t forget this here, too
  100. continue;
  101. }
  102. }
  103. #endif
  104. if (!m_lpDDS[i]) continue;
  105. RECT r;
  106. GetClientRect(&r);
  107. if (cur_y + curheight + (m_tile_height - curheight) / 2 >= this->GetScrollPos(SB_VERT) && cur_y <= GetScrollPos(SB_VERT) + r.bottom)
  108. {
  109. HDC hDC = NULL;
  110. m_lpDDS[i]->GetDC(&hDC);
  111. HDC hTmpDC = CreateCompatibleDC(hDC);
  112. HBITMAP hBitmap = CreateCompatibleBitmap(hDC, curwidth, curheight);
  113. SelectObject(hTmpDC, hBitmap);
  114. BitBlt(hTmpDC, 0, 0, curwidth, curheight, hDC, 0, 0, SRCCOPY);
  115. m_lpDDS[i]->ReleaseDC(hDC);
  116. BitBlt(pDC->GetSafeHdc(), cur_x + (m_tile_width - curwidth) / 2, cur_y + (m_tile_height - curheight) / 2, curwidth, curheight, hTmpDC, 0, 0, SRCCOPY);
  117. DeleteDC(hTmpDC);
  118. DeleteObject(hBitmap);
  119. if (AD.mode == ACTIONMODE_SETTILE && AD.type == dwID)
  120. {
  121. CPen p;
  122. CBrush b;
  123. p.CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
  124. b.CreateStockObject(NULL_BRUSH);
  125. CPen* old = pDC->SelectObject(&p);
  126. pDC->SetBkMode(TRANSPARENT);
  127. pDC->SelectObject(&b);
  128. pDC->Rectangle(cur_x + 2, cur_y + 2, cur_x + m_tile_width - 2, cur_y + m_tile_height - 2);
  129. pDC->SelectObject(old);
  130. }
  131. }
  132. cur_x += m_tile_width;
  133. if (max_r == 0) max_r = 1;
  134. if (i % max_r == max_r - 1)
  135. {
  136. cur_y += m_tile_height;
  137. cur_x = 0;
  138. }
  139. dwID++;
  140. }
  141. }
  142. #ifndef NOSURFACES
  143. else if (m_CurrentMode == 2)
  144. {
  145. int i;
  146. for (i = 0;i < max_ovrl_img;i++)
  147. {
  148. PICDATA* p = ovrlpics[m_currentOverlay][i];
  149. if (p != NULL && p->pic != NULL)
  150. {
  151. DDSURFACEDESC2 desc;
  152. memset(&desc, 0, sizeof(DDSURFACEDESC2));
  153. desc.dwSize = sizeof(DDSURFACEDESC2);
  154. desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
  155. p->pic->GetSurfaceDesc(&desc);
  156. int curwidth = desc.dwWidth;
  157. int curheight = desc.dwHeight;
  158. HDC hDC = NULL;
  159. p->pic->GetDC(&hDC);
  160. HDC hTmpDC = CreateCompatibleDC(hDC);
  161. HBITMAP hBitmap = CreateCompatibleBitmap(hDC, curwidth, curheight);
  162. SelectObject(hTmpDC, hBitmap);
  163. BitBlt(hTmpDC, 0, 0, curwidth, curheight, hDC, 0, 0, SRCCOPY);
  164. p->pic->ReleaseDC(hDC);
  165. BitBlt(pDC->GetSafeHdc(), cur_x + (m_tile_width - curwidth) / 2, cur_y + (m_tile_height - curheight) / 2, curwidth, curheight, hTmpDC, 0, 0, SRCCOPY);
  166. DeleteDC(hTmpDC);
  167. DeleteObject(hBitmap);
  168. if (AD.mode == ACTIONMODE_PLACE && AD.data2 == m_currentOverlay && AD.data3 == i && AD.data == 33 && AD.type == 6)
  169. {
  170. CPen p;
  171. CBrush b;
  172. p.CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
  173. b.CreateStockObject(NULL_BRUSH);
  174. CPen* old = pDC->SelectObject(&p);
  175. pDC->SetBkMode(TRANSPARENT);
  176. pDC->SelectObject(&b);
  177. pDC->Rectangle(cur_x + 2, cur_y + 2, cur_x + m_tile_width - 2, cur_y + m_tile_height - 2);
  178. pDC->SelectObject(old);
  179. }
  180. cur_x += m_tile_width;
  181. if (max_r == 0) max_r = 1;
  182. if (i % max_r == max_r - 1)
  183. {
  184. cur_y += m_tile_height;
  185. cur_x = 0;
  186. }
  187. }
  188. }
  189. }
  190. #else
  191. else if (m_CurrentMode == 2)
  192. {
  193. int i;
  194. for (i = 0;i < max_ovrl_img;i++)
  195. {
  196. PICDATA* p = ovrlpics[m_currentOverlay][i];
  197. if (p != NULL && p->pic != NULL)
  198. {
  199. int curwidth = p->wMaxWidth;
  200. int curheight = p->wMaxHeight;
  201. BITMAPINFO biinfo;
  202. memset(&biinfo, 0, sizeof(BITMAPINFO));
  203. biinfo.bmiHeader.biBitCount = 24;
  204. biinfo.bmiHeader.biWidth = curwidth;
  205. biinfo.bmiHeader.biHeight = curheight;
  206. biinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  207. biinfo.bmiHeader.biClrUsed = 0;
  208. biinfo.bmiHeader.biPlanes = 1;
  209. biinfo.bmiHeader.biCompression = BI_RGB;
  210. biinfo.bmiHeader.biClrImportant = 0;
  211. int pitch = curwidth * 3;
  212. if (pitch == 0)
  213. continue;
  214. if (pitch % sizeof(DWORD))
  215. {
  216. pitch += sizeof(DWORD) - (curwidth * 3) % sizeof(DWORD);
  217. }
  218. BYTE* colors = new(BYTE[pitch * curheight]);
  219. memset(colors, 255, pitch * (curheight));
  220. RGBTRIPLE* pal = palIso;
  221. if (p->pal == iPalTheater)
  222. pal = palTheater;
  223. if (p->pal == iPalUnit)
  224. pal = palUnit;
  225. int k, l;
  226. for (k = 0;k < curheight;k++)
  227. {
  228. for (l = 0;l < curwidth;l++)
  229. {
  230. if (((BYTE*)p->pic)[l + k * curwidth])
  231. {
  232. memcpy(&colors[l * 3 + (curheight - k - 1) * pitch], &pal[((BYTE*)p->pic)[l + k * curwidth]], 3);
  233. }
  234. }
  235. }
  236. StretchDIBits(pDC->GetSafeHdc(), cur_x + (m_tile_width - curwidth) / 2, cur_y + (m_tile_height - curheight) / 2, curwidth, curheight,
  237. 0, 0, curwidth, curheight, colors, &biinfo, DIB_RGB_COLORS, SRCCOPY);
  238. delete[] colors;
  239. if (AD.mode == ACTIONMODE_PLACE && AD.data2 == m_currentOverlay && AD.data3 == i && AD.data == 33 && AD.type == 6)
  240. {
  241. CPen p;
  242. CBrush b;
  243. p.CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
  244. b.CreateStockObject(NULL_BRUSH);
  245. CPen* old = pDC->SelectObject(&p);
  246. pDC->SetBkMode(TRANSPARENT);
  247. pDC->SelectObject(&b);
  248. pDC->Rectangle(cur_x + 2, cur_y + 2, cur_x + m_tile_width - 2, cur_y + m_tile_height - 2);
  249. pDC->SelectObject(old);
  250. }
  251. cur_x += m_tile_width;
  252. if (max_r == 0)
  253. max_r = 1;
  254. if (i % max_r == max_r - 1)
  255. {
  256. cur_y += m_tile_height;
  257. cur_x = 0;
  258. }
  259. }
  260. }
  261. }
  262. #endif
  263. }
  264. /////////////////////////////////////////////////////////////////////////////
  265. // Diagnose CTileSetBrowserView
  266. #ifdef _DEBUG
  267. void CTileSetBrowserView::AssertValid() const
  268. {
  269. CScrollView::AssertValid();
  270. }
  271. void CTileSetBrowserView::Dump(CDumpContext& dc) const
  272. {
  273. CScrollView::Dump(dc);
  274. }
  275. #endif //_DEBUG
  276. /////////////////////////////////////////////////////////////////////////////
  277. // Behandlungsroutinen für Nachrichten CTileSetBrowserView
  278. void CTileSetBrowserView::PostNcDestroy()
  279. {
  280. // TODO: Speziellen Code hier einfügen und/oder Basisklasse aufrufen
  281. // CScrollView::PostNcDestroy();
  282. }
  283. DWORD CTileSetBrowserView::GetTileID(DWORD dwTileSet, DWORD dwType)
  284. {
  285. int i, e;
  286. DWORD tilecount = 0;
  287. for (i = 0;i < 10000;i++)
  288. {
  289. CString tset;
  290. char c[50];
  291. itoa(i, c, 10);
  292. int e;
  293. for (e = 0;e < 4 - strlen(c);e++)
  294. tset += "0";
  295. tset += c;
  296. CString sec = "TileSet";
  297. sec += tset;
  298. if (tiles->sections.find(sec) == tiles->sections.end())
  299. return 0xFFFFFFFF;
  300. for (e = 0;e < atoi(tiles->sections[sec].values["TilesInSet"]);e++)
  301. {
  302. if (i == dwTileSet && e == dwType)
  303. return tilecount;
  304. tilecount++;
  305. }
  306. }
  307. return tilecount;
  308. }
  309. void CTileSetBrowserView::SetTileSet(DWORD dwTileSet, BOOL bOnlyRedraw)
  310. {
  311. m_currentTileSet = dwTileSet;
  312. m_CurrentMode = 1;
  313. char currentTileSet[50];
  314. itoa(m_currentTileSet, currentTileSet, 10);
  315. CString tset;
  316. int e;
  317. for (e = 0;e < 4 - strlen(currentTileSet);e++)
  318. tset += "0";
  319. tset += currentTileSet;
  320. m_tile_width = 0;
  321. m_tile_height = 0;
  322. int i;
  323. int max = atoi(tiles->sections[(CString)"TileSet" + tset].values["TilesInSet"]);
  324. DWORD dwStartID = GetTileID(dwTileSet, 0);
  325. if ((*tiledata)[dwStartID].wTileCount && (*tiledata)[dwStartID].tiles[0].pic)
  326. {
  327. if (!bOnlyRedraw)
  328. {
  329. AD.mode = ACTIONMODE_SETTILE;
  330. AD.type = dwStartID;
  331. AD.data = 0;
  332. AD.data2 = 0;
  333. AD.z_data = 0;
  334. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_settingsbar.m_BrushSize = 0;
  335. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_settingsbar.UpdateData(FALSE);
  336. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_x = 1;
  337. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_y = 1;
  338. int i;
  339. for (i = 0;i < g_data.sections["StdBrushSize"].values.size();i++)
  340. {
  341. CString n = *g_data.sections["StdBrushSize"].GetValueName(i);
  342. if ((*tiles).sections["General"].FindName(n) >= 0)
  343. {
  344. int tset = atoi((*tiles).sections["General"].values[n]);
  345. if (tset == m_currentTileSet)
  346. {
  347. int bs = atoi(*g_data.sections["StdBrushSize"].GetValue(i));
  348. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_settingsbar.m_BrushSize = bs - 1;
  349. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_settingsbar.UpdateData(FALSE);
  350. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_x = bs;
  351. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_y = bs;
  352. }
  353. }
  354. }
  355. }
  356. }
  357. DWORD dwID;
  358. for (i = 0;i < max;i++)
  359. {
  360. CString str;
  361. char c[50];
  362. itoa(i, c, 10);
  363. for (e = 0;e < 2 - strlen(c);e++)
  364. str += "0";
  365. str += c;
  366. dwID = dwStartID + i; // just faster than always calling GetTileID()
  367. if (dwID < *tiledata_count)
  368. {
  369. if ((*tiledata)[dwID].rect.right - (*tiledata)[dwID].rect.left > m_tile_width) m_tile_width = (*tiledata)[dwID].rect.right - (*tiledata)[dwID].rect.left;
  370. if (GetAddedHeight(dwID) + (*tiledata)[dwID].rect.bottom - (*tiledata)[dwID].rect.top > m_tile_height) m_tile_height = GetAddedHeight(dwID) + (*tiledata)[dwID].rect.bottom - (*tiledata)[dwID].rect.top;
  371. }
  372. }
  373. m_tile_width += 6;
  374. m_tile_height += 6;
  375. if (m_lpDDS)
  376. {
  377. int i;
  378. for (i = 0;i < m_tilecount;i++)
  379. {
  380. if (m_lpDDS[i]) m_lpDDS[i]->Release();
  381. }
  382. delete[] m_lpDDS;
  383. }
  384. m_tilecount = max;
  385. m_lpDDS = new(LPDIRECTDRAWSURFACE4[m_tilecount]);
  386. for (i = 0;i < m_tilecount;i++)
  387. {
  388. m_lpDDS[i] = RenderTile(dwStartID + i);
  389. }
  390. RECT r;
  391. GetClientRect(&r);
  392. int max_r = r.right / m_tile_width;
  393. if (max_r <= 0) max_r = 1;
  394. m_bottom_needed = m_tile_height * (1 + m_tilecount / max_r);
  395. GetParentFrame()->RecalcLayout(TRUE);
  396. RedrawWindow();
  397. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->SetForegroundWindow();
  398. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->SetFocus();
  399. //DrawIt();
  400. }
  401. #ifdef NOSURFACES
  402. struct BlitRect
  403. {
  404. short left;
  405. short top;
  406. short right;
  407. short bottom;
  408. };
  409. __forceinline void BlitTerrainTSB(void* dst, int x, int y, int dleft, int dtop, int dpitch, int dright, int dbottom, SUBTILE& st)//BYTE* src, int swidth, int sheight)
  410. {
  411. BYTE* src = st.pic;
  412. unsigned short& swidth = st.wWidth;
  413. unsigned short& sheight = st.wHeight;
  414. if (src == NULL || dst == NULL)
  415. return;
  416. if (x + swidth < dleft || y + sheight < dtop)
  417. return;
  418. if (x >= dright || y >= dbottom)
  419. return;
  420. BlitRect blrect;
  421. BlitRect srcRect;
  422. srcRect.left = 0;
  423. srcRect.top = 0;
  424. srcRect.right = swidth;
  425. srcRect.bottom = sheight;
  426. blrect.left = x;
  427. if (blrect.left < 0)
  428. {
  429. srcRect.left = 1 - blrect.left;
  430. blrect.left = 1;
  431. }
  432. blrect.top = y;
  433. if (blrect.top < 0)
  434. {
  435. srcRect.top = 1 - blrect.top;
  436. blrect.top = 1;
  437. }
  438. blrect.right = (x + swidth);
  439. if (x + swidth > dright)
  440. {
  441. srcRect.right = dright - x;//swidth-((x+swidth)-dright);
  442. blrect.right = dright;
  443. }
  444. blrect.bottom = (y + sheight);
  445. if (y + sheight > dbottom)
  446. {
  447. srcRect.bottom = dbottom - y;//sheight-((y+sheight)-dbottom);
  448. blrect.bottom = dbottom;
  449. }
  450. short i, e;
  451. #ifdef NOSURFACES_EXTRACT
  452. int pos = 0;
  453. if (!st.bNotExtracted)
  454. {
  455. for (e = srcRect.top;e < srcRect.bottom;e++)
  456. {
  457. short& left = st.vborder[e].left;
  458. short& right = st.vborder[e].right;
  459. if (right >= left)
  460. {
  461. void* dest = ((BYTE*)dst + (blrect.left + left) * bpp + (blrect.top + e) * dpitch);
  462. memcpy(dest, &st.pic[pos], bpp * (right - left + 1));
  463. pos += (right - left + 1) * bpp;
  464. }
  465. }
  466. }
  467. else
  468. #endif
  469. for (e = srcRect.top;e < srcRect.bottom;e++)
  470. {
  471. short& left = st.vborder[e].left;
  472. short& right = st.vborder[e].right;
  473. for (i = left;i <= right;i++)
  474. {
  475. if (i < srcRect.left || i >= srcRect.right)
  476. {
  477. //dest+=bpp;
  478. }
  479. else
  480. {
  481. BYTE& val = src[i + e * swidth];
  482. if (val)
  483. {
  484. void* dest = ((BYTE*)dst + (blrect.left + i) * bpp + (blrect.top + e) * dpitch);
  485. memcpy(dest, &iPalIso[val], bpp);
  486. }
  487. }
  488. }
  489. }
  490. }
  491. #endif
  492. LPDIRECTDRAWSURFACE4 CTileSetBrowserView::RenderTile(DWORD dwID)
  493. {
  494. if (theApp.m_Options.bMarbleMadness)
  495. {
  496. if ((*tiledata)[dwID].wMarbleGround != 0xFFFF)
  497. {
  498. dwID = (*tiledata)[dwID].wMarbleGround;
  499. }
  500. }
  501. LPDIRECTDRAWSURFACE4 lpdds = NULL;
  502. LPDIRECTDRAW4 lpdd = ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->dd;
  503. DDSURFACEDESC2 ddsd;
  504. memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
  505. ddsd.dwSize = sizeof(DDSURFACEDESC2);
  506. ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
  507. ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
  508. int added_height = GetAddedHeight(dwID);
  509. ddsd.dwHeight = (*tiledata)[dwID].rect.bottom - (*tiledata)[dwID].rect.top + added_height;
  510. ddsd.dwWidth = (*tiledata)[dwID].rect.right - (*tiledata)[dwID].rect.left;
  511. if (lpdd->CreateSurface(&ddsd, &lpdds, NULL) != DD_OK)
  512. {
  513. return NULL;
  514. }
  515. DDBLTFX ddfx;
  516. memset(&ddfx, 0, sizeof(DDBLTFX));
  517. ddfx.dwSize = sizeof(DDBLTFX);
  518. lpdds->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &ddfx);
  519. int y_added = ddsd.dwHeight - ((*tiledata)[dwID].cx * f_y / 2 + (*tiledata)[dwID].cy * f_y / 2);
  520. int i, e, p = 0;;
  521. for (i = 0;i < (*tiledata)[dwID].cx;i++)
  522. {
  523. for (e = 0;e < (*tiledata)[dwID].cy;e++)
  524. {
  525. int drawx = e * f_x / 2 - i * f_x / 2 - (*tiledata)[dwID].rect.left;
  526. int drawy = e * f_y / 2 + i * f_y / 2 - (*tiledata)[dwID].rect.top;
  527. drawx += (*tiledata)[dwID].tiles[p].sX;
  528. drawy += added_height + (*tiledata)[dwID].tiles[p].sY - (*tiledata)[dwID].tiles[p].bZHeight * f_y / 2;
  529. //drawy+=y_added;
  530. if ((*tiledata)[dwID].tiles[p].pic)
  531. {
  532. RECT dest;
  533. dest.left = drawx;
  534. dest.top = drawy;
  535. dest.right = drawx + (*tiledata)[dwID].tiles[p].wWidth;
  536. dest.bottom = drawy + (*tiledata)[dwID].tiles[p].wHeight;
  537. DDBLTFX fx;
  538. memset(&fx, 0, sizeof(DDBLTFX));
  539. fx.dwSize = sizeof(DDBLTFX);
  540. #ifndef NOSURFACES
  541. if (lpdds->Blt(&dest, (*tiledata)[dwID].tiles[p].pic, NULL, DDBLT_KEYSRC, &fx) != DD_OK)
  542. TRACE("Blit failed\n");
  543. #else
  544. DDSURFACEDESC2 ddsd;
  545. ZeroMemory(&ddsd, sizeof(ddsd));
  546. ddsd.dwSize = sizeof(DDSURFACEDESC2);
  547. ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
  548. lpdds->GetSurfaceDesc(&ddsd);
  549. lpdds->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT | DDLOCK_NOSYSLOCK, NULL);
  550. BlitTerrainTSB(ddsd.lpSurface, drawx, drawy, 0, 0, ddsd.lPitch, ddsd.dwWidth, ddsd.dwHeight, (*tiledata)[dwID].tiles[p]);
  551. lpdds->Unlock(NULL);
  552. #endif
  553. }
  554. p++;
  555. }
  556. }
  557. FSunPackLib::SetColorKey(lpdds, -1);
  558. return lpdds;
  559. }
  560. void CTileSetBrowserView::DrawIt()
  561. {
  562. CPaintDC myDC(this);
  563. }
  564. void CTileSetBrowserView::OnLButtonDown(UINT nFlags, CPoint point)
  565. {
  566. RECT r;
  567. GetClientRect(&r);
  568. if (m_tilecount == 0)
  569. return;
  570. SCROLLINFO scrinfo;
  571. scrinfo.cbSize = sizeof(SCROLLINFO);
  572. scrinfo.fMask = SIF_ALL;
  573. GetScrollInfo(SB_HORZ, &scrinfo);
  574. point.x += scrinfo.nPos;
  575. GetScrollInfo(SB_VERT, &scrinfo);
  576. point.y += scrinfo.nPos;
  577. int max_r = r.right / m_tile_width;
  578. if (max_r == 0) max_r = 1;
  579. int cur_y = 0;
  580. int cur_x = 0;
  581. int tile_width = m_tile_width;
  582. int tile_height = m_tile_height;
  583. if (m_CurrentMode == 1)
  584. {
  585. DWORD dwID = GetTileID(m_currentTileSet, 0);
  586. int i;
  587. for (i = 0;i < m_tilecount;i++)
  588. {
  589. int curwidth = (*tiledata)[dwID].rect.right - (*tiledata)[dwID].rect.left;
  590. int curheight = (*tiledata)[dwID].rect.bottom - (*tiledata)[dwID].rect.top;
  591. curwidth = m_tile_width;
  592. curheight = m_tile_height;
  593. #ifdef RA2_MODE
  594. if ((m_currentTileSet == 80 && Map->GetTheater() == "TEMPERATE") || (m_currentTileSet == 73 && Map->GetTheater() == "SNOW") || (m_currentTileSet == 101 && Map->GetTheater() == "URBAN"))
  595. {
  596. if (i == 10 || i == 15)
  597. {
  598. dwID++; // don´t forget this
  599. continue;
  600. }
  601. }
  602. #endif
  603. int posaddedx = (m_tile_width - curwidth) / 2;
  604. int posaddedy = (m_tile_height - curheight) / 2;
  605. if (point.x > cur_x + posaddedx && point.y > cur_y + posaddedy && point.x < cur_x + tile_width - posaddedx && point.y < cur_y + tile_height - posaddedy)
  606. {
  607. char c[50];
  608. itoa(GetAddedHeight(dwID), c, 10);
  609. OutputDebugString(c);
  610. int oldmode = AD.mode;
  611. int oldid = AD.type;
  612. AD.mode = ACTIONMODE_SETTILE;
  613. AD.type = dwID;
  614. AD.data = 0;
  615. AD.data2 = 0;
  616. AD.data3 = 0;
  617. AD.z_data = 0;
  618. if (oldid > *tiledata_count) oldid = 0;
  619. if (oldmode != ACTIONMODE_SETTILE || (*tiledata)[oldid].wTileSet != m_currentTileSet)
  620. {
  621. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_settingsbar.m_BrushSize = 0;
  622. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_settingsbar.UpdateData(FALSE);
  623. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_x = 1;
  624. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_y = 1;
  625. int i;
  626. for (i = 0;i < g_data.sections["StdBrushSize"].values.size();i++)
  627. {
  628. CString n = *g_data.sections["StdBrushSize"].GetValueName(i);
  629. if ((*tiles).sections["General"].FindName(n) >= 0)
  630. {
  631. int tset = atoi((*tiles).sections["General"].values[n]);
  632. if (tset == m_currentTileSet)
  633. {
  634. int bs = atoi(*g_data.sections["StdBrushSize"].GetValue(i));
  635. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_settingsbar.m_BrushSize = bs - 1;
  636. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_settingsbar.UpdateData(FALSE);
  637. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_x = bs;
  638. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_y = bs;
  639. }
  640. }
  641. }
  642. }
  643. RedrawWindow();
  644. return;
  645. }
  646. cur_x += tile_width;
  647. if (i % max_r == max_r - 1)
  648. {
  649. cur_y += tile_height;
  650. cur_x = 0;
  651. }
  652. dwID++;
  653. }
  654. }
  655. else if (m_CurrentMode == 2)
  656. {
  657. int i;
  658. for (i = 0;i < max_ovrl_img;i++)
  659. {
  660. PICDATA* p = ovrlpics[m_currentOverlay][i];
  661. if (p != NULL && p->pic != NULL)
  662. {
  663. int curwidth = m_tile_width;
  664. int curheight = m_tile_height;
  665. int posaddedx = (m_tile_width - curwidth) / 2;
  666. int posaddedy = (m_tile_height - curheight) / 2;
  667. if (point.x > cur_x + posaddedx && point.y > cur_y + posaddedy && point.x < cur_x + tile_width - posaddedx && point.y < cur_y + tile_height - posaddedy)
  668. {
  669. AD.mode = ACTIONMODE_PLACE;
  670. AD.type = 6;
  671. AD.data = 33;
  672. AD.data2 = m_currentOverlay;
  673. AD.data3 = i;
  674. RedrawWindow();
  675. return;
  676. }
  677. cur_x += tile_width;
  678. if (i % max_r == max_r - 1)
  679. {
  680. cur_y += tile_height;
  681. cur_x = 0;
  682. }
  683. }
  684. }
  685. }
  686. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->SetForegroundWindow();
  687. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->SetFocus();
  688. CScrollView::OnLButtonDown(nFlags, point);
  689. }
  690. // calculates additional height added to the top of a tile if needed
  691. int CTileSetBrowserView::GetAddedHeight(DWORD dwID)
  692. {
  693. //int i;
  694. int cur_added = 0;
  695. //for(i=0;i<(*tiledata)[dwID].wTileCount;i++)
  696. {
  697. int i, e, p = 0;;
  698. for (i = 0;i < (*tiledata)[dwID].cx;i++)
  699. {
  700. for (e = 0;e < (*tiledata)[dwID].cy;e++)
  701. {
  702. int drawy = e * f_y / 2 + i * f_y / 2 - (*tiledata)[dwID].rect.top;
  703. drawy += (*tiledata)[dwID].tiles[p].sY - (*tiledata)[dwID].tiles[p].bZHeight * f_y / 2;
  704. if (drawy < cur_added) cur_added = drawy;
  705. p++;
  706. }
  707. }
  708. }
  709. return -cur_added;
  710. }
  711. void CTileSetBrowserView::SetOverlay(DWORD dwID)
  712. {
  713. int k;
  714. int need_pos = -1;
  715. int need_width = 0;
  716. int need_height = 0;
  717. // m_tilecount=0;
  718. int iovrlcount = 0;
  719. BOOL bFound = FALSE;
  720. for (k = 0;k < max_ovrl_img;k++)
  721. {
  722. PICDATA* p = ovrlpics[dwID][k];
  723. if (p != NULL && p->pic != NULL)
  724. {
  725. bFound = TRUE;
  726. }
  727. }
  728. if (!bFound)
  729. {
  730. theApp.m_loading->LoadOverlayGraphic(*rules.sections["OverlayTypes"].GetValue(dwID), dwID);
  731. ((CFinalSunDlg*)(theApp.m_pMainWnd))->m_view.m_isoview->UpdateOverlayPictures();
  732. //p=ovrlpics[dwID][k];
  733. }
  734. for (k = 0;k < max_ovrl_img;k++)
  735. {
  736. PICDATA* p = ovrlpics[dwID][k];
  737. if (p == NULL || p->pic == NULL)
  738. {
  739. //if(!p->bTried)
  740. {
  741. }
  742. }
  743. if (p != NULL && p->pic != NULL)
  744. {
  745. iovrlcount++;
  746. }
  747. }
  748. for (k = 0;k < max_ovrl_img;k++)
  749. {
  750. PICDATA* p = ovrlpics[dwID][k];
  751. if (p != NULL && p->pic != NULL)
  752. {
  753. need_pos = k;
  754. need_width = p->wMaxWidth;
  755. need_height = p->wMaxHeight;
  756. break;
  757. }
  758. }
  759. if (need_pos < 0)
  760. return;
  761. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_settingsbar.m_BrushSize = 0;
  762. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_settingsbar.UpdateData(FALSE);
  763. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_x = 1;
  764. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->m_BrushSize_y = 1;
  765. m_CurrentMode = 2;
  766. m_tile_width = 0;
  767. m_tile_height = 0;
  768. m_currentOverlay = dwID;
  769. m_tile_width = need_width + 6;
  770. m_tile_height = need_height + 6;
  771. RECT r;
  772. GetClientRect(&r);
  773. int max_r = r.right / m_tile_width;
  774. if (max_r <= 0) max_r = 1;
  775. m_bottom_needed = m_tile_height * (1 + (iovrlcount) / max_r);
  776. GetParentFrame()->RecalcLayout(TRUE);
  777. RedrawWindow();
  778. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->SetForegroundWindow();
  779. ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->SetFocus();
  780. }
  781. #ifdef IGNORETHIS
  782. LPDIRECTDRAWSURFACE4 CTileSetBrowserView::RenderOverlay(DWORD dwType, DWORD dwData)
  783. {
  784. LPDIRECTDRAWSURFACE4 lpdds = NULL;
  785. LPDIRECTDRAW4 lpdd = ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->dd;
  786. DDSURFACEDESC2 ddsd;
  787. memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
  788. ddsd.dwSize = sizeof(DDSURFACEDESC2);
  789. ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
  790. ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
  791. int added_height = GetAddedHeight(dwID);
  792. ddsd.dwHeight =//(*tiledata)[dwID].rect.bottom-(*tiledata)[dwID].rect.top+added_height;
  793. ddsd.dwWidth = (*tiledata)[dwID].rect.right - (*tiledata)[dwID].rect.left;
  794. if (lpdd->CreateSurface(&ddsd, &lpdds, NULL) != DD_OK)
  795. {
  796. return NULL;
  797. }
  798. DDBLTFX ddfx;
  799. memset(&ddfx, 0, sizeof(DDBLTFX));
  800. ddfx.dwSize = sizeof(DDBLTFX);
  801. lpdds->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &ddfx);
  802. int y_added = ddsd.dwHeight - ((*tiledata)[dwID].cx * f_y / 2 + (*tiledata)[dwID].cy * f_y / 2);
  803. int i, e, p = 0;;
  804. for (i = 0;i < (*tiledata)[dwID].cx;i++)
  805. {
  806. for (e = 0;e < (*tiledata)[dwID].cy;e++)
  807. {
  808. int drawx = e * f_x / 2 - i * f_x / 2 - (*tiledata)[dwID].rect.left;
  809. int drawy = e * f_y / 2 + i * f_y / 2 - (*tiledata)[dwID].rect.top;
  810. drawx += (*tiledata)[dwID].tiles[p].sX;
  811. drawy += added_height + (*tiledata)[dwID].tiles[p].sY - (*tiledata)[dwID].tiles[p].bZHeight * f_y / 2;
  812. //drawy+=y_added;
  813. if ((*tiledata)[dwID].tiles[p].pic)
  814. {
  815. RECT dest;
  816. dest.left = drawx;
  817. dest.top = drawy;
  818. dest.right = drawx + (*tiledata)[dwID].tiles[p].wWidth;
  819. dest.bottom = drawy + (*tiledata)[dwID].tiles[p].wHeight;
  820. DDBLTFX fx;
  821. memset(&fx, 0, sizeof(DDBLTFX));
  822. fx.dwSize = sizeof(DDBLTFX);
  823. DDSURFACEDESC2 ddsd;
  824. ZeroMemory(&ddsd, sizeof(ddsd));
  825. ddsd.dwSize = sizeof(DDSURFACEDESC2);
  826. ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
  827. lpdds->GetSurfaceDesc(&ddsd);
  828. lpdds->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT | DDLOCK_NOSYSLOCK, NULL);
  829. BlitTerrainTSB(ddsd.lpSurface, drawx, drawy, 0, 0, ddsd.lPitch, ddsd.dwWidth, ddsd.dwHeight, (*tiledata)[dwID].tiles[p]);
  830. lpdds->Unlock(NULL);
  831. }
  832. p++;
  833. }
  834. }
  835. SetSurfaceColorKey(lpdds, -1);
  836. }
  837. #endif
  838. void CTileSetBrowserView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  839. {
  840. //RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  841. CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
  842. }