1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 //#include "tile_edit_dll.h"
29 using namespace NLMISC
;
31 extern CTileBank tileBank2
;
33 /////////////////////////////////////////////////////////////////////////////
36 Browse::Browse(int nland
, CWnd
* pParent
/*=NULL*/)
37 : CDialog(Browse::IDD
, pParent
)
39 //{{AFX_DATA_INIT(Browse)
59 void Browse::DoDataExchange(CDataExchange
* pDX
)
61 CDialog::DoDataExchange(pDX
);
62 //{{AFX_DATA_MAP(Browse)
63 DDX_Radio(pDX
, IDC_128X128
, m_128x128
);
64 DDX_Control(pDX
, IDC_VIEW
, m_ctrl
);
65 DDX_Control(pDX
, IDC_INFONUM
, m_infotexte
);
66 DDX_Control(pDX
, IDC_JOUR
, m_rb_jour
);
67 DDX_Check(pDX
, IDC_SUBGROUP0
, SubGroup0
);
68 DDX_Check(pDX
, IDC_SUBGROUP1
, SubGroup1
);
69 DDX_Check(pDX
, IDC_SUBGROUP2
, SubGroup2
);
70 DDX_Check(pDX
, IDC_SUBGROUP3
, SubGroup3
);
71 DDX_Check(pDX
, IDC_SUBGROUP4
, SubGroup4
);
72 DDX_Check(pDX
, IDC_SUBGROUP5
, SubGroup5
);
73 DDX_Check(pDX
, IDC_SUBGROUP6
, SubGroup6
);
74 DDX_Check(pDX
, IDC_SUBGROUP7
, SubGroup7
);
75 DDX_Check(pDX
, IDC_SUBGROUP10
, SubGroup10
);
76 DDX_Check(pDX
, IDC_SUBGROUP11
, SubGroup11
);
77 DDX_Check(pDX
, IDC_SUBGROUP8
, SubGroup8
);
78 DDX_Check(pDX
, IDC_SUBGROUP9
, SubGroup9
);
79 DDX_Check(pDX
, IDC_ORIENTED
, Oriented
);
84 BEGIN_MESSAGE_MAP(Browse
, CDialog
)
85 //{{AFX_MSG_MAP(Browse)
87 ON_BN_CLICKED(IDC_ALPHA
, OnAlpha
)
88 ON_BN_CLICKED(IDC_128X128
, OnChangeVariety
)
89 ON_BN_CLICKED(IDC_JOUR
, OnJour
)
90 ON_BN_CLICKED(IDC_NUIT
, OnNuit
)
91 ON_BN_CLICKED(IDC_OK
, OnOk
)
93 ON_BN_CLICKED(IDC_OK2
, OnUpdateTiles
)
94 ON_BN_CLICKED(IDC_BATCH_LOAD
, OnBatchLoad
)
95 ON_BN_CLICKED(IDC_SUBGROUP0
, OnSubgroup0
)
96 ON_BN_CLICKED(IDC_SUBGROUP1
, OnSubgroup1
)
97 ON_BN_CLICKED(IDC_SUBGROUP2
, OnSubgroup2
)
98 ON_BN_CLICKED(IDC_SUBGROUP3
, OnSubgroup3
)
99 ON_BN_CLICKED(IDC_SUBGROUP4
, OnSubgroup4
)
100 ON_BN_CLICKED(IDC_SUBGROUP5
, OnSubgroup5
)
101 ON_BN_CLICKED(IDC_SUBGROUP6
, OnSubgroup6
)
102 ON_BN_CLICKED(IDC_SUBGROUP7
, OnSubgroup7
)
103 ON_BN_CLICKED(IDC_SUBGROUP8
, OnSubgroup8
)
104 ON_BN_CLICKED(IDC_SUBGROUP9
, OnSubgroup9
)
105 ON_BN_CLICKED(IDC_SUBGROUP10
, OnSubgroup10
)
106 ON_BN_CLICKED(IDC_SUBGROUP11
, OnSubgroup11
)
107 ON_BN_CLICKED(IDC_EXPORT_BORDER
, OnExportBorder
)
108 ON_BN_CLICKED(IDC_ZOOM5
, OnChangeVariety
)
109 ON_BN_CLICKED(IDC_ZOOM6
, OnChangeVariety
)
110 ON_BN_CLICKED(IDCANCEL
, OnCancel
)
111 ON_BN_CLICKED(IDC_CANCEL
, OnCancel
)
112 ON_BN_CLICKED(IDC_DISPLACE
, OnChangeVariety
)
113 ON_BN_CLICKED(IDC_IMPORT_BORDER2
, OnImportBorder
)
117 /////////////////////////////////////////////////////////////////////////////
118 // Browse message handlers
120 BOOL
Browse::PreCreateWindow(CREATESTRUCT
& cs
)
122 // TODO: Add your specialized code here and/or call the base class
124 return CDialog::PreCreateWindow(cs
);
128 int thread_actif
= 0;
132 LRESULT
Browse::WindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
135 // TODO: Add your specialized code here and/or call the base class
136 if (ccount
==0 && message
==WM_PAINT
)
140 if (message
==WM_KEYUP
|| message
==WM_KEYDOWN
)
143 GetWindowRect(&parent
); m_ctrl
.GetWindowRect(&client
);
144 if (m_ctrl
.MousePos
.x
<(client
.right
- parent
.left
) &&
145 m_ctrl
.MousePos
.x
>0 &&
146 m_ctrl
.MousePos
.y
<(client
.bottom
- client
.top
) &&
149 m_ctrl
.SendMessage(message
,wParam
,lParam
);
153 if (message
==WM_MOUSEMOVE
)
155 m_ctrl
.MousePos
.x
= LOWORD(lParam
);
156 m_ctrl
.MousePos
.y
= HIWORD(lParam
);
160 ClientToScreen (&m_ctrl
.MousePos
);
161 m_ctrl
.ScreenToClient (&m_ctrl
.MousePos
);
163 m_ctrl
.GetWindowRect(&client
);
164 GetWindowRect(&parent
);
165 if (m_ctrl
.MousePos
.x
<0)
167 if (m_ctrl
.MousePos
.x
>client
.right
-client
.left
)
168 m_ctrl
.MousePos
.x
=client
.right
-client
.left
;
169 if (m_ctrl
.MousePos
.y
<0)
171 if (m_ctrl
.MousePos
.y
>client
.bottom
-client
.top
)
172 m_ctrl
.MousePos
.y
=client
.bottom
-client
.top
;
174 m_ctrl
.ClientToScreen (&m_ctrl
.MousePos
);
175 ScreenToClient (&m_ctrl
.MousePos
);
177 if (lbutton
) //on dessine le carre de selection
181 SIZE size
; size
.cx
= size
.cy
= 1;
182 current
.left
= OriginalPos
.x
;
183 current
.top
= OriginalPos
.y
;
184 current
.right
= m_ctrl
.MousePos
.x
;
185 current
.bottom
= m_ctrl
.MousePos
.y
;
186 if (current
.left
>current
.right
) {int temp
= current
.left
; current
.left
= current
.right
; current
.right
= temp
;}
187 if (current
.top
>current
.bottom
) {int temp
= current
.bottom
; current
.bottom
= current
.top
; current
.top
= temp
;}
190 m_ctrl
.DrawDragRect(pDC
,NULL
,size
,&last_sel
,size
); //on efface l'ancien carre
192 m_ctrl
.UpdateSelection(¤t
, (int)wParam
, m_128x128
); //on affiche les modifes
194 m_ctrl
.DrawDragRect(pDC
,¤t
,size
,NULL
,size
); //on affiche le nouveau carre
195 ::ReleaseDC(*this,*pDC
);
200 if (message
==WM_DROPFILES
)
202 m_ctrl
.PostMessage(WM_DROPFILES
,wParam
,lParam
);
204 if (message
==WM_COMMAND
&& !thread_actif
)
206 int button
= LOWORD(wParam
);
207 if (button
==IDC_ZOOM1
|| button
==IDC_ZOOM2
|| button
==IDC_ZOOM3
)
209 m_ctrl
.Zoom
= button
- IDC_ZOOM1
+1;
210 m_ctrl
.UpdateSize(m_128x128
);
211 m_ctrl
.scrollpos
= 0;
212 SetScrollPos(SB_VERT
,0,true);
213 m_ctrl
.RedrawWindow();
215 else if (button
==IDC_INFONUM
)
217 m_ctrl
.InfoTexte
= 1;
218 m_ctrl
.RedrawWindow();
220 else if (button
==IDC_FILENAME
)
223 m_ctrl
.RedrawWindow();
225 else if (button
==IDC_GROUP
)
227 m_ctrl
.InfoTexte
= 3;
228 m_ctrl
.RedrawWindow();
230 else if (button
>=10 && button
<=15)
231 m_ctrl
.PostMessage(WM_COMMAND
,wParam
,lParam
);
233 if (message
==WM_LBUTTONDOWN
)
235 int xPos
= LOWORD(lParam
); // horizontal position of cursor
236 int yPos
= HIWORD(lParam
); // vertical position of cursor
238 if (lbutton
) //on dessine le carre de selection
242 SIZE size
; size
.cx
= size
.cy
= 1;
243 current
.left
= OriginalPos
.x
;
244 current
.top
= OriginalPos
.y
;
245 current
.right
= m_ctrl
.MousePos
.x
;
246 current
.bottom
= m_ctrl
.MousePos
.y
;
247 if (current
.left
>current
.right
) {int temp
= current
.left
; current
.left
= current
.right
; current
.right
= temp
;}
248 if (current
.top
>current
.bottom
) {int temp
= current
.bottom
; current
.bottom
= current
.top
; current
.top
= temp
;}
251 m_ctrl
.DrawDragRect(pDC
,NULL
,size
,&last_sel
,size
); //on efface l'ancien carre
253 m_ctrl
.UpdateSelection(¤t
,(int)wParam
, m_128x128
); //on affiche les modifes
255 ::ReleaseDC(*this,*pDC
);
260 RECT p
,rect
; p
.left
= m_ctrl
.MousePos
.x
; p
.top
= m_ctrl
.MousePos
.y
;
262 m_ctrl
.GetClientRect(&rect
);
263 POINT pt
; pt
.x
= p
.left
; pt
.y
= p
.top
;
264 m_ctrl
.ScreenToClient(&pt
);
265 if (pt
.x
>=rect
.left
&& pt
.x
<rect
.right
&& pt
.y
>=rect
.top
&& pt
.y
<rect
.bottom
)
268 int index
= m_ctrl
.GetIndex(&pt
, m_128x128
);
269 if (index
!=-1 && !(wParam
&MK_SHIFT
)/* && !(wParam&MK_CONTROL)*/)
271 tilelist::iterator p
= m_ctrl
.InfoList
.Get(index
, m_128x128
);
272 if (p
!=m_ctrl
.InfoList
.GetLast(m_128x128
))
274 tilelist::iterator pp
= p
;
275 if (wParam
&MK_CONTROL
)
276 p
->Selected
= p
->Selected
?0:7;
281 for (p
=m_ctrl
.InfoList
.GetFirst(m_128x128
);p
!=m_ctrl
.InfoList
.GetLast(m_128x128
);++p
, indexx
++)
283 if (p
!=pp
&& p
->Selected
)
285 if (!(wParam
&MK_CONTROL
))
288 if (pDC
==NULL
) pDC
= m_ctrl
.GetDC();
289 m_ctrl
.DrawTile(p
,pDC
,1,m_128x128
);
296 if (pDC
==NULL
) pDC
= m_ctrl
.GetDC();
297 m_ctrl
.DrawTile(p
,pDC
,1,m_128x128
);
301 if (pDC
) ::ReleaseDC(*this,*pDC
);
306 if (!(wParam
&MK_CONTROL
) && !(wParam
&MK_SHIFT
))
308 tilelist::iterator p
= m_ctrl
.InfoList
.GetFirst(m_128x128
);
310 for (int i
= 0; i
<m_ctrl
.InfoList
.GetSize(m_128x128
); i
++)
314 if (pDC
==NULL
) pDC
= m_ctrl
.GetDC();
315 //m_ctrl.InfoList.setSelection (i, 0);
317 m_ctrl
.DrawTile(p
,pDC
,1,m_128x128
);
321 if (pDC
) ::ReleaseDC(*this,*pDC
);
326 SIZE size
; size
.cx
= size
.cy
= 1;
329 last_sel
.left
= yPos
;
330 last_sel
.bottom
= xPos
;
331 last_sel
.right
= yPos
;
336 if (message
==WM_LBUTTONUP
|| message
==WM_NCLBUTTONUP
)
338 RECT p
; p
.left
= m_ctrl
.MousePos
.x
; p
.top
= m_ctrl
.MousePos
.y
;
340 POINT pt
; pt
.x
= p
.left
; pt
.y
= p
.top
;
341 m_ctrl
.ScreenToClient(&pt
);
342 int index
= m_ctrl
.GetIndex(&pt
, m_128x128
);
343 if (!selection
&& index
!=-1)
350 CSize size
; size
.cx
= size
.cy
= 1;
351 m_ctrl
.DrawDragRect(pDC
,NULL
,size
,&last_sel
,size
);
352 ::ReleaseDC(*this,*pDC
);
354 for (tilelist::iterator p
= m_ctrl
.InfoList
.GetFirst(m_128x128
);p
!=m_ctrl
.InfoList
.GetLast(m_128x128
);++p
, index
++)
367 if (message
==WM_KEYDOWN
)
371 if (message
==WM_SIZE
&& m_ctrl
.count_
)
373 int x
= LOWORD(lParam
);
374 int y
= HIWORD(lParam
);
376 int i
= std::max (1, m_ctrl
.GetNbTileLine());
377 int j
= std::max (1, m_ctrl
.GetNbTileColumn());
378 int pos
= m_ctrl
.GetScrollPos(SB_VERT
);
379 int hview
= (m_ctrl
.InfoList
.GetSize(m_128x128
)/i
+ 1)*(m_ctrl
.sizeicon_y
+ m_ctrl
.spacing_y
) + m_ctrl
.spacing_y
;
380 m_ctrl
.scrollpos
= (pos
*hview
)/SCROLL_MAX
;
382 RECT clientrect
,rect
;
383 m_ctrl
.GetWindowRect(&clientrect
);
384 InvalidateRect(NULL
,false);
385 GetWindowRect(&rect
);
386 m_ctrl
.SetWindowPos(NULL
, 0, 0, std::max (100, x
- 120), y
- 20, SWP_NOMOVE
);
388 m_ctrl
.GetVisibility(iFirst
, iLast
, m_128x128
);
389 m_ctrl
.UpdateBar(iFirst
, iLast
, m_128x128
);
392 if (message
==WM_VSCROLL
|| message
==WM_MOUSEWHEEL
)
395 RECT rect_scroll
,rect_clip
;
398 GetScrollInfo(SB_VERT
,&inf
);
399 m_ctrl
.GetClientRect(&rect_scroll
);
400 int i
= m_ctrl
.GetNbTileLine();
401 int hview
= (m_ctrl
.InfoList
.GetSize(m_128x128
)/i
+ 2)*(m_ctrl
.sizeicon_y
+ m_ctrl
.spacing_y
) + m_ctrl
.spacing_y
;
403 if (message
==WM_MOUSEWHEEL
)
405 int inc
= ((int)(short)HIWORD(wParam
))/WHEEL_DELTA
;
406 pos
= inf
.nPos
- inc
*(((m_ctrl
.sizeicon_y
+m_ctrl
.spacing_y
)*SCROLL_MAX
)/(hview
- m_ctrl
.spacing_y
));
410 scrollcode
= LOWORD(wParam
);
415 pos
= SCROLL_MAX
- inf
.nPage
;
418 pos
= inf
.nPos
+ inf
.nPage
;
421 pos
= inf
.nPos
- inf
.nPage
;
424 pos
= inf
.nPos
- (((m_ctrl
.sizeicon_y
+m_ctrl
.spacing_y
)*SCROLL_MAX
)/(hview
- m_ctrl
.spacing_y
));
427 pos
= inf
.nPos
+ (((m_ctrl
.sizeicon_y
+m_ctrl
.spacing_y
)*SCROLL_MAX
)/(hview
- m_ctrl
.spacing_y
));
432 case SB_THUMBPOSITION
:
440 if (pos
>(SCROLL_MAX
- (int)inf
.nPage
))
441 pos
= SCROLL_MAX
- inf
.nPage
;
443 SetScrollPos(SB_VERT
,pos
,1);
444 rect_scroll
.bottom
-= rect_scroll
.top
;
446 rect_clip
= rect_scroll
;
447 int scroll_pixel
= m_ctrl
.scrollpos
;
449 m_ctrl
.GetVisibility(old_iFV
, old_iLV
, m_128x128
);
450 m_ctrl
.scrollpos
= (pos
*hview
)/(SCROLL_MAX
);
452 m_ctrl
.GetVisibility(iFV
, iLV
, m_128x128
);
454 if (iFV
>old_iLV
|| iLV
<old_iFV
|| scrollcode
==SB_PAGEDOWN
|| scrollcode
==SB_PAGEUP
)
456 m_ctrl
.RedrawWindow();
460 scroll_pixel
-= m_ctrl
.scrollpos
;
463 CDC
*pDC
= m_ctrl
.GetDC();
464 if (abs(scroll_pixel
)>(rect_clip
.bottom
- rect_clip
.top
)) scroll_pixel
= 0;
465 else pDC
->ScrollDC(0,scroll_pixel
,&rect_scroll
,&rect_clip
,NULL
,NULL
);
467 tilelist::iterator p
= m_ctrl
.InfoList
.GetFirst(m_128x128
);
468 CBrush
brush (GetSysColor(COLOR_3DFACE
));
471 rect_scroll
.top
= rect_scroll
.bottom
+ scroll_pixel
;
472 pDC
->FillRect(&rect_scroll
,&brush
);
473 if ((iLV
-i
)<iFV
) i
= iLV
- iFV
;
475 for (k
= 0;k
<old_iLV
-i
;k
++) p
++;
476 for (k
=old_iLV
- i
;k
<=iLV
;k
++)
478 m_ctrl
.DrawTile(p
,pDC
,0,m_128x128
);
484 rect_scroll
.bottom
= rect_scroll
.top
+ scroll_pixel
;
485 pDC
->FillRect(&rect_scroll
,&brush
);
487 for (k
= 0;k
<iFV
;k
++) p
++;
488 for (k
= iFV
;k
<(old_iFV
+i
);k
++)
490 m_ctrl
.DrawTile(p
,pDC
,0,m_128x128
);
494 ::ReleaseDC(m_ctrl
,*pDC
);
497 m_ctrl
.lastVBarPos
= pos
;
499 if (message
==WM_CLOSE
)
502 this->m_ctrl
.count_
=0;
505 if (message
==WM_LBUTTONDBLCLK
)
507 m_ctrl
.SendMessage(WM_LBUTTONDBLCLK
,wParam
,lParam
);
510 return CDialog::WindowProc(message
, wParam
, lParam
);
514 unsigned long Browse::MyControllingFunction( void* pParam
)
517 Browse
*br
= (Browse
*)pParam
;
518 br
->m_ctrl
.lockInsertion
= 1;
520 br
->m_ctrl
.GetVisibility(iFV
, iLV
, br
->m_128x128
);
521 br
->m_ctrl
.UpdateBar(iFV
, iLV
, br
->m_128x128
);
522 tilelist::iterator p
= br
->m_ctrl
.InfoList
.GetFirst(br
->m_128x128
);
523 tilelist::iterator plast
= p
;
524 for (int i
=0;i
<br
->m_ctrl
.InfoList
.GetSize(br
->m_128x128
);i
++)
530 std::vector
<NLMISC::CBGRA
>* bits
;
532 switch (br
->m_128x128
)
535 path
= tileBank2
.getTile (tileBank2
.getTileSet (br
->m_ctrl
.InfoList
._tileSet
)->getTile128 (i
))->
536 getRelativeFileName ((CTile::TBitmap
)(br
->m_ctrl
.Texture
-1));
539 path
= tileBank2
.getTile (tileBank2
.getTileSet (br
->m_ctrl
.InfoList
._tileSet
)->getTile256 (i
))->
540 getRelativeFileName ((CTile::TBitmap
)(br
->m_ctrl
.Texture
-1));
544 int index
=tileBank2
.getTileSet (br
->m_ctrl
.InfoList
._tileSet
)->getTransition (i
)->getTile();
547 path
= tileBank2
.getTile (index
)->getRelativeFileName ((CTile::TBitmap
)(br
->m_ctrl
.Texture
-1));
548 if (br
->m_ctrl
.Texture
==3)
549 rot
= tileBank2
.getTile (index
)->getRotAlpha ();
556 // Get diplacement filename
557 path
= tileBank2
.getDisplacementMap (tileBank2
.getTileSet (br
->m_ctrl
.InfoList
._tileSet
)->getDisplacementTile ((CTileSet::TDisplacement
)i
));
560 std::vector
<NLMISC::CBGRA
>* pAlpha
=NULL
;
561 switch (br
->m_ctrl
.Texture
)
567 pAlpha
= &p
->alphaBits
;
570 ld
= &p
->nightLoaded
;
571 pBmp
= &p
->nightBmpInfo
;
572 bits
= &p
->nightBits
;
573 pAlpha
= &p
->alphaBits
;
576 ld
= &p
->alphaLoaded
;
577 pBmp
= &p
->alphaBmpInfo
;
578 bits
= &p
->alphaBits
;
582 if (!path
.empty() && _LoadBitmap(tileBank2
.getAbsPath() + path
, pBmp
, *bits
, pAlpha
, rot
))
585 int iFV
,iLV
; br
->m_ctrl
.GetVisibility(iFV
, iLV
, br
->m_128x128
);
586 if (i
<=iLV
&& i
>=iFV
)
588 CDC
*pDC
= br
->m_ctrl
.GetDC();
589 br
->m_ctrl
.DrawTile(p
,pDC
,1,br
->m_128x128
);
590 ::ReleaseDC(*br
,*pDC
);
595 br
->m_ctrl
.lockInsertion
= 0;
600 void Browse::LoadInThread(void)
603 MyControllingFunction (this);
613 m_ctrl
.lockInsertion
= 0; oldsel
= -1;
617 int cx
=-1,cy
=-1,x
=-1,y
=-1;
618 TCHAR sWindowpl
[256];
620 if (RegOpenKey(HKEY_CURRENT_USER
,REGKEY_TILEDIT
,®key
)==ERROR_SUCCESS
)
624 if (RegQueryValueEx(regkey
,REGKEY_WNDPL
,0,&type
,(unsigned char *)&sWindowpl
,&value
)==ERROR_SUCCESS
)
626 WINDOWPLACEMENT wndpl
;
627 _stscanf(sWindowpl
,_T("%d %d %d %d %d %d %d %d %d %d"),
629 &wndpl
.ptMaxPosition
.x
,&wndpl
.ptMaxPosition
.y
,
630 &wndpl
.ptMinPosition
.x
,&wndpl
.ptMinPosition
.y
,
631 &wndpl
.rcNormalPosition
.bottom
,&wndpl
.rcNormalPosition
.left
,&wndpl
.rcNormalPosition
.right
,&wndpl
.rcNormalPosition
.top
,
633 wndpl
.length
= sizeof(WINDOWPLACEMENT
);
634 this->SetWindowPlacement(&wndpl
);
638 if (RegQueryValueEx(regkey
, REGKEY_LASTPATH
, 0, &type
, (unsigned char *)&sWindowpl
, &value
) != ERROR_SUCCESS
)
639 m_ctrl
.LastPath
.clear();
641 m_ctrl
.LastPath
= tStrToUtf8(sWindowpl
);
644 if (RegQueryValueEx(regkey
,REGKEY_BUTTONZOOM
,0,&type
,(unsigned char *)&m_ctrl
.Zoom
,&value
)!=ERROR_SUCCESS
)
648 if (RegQueryValueEx(regkey
,REGKEY_BUTTONVARIETY
,0,&type
,(unsigned char *)&m_128x128
,&value
)!=ERROR_SUCCESS
)
652 if (RegQueryValueEx(regkey
,REGKEY_BUTTONTEXTURE
,0,&type
,(unsigned char *)&m_ctrl
.Texture
,&value
)!=ERROR_SUCCESS
)
656 if (RegQueryValueEx(regkey
,REGKEY_BUTTONTEXTINFO
,0,&type
,(unsigned char *)&m_ctrl
.InfoTexte
,&value
)!=ERROR_SUCCESS
)
657 m_ctrl
.InfoTexte
= 1;
660 CButton
*button
= (CButton
*)GetDlgItem(IDC_ZOOM1
+ m_ctrl
.Zoom
-1);
662 button
= (CButton
*)GetDlgItem(IDC_JOUR
+ m_ctrl
.Texture
-1);
664 button
= (CButton
*)GetDlgItem(IDC_INFONUM
+ m_ctrl
.InfoTexte
-1);
666 if (cx
!=-1 && cy
!=-1 && x
!=-1 && y
!=-1) SetWindowPos(0,x
,y
,cx
,cy
,0);
668 m_ctrl
.Init(land
, m_128x128
);
669 SelectionTerritoire
*slt
= (SelectionTerritoire
*)GetParent();
673 this->GetWindowRect(&rect
);
674 SendMessage(WM_SIZE
,rect
.right
- rect
.left
,rect
.bottom
- rect
.top
); //force resize
676 SelectionTerritoire
*parent
= (SelectionTerritoire
*)GetParent();
679 CTileSet
*tileSet
=tileBank2
.getTileSet (land
);
681 if (tileSet
->getOriented())
687 m_ctrl
.InfoList
.theList128
.resize (tileSet
->getNumTile128 ());
689 for (i
=0; i
<tileSet
->getNumTile128 (); i
++)
691 m_ctrl
.InfoList
.theList128
[i
].id
=i
;
692 m_ctrl
.InfoList
.theList128
[i
].Selected
=0;
693 m_ctrl
.InfoList
.theList128
[i
].loaded
=0;
694 m_ctrl
.InfoList
.theList128
[i
].nightLoaded
=0;
695 m_ctrl
.InfoList
.theList128
[i
].alphaLoaded
=0;
697 m_ctrl
.InfoList
.Reload (0, tileSet
->getNumTile128 (), 0);
700 m_ctrl
.InfoList
.theList256
.resize (tileSet
->getNumTile256 ());
701 for (i
=0; i
<tileSet
->getNumTile256 (); i
++)
703 m_ctrl
.InfoList
.theList256
[i
].id
=i
;
704 m_ctrl
.InfoList
.theList256
[i
].Selected
=0;
705 m_ctrl
.InfoList
.theList256
[i
].loaded
=0;
706 m_ctrl
.InfoList
.theList256
[i
].nightLoaded
=0;
707 m_ctrl
.InfoList
.theList256
[i
].alphaLoaded
=0;
709 m_ctrl
.InfoList
.Reload (0, tileSet
->getNumTile256 (), 1);
712 for (i
=0; i
<CTileSet::count
; i
++)
714 m_ctrl
.InfoList
.theListTransition
[i
].id
=i
;
715 m_ctrl
.InfoList
.theListTransition
[i
].Selected
=0;
716 m_ctrl
.InfoList
.theListTransition
[i
].loaded
=0;
717 m_ctrl
.InfoList
.theListTransition
[i
].nightLoaded
=0;
718 m_ctrl
.InfoList
.theListTransition
[i
].alphaLoaded
=0;
720 m_ctrl
.InfoList
.Reload (0, CTileSet::count
, 2);
723 for (i
=0; i
<CTileSet::CountDisplace
; i
++)
725 m_ctrl
.InfoList
.theListDisplacement
[i
].id
=i
;
726 m_ctrl
.InfoList
.theListDisplacement
[i
].Selected
=0;
727 m_ctrl
.InfoList
.theListDisplacement
[i
].loaded
=0;
728 m_ctrl
.InfoList
.theListDisplacement
[i
].nightLoaded
=0;
729 m_ctrl
.InfoList
.theListDisplacement
[i
].alphaLoaded
=0;
731 m_ctrl
.InfoList
.Reload (0, CTileSet::CountDisplace
, 3);
733 CString fullpath
= parent
->DefautPath
+ parent
->CurrentTerritory
;
743 void Browse::OnSize(UINT nType
, int cx
, int cy
)
745 CDialog::OnSize(nType
, cx
, cy
);
748 void Browse::OnAlpha ()
750 // TODO: Add your control notification handler code here
753 m_ctrl
.RedrawWindow();
756 void Browse::OnJour ()
758 // TODO: Add your control notification handler code here
761 m_ctrl
.RedrawWindow();
764 void Browse::OnNuit ()
766 // TODO: Add your control notification handler code here
769 m_ctrl
.RedrawWindow();
774 // TODO: Add your control notification handler code here
776 m_ctrl
.SendMessage(WM_PAINT
);
779 void Browse::OnCancel()
781 // TODO: Add your control notification handler code here
782 if (thread_actif
) return;
784 if (::MessageBox (NULL
, _T("Are you sure you want to cancel?"), _T("Cancel"), MB_OK
|MB_ICONQUESTION
|MB_YESNO
)==IDYES
)
786 this->SendMessage(WM_CLOSE
);
793 void Browse::UpdateAll(void)
798 void Browse::OnDestroy()
800 // TODO: Add your control notification handler code here
802 WINDOWPLACEMENT wndpl
;
803 this->GetWindowPlacement(&wndpl
);
805 sprintf(sWindowpl
,"%d %d %d %d %d %d %d %d %d %d",
807 wndpl
.ptMaxPosition
.x
,wndpl
.ptMaxPosition
.y
,
808 wndpl
.ptMinPosition
.x
,wndpl
.ptMinPosition
.y
,
809 wndpl
.rcNormalPosition
.bottom
,wndpl
.rcNormalPosition
.left
,wndpl
.rcNormalPosition
.right
,wndpl
.rcNormalPosition
.top
,
811 if (RegCreateKey(HKEY_CURRENT_USER
,REGKEY_TILEDIT
,®key
)==ERROR_SUCCESS
)
813 //int sel = ((CComboBox*)GetDlgItem(IDC_LISTTYPE))->GetCurSel();
814 tstring tWindowpl
= utf8ToTStr(sWindowpl
);
815 tstring tLastPath
= utf8ToTStr(m_ctrl
.LastPath
);
816 RegSetValueEx(regkey
, REGKEY_WNDPL
, 0, REG_SZ
, (const BYTE
*)tWindowpl
.c_str(), (tWindowpl
.size() + 1) * sizeof(TCHAR
));
817 RegSetValueEx(regkey
, REGKEY_LASTPATH
, 0, REG_SZ
, (const BYTE
*)tLastPath
.c_str(), (tLastPath
.size() + 1) * sizeof(TCHAR
));
818 RegSetValueEx(regkey
,REGKEY_BUTTONZOOM
,0,REG_DWORD
,(const unsigned char*)&m_ctrl
.Zoom
,4);
819 RegSetValueEx(regkey
,REGKEY_BUTTONVARIETY
,0,REG_DWORD
,(const unsigned char*)&m_128x128
,4);
820 RegSetValueEx(regkey
,REGKEY_BUTTONTEXTURE
,0,REG_DWORD
,(const unsigned char*)&m_ctrl
.Texture
,4);
821 RegSetValueEx(regkey
,REGKEY_BUTTONSORT
,0,REG_DWORD
,(const unsigned char*)&m_ctrl
.Sort
,4);
822 RegSetValueEx(regkey
,REGKEY_BUTTONTEXTINFO
,0,REG_DWORD
,(const unsigned char*)&m_ctrl
.InfoTexte
,4);
829 // TODO: Add your control notification handler code here
830 if (thread_actif
) return;
832 // trap - Don't know if this is the right place to do this
834 CTileSet
*tileSet
=tileBank2
.getTileSet (land
);
835 tileSet
->setOriented(Oriented
?true:false);
838 this->SendMessage(WM_CLOSE
);
842 void Browse::OnRButtonDown(UINT nFlags
, CPoint point
)
844 // TODO: Add your message handler code here and/or call default
845 m_ctrl
.PostMessage(WM_RBUTTONDOWN
,point
.x
,point
.y
);
846 CDialog::OnRButtonDown(nFlags
, point
);
849 void Browse::OnSelchangeListtype()
853 void Browse::OnUpdateTiles()
855 // TODO: Add your control notification handler code here
860 void Browse::OnChangeVariety()
863 m_ctrl
.UpdateSize (m_128x128
);
866 GetDlgItem (IDC_JOUR
)->EnableWindow (m_128x128
!=3);
867 GetDlgItem (IDC_NUIT
)->EnableWindow (m_128x128
!=3);
868 GetDlgItem (IDC_ALPHA
)->EnableWindow (m_128x128
==2);
869 GetDlgItem (IDC_BATCH_LOAD
)->EnableWindow (m_128x128
==2);
871 if ((m_ctrl
.Texture
==3)&&(m_128x128
!=2))
874 ((CButton
*)GetDlgItem (IDC_ALPHA
))->SetCheck (0);
875 ((CButton
*)GetDlgItem (IDC_NUIT
))->SetCheck (1);
878 if ((m_ctrl
.Texture
!=1)&&(m_128x128
==3))
881 ((CButton
*)GetDlgItem (IDC_ALPHA
))->SetCheck (0);
882 ((CButton
*)GetDlgItem (IDC_NUIT
))->SetCheck (0);
883 ((CButton
*)GetDlgItem (IDC_JOUR
))->SetCheck (1);
886 m_ctrl
.Invalidate ();
890 void Browse::OnBatchLoad ()
892 CFileDialog
sFile (true, NULL
, NULL
, OFN_ENABLESIZING
, _T("PNG Bitmap (*.png)|*.png|Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||"), NULL
);
894 if (sFile
.DoModal()==IDOK
)
896 std::string fullPath
= tStrToUtf8(sFile
.GetPathName());
898 std::string path
= NLMISC::CFile::getPath(fullPath
);
899 std::string filename
= NLMISC::CFile::getFilenameWithoutExtension(fullPath
);
900 std::string ext
= NLMISC::CFile::getExtension(fullPath
);
902 // look for some numbers..
903 std::string::size_type pos
= filename
.find_last_not_of("0123456789");
905 if (pos
!= std::string::npos
)
907 filename
= filename
.substr(0, pos
+ 1);
912 if (::MessageBox (NULL
, _T("Do you want to use rotation to reuse alpha tiles ?"), _T("Import rotated tiles"), MB_OK
|MB_ICONQUESTION
|MB_YESNO
)==IDYES
)
915 for (int i
=0; i
<CTileSet::count
; i
++)
917 if (m_ctrl
.Texture
==3)
919 // Current transition
920 CTileSet::TTransition transition
=(CTileSet::TTransition
)i
;
922 // Transition to patch
923 CTileSetTransition
* trans
=tileBank2
.getTileSet (land
)->getTransition (transition
);
924 if (tileBank2
.getTile (trans
->getTile())->getRelativeFileName (CTile::alpha
).empty())
929 // Try to load transition with rotation
930 for (int rot
=0; rot
<4; rot
++)
932 // Try to load a tile with a file name like /tiletransition0.tga
933 std::string sFinal
= path
+ toString("%s%02d.%s", filename
.c_str(), (int)transition
, ext
.c_str());
935 FILE *pFile
= nlfopen (sFinal
, "rb");
937 // Close the file and add the tile if opened
941 ok
=m_ctrl
.InfoList
.setTileTransitionAlpha (i
, sFinal
, (4-rot
)%4);
947 // Rotate the transition
948 transition
=CTileSet::rotateTransition (transition
);
959 // Current transition
960 CTileSet::TTransition transition
=(CTileSet::TTransition
)i
;
962 // Transition to patch
963 CTileSetTransition
* trans
=tileBank2
.getTileSet (land
)->getTransition (transition
);
964 if (tileBank2
.getTile (trans
->getTile())->getRelativeFileName (m_ctrl
.Texture
==1?CTile::diffuse
:CTile::additive
).empty())
966 // Try to load a tile with a file name like /tiletransition0.tga
967 std::string sFinal
= path
+ toString("%s%02d.%s", filename
.c_str(), (int)transition
, ext
.c_str());
969 FILE *pFile
= nlfopen (sFinal
, "rb");
971 // Close the file and add the tile if opened
975 if (!m_ctrl
.InfoList
.setTileTransition (i
, sFinal
, m_ctrl
.Texture
==1?CTile::diffuse
:CTile::additive
))
981 m_ctrl
.Invalidate ();
986 void Browse::UpdateFlags ()
1002 uint
or=0, and=0xffffffff;
1006 for (int i
=0;i
<m_ctrl
.InfoList
.GetSize(m_128x128
);i
++)
1009 if (m_ctrl
.InfoList
.theList
[m_128x128
][i
].Selected
)
1019 index
=tileBank2
.getTileSet (land
)->getTile128 (i
);
1023 index
=tileBank2
.getTileSet (land
)->getTile256 (i
);
1027 index
=tileBank2
.getTileSet (land
)->getTransition (i
)->getTile ();
1034 nlassert (0); // no!
1041 or|=tileBank2
.getTile (index
)->getGroupFlags ();
1042 and&=tileBank2
.getTile (index
)->getGroupFlags ();
1051 GetDlgItem (IDC_SUBGROUP0
)->EnableWindow (find
?TRUE
:FALSE
);
1052 GetDlgItem (IDC_SUBGROUP1
)->EnableWindow (find
?TRUE
:FALSE
);
1053 GetDlgItem (IDC_SUBGROUP2
)->EnableWindow (find
?TRUE
:FALSE
);
1054 GetDlgItem (IDC_SUBGROUP3
)->EnableWindow (find
?TRUE
:FALSE
);
1055 GetDlgItem (IDC_SUBGROUP4
)->EnableWindow (find
?TRUE
:FALSE
);
1056 GetDlgItem (IDC_SUBGROUP5
)->EnableWindow (find
?TRUE
:FALSE
);
1057 GetDlgItem (IDC_SUBGROUP6
)->EnableWindow (find
?TRUE
:FALSE
);
1058 GetDlgItem (IDC_SUBGROUP7
)->EnableWindow (find
?TRUE
:FALSE
);
1059 GetDlgItem (IDC_SUBGROUP8
)->EnableWindow (find
?TRUE
:FALSE
);
1060 GetDlgItem (IDC_SUBGROUP9
)->EnableWindow (find
?TRUE
:FALSE
);
1061 GetDlgItem (IDC_SUBGROUP10
)->EnableWindow (find
?TRUE
:FALSE
);
1062 GetDlgItem (IDC_SUBGROUP11
)->EnableWindow (find
?TRUE
:FALSE
);
1064 // Find at least one tile ?
1068 SubGroup0
=(and&0x1)?1:(or&0x1)?2:0;
1069 SubGroup1
=(and&0x2)?1:(or&0x2)?2:0;
1070 SubGroup2
=(and&0x4)?1:(or&0x4)?2:0;
1071 SubGroup3
=(and&0x8)?1:(or&0x8)?2:0;
1072 SubGroup4
=(and&0x10)?1:(or&0x10)?2:0;
1073 SubGroup5
=(and&0x20)?1:(or&0x20)?2:0;
1074 SubGroup6
=(and&0x40)?1:(or&0x40)?2:0;
1075 SubGroup7
=(and&0x80)?1:(or&0x80)?2:0;
1076 SubGroup8
=(and&0x100)?1:(or&0x100)?2:0;
1077 SubGroup9
=(and&0x200)?1:(or&0x200)?2:0;
1078 SubGroup10
=(and&0x400)?1:(or&0x400)?2:0;
1079 SubGroup11
=(and&0x800)?1:(or&0x800)?2:0;
1086 void Browse::Flags (int flagNumber
, bool go
)
1089 for (int i
=0;i
<m_ctrl
.InfoList
.GetSize(m_128x128
);i
++)
1092 if (m_ctrl
.InfoList
.theList
[m_128x128
][i
].Selected
)
1102 index
=tileBank2
.getTileSet (land
)->getTile128 (i
);
1106 index
=tileBank2
.getTileSet (land
)->getTile256 (i
);
1110 index
=tileBank2
.getTileSet (land
)->getTransition (i
)->getTile ();
1113 nlassert (0); // no!
1120 uint value
=tileBank2
.getTile (index
)->getGroupFlags ();
1123 value
&=~(1<<flagNumber
);
1127 value
|=(1<<flagNumber
);
1130 tileBank2
.getTile (index
)->setGroupFlags (value
);
1137 void Browse::OnSubgroup0()
1139 // TODO: Add your control notification handler code here
1149 nlassert (SubGroup0
!=2);
1156 void Browse::OnSubgroup1()
1158 // TODO: Add your control notification handler code here
1168 nlassert (SubGroup1
!=2);
1175 void Browse::OnSubgroup2()
1177 // TODO: Add your control notification handler code here
1187 nlassert (SubGroup2
!=2);
1194 void Browse::OnSubgroup3()
1196 // TODO: Add your control notification handler code here
1206 nlassert (SubGroup3
!=2);
1213 void Browse::OnSubgroup4()
1215 // TODO: Add your control notification handler code here
1225 nlassert (SubGroup4
!=2);
1232 void Browse::OnSubgroup5()
1234 // TODO: Add your control notification handler code here
1244 nlassert (SubGroup5
!=2);
1251 void Browse::OnSubgroup6()
1253 // TODO: Add your control notification handler code here
1263 nlassert (SubGroup6
!=2);
1270 void Browse::OnSubgroup7()
1272 // TODO: Add your control notification handler code here
1282 nlassert (SubGroup7
!=2);
1289 void Browse::OnSubgroup8()
1291 // TODO: Add your control notification handler code here
1301 nlassert (SubGroup8
!=2);
1308 void Browse::OnSubgroup9()
1310 // TODO: Add your control notification handler code here
1320 nlassert (SubGroup9
!=2);
1327 void Browse::OnSubgroup10()
1329 // TODO: Add your control notification handler code here
1339 nlassert (SubGroup10
!=2);
1346 void Browse::OnSubgroup11()
1348 // TODO: Add your control notification handler code here
1358 nlassert (SubGroup11
!=2);
1365 void Browse::OnExportBorder()
1368 CFileDialog
sFile (false, NULL
, NULL
, OFN_ENABLESIZING
, _T("PNG Bitmap (*.png)|*.png|Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||"), NULL
);
1369 if (sFile
.DoModal()==IDOK
)
1371 // Get the border of the bank
1372 std::vector
<NLMISC::CBGRA
> array
;
1376 tileBank2
.getTileSet (land
)->getBorder128 (m_ctrl
.Texture
==1?CTile::diffuse
:CTile::additive
)->get (width
, height
, array
);
1381 NLMISC::CBitmap bitmap
;
1382 bitmap
.resize (width
, height
, NLMISC::CBitmap::RGBA
);
1385 CRGBA
*pPixel
=(CRGBA
*)&bitmap
.getPixels()[0];
1388 for (int i
=0; i
<width
*height
; i
++)
1391 pPixel
->R
=array
[i
].R
;
1392 pPixel
->G
=array
[i
].G
;
1393 pPixel
->B
=array
[i
].B
;
1394 pPixel
->A
=array
[i
].A
;
1400 CString pathName
=sFile
.GetPathName();
1404 if (file
.open (tStrToUtf8(pathName
)))
1407 bitmap
.writeTGA (file
, 32);
1412 catch (const Exception
& e
)
1414 const char *toto
=e
.what ();
1418 // Error during export ?
1422 std::string tmp
= toString("Can't write bitmap %s", tStrToUtf8(pathName
).c_str());
1423 MessageBox(nlUtf8ToTStr(tmp
), _T("Export border"), MB_OK
| MB_ICONEXCLAMATION
);
1429 void Browse::OnImportBorder()
1432 CFileDialog
sFile (true, NULL
, NULL
, OFN_ENABLESIZING
,_T("PNG Bitmap (*.png)|*.png|Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||"), NULL
);
1433 if (sFile
.DoModal()==IDOK
)
1435 // Get the border of the bank
1436 std::vector
<NLMISC::CBGRA
> array(128*128);
1439 NLMISC::CBitmap bitmap
;
1443 CString pathName
=sFile
.GetPathName();
1447 if (file
.open (tStrToUtf8(pathName
)))
1455 catch (const Exception
& e
)
1457 const char *toto
=e
.what ();
1461 // Error during import ?
1465 std::string tmp
= toString("Can't read bitmap %s", tStrToUtf8(pathName
).c_str());
1466 MessageBox(nlUtf8ToTStr(tmp
), _T("Import border"), MB_OK
| MB_ICONEXCLAMATION
);
1470 CRGBA
*pPixel
=(CRGBA
*)&bitmap
.getPixels()[0];
1473 if ((bitmap
.getWidth()==128)&&(bitmap
.getHeight()==128))
1476 for (int i
=0; i
<128*128; i
++)
1479 array
[i
].R
=pPixel
->R
;
1480 array
[i
].G
=pPixel
->G
;
1481 array
[i
].B
=pPixel
->B
;
1482 array
[i
].A
=pPixel
->A
;
1489 std::string tmp
= toString("The bitmap must have a size of 128x128 (%s)", tStrToUtf8(pathName
).c_str());
1490 MessageBox(nlUtf8ToTStr(tmp
), _T("Import border"), MB_OK
| MB_ICONEXCLAMATION
);
1495 border
.set (128, 128, array
);
1496 tileBank2
.getTileSet (land
)->setBorder (m_ctrl
.Texture
==1?CTile::diffuse
:CTile::additive
, border
);
1499 MessageBox (_T("The border has been changed."), _T("Import border"), MB_OK
|MB_ICONINFORMATION
);