changes to wose stats
This commit is contained in:
parent
5ae112140a
commit
e2597cbc83
18 changed files with 189 additions and 57 deletions
|
@ -127,7 +127,7 @@
|
||||||
[/race]
|
[/race]
|
||||||
[race]
|
[race]
|
||||||
name=wose
|
name=wose
|
||||||
num_traits=2
|
num_traits=0
|
||||||
[/race]
|
[/race]
|
||||||
[race]
|
[race]
|
||||||
name=human
|
name=human
|
||||||
|
@ -617,10 +617,10 @@
|
||||||
|
|
||||||
[resistance]
|
[resistance]
|
||||||
blade=100
|
blade=100
|
||||||
pierce=70
|
pierce=30
|
||||||
impact=80
|
impact=50
|
||||||
fire=150
|
fire=150
|
||||||
cold=100
|
cold=50
|
||||||
holy=80
|
holy=80
|
||||||
[/resistance]
|
[/resistance]
|
||||||
[/movetype]
|
[/movetype]
|
||||||
|
|
|
@ -400,6 +400,7 @@ vacant_slot="Vacant Slot"
|
||||||
vacant_slots="Vacant Slots"
|
vacant_slots="Vacant Slots"
|
||||||
|
|
||||||
host_game="Host Multiplayer Game"
|
host_game="Host Multiplayer Game"
|
||||||
|
join_server="Join Official Server"
|
||||||
join_game="Join Game"
|
join_game="Join Game"
|
||||||
observe_game="Observe Game"
|
observe_game="Observe Game"
|
||||||
load_game="Load Game"
|
load_game="Load Game"
|
||||||
|
|
|
@ -11,7 +11,7 @@ alignment=chaotic
|
||||||
advanceto=Direwolf Rider
|
advanceto=Direwolf Rider
|
||||||
cost=28
|
cost=28
|
||||||
usage=scout
|
usage=scout
|
||||||
unit_description="The Goblin Knights are the elite of the Goblin Wolf Riders. They travel with great speed, outpacing their human and Elvish counterparts."
|
unit_description="The Goblin Knights are the elite of the Goblin Wolf Riders. They travel with great speed, yet can inflict substantial damage in battle."
|
||||||
get_hit_sound=wolf-cry.wav
|
get_hit_sound=wolf-cry.wav
|
||||||
[attack]
|
[attack]
|
||||||
name=fangs
|
name=fangs
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[unit]
|
[unit]
|
||||||
name=Wose
|
name=Elder Wose
|
||||||
race=wose
|
race=wose
|
||||||
image=wose.png
|
image=wose.png
|
||||||
image_defensive=wose-defend.png
|
image_defensive=wose-defend.png
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
[unit]
|
[unit]
|
||||||
name=Wose Sapling
|
name=Wose
|
||||||
race=wose
|
race=wose
|
||||||
image=wose-sapling.png
|
image=wose-sapling.png
|
||||||
image_defensive=wose-sapling-defend.png
|
image_defensive=wose-sapling-defend.png
|
||||||
ability=ambush,regenerates
|
ability=ambush,regenerates
|
||||||
hitpoints=44
|
hitpoints=52
|
||||||
movement_type=treefolk
|
movement_type=treefolk
|
||||||
movement=3
|
movement=3
|
||||||
experience=40
|
experience=40
|
||||||
level=1
|
level=1
|
||||||
alignment=lawful
|
alignment=lawful
|
||||||
advanceto=Wose
|
advanceto=Elder Wose
|
||||||
cost=20
|
cost=20
|
||||||
usage=fighter
|
usage=fighter
|
||||||
[attack]
|
[attack]
|
||||||
name=crush
|
name=crush
|
||||||
type=impact
|
type=impact
|
||||||
range=short
|
range=short
|
||||||
damage=9
|
damage=14
|
||||||
number=2
|
number=2
|
||||||
[frame]
|
[frame]
|
||||||
begin=-100
|
begin=-100
|
||||||
|
|
|
@ -191,7 +191,7 @@ void ai_interface::sync_network()
|
||||||
|
|
||||||
gamemap::location ai_interface::move_unit(location from, location to, std::map<location,paths>& possible_moves)
|
gamemap::location ai_interface::move_unit(location from, location to, std::map<location,paths>& possible_moves)
|
||||||
{
|
{
|
||||||
std::cerr << "ai_interface::move_unit " << (from.x+1) << (from.y+1) << " -> " << (to.x+1) << "," << (to.y+1) << "\n";
|
std::cerr << "ai_interface::move_unit " << (from.x+1) << "," << (from.y+1) << " -> " << (to.x+1) << "," << (to.y+1) << "\n";
|
||||||
//stop the user from issuing any commands while the unit is moving
|
//stop the user from issuing any commands while the unit is moving
|
||||||
const command_disabler disable_commands(&info_.disp);
|
const command_disabler disable_commands(&info_.disp);
|
||||||
|
|
||||||
|
@ -346,7 +346,6 @@ bool ai::multistep_move_possible(location from, location to, location via, std::
|
||||||
|
|
||||||
gamemap::location ai::move_unit(location from, location to, std::map<location,paths>& possible_moves)
|
gamemap::location ai::move_unit(location from, location to, std::map<location,paths>& possible_moves)
|
||||||
{
|
{
|
||||||
std::cerr << "ai::move_unit " << (from.x+1) << (from.y+1) << " -> " << (to.x+1) << "," << (to.y+1) << "\n";
|
|
||||||
std::map<location,paths> temp_possible_moves;
|
std::map<location,paths> temp_possible_moves;
|
||||||
std::map<location,paths>* possible_moves_ptr = &possible_moves;
|
std::map<location,paths>* possible_moves_ptr = &possible_moves;
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#define AI_DIAGNOSTIC(MSG) if(game_config::debug) { diagnostic(MSG); std::cerr << "AI_DIAGNOSTIC: " << MSG << "\n"; }
|
#define AI_DIAGNOSTIC(MSG) if(game_config::debug) { diagnostic(MSG); } std::cerr << "AI_DIAGNOSTIC: " << MSG << "\n";
|
||||||
#define AI_LOG(MSG) if(game_config::debug) { log_message(MSG); std::cerr << "AI_LOG: " << MSG << "\n";}
|
#define AI_LOG(MSG) if(game_config::debug) { log_message(MSG); } std::cerr << "AI_LOG: " << MSG << "\n";
|
||||||
|
|
||||||
class ai_interface {
|
class ai_interface {
|
||||||
public:
|
public:
|
||||||
|
|
36
src/game.cpp
36
src/game.cpp
|
@ -329,6 +329,8 @@ int play_game(int argc, char** argv)
|
||||||
|
|
||||||
bool use_caching = true;
|
bool use_caching = true;
|
||||||
|
|
||||||
|
int force_bpp = -1;
|
||||||
|
|
||||||
for(arg = 1; arg != argc; ++arg) {
|
for(arg = 1; arg != argc; ++arg) {
|
||||||
const std::string val(argv[arg]);
|
const std::string val(argv[arg]);
|
||||||
if(val.empty()) {
|
if(val.empty()) {
|
||||||
|
@ -351,6 +353,11 @@ int play_game(int argc, char** argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if(val == "--bpp") {
|
||||||
|
if(arg+1 != argc) {
|
||||||
|
++arg;
|
||||||
|
force_bpp = lexical_cast_default<int>(argv[arg],-1);
|
||||||
|
}
|
||||||
} else if(val == "--nogui") {
|
} else if(val == "--nogui") {
|
||||||
no_gui = true;
|
no_gui = true;
|
||||||
} else if(val == "--windowed" || val == "-w") {
|
} else if(val == "--windowed" || val == "-w") {
|
||||||
|
@ -439,6 +446,10 @@ int play_game(int argc, char** argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(force_bpp > 0) {
|
||||||
|
bpp = force_bpp;
|
||||||
|
}
|
||||||
|
|
||||||
std::cerr << "setting mode to " << resolution.first << "x" << resolution.second << "x" << bpp << "\n";
|
std::cerr << "setting mode to " << resolution.first << "x" << resolution.second << "x" << bpp << "\n";
|
||||||
const int res = video.setMode(resolution.first,resolution.second,bpp,video_flags);
|
const int res = video.setMode(resolution.first,resolution.second,bpp,video_flags);
|
||||||
video.setBpp(bpp);
|
video.setBpp(bpp);
|
||||||
|
@ -713,7 +724,7 @@ int play_game(int argc, char** argv)
|
||||||
std::cerr << "title screen returned result\n";
|
std::cerr << "title screen returned result\n";
|
||||||
|
|
||||||
if(res == gui::QUIT_GAME) {
|
if(res == gui::QUIT_GAME) {
|
||||||
std::cerr << "quiting game...\n";
|
std::cerr << "quitting game...\n";
|
||||||
return 0;
|
return 0;
|
||||||
} else if(res == gui::LOAD_GAME) {
|
} else if(res == gui::LOAD_GAME) {
|
||||||
|
|
||||||
|
@ -904,13 +915,19 @@ int play_game(int argc, char** argv)
|
||||||
state.campaign_define = "MULTIPLAYER";
|
state.campaign_define = "MULTIPLAYER";
|
||||||
|
|
||||||
std::vector<std::string> host_or_join;
|
std::vector<std::string> host_or_join;
|
||||||
host_or_join.push_back(string_table["join_game"]);
|
host_or_join.push_back(string_table["join_server"] + menu::HELP_STRING_SEPERATOR + string_table["join_server_help"]);
|
||||||
host_or_join.push_back(string_table["host_game"]);
|
host_or_join.push_back(string_table["join_game"] + menu::HELP_STRING_SEPERATOR + string_table["join_game_help"]);
|
||||||
|
host_or_join.push_back(string_table["host_game"] + menu::HELP_STRING_SEPERATOR + string_table["host_game_help"]);
|
||||||
|
|
||||||
const int res = gui::show_dialog(disp,NULL,"","",gui::OK_CANCEL,&host_or_join);
|
std::string login = preferences::login();
|
||||||
|
const int res = gui::show_dialog(disp,NULL,string_table["multiplayer"],"",gui::OK_CANCEL,&host_or_join,NULL,string_table["login"] + ": ",&login);
|
||||||
|
|
||||||
|
if(res >= 0) {
|
||||||
|
preferences::set_login(login);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if(res == 1) {
|
if(res == 2) {
|
||||||
std::vector<std::string> chat;
|
std::vector<std::string> chat;
|
||||||
config game_data;
|
config game_data;
|
||||||
multiplayer_game_setup_dialog mp_dialog(disp,units_data,game_config,state,true);
|
multiplayer_game_setup_dialog mp_dialog(disp,units_data,game_config,state,true);
|
||||||
|
@ -922,8 +939,13 @@ int play_game(int argc, char** argv)
|
||||||
if(res == lobby::CREATE) {
|
if(res == lobby::CREATE) {
|
||||||
mp_dialog.start_game();
|
mp_dialog.start_game();
|
||||||
}
|
}
|
||||||
} else if(res == 0) {
|
} else if(res == 0 || res == 1) {
|
||||||
play_multiplayer_client(disp,units_data,game_config,state);
|
std::string host;
|
||||||
|
if(res == 0) {
|
||||||
|
host = preferences::official_network_host();
|
||||||
|
}
|
||||||
|
|
||||||
|
play_multiplayer_client(disp,units_data,game_config,state,host);
|
||||||
}
|
}
|
||||||
} catch(gamestatus::load_game_failed& e) {
|
} catch(gamestatus::load_game_failed& e) {
|
||||||
gui::show_dialog(disp,NULL,"","error loading the game: " + e.message,gui::OK_ONLY);
|
gui::show_dialog(disp,NULL,"","error loading the game: " + e.message,gui::OK_ONLY);
|
||||||
|
|
|
@ -465,12 +465,6 @@ void extract_summary_data_from_save(const game_state& state, config& out)
|
||||||
out["replay"] = has_replay ? "yes" : "no";
|
out["replay"] = has_replay ? "yes" : "no";
|
||||||
out["snapshot"] = has_snapshot ? "yes" : "no";
|
out["snapshot"] = has_snapshot ? "yes" : "no";
|
||||||
|
|
||||||
if(has_snapshot) {
|
|
||||||
out["map_data"] = state.snapshot["map_data"];
|
|
||||||
} else if(has_replay) {
|
|
||||||
out["map_data"] = state.starting_pos["map_data"];
|
|
||||||
}
|
|
||||||
|
|
||||||
out["campaign_type"] = state.campaign_type;
|
out["campaign_type"] = state.campaign_type;
|
||||||
out["scenario"] = state.scenario;
|
out["scenario"] = state.scenario;
|
||||||
out["difficulty"] = state.difficulty;
|
out["difficulty"] = state.difficulty;
|
||||||
|
@ -492,6 +486,8 @@ void extract_summary_data_from_save(const game_state& state, config& out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool shrouded = false;
|
||||||
|
|
||||||
if(leader == "") {
|
if(leader == "") {
|
||||||
const config& snapshot = has_snapshot ? state.snapshot : state.starting_pos;
|
const config& snapshot = has_snapshot ? state.snapshot : state.starting_pos;
|
||||||
const config::child_list& sides = snapshot.get_children("side");
|
const config::child_list& sides = snapshot.get_children("side");
|
||||||
|
@ -501,6 +497,10 @@ void extract_summary_data_from_save(const game_state& state, config& out)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if((**s)["shroud"] == "yes") {
|
||||||
|
shrouded = true;
|
||||||
|
}
|
||||||
|
|
||||||
const config::child_list& units = (**s).get_children("unit");
|
const config::child_list& units = (**s).get_children("unit");
|
||||||
for(config::child_list::const_iterator u = units.begin(); u != units.end(); ++u) {
|
for(config::child_list::const_iterator u = units.begin(); u != units.end(); ++u) {
|
||||||
if((**u)["canrecruit"] == "1") {
|
if((**u)["canrecruit"] == "1") {
|
||||||
|
@ -512,4 +512,12 @@ void extract_summary_data_from_save(const game_state& state, config& out)
|
||||||
}
|
}
|
||||||
|
|
||||||
out["leader"] = leader;
|
out["leader"] = leader;
|
||||||
|
|
||||||
|
if(!shrouded) {
|
||||||
|
if(has_snapshot) {
|
||||||
|
out["map_data"] = state.snapshot["map_data"];
|
||||||
|
} else if(has_replay) {
|
||||||
|
out["map_data"] = state.starting_pos["map_data"];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -206,19 +206,21 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
|
void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
|
||||||
game_state& state)
|
game_state& state, std::string& host)
|
||||||
{
|
{
|
||||||
log_scope("playing multiplayer client");
|
log_scope("playing multiplayer client");
|
||||||
|
|
||||||
const network::manager net_manager;
|
const network::manager net_manager;
|
||||||
|
|
||||||
std::string host = preferences::network_host();
|
if(host.empty()) {
|
||||||
|
host = preferences::network_host();
|
||||||
const int res = gui::show_dialog(disp,NULL,"","",
|
const int res = gui::show_dialog(disp,NULL,"","",
|
||||||
gui::OK_CANCEL,NULL,NULL,
|
gui::OK_CANCEL,NULL,NULL,
|
||||||
string_table["remote_host"] + ": ",&host);
|
string_table["remote_host"] + ": ",&host);
|
||||||
if(res != 0 || host.empty()) {
|
if(res != 0 || host.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
network::connection sock;
|
network::connection sock;
|
||||||
|
|
||||||
|
@ -249,6 +251,7 @@ void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
|
||||||
//if we got a direction to login
|
//if we got a direction to login
|
||||||
if(data.child("mustlogin")) {
|
if(data.child("mustlogin")) {
|
||||||
|
|
||||||
|
bool first_time = true;
|
||||||
config* error = NULL;
|
config* error = NULL;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -257,6 +260,8 @@ void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string login = preferences::login();
|
std::string login = preferences::login();
|
||||||
|
|
||||||
|
if(!first_time) {
|
||||||
const int res = gui::show_dialog(disp,NULL,"",
|
const int res = gui::show_dialog(disp,NULL,"",
|
||||||
string_table["must_login"],gui::OK_CANCEL,
|
string_table["must_login"],gui::OK_CANCEL,
|
||||||
NULL,NULL,string_table["login"] + ": ",&login);
|
NULL,NULL,string_table["login"] + ": ",&login);
|
||||||
|
@ -265,6 +270,9 @@ void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
|
||||||
}
|
}
|
||||||
|
|
||||||
preferences::set_login(login);
|
preferences::set_login(login);
|
||||||
|
}
|
||||||
|
|
||||||
|
first_time = false;
|
||||||
|
|
||||||
config response;
|
config response;
|
||||||
response.add_child("login")["username"] = login;
|
response.add_child("login")["username"] = login;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
//function to play a game as a client, joining either another player who is
|
//function to play a game as a client, joining either another player who is
|
||||||
//hosting a game, or connecting to a server.
|
//hosting a game, or connecting to a server.
|
||||||
void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
|
void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
|
||||||
game_state& state);
|
game_state& state, std::string& host);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -277,6 +277,12 @@ void set_grid(bool ison)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& official_network_host()
|
||||||
|
{
|
||||||
|
static const std::string host = "devsrv.wesnoth.org";
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
const std::string& network_host()
|
const std::string& network_host()
|
||||||
{
|
{
|
||||||
std::string& res = prefs["host"];
|
std::string& res = prefs["host"];
|
||||||
|
|
|
@ -60,6 +60,8 @@ namespace preferences {
|
||||||
bool grid();
|
bool grid();
|
||||||
void set_grid(bool ison);
|
void set_grid(bool ison);
|
||||||
|
|
||||||
|
const std::string& official_network_host();
|
||||||
|
|
||||||
const std::string& network_host();
|
const std::string& network_host();
|
||||||
void set_network_host(const std::string& host);
|
void set_network_host(const std::string& host);
|
||||||
|
|
||||||
|
|
|
@ -591,8 +591,21 @@ int show_dialog(display& disp, SDL_Surface* image,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int text_widget_y = yloc+top_padding+text_and_image_height-6+menu_hpadding;
|
||||||
|
|
||||||
|
if(use_textbox) {
|
||||||
|
const int text_widget_y_unpadded = text_widget_y + (text_widget_height - text_widget.location().h)/2;
|
||||||
|
text_widget.set_location(xloc + left_padding +
|
||||||
|
text_widget_width - text_widget.location().w,
|
||||||
|
text_widget_y_unpadded);
|
||||||
|
events::raise_draw_event();
|
||||||
|
font::draw_text(&disp, clipRect, message_font_size,
|
||||||
|
font::NORMAL_COLOUR, text_widget_label,
|
||||||
|
xloc + left_padding,text_widget_y_unpadded);
|
||||||
|
}
|
||||||
|
|
||||||
const int menu_xpos = xloc+total_image_width+left_padding+image_h_padding;
|
const int menu_xpos = xloc+total_image_width+left_padding+image_h_padding;
|
||||||
const int menu_ypos = yloc+top_padding+text_and_image_height+menu_hpadding;
|
const int menu_ypos = yloc+top_padding+text_and_image_height+menu_hpadding+ (use_textbox ? text_widget.location().h + top_padding : 0);
|
||||||
if(menu_.height() > 0) {
|
if(menu_.height() > 0) {
|
||||||
menu_.set_loc(menu_xpos,menu_ypos);
|
menu_.set_loc(menu_xpos,menu_ypos);
|
||||||
}
|
}
|
||||||
|
@ -622,19 +635,6 @@ int show_dialog(display& disp, SDL_Surface* image,
|
||||||
xloc+total_image_width+left_padding+image_h_padding,
|
xloc+total_image_width+left_padding+image_h_padding,
|
||||||
yloc+top_padding);
|
yloc+top_padding);
|
||||||
|
|
||||||
const int text_widget_y = yloc+top_padding+text_and_image_height-6+menu_hpadding;
|
|
||||||
|
|
||||||
if(use_textbox) {
|
|
||||||
const int text_widget_y_unpadded = text_widget_y + (text_widget_height - text_widget.location().h)/2;
|
|
||||||
text_widget.set_location(xloc + left_padding +
|
|
||||||
text_widget_width - text_widget.location().w,
|
|
||||||
text_widget_y_unpadded);
|
|
||||||
events::raise_draw_event();
|
|
||||||
font::draw_text(&disp, clipRect, message_font_size,
|
|
||||||
font::NORMAL_COLOUR, text_widget_label,
|
|
||||||
xloc + left_padding,text_widget_y_unpadded);
|
|
||||||
}
|
|
||||||
|
|
||||||
//set the position of any tick boxes. they go right below the menu, slammed against
|
//set the position of any tick boxes. they go right below the menu, slammed against
|
||||||
//the right side of the dialog
|
//the right side of the dialog
|
||||||
if(check_buttons.empty() == false) {
|
if(check_buttons.empty() == false) {
|
||||||
|
|
|
@ -49,6 +49,7 @@ manager::manager()
|
||||||
|
|
||||||
manager::~manager()
|
manager::~manager()
|
||||||
{
|
{
|
||||||
|
std::cerr << "closing audio...\n";
|
||||||
if(!mix_ok)
|
if(!mix_ok)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -65,7 +66,9 @@ manager::~manager()
|
||||||
Mix_FreeMusic(j->second);
|
Mix_FreeMusic(j->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cerr << "final closing audio...\n";
|
||||||
Mix_CloseAudio();
|
Mix_CloseAudio();
|
||||||
|
std::cerr << "done closing audio...\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void play_music(const std::string& file)
|
void play_music(const std::string& file)
|
||||||
|
|
|
@ -219,7 +219,9 @@ CVideo::CVideo( int x, int y, int bits_per_pixel, int flags)
|
||||||
|
|
||||||
CVideo::~CVideo()
|
CVideo::~CVideo()
|
||||||
{
|
{
|
||||||
|
std::cerr << "calling SDL_Quit()\n";
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
std::cerr << "called SDL_Quit()\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CVideo::make_fake()
|
void CVideo::make_fake()
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace gui {
|
||||||
menu::menu(display& disp, const std::vector<std::string>& items,
|
menu::menu(display& disp, const std::vector<std::string>& items,
|
||||||
bool click_selects, int max_height)
|
bool click_selects, int max_height)
|
||||||
: max_height_(max_height), max_items_(-1), item_height_(-1),
|
: max_height_(max_height), max_items_(-1), item_height_(-1),
|
||||||
display_(&disp), x_(0), y_(0), buffer_(NULL),
|
display_(&disp), x_(0), y_(0), cur_help_(-1,-1), help_string_(-1), buffer_(NULL),
|
||||||
selected_(click_selects ? -1:0), click_selects_(click_selects),
|
selected_(click_selects ? -1:0), click_selects_(click_selects),
|
||||||
previous_button_(true), drawn_(false), show_result_(false),
|
previous_button_(true), drawn_(false), show_result_(false),
|
||||||
height_(-1), width_(-1), first_item_on_screen_(0),
|
height_(-1), width_(-1), first_item_on_screen_(0),
|
||||||
|
@ -45,6 +45,29 @@ menu::menu(display& disp, const std::vector<std::string>& items,
|
||||||
first_item.erase(first_item.begin());
|
first_item.erase(first_item.begin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
create_help_strings();
|
||||||
|
}
|
||||||
|
|
||||||
|
void menu::create_help_strings()
|
||||||
|
{
|
||||||
|
help_.clear();
|
||||||
|
for(std::vector<std::vector<std::string> >::iterator i = items_.begin(); i != items_.end(); ++i) {
|
||||||
|
help_.resize(help_.size()+1);
|
||||||
|
for(std::vector<std::string>::iterator j = i->begin(); j != i->end(); ++j) {
|
||||||
|
if(std::find(j->begin(),j->end(),HELP_STRING_SEPERATOR) == j->end()) {
|
||||||
|
help_.back().push_back("");
|
||||||
|
} else {
|
||||||
|
const std::vector<std::string>& items = config::split(*j,HELP_STRING_SEPERATOR,0);
|
||||||
|
if(items.size() >= 2) {
|
||||||
|
*j = items.front();
|
||||||
|
help_.back().push_back(items.back());
|
||||||
|
} else {
|
||||||
|
help_.back().push_back("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The scrollbar height depends on the number of visible items versus
|
// The scrollbar height depends on the number of visible items versus
|
||||||
|
@ -641,6 +664,27 @@ int menu::hit(int x, int y) const
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<int,int> menu::hit_cell(int x, int y) const
|
||||||
|
{
|
||||||
|
if(x > x_ && x < x_ + width() - scrollbar_.get_width() &&
|
||||||
|
y > y_ && y < y_ + height()) {
|
||||||
|
for(size_t i = 0; i != items_.size(); ++i) {
|
||||||
|
const SDL_Rect& rect = get_item_rect(i);
|
||||||
|
if(y > rect.y && y < rect.y + rect.h) {
|
||||||
|
const std::vector<int>& widths = column_widths();
|
||||||
|
for(std::vector<int>::const_iterator w = widths.begin(); w != widths.end(); ++w) {
|
||||||
|
x -= *w;
|
||||||
|
if(x <= x_) {
|
||||||
|
return std::pair<int,int>(int(i),int(w-widths.begin()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::pair<int,int>(-1,-1);
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Rect menu::get_item_rect(int item) const
|
SDL_Rect menu::get_item_rect(int item) const
|
||||||
{
|
{
|
||||||
const SDL_Rect empty_rect = {0,0,0,0};
|
const SDL_Rect empty_rect = {0,0,0,0};
|
||||||
|
@ -709,4 +753,30 @@ size_t menu::get_item_height(int item) const
|
||||||
return item_height_ = max_height;
|
return item_height_ = max_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void menu::process_help_string(int mousex, int mousey)
|
||||||
|
{
|
||||||
|
const std::pair<int,int> loc = hit_cell(mousex,mousey);
|
||||||
|
if(loc == cur_help_) {
|
||||||
|
return;
|
||||||
|
} else if(loc.first == -1) {
|
||||||
|
display_->clear_help_string(help_string_);
|
||||||
|
help_string_ = -1;
|
||||||
|
} else {
|
||||||
|
if(help_string_ != -1) {
|
||||||
|
display_->clear_help_string(help_string_);
|
||||||
|
help_string_ = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(size_t(loc.first) < help_.size()) {
|
||||||
|
const std::vector<std::string>& row = help_[loc.first];
|
||||||
|
if(size_t(loc.second) < help_.size()) {
|
||||||
|
const std::string& help = row[loc.second];
|
||||||
|
help_string_ = display_->set_help_string(help);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cur_help_ = loc;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,8 @@ public:
|
||||||
|
|
||||||
void set_dirty() { drawn_ = false; }
|
void set_dirty() { drawn_ = false; }
|
||||||
|
|
||||||
|
enum { HELP_STRING_SEPERATOR = '|' };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t max_items_onscreen() const;
|
size_t max_items_onscreen() const;
|
||||||
|
|
||||||
|
@ -71,7 +73,14 @@ private:
|
||||||
|
|
||||||
display* display_;
|
display* display_;
|
||||||
int x_, y_;
|
int x_, y_;
|
||||||
std::vector<std::vector<std::string> > items_;
|
std::vector<std::vector<std::string> > items_, help_;
|
||||||
|
|
||||||
|
void create_help_strings();
|
||||||
|
void process_help_string(int mousex, int mousey);
|
||||||
|
|
||||||
|
std::pair<int,int> cur_help_;
|
||||||
|
int help_string_;
|
||||||
|
|
||||||
mutable std::vector<int> column_widths_;
|
mutable std::vector<int> column_widths_;
|
||||||
|
|
||||||
scoped_sdl_surface buffer_;
|
scoped_sdl_surface buffer_;
|
||||||
|
@ -97,6 +106,8 @@ private:
|
||||||
void draw();
|
void draw();
|
||||||
int hit(int x, int y) const;
|
int hit(int x, int y) const;
|
||||||
|
|
||||||
|
std::pair<int,int> hit_cell(int x, int y) const;
|
||||||
|
|
||||||
mutable std::map<int,SDL_Rect> itemRects_;
|
mutable std::map<int,SDL_Rect> itemRects_;
|
||||||
|
|
||||||
SDL_Rect get_item_rect(int item) const;
|
SDL_Rect get_item_rect(int item) const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue