more newlobby WIP
This commit is contained in:
parent
df99e391d5
commit
b71faa6269
5 changed files with 106 additions and 28 deletions
|
@ -67,13 +67,9 @@
|
|||
definition = "default"
|
||||
[header]
|
||||
[row]
|
||||
{GAMELISTBOX_HEADER_LABEL "name" "Name"}
|
||||
{GAMELISTBOX_HEADER_LABEL "map" "Map"}
|
||||
{GAMELISTBOX_HEADER_LABEL "era" "Era"}
|
||||
{GAMELISTBOX_HEADER_LABEL "slots" "Slots"}
|
||||
{GAMELISTBOX_HEADER_LABEL "options" "Options"}
|
||||
{GAMELISTBOX_HEADER_LABEL "info" "Name"}
|
||||
{GAMELISTBOX_HEADER_LABEL "join" "Join"}
|
||||
{GAMELISTBOX_HEADER_LABEL "observe" "Observe"}
|
||||
[/row]
|
||||
[/header]
|
||||
[list_definition]
|
||||
|
@ -83,17 +79,40 @@
|
|||
horizontal_grow = "true"
|
||||
[toggle_panel]
|
||||
definition = "default"
|
||||
[grid]
|
||||
[row]
|
||||
{GAMELISTBOX_BODY_LABEL "name" "Name"}
|
||||
{GAMELISTBOX_BODY_LABEL "map" "Map"}
|
||||
{GAMELISTBOX_BODY_LABEL "era" "Era"}
|
||||
{GAMELISTBOX_BODY_LABEL "slots" "Slots"}
|
||||
{GAMELISTBOX_BODY_LABEL "options" "Options"}
|
||||
{GAMELISTBOX_BODY_BUTTON "join" "Join"}
|
||||
{GAMELISTBOX_BODY_BUTTON "observe" "Observe"}
|
||||
[/row]
|
||||
[/grid]
|
||||
{HORIZONTAL_BEGIN}
|
||||
[label]
|
||||
id = {ID}
|
||||
definition = "default"
|
||||
label = "Here be minimap"
|
||||
[/label]
|
||||
{HORIZONTAL_SEP}
|
||||
{VERTICAL_BEGIN}
|
||||
[grid]
|
||||
[row]
|
||||
{GAMELISTBOX_BODY_LABEL "name" "Name"}
|
||||
{GAMELISTBOX_BODY_LABEL "map" "Map"}
|
||||
{GAMELISTBOX_BODY_LABEL "era" "Era"}
|
||||
[/row]
|
||||
[/grid]
|
||||
{VERTICAL_SEP}
|
||||
[grid]
|
||||
[row]
|
||||
{GAMELISTBOX_BODY_LABEL "map_info" "Map info"}
|
||||
{GAMELISTBOX_BODY_LABEL "slots" "Slots"}
|
||||
{GAMELISTBOX_BODY_LABEL "options" "Options"}
|
||||
[/row]
|
||||
[/grid]
|
||||
{VERTICAL_END}
|
||||
{HORIZONTAL_SEP}
|
||||
[grid]
|
||||
[row]
|
||||
{GAMELISTBOX_BODY_BUTTON "join" "Join"}
|
||||
[/row]
|
||||
[row]
|
||||
{GAMELISTBOX_BODY_BUTTON "observe" "Observe"}
|
||||
[/row]
|
||||
[/grid]
|
||||
{HORIZONTAL_END}
|
||||
[/toggle_panel]
|
||||
[/column]
|
||||
[/row]
|
||||
|
@ -103,7 +122,7 @@
|
|||
|
||||
#define PLAYERLISTBOX
|
||||
[listbox]
|
||||
id = "player_list"
|
||||
id = "user_list"
|
||||
definition = "default"
|
||||
[header]
|
||||
[row]
|
||||
|
|
|
@ -86,19 +86,34 @@ twindow* tlobby_main::build_window(CVideo& video)
|
|||
return build(video, get_id(LOBBY_MAIN));
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
void add_label_data(std::map<std::string, string_map>& map,
|
||||
const std::string& key, const std::string& label)
|
||||
{
|
||||
string_map item;
|
||||
item["label"] = label;
|
||||
map.insert(std::make_pair(key, item));
|
||||
}
|
||||
|
||||
} //end anonymous namespace
|
||||
|
||||
void tlobby_main::update_gamelist()
|
||||
{
|
||||
foreach (const game_info &game, lobby_info_->games())
|
||||
{
|
||||
std::map<std::string, string_map> data;
|
||||
string_map item;
|
||||
std::string tmp;
|
||||
|
||||
item["label"] = game.name;
|
||||
data.insert(std::make_pair("name", item));
|
||||
|
||||
item["label"] = game.map_info;
|
||||
data.insert(std::make_pair("name", item));
|
||||
add_label_data(data, "name", game.name);
|
||||
add_label_data(data, "era", game.era);
|
||||
add_label_data(data, "era_short", game.era_short);
|
||||
add_label_data(data, "map_info", game.map_info);
|
||||
add_label_data(data, "time_limit", game.time_limit);
|
||||
add_label_data(data, "status", game.status);
|
||||
add_label_data(data, "gold", game.gold);
|
||||
add_label_data(data, "xp", game.xp);
|
||||
add_label_data(data, "vision", game.vision);
|
||||
add_label_data(data, "map_info", game.map_info);
|
||||
|
||||
gamelistbox_->add_row(data);
|
||||
tgrid* grid = gamelistbox_->get_row_grid(gamelistbox_->get_item_count() - 1);
|
||||
|
@ -113,6 +128,12 @@ void tlobby_main::update_gamelist()
|
|||
observe_button->set_callback_mouse_left_click(
|
||||
dialog_callback<tlobby_main, &tlobby_main::observe_button_callback>);
|
||||
}
|
||||
foreach (const user_info& user, lobby_info_->users())
|
||||
{
|
||||
std::map<std::string, string_map> data;
|
||||
add_label_data(data, "player", user.name);
|
||||
userlistbox_->add_row(data);
|
||||
}
|
||||
window_->invalidate_layout();
|
||||
}
|
||||
|
||||
|
@ -121,6 +142,9 @@ void tlobby_main::pre_show(CVideo& /*video*/, twindow& window)
|
|||
gamelistbox_ = dynamic_cast<tlistbox*>(window.find_widget("game_list", false));
|
||||
VALIDATE(gamelistbox_, missing_widget("game_list"));
|
||||
|
||||
userlistbox_ = dynamic_cast<tlistbox*>(window.find_widget("user_list", false));
|
||||
VALIDATE(userlistbox_, missing_widget("user_list"));
|
||||
|
||||
chat_log_ = dynamic_cast<tlabel*>(window.find_widget("chat_log", false));
|
||||
VALIDATE(chat_log_, missing_widget("chat_log"));
|
||||
|
||||
|
|
|
@ -83,6 +83,8 @@ private:
|
|||
|
||||
tlistbox* gamelistbox_;
|
||||
|
||||
tlistbox* userlistbox_;
|
||||
|
||||
tlabel* chat_log_;
|
||||
|
||||
ttext_box* chat_input_;
|
||||
|
|
|
@ -113,6 +113,26 @@ game_info::game_info() :
|
|||
{
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
std::string make_short_name(const std::string long_name)
|
||||
{
|
||||
if (long_name.empty()) return "";
|
||||
std::string sh;
|
||||
bool had_space = true;
|
||||
for (size_t i = 1; i < long_name.size(); ++i) {
|
||||
if (long_name[i] == ' ') {
|
||||
had_space = true;
|
||||
} else if (had_space && long_name[i] != '?') {
|
||||
sh += long_name[i];
|
||||
had_space = false;
|
||||
}
|
||||
}
|
||||
return sh;
|
||||
}
|
||||
|
||||
} //end anonymous namespace
|
||||
|
||||
game_info::game_info(const config& game, const config& game_config)
|
||||
: mini_map()
|
||||
, id(game["id"])
|
||||
|
@ -120,6 +140,8 @@ game_info::game_info(const config& game, const config& game_config)
|
|||
, name(game["name"])
|
||||
, map_info()
|
||||
, map_info_size()
|
||||
, era()
|
||||
, era_short()
|
||||
, gold(game["mp_village_gold"])
|
||||
, xp(game["experience_modifier"] + "%")
|
||||
, vision()
|
||||
|
@ -145,16 +167,23 @@ game_info::game_info(const config& game, const config& game_config)
|
|||
utils::string_map symbols;
|
||||
symbols["era_id"] = game["mp_era"];
|
||||
if (era_cfg) {
|
||||
map_info = era_cfg["name"];
|
||||
era = era_cfg["name"];
|
||||
era_short = era_cfg["short_name"];
|
||||
if (era_short.empty()) {
|
||||
era_short = make_short_name(era);
|
||||
}
|
||||
} else {
|
||||
have_era = (game["require_era"] == "no");
|
||||
map_info = vgettext("Unknown era: $era_id", symbols);
|
||||
era = vgettext("Unknown era: $era_id", symbols);
|
||||
era_short = "?" + make_short_name(era);
|
||||
verified = false;
|
||||
}
|
||||
} else {
|
||||
map_info = _("Unknown era");
|
||||
era = _("Unknown era");
|
||||
era_short = "??";
|
||||
verified = false;
|
||||
}
|
||||
map_info = era;
|
||||
|
||||
if (map_data.empty()) {
|
||||
map_data = read_map(game["map"]);
|
||||
|
@ -236,7 +265,7 @@ game_info::game_info(const config& game, const config& game_config)
|
|||
started = false;
|
||||
if (vacant_slots > 0) {
|
||||
status = std::string(_n("Vacant Slot:", "Vacant Slots:",
|
||||
vacant_slots)) + " " + slots;
|
||||
vacant_slots)) + " " + game["slots"];
|
||||
if (password_required) {
|
||||
status += std::string(" (") + std::string(_("Password Required")) + ")";
|
||||
}
|
||||
|
|
|
@ -75,12 +75,16 @@ struct game_info
|
|||
std::string name;
|
||||
std::string map_info;
|
||||
std::string map_info_size;
|
||||
std::string era;
|
||||
std::string era_short;
|
||||
|
||||
std::string gold;
|
||||
std::string xp;
|
||||
std::string vision;
|
||||
std::string status;
|
||||
std::string time_limit;
|
||||
size_t vacant_slots;
|
||||
|
||||
unsigned int current_turn;
|
||||
bool reloaded;
|
||||
bool started;
|
||||
|
|
Loading…
Add table
Reference in a new issue