RTPDlg.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. // RTPDlg.cpp: Implementierungsdatei
  17. //
  18. #include "stdafx.h"
  19. #include "finalsun.h"
  20. #include "RTPDlg.h"
  21. #include "variables.h"
  22. #include "functions.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. /////////////////////////////////////////////////////////////////////////////
  29. // Dialogfeld CRTPDlg
  30. CRTPDlg::CRTPDlg(CWnd* pParent /*=NULL*/)
  31. : CDialog(CRTPDlg::IDD, pParent)
  32. {
  33. //{{AFX_DATA_INIT(CRTPDlg)
  34. // HINWEIS: Der Klassen-Assistent fügt hier Elementinitialisierung ein
  35. //}}AFX_DATA_INIT
  36. }
  37. void CRTPDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CRTPDlg)
  41. DDX_Control(pDX, IDC_PREVIEW, m_Preview);
  42. DDX_Control(pDX, IDC_USED, m_Used);
  43. DDX_Control(pDX, IDC_AVAIL, m_Available);
  44. //}}AFX_DATA_MAP
  45. }
  46. BEGIN_MESSAGE_MAP(CRTPDlg, CDialog)
  47. //{{AFX_MSG_MAP(CRTPDlg)
  48. ON_BN_CLICKED(IDC_ADD, OnAdd)
  49. ON_BN_CLICKED(IDC_REMOVE, OnRemove)
  50. ON_LBN_SELCHANGE(IDC_AVAIL, OnSelchangeAvail)
  51. ON_LBN_DBLCLK(IDC_AVAIL, OnDblclkAvail)
  52. ON_LBN_SELCHANGE(IDC_USED, OnSelchangeUsed)
  53. ON_LBN_DBLCLK(IDC_USED, OnDblclkUsed)
  54. ON_WM_PAINT()
  55. //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57. /////////////////////////////////////////////////////////////////////////////
  58. // Behandlungsroutinen für Nachrichten CRTPDlg
  59. BOOL CRTPDlg::OnInitDialog()
  60. {
  61. CDialog::OnInitDialog();
  62. int i;
  63. for(i=0;i<rules.sections["TerrainTypes"].values.size();i++)
  64. {
  65. CString unitname=*rules.sections["TerrainTypes"].GetValue(i);
  66. CString addedString=unitname;
  67. if(g_data.sections["IgnoreRA2"].FindValue(unitname)>=0) continue;
  68. addedString=TranslateStringACP(addedString);
  69. if(unitname.Find("TREE")>=0)
  70. {
  71. if(unitname.GetLength()>0 && unitname!="VEINTREE") // out with it :-)
  72. {
  73. int TreeMin=atoi(g_data.sections[Map->GetTheater()+"Limits"].values["TreeMin"]);
  74. int TreeMax=atoi(g_data.sections[Map->GetTheater()+"Limits"].values["TreeMax"]);
  75. CString id=unitname;
  76. id.Delete(0, 4);
  77. int n=atoi(id);
  78. if(n<TreeMin || n>TreeMax) continue;
  79. m_Available.AddString(unitname);
  80. }
  81. }
  82. }
  83. return TRUE; // return TRUE unless you set the focus to a control
  84. // EXCEPTION: OCX-Eigenschaftenseiten sollten FALSE zurückgeben
  85. }
  86. void CRTPDlg::OnAdd()
  87. {
  88. int sel=m_Available.GetCurSel();
  89. if(sel<0) return;
  90. CString currentname;
  91. m_Available.GetText(sel, currentname);
  92. m_Available.DeleteString(sel);
  93. m_Used.AddString(currentname);
  94. }
  95. void CRTPDlg::OnRemove()
  96. {
  97. int sel=m_Used.GetCurSel();
  98. if(sel<0) return;
  99. CString currentname;
  100. m_Used.GetText(sel, currentname);
  101. m_Used.DeleteString(sel);
  102. m_Available.AddString(currentname);
  103. }
  104. void CRTPDlg::OnOK()
  105. {
  106. if(m_Used.GetCount()<=0)
  107. {
  108. //AfxMessageBox("Please select at least one tree","Error", MB_OK);
  109. return;
  110. }
  111. rndterrainsrc.clear();
  112. int i;
  113. for(i=0;i<m_Used.GetCount();i++)
  114. {
  115. CString str;
  116. m_Used.GetText(i, str);
  117. rndterrainsrc.push_back(str);
  118. }
  119. CDialog::OnOK();
  120. }
  121. void CRTPDlg::OnSelchangeAvail()
  122. {
  123. int sel=m_Available.GetCurSel();
  124. if(sel<0)
  125. {
  126. m_LastSelected="";
  127. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  128. return;
  129. }
  130. CString s;
  131. m_Available.GetText(sel, s);
  132. m_LastSelected=s;
  133. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  134. }
  135. void CRTPDlg::OnDblclkAvail()
  136. {
  137. int sel=m_Available.GetCurSel();
  138. if(sel<0) return;
  139. CString currentname;
  140. m_Available.GetText(sel, currentname);
  141. m_Available.DeleteString(sel);
  142. m_Used.AddString(currentname);
  143. }
  144. void CRTPDlg::OnSelchangeUsed()
  145. {
  146. int sel=m_Used.GetCurSel();
  147. if(sel<0)
  148. {
  149. m_LastSelected="";
  150. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  151. return;
  152. }
  153. CString s;
  154. m_Used.GetText(sel, s);
  155. m_LastSelected=s;
  156. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
  157. }
  158. void CRTPDlg::OnDblclkUsed()
  159. {
  160. int sel=m_Used.GetCurSel();
  161. if(sel<0) return;
  162. CString currentname;
  163. m_Used.GetText(sel, currentname);
  164. m_Used.DeleteString(sel);
  165. m_Available.AddString(currentname);
  166. }
  167. void CRTPDlg::OnPaint()
  168. {
  169. if(m_LastSelected=="") return;
  170. CPaintDC dc(this); // device context for painting
  171. int id=Map->GetUnitTypeID(m_LastSelected);
  172. PICDATA* p=&treeinfo[id].pic; //ovrlpics[m_currentOverlay][i];
  173. if(p->pic==NULL)
  174. {
  175. CString type;
  176. type=m_LastSelected;
  177. if(missingimages.find(type)==missingimages.end())
  178. {
  179. theApp.m_loading->LoadUnitGraphic(type);
  180. Map->UpdateTreeInfo(type);
  181. p=&treeinfo[id].pic;
  182. }
  183. if(p->pic==NULL)
  184. {
  185. missingimages[type]=TRUE;
  186. }
  187. }
  188. int curwidth=p->wMaxWidth;
  189. int curheight=p->wMaxHeight;
  190. BITMAPINFO biinfo;
  191. memset(&biinfo, 0, sizeof(BITMAPINFO));
  192. biinfo.bmiHeader.biBitCount=24;
  193. biinfo.bmiHeader.biWidth=curwidth;
  194. biinfo.bmiHeader.biHeight=curheight;
  195. biinfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
  196. biinfo.bmiHeader.biClrUsed=0;
  197. biinfo.bmiHeader.biPlanes=1;
  198. biinfo.bmiHeader.biCompression=BI_RGB;
  199. biinfo.bmiHeader.biClrImportant=0;
  200. int pitch=curwidth*3;
  201. if(pitch==0) return;
  202. if(pitch%sizeof(DWORD))
  203. {
  204. pitch+=sizeof(DWORD)-(curwidth*3)%sizeof(DWORD);
  205. }
  206. BYTE* colors=new(BYTE[pitch*curheight]);
  207. memset(colors, 255, pitch*(curheight));
  208. RGBTRIPLE* pal=palIso;
  209. #ifdef NOSURFACES
  210. if(p->pal==iPalTheater) pal=palTheater;
  211. if(p->pal==iPalUnit) pal=palUnit;
  212. #endif
  213. int k,l;
  214. for(k=0;k<curheight;k++)
  215. {
  216. for(l=0;l<curwidth;l++)
  217. {
  218. if(((BYTE*)p->pic)[l+k*curwidth])
  219. {
  220. memcpy(&colors[l*3+(curheight-k-1)*pitch], &pal[((BYTE*)p->pic)[l+k*curwidth]], 3);
  221. }
  222. }
  223. }
  224. RECT pr;
  225. m_Preview.GetWindowRect(&pr);
  226. this->ScreenToClient(&pr);
  227. pr.top += 15;
  228. pr.bottom -= 5;
  229. pr.left += 5;
  230. pr.right -= 5;
  231. CBrush f;
  232. f.Attach(GetStockObject(WHITE_BRUSH));
  233. dc.FillRect(&pr,&f);
  234. f.Detach();
  235. auto clientDC = m_Preview.GetWindowDC();
  236. StretchDIBits(clientDC->GetSafeHdc(), 20, 30,curwidth, curheight,
  237. 0, 0, curwidth, curheight, colors, &biinfo, DIB_RGB_COLORS, SRCCOPY);
  238. delete[] colors;
  239. // Kein Aufruf von CDialog::OnPaint() für Zeichnungsnachrichten
  240. }