Update checkRpItemsPosition and getTeam
[ryzomcore.git] / ryzom / tools / client / client_config / client_configDlg.cpp
blob28ad963c5366bc98513b7971786af03873c2be23
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
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 Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // client_configDlg.cpp : implementation file
20 #include "stdafx.h"
21 #include "client_config.h"
22 #include "client_configDlg.h"
23 #include "cfg_file.h"
24 #include "database.h"
26 #include <nel/misc/debug.h>
27 #include <nel/misc/system_utils.h>
29 #define ICON_ZONE_WIDTH 128
31 #define LEFT_WIDTH 256
32 #define LEFT_HEIGHT 512
34 #define BAR_START_X (LEFT_WIDTH+ICON_ZONE_WIDTH)
35 #define BAR_WIDTH 448
36 #define BAR_HEIGHT 72
37 #define TREE_ZONE_WIDTH 150
38 #define TREE_OFFSET_LEFT 10
39 #define TREE_OFFSET_TOP 10
41 // Label
42 #define LARGE_LABEL_HEIGHT -22
43 #define LARGE_LABEL_START_X (LEFT_WIDTH+TREE_ZONE_WIDTH)
44 #define LARGE_LABEL_START_Y (15)
45 #define LARGE_LABEL_END_X (LEFT_WIDTH+ICON_ZONE_WIDTH+BAR_WIDTH)
46 #define LARGE_LABEL_END_Y BAR_HEIGHT
48 // Icon
49 #define ICON_WIDTH 64
50 #define ICON_HEIGHT 64
51 #define ICON_START_Y ((BAR_HEIGHT-ICON_HEIGHT)/2)
52 #define ICON_START_X (LEFT_WIDTH+ICON_START_Y)
53 #define ICON_START_Y ((BAR_HEIGHT-ICON_HEIGHT)/2)
55 // ***************************************************************************
56 // CAboutDlg dialog used for App About
57 // ***************************************************************************
59 class CAboutDlg : public CDialog
61 public:
62 CAboutDlg();
64 // Dialog Data
65 //{{AFX_DATA(CAboutDlg)
66 enum { IDD = IDD_ABOUTBOX };
67 //}}AFX_DATA
69 // ClassWizard generated virtual function overrides
70 //{{AFX_VIRTUAL(CAboutDlg)
71 protected:
72 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
73 //}}AFX_VIRTUAL
75 // Implementation
76 protected:
77 //{{AFX_MSG(CAboutDlg)
78 virtual BOOL OnInitDialog();
79 //}}AFX_MSG
80 DECLARE_MESSAGE_MAP()
83 // ***************************************************************************
85 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
87 //{{AFX_DATA_INIT(CAboutDlg)
88 //}}AFX_DATA_INIT
91 // ***************************************************************************
93 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
95 CDialog::DoDataExchange(pDX);
96 //{{AFX_DATA_MAP(CAboutDlg)
97 //}}AFX_DATA_MAP
100 // ***************************************************************************
102 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
103 //{{AFX_MSG_MAP(CAboutDlg)
104 //}}AFX_MSG_MAP
105 END_MESSAGE_MAP()
107 // ***************************************************************************
108 // CClient_configDlg dialog
109 // ***************************************************************************
111 CClient_configDlg::CClient_configDlg(CWnd* pParent /*=NULL*/)
112 : CDialog(CClient_configDlg::IDD, pParent)
114 //{{AFX_DATA_INIT(CClient_configDlg)
115 // NOTE: the ClassWizard will add member initialization here
116 //}}AFX_DATA_INIT
117 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
118 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
120 // Init dialog pointers
121 Dialogs[PageGeneral] = &GeneralDlg;
122 Dialogs[PageDisplay] = &DisplayDlg;
123 Dialogs[PageDisplayDetails] = &DisplayDetailsDlg;
124 Dialogs[PageDisplayAdvanced] = &DisplayAdvancedDlg;
125 Dialogs[PageDisplaySysInfo] = &SystemInformationDlg;
126 Dialogs[PageDisplayOpenGLInfo] = &DisplayInformationGLDlg;
127 Dialogs[PageDisplayOpenD3DInfo] = &DisplayInformationD3DDlg;
128 Dialogs[PageSound] = &SoundDlg;
129 _CurrentPage = 0;
132 // ***************************************************************************
134 void CClient_configDlg::DoDataExchange(CDataExchange* pDX)
136 CDialog::DoDataExchange(pDX);
137 //{{AFX_DATA_MAP(CClient_configDlg)
138 DDX_Control(pDX, ID_APPLY, ApplyCtrl);
139 //}}AFX_DATA_MAP
142 // ***************************************************************************
144 BEGIN_MESSAGE_MAP(CClient_configDlg, CDialog)
145 //{{AFX_MSG_MAP(CClient_configDlg)
146 ON_WM_SYSCOMMAND()
147 ON_WM_PAINT()
148 ON_WM_QUERYDRAGICON()
149 ON_BN_CLICKED(ID_APPLY, OnApply)
150 ON_BN_CLICKED(ID_DEFAULT, OnDefault)
151 ON_BN_CLICKED(ID_LAUNCH, OnLaunch)
152 //}}AFX_MSG_MAP
153 END_MESSAGE_MAP()
155 // ***************************************************************************
156 // CClient_configDlg message handlers
157 // ***************************************************************************
159 BOOL CClient_configDlg::OnInitDialog()
161 CDialog::OnInitDialog();
163 // Add "About..." menu item to system menu.
165 // IDM_ABOUTBOX must be in the system command range.
166 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
167 ASSERT(IDM_ABOUTBOX < 0xF000);
169 CMenu* pSysMenu = GetSystemMenu(FALSE);
170 if (pSysMenu != NULL)
172 CString strAboutMenu = "uiConfigMenuAbout";
173 if (!strAboutMenu.IsEmpty())
175 pSysMenu->AppendMenu(MF_SEPARATOR);
176 pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
180 // Set the icon for this dialog. The framework does this automatically
181 // when the application's main window is not a dialog
182 SetIcon(m_hIcon, TRUE); // Set big icon
183 SetIcon(m_hIcon, FALSE); // Set small icon
185 // Create bitmaps
186 uint i;
187 for (i=0; i<BitmapCount; i++)
189 Bitmaps[i].LoadBitmap (BitmapId[i].ResId);
192 // Create others controls
193 nlverify (Left.Create (NULL, WS_CHILD|WS_VISIBLE|SS_BITMAP, CRect (0, 0, LEFT_WIDTH, LEFT_HEIGHT), this));
194 Left.SetBitmap (LoadBitmap (theApp.m_hInstance, MAKEINTRESOURCE (IDB_LEFT_0)));
195 nlverify (Icon.Create (NULL, WS_CHILD|WS_VISIBLE|SS_BITMAP, CRect (ICON_START_X, ICON_START_Y, ICON_START_X+ICON_WIDTH, ICON_START_Y+ICON_HEIGHT), this));
196 Icon.SetBitmap (Bitmaps[BitmapWelcome]);
198 // Create bars
199 nlverify (Top.Create (CRect (LEFT_WIDTH, BAR_HEIGHT, LEFT_WIDTH+ICON_ZONE_WIDTH+BAR_WIDTH, BAR_HEIGHT+1), this));
200 nlverify (Bottom.Create (CRect (0, LEFT_HEIGHT, LEFT_WIDTH+ICON_ZONE_WIDTH+BAR_WIDTH, LEFT_HEIGHT+1), this));
202 // Create the tree
203 nlverify (Tree.Create ( WS_CHILD|WS_VISIBLE|TVS_NOSCROLL|TVS_TRACKSELECT|TVS_HASLINES|TVS_HASBUTTONS|TVS_SHOWSELALWAYS,
204 CRect (LEFT_WIDTH+TREE_OFFSET_LEFT, BAR_HEIGHT+2+TREE_OFFSET_TOP,
205 LEFT_WIDTH+TREE_ZONE_WIDTH, BAR_HEIGHT+LEFT_HEIGHT-BAR_HEIGHT), this, TreeId));
206 Tree.SetFont (GetFont ());
208 // Create fonts
209 nlverify (BarFont.CreateFont (LARGE_LABEL_HEIGHT, 0, 0, 0, FW_BOLD, TRUE, FALSE, 0, DEFAULT_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
210 TMPF_TRUETYPE | DEFAULT_PITCH | FF_MODERN, "Arial"));
212 // Create dialog
213 for (i=0; i<PageCount; i++)
215 nlverify (Dialogs[i]->Create (Pages[i].ResId, this));
216 nlverify (Dialogs[i]->SetWindowPos (NULL, LEFT_WIDTH+TREE_ZONE_WIDTH, BAR_HEIGHT+2, 0, 0, SWP_NOZORDER|SWP_NOSIZE));
219 // Build the tree
220 CPage *page = Root.Children[0];
221 HTREEITEM parent = TVI_ROOT;
222 while (page)
224 // Add an item
225 parent = Tree.InsertItem ("", parent);
226 Tree.SetItemData (parent, page->PageId);
227 if (page->Bold)
228 Tree.SetItemState (parent, TVIS_BOLD, TVIS_BOLD);
230 // Next
231 if (page->Children.size ())
232 page = page->Children[0];
233 else
235 // Got a parent ?
236 while (page->Parent)
238 // Brother ?
239 if (page->ChildId < page->Parent->Children.size ()-1)
241 page = page->Parent->Children[page->ChildId+1];
242 parent = Tree.GetParentItem (parent);
243 break;
245 else
247 page = page->Parent;
248 parent = Tree.GetParentItem (parent);
249 Tree.Expand (parent, TVE_EXPAND);
252 if (!page->Parent)
253 break;
257 ApplyCtrl.EnableWindow (FALSE);
259 // Get from the config file
260 GetFromConfigFile ();
262 theApp.Modified = false;
264 // Build the localisation map
265 backupWindowHandleRec ();
267 // Localize the windows
268 changeLanguage (::GetIntForceLanguage()?"en" : ::GetString ("LanguageCode").c_str());
269 theApp.Localized = true;
271 // Focus
272 Tree.SelectItem(Tree.GetChildItem (Tree.GetRootItem()));
273 Tree.SetFocus ();
275 return TRUE; // return TRUE unless you set the focus to a control
278 // ***************************************************************************
280 void CClient_configDlg::changeLanguage (const char *language)
282 // Init CI18N
283 NLMISC::CI18N::load(language);
285 localizeWindowsRec ();
286 translateTree ();
288 // Set the general page
289 setPage (_CurrentPage);
291 DisplayDlg.updateState ();
292 DisplayDlg.UpdateData (FALSE);
293 DisplayDetailsDlg.updateState ();
294 SoundDlg.updateState ();
296 // Set the title
297 setWindowText(*this, (WCHAR*)((NLMISC::CI18N::get ("uiConfigTitle") + (theApp.Modified?" *":"")).c_str()));
299 // The menu
300 CMenu* pSysMenu = GetSystemMenu(FALSE);
301 if (pSysMenu)
303 if (NLMISC::CSystemUtils::supportUnicode())
305 nlverify (::ModifyMenuW(*pSysMenu, IDM_ABOUTBOX, MF_BYCOMMAND|MF_STRING, IDM_ABOUTBOX, (WCHAR*)NLMISC::CI18N::get ("uiConfigMenuAbout").c_str()));
307 else
309 nlverify (::ModifyMenu(*pSysMenu, IDM_ABOUTBOX, MF_BYCOMMAND|MF_STRING, IDM_ABOUTBOX, (LPCTSTR)NLMISC::CI18N::get ("uiConfigMenuAbout").toString().c_str()));
314 // ***************************************************************************
316 void CClient_configDlg::translateTree ()
318 // Set the item text
319 HTREEITEM item = Tree.GetRootItem ();
320 while (item)
322 // Set the item text
323 uint page = (uint)Tree.GetItemData (item);
324 ucstring name = NLMISC::CI18N::get (Pages[page].Name);
325 if (NLMISC::CSystemUtils::supportUnicode())
327 TVITEMEXW itemDesc;
328 memset (&itemDesc, 0, sizeof(TVITEMEXW));
329 itemDesc.hItem = item;
330 itemDesc.mask = TVIF_TEXT;
331 itemDesc.pszText = (WCHAR*)name.c_str();
332 nlverify (SendMessageW (Tree, TVM_SETITEMW, 0, (LPARAM)&itemDesc));
334 else
336 TVITEMEXA itemDesc;
337 memset (&itemDesc, 0, sizeof(TVITEMEXA));
338 itemDesc.hItem = item;
339 itemDesc.mask = TVIF_TEXT;
340 std::string tmpStr = name.toString();
341 itemDesc.pszText = (LPSTR) tmpStr.c_str();
342 nlverify (::SendMessageA(Tree, TVM_SETITEMA, 0 , (LPARAM)&itemDesc));
344 // Next item
345 HTREEITEM old = item;
346 item = Tree.GetChildItem (item);
347 if (!item)
349 // No more child, try a brother
350 item = Tree.GetNextSiblingItem (old);
352 if (!item)
354 // No more brother, try an oncle
355 item = Tree.GetParentItem (old);
356 if (item)
357 item = Tree.GetNextSiblingItem (item);
362 // ***************************************************************************
364 void CClient_configDlg::OnSysCommand(UINT nID, LPARAM lParam)
366 if ((nID & 0xFFF0) == IDM_ABOUTBOX)
368 CAboutDlg dlgAbout;
369 dlgAbout.DoModal();
371 else
373 CDialog::OnSysCommand(nID, lParam);
377 // ***************************************************************************
379 // If you add a minimize button to your dialog, you will need the code below
380 // to draw the icon. For MFC applications using the document/view model,
381 // this is automatically done for you by the framework.
383 void CClient_configDlg::OnPaint()
385 if (IsIconic())
387 CPaintDC dc(this); // device context for painting
389 SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
391 // Center icon in client rectangle
392 int cxIcon = GetSystemMetrics(SM_CXICON);
393 int cyIcon = GetSystemMetrics(SM_CYICON);
394 CRect rect;
395 GetClientRect(&rect);
396 int x = (rect.Width() - cxIcon + 1) / 2;
397 int y = (rect.Height() - cyIcon + 1) / 2;
399 // Draw the icon
400 dc.DrawIcon(x, y, m_hIcon);
402 else
404 // Draw rect
405 CPaintDC dc(this); // device context for painting
406 dc.FillSolidRect( LEFT_WIDTH, BAR_HEIGHT+2, TREE_ZONE_WIDTH, LEFT_HEIGHT-BAR_HEIGHT-2, GetSysColor (COLOR_WINDOW));
408 // Draw top bar
409 dc.FillSolidRect( LEFT_WIDTH, 0, ICON_ZONE_WIDTH, BAR_HEIGHT, RGB (255,255,255));
410 CDC bitmapDC;
411 bitmapDC.CreateCompatibleDC (&dc);
412 bitmapDC.SelectObject (&Bitmaps[BitmapTopRight]);
413 nlverify (dc.BitBlt( LEFT_WIDTH + ICON_ZONE_WIDTH, 0, BAR_WIDTH, BAR_HEIGHT, &bitmapDC, 0, 0, SRCCOPY));
415 // Draw some text
416 dc.SetBkMode (TRANSPARENT);
417 dc.SelectObject (&BarFont);
418 CRect labelRect (LARGE_LABEL_START_X, LARGE_LABEL_START_Y, LARGE_LABEL_END_X, LARGE_LABEL_END_Y);
419 DrawTextW (&(*dc), (WCHAR*)TopLargeLabel.c_str (), (sint)TopLargeLabel.size (), &labelRect, DT_LEFT|DT_TOP);
421 CDialog::OnPaint();
425 // ***************************************************************************
427 HCURSOR CClient_configDlg::OnQueryDragIcon()
429 return (HCURSOR) m_hIcon;
432 // ***************************************************************************
434 void CClient_configDlg::setPage (uint pageId)
436 CPage &page = Pages[pageId];
437 Icon.SetBitmap (Bitmaps[page.Icon]);
438 TopLargeLabel = NLMISC::CI18N::get (std::string(page.Name));
440 // Hide all the dialog
441 uint i;
442 for (i=0; i<PageCount; i++)
443 Dialogs[i]->ShowWindow (SW_HIDE);
445 // Show the dialog
446 Dialogs[pageId]->ShowWindow (SW_SHOW);
448 // Invalidate bar
449 InvalidateBar ();
450 _CurrentPage = pageId;
453 // ***************************************************************************
455 BOOL CClient_configDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
457 // TODO: Add your specialized code here and/or call the base class
458 int idCtrl = (int) wParam;
459 LPNMHDR pnmh = (LPNMHDR) lParam;
461 switch (idCtrl)
463 case TreeId:
465 switch (pnmh->code)
467 case TVN_SELCHANGED:
469 // Get the selection
470 HTREEITEM item = Tree.GetSelectedItem ();
471 if (item)
473 // Get the page
474 uint pageId = (uint)Tree.GetItemData (item);
475 setPage (pageId);
478 break;
481 break;
484 return CDialog::OnNotify(wParam, lParam, pResult);
487 // ***************************************************************************
489 void CClient_configDlg::InvalidateBar ()
491 CRect rect (BAR_START_X, 0, BAR_START_X+BAR_WIDTH, BAR_HEIGHT);
492 InvalidateRect (&rect);
495 // ***************************************************************************
497 BOOL CClient_configDlg::UpdateData ( BOOL bSaveAndValidate )
499 // For each pages
500 uint i;
501 for (i=0; i<PageCount; i++)
503 Dialogs[i]->UpdateData (bSaveAndValidate);
506 return CDialog::UpdateData ( bSaveAndValidate );
509 // ***************************************************************************
511 void CClient_configDlg::OnApply()
513 // Update config file
514 SetToConfigFile ();
516 // Save the config file
517 SaveConfigFile ();
519 // Doc is validated
520 theApp.Modified = false;
521 ApplyCtrl.EnableWindow (FALSE);
523 // Set the title
524 setWindowText(*this, (WCHAR*)NLMISC::CI18N::get ("uiConfigTitle").c_str());
527 // ***************************************************************************
529 void CClient_configDlg::OnCancel()
531 // Modified ?
532 if (theApp.Modified)
534 // Quit without saving ?
535 if (theApp.yesNo (NLMISC::CI18N::get ("uiConfigQuitWithoutSaving")))
537 CDialog::OnCancel();
540 else
541 CDialog::OnCancel();
544 // ***************************************************************************
546 void CClient_configDlg::OnOK()
548 if (theApp.Modified)
550 // Update config file
551 SetToConfigFile ();
553 // Save the config file
554 SaveConfigFile ();
556 // Doc is validated
557 theApp.Modified = false;
560 CDialog::OnOK();
563 // ***************************************************************************
565 void CClient_configDlg::OnDefault()
567 /* Yoyo: Don't use the preset dlg for now cause doesn't work everywhere
568 // Open the preset dialog
569 CPresetDlg preset;
570 if (preset.DoModal () == IDOK)
572 // Reset the CFG to default
573 ResetConfigFile();
575 // invalidate
576 InvalidateConfig ();
578 // Update widgets
579 GetFromConfigFile ();
582 // Quit without saving ?
583 if (theApp.yesNo (NLMISC::CI18N::get ("uiConfigRestaureDefault")))
585 // Reset the CFG to default
586 ResetConfigFileToDefault();
588 // invalidate
589 InvalidateConfig ();
591 // Update widgets
592 GetFromConfigFile ();
596 // ***************************************************************************
598 void CClient_configDlg::OnLaunch()
600 if (theApp.Modified)
602 // Update config file
603 SetToConfigFile ();
605 // Save the config file
606 SaveConfigFile ();
608 // Doc is validated
609 theApp.Modified = false;
612 // launch ryzom
613 NLMISC::launchProgram("client_ryzom_rd.exe","");
615 CDialog::OnOK();
618 // ***************************************************************************
620 BOOL CAboutDlg::OnInitDialog()
622 CDialog::OnInitDialog();
624 localizeWindowsRec (this, false);
626 return TRUE; // return TRUE unless you set the focus to a control
627 // EXCEPTION: OCX Property Pages should return FALSE