Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
addplayerdialog.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
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**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19// addplayerdialog.cpp : implementation file
20//
21
22#include "stdafx.h"
23#include "worldbuilder.h"
24#include "addplayerdialog.h"
27#include "GameLogic/SidesList.h"
28#include "WorldBuilderDoc.h"
29#include "CUndoable.h"
30
32// AddPlayerDialog dialog
33
34
35AddPlayerDialog::AddPlayerDialog(AsciiString side, CWnd* pParent /*=NULL*/)
36 : CDialog(AddPlayerDialog::IDD, pParent)
37{
38 //{{AFX_DATA_INIT(AddPlayerDialog)
39 // NOTE: the ClassWizard will add member initialization here
40 //}}AFX_DATA_INIT
41
42 m_side = side;
43 m_addedSide.clear();
44}
45
46
47void AddPlayerDialog::DoDataExchange(CDataExchange* pDX)
48{
49 CDialog::DoDataExchange(pDX);
50 //{{AFX_DATA_MAP(AddPlayerDialog)
51 // NOTE: the ClassWizard will add DDX and DDV calls here
52 //}}AFX_DATA_MAP
53}
54
55
56BEGIN_MESSAGE_MAP(AddPlayerDialog, CDialog)
57 //{{AFX_MSG_MAP(AddPlayerDialog)
58 ON_CBN_EDITCHANGE(IDC_COMBO1, OnEditchangeCombo1)
59 //}}AFX_MSG_MAP
60END_MESSAGE_MAP()
61
62
63// AddPlayerDialog message handlers
64
66{
67 CComboBox *faction = (CComboBox*)GetDlgItem(IDC_COMBO1);
68
69 if (faction)
70 {
71 // get the text out of the combo. If it is user-typed, sel will be -1, otherwise it will be >=0
72 CString theText;
73 Int sel = faction->GetCurSel();
74 if (sel >= 0) {
75 faction->GetLBText(sel, theText);
76 } else {
77 faction->GetWindowText(theText);
78 }
79 AsciiString name((LPCTSTR)theText);
80
81 const PlayerTemplate* pt = ThePlayerTemplateStore->findPlayerTemplate(NAMEKEY(name));
82 if (pt)
83 {
84 m_addedSide = pt ? pt->getName() : AsciiString::TheEmptyString;
85 SidesList newSides = *TheSidesList;
86 newSides.addPlayerByTemplate(m_addedSide);
87 Bool modified = newSides.validateSides();
88 DEBUG_ASSERTLOG(!modified,("had to clean up sides in AddPlayerDialog::OnOK"));
89
91 SidesListUndoable *pUndo = new SidesListUndoable(newSides, pDoc);
92 pDoc->AddAndDoUndoable(pUndo);
93 REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
94 }
95 }
96
97 CDialog::OnOK();
98}
99
101{
102 m_addedSide.clear();
103 CDialog::OnCancel();
104}
105
107{
108 CDialog::OnInitDialog();
109
110 CComboBox *factions = (CComboBox*)GetDlgItem(IDC_COMBO1);
111 factions->ResetContent();
113 {
114 for (int i = 0; i < ThePlayerTemplateStore->getPlayerTemplateCount(); i++)
115 {
116 const PlayerTemplate* pt = ThePlayerTemplateStore->getNthPlayerTemplate(i);
117 if (!pt)
118 continue;
119 if (m_side.isEmpty() || m_side == pt->getSide())
120 factions->AddString(pt->getName().str());
121 }
122 }
123 factions->SetCurSel(0);
124
125 return TRUE;
126}
127
129{
130 // TODO: Add your control notification handler code here
131
132}
bool Bool
Definition BaseType.h:132
#define TRUE
Definition BaseType.h:109
#define DEBUG_ASSERTLOG(c, m)
Definition Debug.h:158
NameKeyType NAMEKEY(const AsciiString &name)
PlayerTemplateStore * ThePlayerTemplateStore
singleton instance of PlayerTemplateStore
SidesList * TheSidesList
singleton instance of SidesList
#define IDC_COMBO1
Definition resource.h:409
#define BOOL
Definition Wnd_File.h:57
virtual BOOL OnInitDialog()
virtual void OnOK()
AddPlayerDialog(AsciiString side, CWnd *pParent=NULL)
virtual void OnCancel()
afx_msg void OnEditchangeCombo1()
virtual void DoDataExchange(CDataExchange *pDX)
const char * str() const
static AsciiString TheEmptyString
static CWorldBuilderDoc * GetActiveDoc()
void AddAndDoUndoable(Undoable *pUndo)
AsciiString getSide() const
AsciiString getName() const
void addPlayerByTemplate(AsciiString playerTemplateName)
Bool validateSides(void)
#define REF_PTR_RELEASE(x)
Definition refcount.h:80