FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
bc2-query/ServerList_Window.cpp at master · anthnich/bc2-query · GitHub
anthnich
/
bc2-query
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
bc2-query
/
ServerList_Window.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
179 lines (112 loc) · 4.28 KB
Breadcrumbs
bc2-query
/
ServerList_Window.cpp
Copy path
File metadata and controls
179 lines (112 loc) · 4.28 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#
include
"
ServerList_Window.hpp
"
int
ServerList_Window::serverbrowser_widths[] = {
272
,
272
};
void
ServerList_Window::ServerListFile_LoadEntries
() {
serverbrowserentries.
clear
();
pugi::xml_document *doc =
new
pugi::xml_document
();
if
(!doc->
load_file
(
"
serv.xml
"
) != pugi::xml_parse_status::status_file_not_found) {
for
(pugi::xml_node xmlserver = doc->
child
(
"
server
"
); xmlserver; xmlserver = xmlserver.
next_sibling
(
"
server
"
)) {
serverfileentry sfe;
sfe.
ip
= xmlserver.
child_value
(
"
ip
"
);
sfe.
name
= xmlserver.
child_value
(
"
name
"
);
serverbrowserentries.
push_back
(sfe);
}
}
delete
doc;
}
void
ServerList_Window::ServerListFile_SaveEntries
() {
pugi::xml_document *doc =
new
pugi::xml_document
();
if
(!serverbrowserentries.
empty
()) {
for
(
int
i =
0
; i < serverbrowserentries.
size
(); i++) {
pugi::xml_node server = doc->
append_child
(
"
server
"
);
server.
append_child
(
"
ip
"
).
text
().
set
(serverbrowserentries.
at
(i).
ip
.
c_str
());
server.
append_child
(
"
name
"
).
text
().
set
(serverbrowserentries.
at
(i).
name
.
c_str
());
}
}
doc->
save_file
(
"
serv.xml
"
);
delete
doc;
}
void
ServerList_Window::ServerList_FillBrowser
() {
if
(!serverbrowserentries.
empty
()) {
serverbrowser->
clear
();
for
(
int
i =
0
; i < serverbrowserentries.
size
(); i++) {
std::string ent = serverbrowserentries.
at
(i).
name
+
"
\t
"
+ serverbrowserentries.
at
(i).
ip
;
serverbrowser->
add
(ent.
c_str
());
}
}
}
void
ServerList_Window::CALLBACK_done
(Fl_Widget *,
void
*data) {
ServerList_Window *win =
static_cast
<ServerList_Window *>(data);
if
(!win->
serverbrowserentries
.
empty
()) {
//
if selected. 0 means nothing has been selected.
if
(win->
serverbrowser
->
value
() >
0
)
win->
selectedIP
= win->
serverbrowserentries
.
at
(win->
serverbrowser
->
value
() -
1
).
ip
;
}
win->
hide
();
}
void
ServerList_Window::CALLBACK_save
(Fl_Widget *,
void
*data) {
ServerList_Window *win =
static_cast
<ServerList_Window *>(data);
serverfileentry sfe;
sfe.
ip
= win->
input_ip
->
value
();
sfe.
name
= win->
input_name
->
value
();
if
(sfe.
ip
!=
"
"
) {
win->
serverbrowserentries
.
push_back
(sfe);
win->
ServerListFile_SaveEntries
();
win->
ServerList_FillBrowser
();
}
}
void
ServerList_Window::CALLBACK_remove
(Fl_Widget *,
void
*data) {
ServerList_Window *win =
static_cast
<ServerList_Window *>(data);
//
remove from vector.
if
(win->
serverbrowser
->
value
() >
0
)
win->
serverbrowserentries
.
erase
(win->
serverbrowserentries
.
begin
() + (win->
serverbrowser
->
value
() -
1
));
//
remove from server browser.
win->
serverbrowser
->
remove
(win->
serverbrowser
->
value
());
//
save xml.
win->
ServerListFile_SaveEntries
();
}
void
ServerList_Window::Think
() {
//
an fltk bug forces me to save the width/height of a window
//
and resize it on each show.
resize
(windowvars.
x
, windowvars.
y
, windowvars.
w
, windowvars.
h
);
show
();
}
ServerList_Window::ServerList_Window
(
const
int
width,
const
int
height,
const
char
*label) :
Fl_Window(width, height, label) {
windowvars.
x
=
64
;
windowvars.
y
=
64
;
windowvars.
w
= width;
windowvars.
h
= height;
int
posx =
48
;
int
posy =
8
+
24
;
//
window.
icon
((
char
*)
LoadIcon
(fl_display,
"
IDI_SMALL
"
));
color
((Fl_Color)
FL_LIGHT1
);
//
INPUT / SAVE IP BUTTON
input_ip =
new
Fl_Input
(posx +
48
, posy,
148
,
24
,
"
IP:
"
);
posy +=
32
;
input_name =
new
Fl_Input
(posx +
48
, posy,
148
,
24
,
"
Name:
"
);
input_ipsave =
new
Fl_Button
(posx +
216
, posy,
96
,
24
,
"
Save
"
);
input_ipsave->
callback
(CALLBACK_save, (
void
*)
this
);
input_ipremove =
new
Fl_Button
(posx +
216
+
112
, posy,
96
,
24
,
"
Remove
"
);
input_ipremove->
callback
(CALLBACK_remove, (
void
*)
this
);
input_done =
new
Fl_Button
(width -
96
, height -
48
,
80
,
32
,
"
Select
"
);
input_done->
callback
(CALLBACK_done, (
void
*)
this
);
posy +=
24
+
16
;
//
SCROLL -- For player list.
scroll =
new
Fl_Scroll
(posx, posy, width -
96
, height -
160
);
scroll->
box
(
FL_DOWN_BOX
);
scroll->
color
((Fl_Color)
FL_WHITE
);
scroll->
type
(
FL_VERTICAL
);
scroll->
begin
();
//
BROWSER -- Player list.
serverbrowser =
new
Fl_Browser
(posx, posy, width -
96
, height -
160
);
serverbrowser->
column_widths
(serverbrowser_widths);
serverbrowser->
column_char
(
'
\t
'
);
serverbrowser->
type
(
FL_MULTI_BROWSER
);
serverbrowser->
align
(
FL_ALIGN_LEFT
|
FL_ALIGN_TOP
|
FL_ALIGN_INSIDE
);
ServerListFile_LoadEntries
();
ServerList_FillBrowser
();
scroll->
end
();
end
();
set_modal
();
}
Back
|
FazBrowse Home
|
New Git URL