some fixes to multiplayer setup screens

This commit is contained in:
uid68803 2004-01-08 18:22:40 +00:00
parent ffd860c8f4
commit 0521c59b88
11 changed files with 99 additions and 53 deletions

View file

@ -126,6 +126,7 @@ public:
got_side = false;
throw network::error("Side chosen is unavailable");
} else if(reply["side_secured"].empty() == false) {
std::cerr << "received side secured message\n";
got_side = true;
} else if(reply.child("start_game")) {
std::cerr << "received start_game message\n";

View file

@ -266,7 +266,7 @@ void mp_connect::lists_init()
player_colors_.push_back(string_table["purple"]);
}
void mp_connect::add_player(std::string name)
void mp_connect::add_player(const std::string& name)
{
player_types_.push_back(name);
@ -275,6 +275,13 @@ void mp_connect::add_player(std::string name)
}
}
void mp_connect::remove_player(const std::string& name)
{
const std::vector<std::string>::iterator itor = std::find(player_types_.begin(),player_types_.end(),name);
if(itor != player_types_.end())
player_types_.erase(itor);
}
void mp_connect::gui_init()
{
@ -458,7 +465,8 @@ int mp_connect::gui_do()
//Player type
//Don't let user change this if a player is sitting
if(combos_type_[n].selected() < 4) {
combos_type_[n].enable(combos_type_[n].selected() < 4);
int old_select = combos_type_[n].selected();
if(combos_type_[n].process(mousex, mousey, left_button)) {
if(combos_type_[n].selected() == 0) {
@ -491,42 +499,30 @@ int mp_connect::gui_do()
}
network::send_data(*level_);
}
}
//Player race
if(!save_) {
if(combos_race_[n].process(mousex, mousey, left_button)) {
const string_map& values =
possible_sides[combos_race_[n].selected()]->values;
for(string_map::const_iterator i = values.begin(); i != values.end(); ++i) {
side[i->first] = i->second;
}
network::send_data(*level_);
combos_race_[n].enable(!save_);
combos_team_[n].enable(!save_);
combos_color_[n].enable(!save_);
if(combos_race_[n].process(mousex, mousey, left_button)) {
const string_map& values = possible_sides[combos_race_[n].selected()]->values;
for(string_map::const_iterator i = values.begin(); i != values.end(); ++i) {
side[i->first] = i->second;
}
} else {
combos_race_[n].draw();
network::send_data(*level_);
}
//Player team
if(!save_) {
if(combos_team_[n].process(mousex, mousey, left_button)) {
std::stringstream str;
str << (combos_team_[n].selected()+1);
side["team_name"] = str.str();
network::send_data(*level_);
}
} else {
combos_team_[n].draw();
if(combos_team_[n].process(mousex, mousey, left_button)) {
std::stringstream str;
str << (combos_team_[n].selected()+1);
side["team_name"] = str.str();
network::send_data(*level_);
}
//Player color
if(!save_) {
if(combos_color_[n].process(mousex, mousey, left_button)) {
network::send_data(*level_);
}
} else {
combos_color_[n].draw();
if(combos_color_[n].process(mousex, mousey, left_button)) {
network::send_data(*level_);
}
if(!save_){
@ -561,7 +557,8 @@ int mp_connect::gui_do()
return status_;
}
if(full_ == true) {
launch_.enable(full_);
if(launch_.process(mousex,mousey,left_button)) {
//Tell everyone to start
config cfg;
@ -592,9 +589,6 @@ int mp_connect::gui_do()
status_ = 0;
return status_;
}
} else {
launch_.draw();
}
gui_update();
update_positions();
@ -615,8 +609,7 @@ void mp_connect::update_positions()
const config::child_list& possible_sides = cfg_->get_children("multiplayer_side");
config::child_iterator sd;
for(sd = sides.first; sd != sides.second; ++sd) {
if((**sd)["controller"] == "network" &&
(**sd)["description"] == "") {
if((**sd)["taken"] != "yes") {
positions_[*sd] = 0;
}
}
@ -666,11 +659,8 @@ void mp_connect::update_network()
i->second = 0;
i->first->values.erase("taken");
// Add to combo list
std::stringstream str;
str << i->first->values["description"];
//remove_player(str.str());
i->first->values["description"]="";
remove_player(i->first->values["description"]);
i->first->values["description"] = "";
}
}
@ -701,17 +691,22 @@ void mp_connect::update_network()
if(side_taken >= 0 && side_taken < int(sides.size())) {
std::map<config*,network::connection>::iterator pos = positions_.find(sides[side_taken]);
if(pos != positions_.end()) {
if(!pos->second) {
if(!pos->second || pos->second == sock) {
std::cerr << "client has taken a valid position\n";
//does the client already own the side, and is just updating
//it, or is it taking a vacant slot?
const bool update_only = pos->second == sock;
//broadcast to everyone the new game status
pos->first->values["controller"] = "network";
pos->first->values["taken"] = "yes";
pos->first->values["description"] = cfg["description"];
pos->first->values["name"] = cfg["name"];
pos->first->values["type"] = cfg["type"];
pos->first->values["recruit"] = cfg["recruit"];
pos->first->values["music"] = cfg["music"];
positions_[sides[side_taken]] = sock;
pos->second = sock;
network::send_data(*level_);
std::cerr << "sent player data\n";
@ -726,9 +721,7 @@ void mp_connect::update_network()
network::send_data(reply,sock);
// Add to combo list
std::stringstream str;
str << cfg["description"];
add_player(str.str());
add_player(cfg["description"]);
} else {
config response;
response.values["failed"] = "yes";

View file

@ -42,7 +42,8 @@ private:
void lists_init();
void gui_init();
void gui_update();
void add_player(std::string name);
void add_player(const std::string& name);
void remove_player(const std::string& name);
void update_positions();
void update_network();
void is_full();

View file

@ -1087,13 +1087,15 @@ void turn_info::status_table()
items.push_back(heading.str());
const team& viewing_team = teams_[gui_.viewing_team()];
//if the player is under shroud or fog, they don't get to see
//details about the other sides, only their own side, and a ??? is
//details about the other sides, only their own side, allied sides and a ??? is
//shown to demonstrate lack of information about the other sides
const bool fog = teams_[gui_.viewing_team()].uses_fog() || teams_[gui_.viewing_team()].uses_shroud();
const bool fog = viewing_team.uses_fog() || viewing_team.uses_shroud();
for(size_t n = 0; n != teams_.size(); ++n) {
if(fog && gui_.viewing_team() != n)
if(fog && viewing_team.is_enemy(n+1))
continue;
const team_data data = calculate_team_data(teams_[n],n+1,units_);

View file

@ -27,6 +27,14 @@ int sdl_add_ref(SDL_Surface* surface)
return 0;
}
SDL_Surface* clone_surface(SDL_Surface* surface)
{
if(surface == NULL)
return NULL;
return scale_surface(surface,surface->w,surface->h);
}
SDL_Surface* scale_surface(SDL_Surface* surface, int w, int h)
{
if(surface == NULL)

View file

@ -41,6 +41,7 @@ int sdl_add_ref(SDL_Surface* surface);
typedef util::scoped_resource<SDL_Surface*,free_sdl_surface> scoped_sdl_surface;
SDL_Surface* clone_surface(SDL_Surface* surface);
SDL_Surface* scale_surface(SDL_Surface* surface, int w, int h);
void adjust_surface_colour(SDL_Surface* surface, int r, int g, int b);

View file

@ -210,8 +210,7 @@ void server::run()
continue;
}
const string_map::const_iterator side =
data.values.find("side");
const string_map::const_iterator side = data.values.find("side");
if(side != data.values.end()) {
const bool res = g->take_side(sock,data);
config response;

View file

@ -31,7 +31,7 @@ button::button(display& disp, const std::string& label, button::TYPE type,
label_(label), display_(&disp),
image_(NULL), pressedImage_(NULL), activeImage_(NULL), pressedActiveImage_(NULL),
x_(0), y_(0), button_(true),
state_(UNINIT), type_(type)
state_(UNINIT), type_(type), enabled_(true)
{
set_label(label);
@ -113,6 +113,19 @@ void button::hide()
restorer_.restore();
}
void button::enable(bool new_val)
{
if(enabled_ != new_val) {
enabled_ = new_val;
draw();
}
}
bool button::enabled() const
{
return enabled_;
}
void button::draw()
{
if(type_ == TYPE_CHECK) {
@ -147,6 +160,13 @@ void button::draw()
textx = x_ + image_w + horizontal_padding/2;
}
scoped_sdl_surface greyed_image(NULL);
if(!enabled_) {
greyed_image.assign(clone_surface(image));
adjust_surface_colour(greyed_image,-50,-50,-50);
image = greyed_image;
}
display_->blit_surface(x_,y_,image);
font::draw_text(display_,clipArea,font_size,
font::BUTTON_COLOUR,label_,textx,texty);
@ -212,6 +232,15 @@ int button::height() const
bool button::process(int mousex, int mousey, bool button)
{
if(!enabled_) {
if(state_ == UNINIT) {
state_ = NORMAL;
draw();
}
return false;
}
enum MOUSE_STATE { UNCHANGED, UP, DOWN };
MOUSE_STATE mouse_state = UNCHANGED;
if(button && !button_)

View file

@ -53,6 +53,9 @@ public:
void backup_background();
void hide();
void enable(bool new_val);
bool enabled() const;
private:
surface_restorer restorer_;
std::string label_;
@ -68,6 +71,8 @@ private:
TYPE type_;
bool enabled_;
bool hit(int x, int y) const;
}; //end class button

View file

@ -82,4 +82,8 @@ bool combo::process(int x, int y, bool button)
return false;
}
void combo::enable(bool new_val) { button_.enable(new_val); }
bool combo::enabled() const { return button_.enabled(); }
}

View file

@ -38,6 +38,9 @@ public:
bool process(int mousex, int mousey, bool button);
void enable(bool new_val);
bool enabled() const;
private:
std::vector<std::string> items_;
int selected_;