Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
NetAddrDlg.cpp
Go to the documentation of this file.
1
/* Project Starshatter 4.5
2
Destroyer Studios LLC
3
Copyright © 1997-2004. All Rights Reserved.
4
5
SUBSYSTEM: Stars.exe
6
FILE: NetAddrDlg.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
Mission Select Dialog Active Window class
13
*/
14
15
#include "
MemDebug.h
"
16
#include "
NetAddrDlg.h
"
17
#include "
MenuScreen.h
"
18
#include "
NetClientConfig.h
"
19
20
#include "
Game.h
"
21
#include "
DataLoader.h
"
22
#include "
Button.h
"
23
#include "
EditBox.h
"
24
#include "
ListBox.h
"
25
#include "
Slider.h
"
26
#include "
Video.h
"
27
#include "
Keyboard.h
"
28
#include "
Mouse.h
"
29
#include "
ParseUtil.h
"
30
#include "
FormatUtil.h
"
31
32
// +--------------------------------------------------------------------+
33
// DECLARE MAPPING FUNCTIONS:
34
35
DEF_MAP_CLIENT
(
NetAddrDlg
, OnSave);
36
DEF_MAP_CLIENT
(
NetAddrDlg
, OnCancel);
37
38
// +--------------------------------------------------------------------+
39
40
NetAddrDlg::NetAddrDlg
(
Screen
* s,
FormDef
& def,
MenuScreen
* mgr)
41
:
FormWindow
(s, 0, 0, s->Width(), s->Height()), manager(mgr),
42
btn_save(0), btn_cancel(0), edt_name(0), edt_addr(0), edt_port(0), edt_pass(0)
43
{
44
Init
(def);
45
}
46
47
NetAddrDlg::~NetAddrDlg
()
48
{
49
}
50
51
// +--------------------------------------------------------------------+
52
53
void
54
NetAddrDlg::RegisterControls
()
55
{
56
btn_save
= (
Button
*)
FindControl
(1);
57
btn_cancel
= (
Button
*)
FindControl
(2);
58
59
REGISTER_CLIENT
(
EID_CLICK
,
btn_save
,
NetAddrDlg
,
OnSave
);
60
REGISTER_CLIENT
(
EID_CLICK
,
btn_cancel
,
NetAddrDlg
,
OnCancel
);
61
62
edt_name
= (
EditBox
*)
FindControl
(200);
63
edt_addr
= (
EditBox
*)
FindControl
(201);
64
edt_port
= (
EditBox
*)
FindControl
(202);
65
edt_pass
= (
EditBox
*)
FindControl
(203);
66
67
if
(
edt_name
)
edt_name
->
SetText
(
""
);
68
if
(
edt_addr
)
edt_addr
->
SetText
(
""
);
69
if
(
edt_port
)
edt_port
->
SetText
(
""
);
70
if
(
edt_pass
)
edt_pass
->
SetText
(
""
);
71
}
72
73
// +--------------------------------------------------------------------+
74
75
void
76
NetAddrDlg::Show
()
77
{
78
if
(!
IsShown
()) {
79
FormWindow::Show
();
80
81
if
(
edt_name
)
edt_name
->
SetText
(
""
);
82
if
(
edt_addr
)
edt_addr
->
SetText
(
""
);
83
if
(
edt_port
)
edt_port
->
SetText
(
""
);
84
if
(
edt_pass
)
edt_pass
->
SetText
(
""
);
85
86
if
(
edt_name
)
edt_name
->
SetFocus
();
87
}
88
}
89
90
// +--------------------------------------------------------------------+
91
92
static
bool
tab_latch =
false
;
93
94
void
95
NetAddrDlg::ExecFrame
()
96
{
97
if
(
Keyboard::KeyDown
(VK_RETURN)) {
98
OnSave
(0);
99
}
100
}
101
102
// +--------------------------------------------------------------------+
103
104
void
105
NetAddrDlg::OnSave
(
AWEvent
* event)
106
{
107
NetClientConfig
* config =
NetClientConfig::GetInstance
();
108
109
if
(config &&
110
edt_addr
&&
edt_addr
->
GetText
().
length
() > 0 &&
111
edt_port
&&
edt_port
->
GetText
().
length
() > 0)
112
{
113
Text
name;
114
Text
addr;
115
Text
pass;
116
int
port;
117
118
sscanf_s(
edt_port
->
GetText
().
data
(),
"%d"
, &port);
119
120
if
(
edt_name
&&
edt_name
->
GetText
().
length
() < 250) {
121
char
buffer[256];
122
strcpy_s(buffer,
edt_name
->
GetText
().
data
());
123
char
* p = strpbrk(buffer,
"\n\r\t"
);
124
if
(p) *p = 0;
125
126
name =
SafeQuotes
(buffer);
127
}
128
129
if
(
edt_pass
&&
edt_pass
->
GetText
().
length
() < 250) {
130
char
buffer[256];
131
strcpy_s(buffer,
edt_pass
->
GetText
().
data
());
132
char
* p = strpbrk(buffer,
"\n\r\t"
);
133
if
(p) *p = 0;
134
135
pass =
SafeQuotes
(buffer);
136
}
137
138
if
(
edt_addr
&&
edt_addr
->
GetText
().
length
() < 250) {
139
char
buffer[256];
140
strcpy_s(buffer,
edt_addr
->
GetText
().
data
());
141
char
* p = strpbrk(buffer,
"\n\r\t"
);
142
if
(p) *p = 0;
143
144
addr =
SafeQuotes
(buffer);
145
}
146
147
config->
AddServer
(name, addr, port, pass,
true
);
148
config->
Save
();
149
}
150
151
if
(
manager
)
152
manager
->
ShowNetClientDlg
();
153
}
154
155
void
156
NetAddrDlg::OnCancel
(
AWEvent
* event)
157
{
158
if
(
manager
)
159
manager
->
ShowNetClientDlg
();
160
}
Stars45
NetAddrDlg.cpp
Generated on Tue Jun 5 2012 20:47:01 for Starshatter_Open by
1.8.1