remove dialogs.cpp
And move its code in other files where it fits better. This also moves some code from actions.cpp to the new file advancements.cpp This also removed a parameter from show_objectives and menu_handler::objectives that was always gui_->viewing_side()
This commit is contained in:
parent
c3f07f1f73
commit
a20f221e83
34 changed files with 570 additions and 629 deletions
|
@ -636,6 +636,7 @@ add_library(wesnoth-schema_validator
|
|||
|
||||
set(wesnoth-main_SRC
|
||||
about.cpp
|
||||
actions/advancement.cpp
|
||||
actions/attack.cpp
|
||||
actions/create.cpp
|
||||
actions/heal.cpp
|
||||
|
@ -710,7 +711,6 @@ set(wesnoth-main_SRC
|
|||
desktop/notifications.cpp
|
||||
desktop/open.cpp
|
||||
desktop/version.cpp
|
||||
dialogs.cpp
|
||||
display_chat_manager.cpp
|
||||
editor/action/action.cpp
|
||||
editor/action/action_item.cpp
|
||||
|
|
|
@ -186,6 +186,7 @@ libcutter = client_env.Library("cutter", libcutter_sources)
|
|||
# Used by both 'wesnoth' and 'test' targets
|
||||
wesnoth_sources = Split("""
|
||||
about.cpp
|
||||
actions/advancement.cpp
|
||||
actions/attack.cpp
|
||||
actions/create.cpp
|
||||
actions/heal.cpp
|
||||
|
@ -256,7 +257,6 @@ wesnoth_sources = Split("""
|
|||
desktop/notifications.cpp
|
||||
desktop/open.cpp
|
||||
desktop/version.cpp
|
||||
dialogs.cpp
|
||||
display_chat_manager.cpp
|
||||
editor/action/action_item.cpp
|
||||
editor/action/action_label.cpp
|
||||
|
|
377
src/actions/advancement.cpp
Normal file
377
src/actions/advancement.cpp
Normal file
|
@ -0,0 +1,377 @@
|
|||
/*
|
||||
Copyright (C) 2016 by the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Fighting.
|
||||
*/
|
||||
|
||||
#include "advancement.hpp"
|
||||
|
||||
#include "vision.hpp"
|
||||
|
||||
#include "ai/lua/aspect_advancements.hpp"
|
||||
#include "game_display.hpp"
|
||||
#include "game_events/manager.hpp"
|
||||
#include "game_events/pump.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
#include "game_data.hpp" //resources::gamedata->phase()
|
||||
#include "gui/dialogs/unit_advance.hpp"
|
||||
#include "gui/widgets/window.hpp" //gui2::twindow::OK
|
||||
#include "log.hpp"
|
||||
#include "play_controller.hpp" //resources::controller
|
||||
#include "random_new.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "statistics.hpp"
|
||||
#include "synced_user_choice.hpp"
|
||||
#include "units/unit.hpp"
|
||||
#include "units/abilities.hpp"
|
||||
#include "units/animation_component.hpp"
|
||||
#include "units/udisplay.hpp"
|
||||
#include "units/helper.hpp" //number_of_possible_advances
|
||||
#include "units/map.hpp" //resources::units
|
||||
#include "whiteboard/manager.hpp"
|
||||
|
||||
static lg::log_domain log_engine("engine");
|
||||
#define DBG_NG LOG_STREAM(debug, log_engine)
|
||||
#define LOG_NG LOG_STREAM(info, log_engine)
|
||||
#define WRN_NG LOG_STREAM(err, log_engine)
|
||||
#define ERR_NG LOG_STREAM(err, log_engine)
|
||||
|
||||
static lg::log_domain log_config("config");
|
||||
#define LOG_CF LOG_STREAM(info, log_config)
|
||||
|
||||
static lg::log_domain log_display("display");
|
||||
#define LOG_DP LOG_STREAM(info, log_display)
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
int advance_unit_dialog(const map_location &loc)
|
||||
{
|
||||
const unit& u = *resources::units->find(loc);
|
||||
std::vector<unit_const_ptr> previews;
|
||||
|
||||
for (const std::string& advance : u.advances_to()) {
|
||||
preferences::encountered_units().insert(advance);
|
||||
previews.push_back(get_advanced_unit(u, advance));
|
||||
}
|
||||
|
||||
size_t num_real_advances = previews.size();
|
||||
bool always_display = false;
|
||||
|
||||
for (const config& advance : u.get_modification_advances()) {
|
||||
if (advance["always_display"]) {
|
||||
always_display = true;
|
||||
}
|
||||
previews.push_back(get_amla_unit(u, advance));
|
||||
}
|
||||
|
||||
if (previews.size() > 1 || always_display) {
|
||||
gui2::tunit_advance dlg(previews, num_real_advances);
|
||||
|
||||
dlg.show(CVideo::get_singleton());
|
||||
|
||||
if (dlg.get_retval() == gui2::twindow::OK) {
|
||||
return dlg.get_selected_index();
|
||||
}
|
||||
|
||||
// This should be unreachable, since canceling is disabled for the dialog
|
||||
assert(false && "Unit advance dialog was cancelled, which should be impossible.");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool animate_unit_advancement(const map_location &loc, size_t choice, const bool &fire_event, const bool animate)
|
||||
{
|
||||
const events::command_disabler cmd_disabler;
|
||||
|
||||
unit_map::iterator u = resources::units->find(loc);
|
||||
if (u == resources::units->end()) {
|
||||
LOG_DP << "animate_unit_advancement suppressed: invalid unit\n";
|
||||
return false;
|
||||
}
|
||||
else if (!u->advances()) {
|
||||
LOG_DP << "animate_unit_advancement suppressed: unit does not advance\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::vector<std::string>& options = u->advances_to();
|
||||
std::vector<config> mod_options = u->get_modification_advances();
|
||||
|
||||
if (choice >= options.size() + mod_options.size()) {
|
||||
LOG_DP << "animate_unit_advancement suppressed: invalid option\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// When the unit advances, it fades to white, and then switches
|
||||
// to the new unit, then fades back to the normal color
|
||||
|
||||
if (animate && !resources::screen->video().update_locked()) {
|
||||
unit_animator animator;
|
||||
bool with_bars = true;
|
||||
animator.add_animation(&*u, "levelout", u->get_location(), map_location(), 0, with_bars);
|
||||
animator.start_animations();
|
||||
animator.wait_for_end();
|
||||
}
|
||||
|
||||
if (choice < options.size()) {
|
||||
// chosen_unit is not a reference, since the unit may disappear at any moment.
|
||||
std::string chosen_unit = options[choice];
|
||||
::advance_unit(loc, chosen_unit, fire_event);
|
||||
}
|
||||
else {
|
||||
const config &mod_option = mod_options[choice - options.size()];
|
||||
::advance_unit(loc, "", fire_event, &mod_option);
|
||||
}
|
||||
|
||||
u = resources::units->find(loc);
|
||||
resources::screen->invalidate_unit();
|
||||
|
||||
if (animate && u != resources::units->end() && !resources::screen->video().update_locked()) {
|
||||
unit_animator animator;
|
||||
animator.add_animation(&*u, "levelin", u->get_location(), map_location(), 0, true);
|
||||
animator.start_animations();
|
||||
animator.wait_for_end();
|
||||
animator.set_all_standing();
|
||||
resources::screen->invalidate(loc);
|
||||
resources::screen->draw();
|
||||
events::pump();
|
||||
}
|
||||
|
||||
resources::screen->invalidate_all();
|
||||
resources::screen->draw();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
class unit_advancement_choice : public mp_sync::user_choice
|
||||
{
|
||||
public:
|
||||
unit_advancement_choice(const map_location& loc, int total_opt, int side_num, const ai::unit_advancements_aspect* ai_advancement, bool force_dialog)
|
||||
: loc_ (loc), nb_options_(total_opt), side_num_(side_num), ai_advancement_(ai_advancement), force_dialog_(force_dialog)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~unit_advancement_choice()
|
||||
{
|
||||
}
|
||||
|
||||
virtual config query_user(int /*side*/) const
|
||||
{
|
||||
//the 'side' parameter might differ from side_num_-
|
||||
int res = 0;
|
||||
team t = (*resources::teams)[side_num_ - 1];
|
||||
//i wonder how this got included here ?
|
||||
bool is_mp = resources::controller->is_networked_mp();
|
||||
bool is_current_side = resources::controller->current_side() == side_num_;
|
||||
//note, that the advancements for networked sides are also determined on the current playing side.
|
||||
|
||||
//to make mp games equal we only allow selecting advancements to the current side.
|
||||
//otherwise we'd give an unfair advantage to the side that hosts ai sides if units advance during ai turns.
|
||||
if(!CVideo::get_singleton().non_interactive() && (force_dialog_ || (t.is_local_human() && !t.is_idle() && (is_current_side || !is_mp))))
|
||||
{
|
||||
res = advance_unit_dialog(loc_);
|
||||
}
|
||||
else if(t.is_local_ai() || t.is_network_ai() || t.is_empty())
|
||||
{
|
||||
res = rand() % nb_options_;
|
||||
|
||||
//if ai_advancement_ is the default advancement the following code will
|
||||
//have no effect because get_advancements returns an empty list.
|
||||
if(ai_advancement_ != nullptr)
|
||||
{
|
||||
unit_map::iterator u = resources::units->find(loc_);
|
||||
const std::vector<std::string>& options = u->advances_to();
|
||||
const std::vector<std::string>& allowed = ai_advancement_->get_advancements(u);
|
||||
|
||||
for(std::vector<std::string>::const_iterator a = options.begin(); a != options.end(); ++a) {
|
||||
if (std::find(allowed.begin(), allowed.end(), *a) != allowed.end()){
|
||||
res = a - options.begin();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//we are in the situation, that the unit is owned by a human, but he's not allowed to do this decision.
|
||||
//because it's a mp game and it's not his turn.
|
||||
//note that it doesn't matter whether we call random_new::generator->next_random() or rand().
|
||||
res = random_new::generator->get_random_int(0, nb_options_-1);
|
||||
}
|
||||
LOG_NG << "unit at position " << loc_ << "choose advancement number " << res << "\n";
|
||||
config retv;
|
||||
retv["value"] = res;
|
||||
return retv;
|
||||
|
||||
}
|
||||
virtual config random_choice(int /*side*/) const
|
||||
{
|
||||
config retv;
|
||||
retv["value"] = 0;
|
||||
return retv;
|
||||
}
|
||||
virtual std::string description() const
|
||||
{
|
||||
return "an advancement choice";
|
||||
}
|
||||
private:
|
||||
const map_location loc_;
|
||||
int nb_options_;
|
||||
int side_num_;
|
||||
const ai::unit_advancements_aspect* ai_advancement_;
|
||||
bool force_dialog_;
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
advances the unit and stores data in the replay (or reads data from replay).
|
||||
*/
|
||||
void advance_unit_at(const advance_unit_params& params)
|
||||
{
|
||||
//i just don't want infinite loops...
|
||||
// the 20 is picked rather randomly.
|
||||
for(int advacment_number = 0; advacment_number < 20; advacment_number++)
|
||||
{
|
||||
unit_map::iterator u = resources::units->find(params.loc_);
|
||||
//this implies u.valid()
|
||||
if(!unit_helper::will_certainly_advance(u)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(params.fire_events_)
|
||||
{
|
||||
LOG_NG << "Firing pre advance event at " << params.loc_ <<".\n";
|
||||
resources::game_events->pump().fire("pre_advance", params.loc_);
|
||||
//TODO: maybe use id instead of location here ?.
|
||||
u = resources::units->find(params.loc_);
|
||||
if(!unit_helper::will_certainly_advance(u))
|
||||
{
|
||||
LOG_NG << "pre advance event aborted advancing.\n";
|
||||
return;
|
||||
}
|
||||
}
|
||||
//we don't want to let side 1 decide it during start/prestart.
|
||||
int side_for = resources::gamedata->phase() == game_data::PLAY ? 0: u->side();
|
||||
config selected = mp_sync::get_user_choice("choose",
|
||||
unit_advancement_choice(params.loc_, unit_helper::number_of_possible_advances(*u), u->side(), params.ai_advancements_, params.force_dialog_), side_for);
|
||||
//calls actions::advance_unit.
|
||||
bool result = animate_unit_advancement(params.loc_, selected["value"], params.fire_events_, params.animate_);
|
||||
|
||||
DBG_NG << "animate_unit_advancement result = " << result << std::endl;
|
||||
u = resources::units->find(params.loc_);
|
||||
// level 10 unit gives 80 XP and the highest mainline is level 5
|
||||
if (u.valid() && u->experience() > 80)
|
||||
{
|
||||
WRN_NG << "Unit has too many (" << u->experience() << ") XP left; cascade leveling goes on still." << std::endl;
|
||||
}
|
||||
}
|
||||
ERR_NG << "unit at " << params.loc_ << "tried to advance more than 20 times. Advancing was aborted" << std::endl;
|
||||
}
|
||||
|
||||
unit_ptr get_advanced_unit(const unit &u, const std::string& advance_to)
|
||||
{
|
||||
const unit_type *new_type = unit_types.find(advance_to);
|
||||
if (!new_type) {
|
||||
throw game::game_error("Could not find the unit being advanced"
|
||||
" to: " + advance_to);
|
||||
}
|
||||
unit_ptr new_unit(new unit(u));
|
||||
new_unit->set_experience(new_unit->experience() - new_unit->max_experience());
|
||||
new_unit->advance_to(*new_type);
|
||||
new_unit->heal_all();
|
||||
new_unit->set_state(unit::STATE_POISONED, false);
|
||||
new_unit->set_state(unit::STATE_SLOWED, false);
|
||||
new_unit->set_state(unit::STATE_PETRIFIED, false);
|
||||
new_unit->set_user_end_turn(false);
|
||||
new_unit->set_hidden(false);
|
||||
return new_unit;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the AMLA-advanced version of a unit (with traits and items retained).
|
||||
*/
|
||||
unit_ptr get_amla_unit(const unit &u, const config &mod_option)
|
||||
{
|
||||
unit_ptr amla_unit(new unit(u));
|
||||
amla_unit->set_experience(amla_unit->experience() - amla_unit->max_experience());
|
||||
amla_unit->add_modification("advancement", mod_option);
|
||||
return amla_unit;
|
||||
}
|
||||
|
||||
|
||||
void advance_unit(map_location loc, const std::string &advance_to,
|
||||
const bool &fire_event, const config * mod_option)
|
||||
{
|
||||
unit_map::unit_iterator u = resources::units->find(loc);
|
||||
if(!u.valid()) {
|
||||
return;
|
||||
}
|
||||
// original_type is not a reference, since the unit may disappear at any moment.
|
||||
std::string original_type = u->type_id();
|
||||
|
||||
// "advance" event.
|
||||
if(fire_event)
|
||||
{
|
||||
LOG_NG << "Firing advance event at " << loc <<".\n";
|
||||
resources::game_events->pump().fire("advance",loc);
|
||||
|
||||
if (!u.valid() || u->experience() < u->max_experience() ||
|
||||
u->type_id() != original_type)
|
||||
{
|
||||
LOG_NG << "WML has invalidated the advancing unit. Aborting.\n";
|
||||
return;
|
||||
}
|
||||
// In case WML moved the unit:
|
||||
loc = u->get_location();
|
||||
}
|
||||
|
||||
// This is not normally necessary, but if a unit loses power when leveling
|
||||
// (e.g. loses "jamming" or ambush), it could be discovered as a result of
|
||||
// the advancement.
|
||||
std::vector<int> not_seeing = actions::get_sides_not_seeing(*u);
|
||||
|
||||
// Create the advanced unit.
|
||||
bool use_amla = mod_option != nullptr;
|
||||
unit_ptr new_unit = use_amla ? get_amla_unit(*u, *mod_option) :
|
||||
get_advanced_unit(*u, advance_to);
|
||||
if ( !use_amla )
|
||||
{
|
||||
statistics::advance_unit(*new_unit);
|
||||
preferences::encountered_units().insert(new_unit->type_id());
|
||||
LOG_CF << "Added '" << new_unit->type_id() << "' to the encountered units.\n";
|
||||
}
|
||||
u = resources::units->replace(loc, *new_unit).first;
|
||||
|
||||
// Update fog/shroud.
|
||||
actions::shroud_clearer clearer;
|
||||
clearer.clear_unit(loc, *new_unit);
|
||||
|
||||
// "post_advance" event.
|
||||
if(fire_event)
|
||||
{
|
||||
LOG_NG << "Firing post_advance event at " << loc << ".\n";
|
||||
resources::game_events->pump().fire("post_advance",loc);
|
||||
}
|
||||
|
||||
// "sighted" event(s).
|
||||
clearer.fire_events();
|
||||
if ( u.valid() )
|
||||
actions::actor_sighted(*u, ¬_seeing);
|
||||
|
||||
resources::whiteboard->on_gamestate_change();
|
||||
}
|
76
src/actions/advancement.hpp
Normal file
76
src/actions/advancement.hpp
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
Copyright (C) 2016 by the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Various functions that implement attacks and attack calculations.
|
||||
* Unit advancements are also included, as they usually occur as a
|
||||
* result of combat.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
struct map_location;
|
||||
class team;
|
||||
class unit;
|
||||
class config;
|
||||
#include "units/types.hpp"
|
||||
#include "ai/lua/aspect_advancements.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
advances the unit at loc if it has enough experience, maximum 20 times.
|
||||
if the unit is on the currently active side, and that side is controlled by a human, a dialog pops up.
|
||||
if we are in a non mp game, and the side is controlled by a human then a dialog is shown too.
|
||||
if the side is controlled by an ai, and if ai_advancement is passed, then ai_advancement will be used.
|
||||
otherwise a random decision will be taken.
|
||||
|
||||
this method is currently not used by unstore_unit, if we want to do that we'd need to allow more arguments (animate, fire_events).
|
||||
*/
|
||||
struct advance_unit_params
|
||||
{
|
||||
advance_unit_params(const map_location& loc) : loc_(loc), ai_advancements_(nullptr), force_dialog_(false), fire_events_(true), animate_(true) {}
|
||||
advance_unit_params& ai_advancements(const ai::unit_advancements_aspect& value) {ai_advancements_ = &value; return *this;}
|
||||
advance_unit_params& force_dialog(bool value) {force_dialog_ = value; return *this;}
|
||||
advance_unit_params& fire_events(bool value) {fire_events_ = value; return *this;}
|
||||
advance_unit_params& animate(bool value) {animate_ = value; return *this;}
|
||||
friend void advance_unit_at(const advance_unit_params&);
|
||||
private:
|
||||
const map_location& loc_;
|
||||
const ai::unit_advancements_aspect* ai_advancements_;
|
||||
bool force_dialog_;
|
||||
bool fire_events_;
|
||||
bool animate_;
|
||||
};
|
||||
void advance_unit_at(const advance_unit_params& params);
|
||||
/**
|
||||
* Returns the advanced version of a unit (with traits and items retained).
|
||||
*/
|
||||
unit_ptr get_advanced_unit(const unit &u, const std::string &advance_to);
|
||||
|
||||
/**
|
||||
* Returns the AMLA-advanced version of a unit (with traits and items retained).
|
||||
*/
|
||||
unit_ptr get_amla_unit(const unit &u, const config &mod_option);
|
||||
|
||||
/**
|
||||
* Function which will advance the unit at @a loc to 'advance_to'.
|
||||
* (Unless mod_option is supplied, in which case an AMLA is performed.)
|
||||
* Note that 'loc' is not a reference, because if it were a reference,
|
||||
* we couldn't safely pass in a reference to the item in the map
|
||||
* that we're going to delete, since deletion would invalidate the reference.
|
||||
*/
|
||||
void advance_unit(map_location loc, const std::string &advance_to,
|
||||
const bool &fire_event = true, const config * mod_option = nullptr);
|
|
@ -19,12 +19,12 @@
|
|||
|
||||
#include "attack.hpp"
|
||||
|
||||
#include "advancement.hpp"
|
||||
#include "vision.hpp"
|
||||
|
||||
#include "ai/lua/aspect_advancements.hpp"
|
||||
#include "attack_prediction.hpp"
|
||||
#include "config_assign.hpp"
|
||||
#include "dialogs.hpp"
|
||||
#include "game_config.hpp"
|
||||
#include "game_display.hpp"
|
||||
#include "game_events/manager.hpp"
|
||||
|
@ -1388,139 +1388,6 @@ void attack_unit(const map_location &attacker, const map_location &defender,
|
|||
dummy.perform();
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class unit_advancement_choice : public mp_sync::user_choice
|
||||
{
|
||||
public:
|
||||
unit_advancement_choice(const map_location& loc, int total_opt, int side_num, const ai::unit_advancements_aspect* ai_advancement, bool force_dialog)
|
||||
: loc_ (loc), nb_options_(total_opt), side_num_(side_num), ai_advancement_(ai_advancement), force_dialog_(force_dialog)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~unit_advancement_choice()
|
||||
{
|
||||
}
|
||||
|
||||
virtual config query_user(int /*side*/) const
|
||||
{
|
||||
//the 'side' parameter might differ from side_num_-
|
||||
int res = 0;
|
||||
team t = (*resources::teams)[side_num_ - 1];
|
||||
//i wonder how this got included here ?
|
||||
bool is_mp = resources::controller->is_networked_mp();
|
||||
bool is_current_side = resources::controller->current_side() == side_num_;
|
||||
//note, that the advancements for networked sides are also determined on the current playing side.
|
||||
|
||||
//to make mp games equal we only allow selecting advancements to the current side.
|
||||
//otherwise we'd give an unfair advantage to the side that hosts ai sides if units advance during ai turns.
|
||||
if(!CVideo::get_singleton().non_interactive() && (force_dialog_ || (t.is_local_human() && !t.is_idle() && (is_current_side || !is_mp))))
|
||||
{
|
||||
res = dialogs::advance_unit_dialog(loc_);
|
||||
}
|
||||
else if(t.is_local_ai() || t.is_network_ai() || t.is_empty())
|
||||
{
|
||||
res = rand() % nb_options_;
|
||||
|
||||
//if ai_advancement_ is the default advancement the following code will
|
||||
//have no effect because get_advancements returns an empty list.
|
||||
if(ai_advancement_ != nullptr)
|
||||
{
|
||||
unit_map::iterator u = resources::units->find(loc_);
|
||||
const std::vector<std::string>& options = u->advances_to();
|
||||
const std::vector<std::string>& allowed = ai_advancement_->get_advancements(u);
|
||||
|
||||
for(std::vector<std::string>::const_iterator a = options.begin(); a != options.end(); ++a) {
|
||||
if (std::find(allowed.begin(), allowed.end(), *a) != allowed.end()){
|
||||
res = a - options.begin();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//we are in the situation, that the unit is owned by a human, but he's not allowed to do this decision.
|
||||
//because it's a mp game and it's not his turn.
|
||||
//note that it doesn't matter whether we call random_new::generator->next_random() or rand().
|
||||
res = random_new::generator->get_random_int(0, nb_options_-1);
|
||||
}
|
||||
LOG_NG << "unit at position " << loc_ << "choose advancement number " << res << "\n";
|
||||
config retv;
|
||||
retv["value"] = res;
|
||||
return retv;
|
||||
|
||||
}
|
||||
virtual config random_choice(int /*side*/) const
|
||||
{
|
||||
config retv;
|
||||
retv["value"] = 0;
|
||||
return retv;
|
||||
}
|
||||
virtual std::string description() const
|
||||
{
|
||||
return "an advancement choice";
|
||||
}
|
||||
private:
|
||||
const map_location loc_;
|
||||
int nb_options_;
|
||||
int side_num_;
|
||||
const ai::unit_advancements_aspect* ai_advancement_;
|
||||
bool force_dialog_;
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
advances the unit and stores data in the replay (or reads data from replay).
|
||||
*/
|
||||
void advance_unit_at(const advance_unit_params& params)
|
||||
{
|
||||
//i just don't want infinite loops...
|
||||
// the 20 is picked rather randomly.
|
||||
for(int advacment_number = 0; advacment_number < 20; advacment_number++)
|
||||
{
|
||||
unit_map::iterator u = resources::units->find(params.loc_);
|
||||
//this implies u.valid()
|
||||
if(!unit_helper::will_certainly_advance(u)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(params.fire_events_)
|
||||
{
|
||||
LOG_NG << "Firing pre advance event at " << params.loc_ <<".\n";
|
||||
resources::game_events->pump().fire("pre_advance", params.loc_);
|
||||
//TODO: maybe use id instead of location here ?.
|
||||
u = resources::units->find(params.loc_);
|
||||
if(!unit_helper::will_certainly_advance(u))
|
||||
{
|
||||
LOG_NG << "pre advance event aborted advancing.\n";
|
||||
return;
|
||||
}
|
||||
}
|
||||
//we don't want to let side 1 decide it during start/prestart.
|
||||
int side_for = resources::gamedata->phase() == game_data::PLAY ? 0: u->side();
|
||||
config selected = mp_sync::get_user_choice("choose",
|
||||
unit_advancement_choice(params.loc_, unit_helper::number_of_possible_advances(*u), u->side(), params.ai_advancements_, params.force_dialog_), side_for);
|
||||
//calls actions::advance_unit.
|
||||
bool result = dialogs::animate_unit_advancement(params.loc_, selected["value"], params.fire_events_, params.animate_);
|
||||
|
||||
DBG_NG << "animate_unit_advancement result = " << result << std::endl;
|
||||
u = resources::units->find(params.loc_);
|
||||
// level 10 unit gives 80 XP and the highest mainline is level 5
|
||||
if (u.valid() && u->experience() > 80)
|
||||
{
|
||||
WRN_NG << "Unit has too many (" << u->experience() << ") XP left; cascade leveling goes on still." << std::endl;
|
||||
}
|
||||
}
|
||||
ERR_NG << "unit at " << params.loc_ << "tried to advance more than 20 times. Advancing was aborted" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
static void advance_unit_at(const map_location& loc, const ai::unit_advancements_aspect ai_advancement = ai::unit_advancements_aspect())
|
||||
{ advance_unit_at(advance_unit_params(loc).ai_advancements(ai_advancement)); }
|
||||
|
||||
void attack_unit_and_advance(const map_location &attacker, const map_location &defender,
|
||||
int attack_with, int defend_with, bool update_display,
|
||||
const ai::unit_advancements_aspect& ai_advancement)
|
||||
|
@ -1528,110 +1395,14 @@ void attack_unit_and_advance(const map_location &attacker, const map_location &d
|
|||
attack_unit(attacker, defender, attack_with, defend_with, update_display);
|
||||
unit_map::const_iterator atku = resources::units->find(attacker);
|
||||
if (atku != resources::units->end()) {
|
||||
advance_unit_at(attacker, ai_advancement);
|
||||
advance_unit_at(advance_unit_params(attacker).ai_advancements(ai_advancement));
|
||||
}
|
||||
|
||||
unit_map::const_iterator defu = resources::units->find(defender);
|
||||
if (defu != resources::units->end()) {
|
||||
advance_unit_at(defender, ai_advancement);
|
||||
advance_unit_at(advance_unit_params(defender).ai_advancements(ai_advancement));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unit_ptr get_advanced_unit(const unit &u, const std::string& advance_to)
|
||||
{
|
||||
const unit_type *new_type = unit_types.find(advance_to);
|
||||
if (!new_type) {
|
||||
throw game::game_error("Could not find the unit being advanced"
|
||||
" to: " + advance_to);
|
||||
}
|
||||
unit_ptr new_unit(new unit(u));
|
||||
new_unit->set_experience(new_unit->experience() - new_unit->max_experience());
|
||||
new_unit->advance_to(*new_type);
|
||||
new_unit->heal_all();
|
||||
new_unit->set_state(unit::STATE_POISONED, false);
|
||||
new_unit->set_state(unit::STATE_SLOWED, false);
|
||||
new_unit->set_state(unit::STATE_PETRIFIED, false);
|
||||
new_unit->set_user_end_turn(false);
|
||||
new_unit->set_hidden(false);
|
||||
return new_unit;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the AMLA-advanced version of a unit (with traits and items retained).
|
||||
*/
|
||||
unit_ptr get_amla_unit(const unit &u, const config &mod_option)
|
||||
{
|
||||
unit_ptr amla_unit(new unit(u));
|
||||
amla_unit->set_experience(amla_unit->experience() - amla_unit->max_experience());
|
||||
amla_unit->add_modification("advancement", mod_option);
|
||||
return amla_unit;
|
||||
}
|
||||
|
||||
|
||||
void advance_unit(map_location loc, const std::string &advance_to,
|
||||
const bool &fire_event, const config * mod_option)
|
||||
{
|
||||
unit_map::unit_iterator u = resources::units->find(loc);
|
||||
if(!u.valid()) {
|
||||
return;
|
||||
}
|
||||
// original_type is not a reference, since the unit may disappear at any moment.
|
||||
std::string original_type = u->type_id();
|
||||
|
||||
// "advance" event.
|
||||
if(fire_event)
|
||||
{
|
||||
LOG_NG << "Firing advance event at " << loc <<".\n";
|
||||
resources::game_events->pump().fire("advance",loc);
|
||||
|
||||
if (!u.valid() || u->experience() < u->max_experience() ||
|
||||
u->type_id() != original_type)
|
||||
{
|
||||
LOG_NG << "WML has invalidated the advancing unit. Aborting.\n";
|
||||
return;
|
||||
}
|
||||
// In case WML moved the unit:
|
||||
loc = u->get_location();
|
||||
}
|
||||
|
||||
// This is not normally necessary, but if a unit loses power when leveling
|
||||
// (e.g. loses "jamming" or ambush), it could be discovered as a result of
|
||||
// the advancement.
|
||||
std::vector<int> not_seeing = actions::get_sides_not_seeing(*u);
|
||||
|
||||
// Create the advanced unit.
|
||||
bool use_amla = mod_option != nullptr;
|
||||
unit_ptr new_unit = use_amla ? get_amla_unit(*u, *mod_option) :
|
||||
get_advanced_unit(*u, advance_to);
|
||||
if ( !use_amla )
|
||||
{
|
||||
statistics::advance_unit(*new_unit);
|
||||
preferences::encountered_units().insert(new_unit->type_id());
|
||||
LOG_CF << "Added '" << new_unit->type_id() << "' to the encountered units.\n";
|
||||
}
|
||||
u = resources::units->replace(loc, *new_unit).first;
|
||||
|
||||
// Update fog/shroud.
|
||||
actions::shroud_clearer clearer;
|
||||
clearer.clear_unit(loc, *new_unit);
|
||||
|
||||
// "post_advance" event.
|
||||
if(fire_event)
|
||||
{
|
||||
LOG_NG << "Firing post_advance event at " << loc << ".\n";
|
||||
resources::game_events->pump().fire("post_advance",loc);
|
||||
}
|
||||
|
||||
// "sighted" event(s).
|
||||
clearer.fire_events();
|
||||
if ( u.valid() )
|
||||
actions::actor_sighted(*u, ¬_seeing);
|
||||
|
||||
resources::whiteboard->on_gamestate_change();
|
||||
}
|
||||
|
||||
map_location under_leadership(const unit_map& units, const map_location& loc,
|
||||
int* bonus)
|
||||
{
|
||||
|
|
|
@ -202,51 +202,6 @@ void attack_unit_and_advance(const map_location &attacker, const map_location &d
|
|||
int attack_with, int defend_with, bool update_display = true,
|
||||
const ai::unit_advancements_aspect& ai_advancement = ai::unit_advancements_aspect());
|
||||
|
||||
/**
|
||||
advances the unit at loc if it has enough experience, maximum 20 times.
|
||||
if the unit is on the currently active side, and that side is controlled by a human, a dialog pops up.
|
||||
if we are in a non mp game, and the side is controlled by a human then a dialog is shown too.
|
||||
if the side is controlled by an ai, and if ai_advancement is passed, then ai_advancement will be used.
|
||||
otherwise a random decision will be taken.
|
||||
|
||||
this method is currently not used by unstore_unit, if we want to do that we'd need to allow more arguments (animate, fire_events).
|
||||
*/
|
||||
struct advance_unit_params
|
||||
{
|
||||
advance_unit_params(const map_location& loc) : loc_(loc), ai_advancements_(nullptr), force_dialog_(false), fire_events_(true), animate_(true) {}
|
||||
advance_unit_params& ai_advancements(const ai::unit_advancements_aspect& value) {ai_advancements_ = &value; return *this;}
|
||||
advance_unit_params& force_dialog(bool value) {force_dialog_ = value; return *this;}
|
||||
advance_unit_params& fire_events(bool value) {fire_events_ = value; return *this;}
|
||||
advance_unit_params& animate(bool value) {animate_ = value; return *this;}
|
||||
friend void advance_unit_at(const advance_unit_params&);
|
||||
private:
|
||||
const map_location& loc_;
|
||||
const ai::unit_advancements_aspect* ai_advancements_;
|
||||
bool force_dialog_;
|
||||
bool fire_events_;
|
||||
bool animate_;
|
||||
};
|
||||
void advance_unit_at(const advance_unit_params& params);
|
||||
/**
|
||||
* Returns the advanced version of a unit (with traits and items retained).
|
||||
*/
|
||||
unit_ptr get_advanced_unit(const unit &u, const std::string &advance_to);
|
||||
|
||||
/**
|
||||
* Returns the AMLA-advanced version of a unit (with traits and items retained).
|
||||
*/
|
||||
unit_ptr get_amla_unit(const unit &u, const config &mod_option);
|
||||
|
||||
/**
|
||||
* Function which will advance the unit at @a loc to 'advance_to'.
|
||||
* (Unless mod_option is supplied, in which case an AMLA is performed.)
|
||||
* Note that 'loc' is not a reference, because if it were a reference,
|
||||
* we couldn't safely pass in a reference to the item in the map
|
||||
* that we're going to delete, since deletion would invalidate the reference.
|
||||
*/
|
||||
void advance_unit(map_location loc, const std::string &advance_to,
|
||||
const bool &fire_event = true, const config * mod_option = nullptr);
|
||||
|
||||
/**
|
||||
* function which tests if the unit at loc is currently affected by leadership.
|
||||
* (i.e. has a higher-level 'leadership' unit next to it).
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
#include "addon/manager.hpp"
|
||||
#include "addon/manager_ui.hpp"
|
||||
#include "dialogs.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "formatter.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "addon/info.hpp"
|
||||
#include "addon/manager.hpp"
|
||||
#include "addon/state.hpp"
|
||||
#include "dialogs.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "formatter.hpp"
|
||||
#include "formula/string_utils.hpp"
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#include "controller_base.hpp"
|
||||
|
||||
#include "dialogs.hpp"
|
||||
#include "show_dialog.hpp" //gui::in_dialog
|
||||
#include "display.hpp"
|
||||
#include "events.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
|
@ -25,7 +25,6 @@
|
|||
#include "mouse_handler_base.hpp"
|
||||
#include "scripting/plugins/context.hpp"
|
||||
#include "soundsource.hpp"
|
||||
|
||||
static lg::log_domain log_display("display");
|
||||
#define ERR_DP LOG_STREAM(err, log_display)
|
||||
|
||||
|
|
254
src/dialogs.cpp
254
src/dialogs.cpp
|
@ -1,254 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 2003 - 2016 by David White <dave@whitevine.net>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Various dialogs: advance_unit, show_objectives, save+load game
|
||||
*/
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
#include "actions/attack.hpp"
|
||||
#include "actions/undo.hpp"
|
||||
#include "dialogs.hpp"
|
||||
#include "format_time_summary.hpp"
|
||||
#include "game_display.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
#include "gui/dialogs/game_delete.hpp"
|
||||
#include "gui/dialogs/message.hpp"
|
||||
#include "gui/dialogs/unit_list.hpp"
|
||||
#include "gui/dialogs/unit_advance.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "help/help.hpp"
|
||||
#include "help/help_button.hpp"
|
||||
#include "language.hpp"
|
||||
#include "log.hpp"
|
||||
#include "map/map.hpp"
|
||||
#include "map/exception.hpp"
|
||||
#include "marked-up_text.hpp"
|
||||
#include "menu_events.hpp"
|
||||
#include "mouse_handler_base.hpp"
|
||||
#include "minimap.hpp"
|
||||
#include "replay.hpp"
|
||||
#include "replay_helper.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "savegame.hpp"
|
||||
#include "save_index.hpp"
|
||||
#include "strftime.hpp"
|
||||
#include "synced_context.hpp"
|
||||
#include "terrain/type_data.hpp"
|
||||
#include "units/unit.hpp"
|
||||
#include "units/animation.hpp"
|
||||
#include "units/helper.hpp"
|
||||
#include "units/types.hpp"
|
||||
#include "wml_separators.hpp"
|
||||
#include "widgets/progressbar.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
#include "formula/string_utils.hpp"
|
||||
#include "gui/dialogs/game_save.hpp"
|
||||
#include "gui/dialogs/transient_message.hpp"
|
||||
#include "gui/dialogs/network_transmission.hpp"
|
||||
#include "ai/lua/aspect_advancements.hpp"
|
||||
#include "wesnothd_connection.hpp"
|
||||
|
||||
//#ifdef _WIN32
|
||||
//#include "locale.h"
|
||||
//#endif
|
||||
|
||||
#include <clocale>
|
||||
|
||||
static lg::log_domain log_engine("engine");
|
||||
#define LOG_NG LOG_STREAM(info, log_engine)
|
||||
#define ERR_NG LOG_STREAM(err, log_engine)
|
||||
|
||||
static lg::log_domain log_display("display");
|
||||
#define LOG_DP LOG_STREAM(info, log_display)
|
||||
|
||||
#define ERR_G LOG_STREAM(err, lg::general)
|
||||
|
||||
static lg::log_domain log_config("config");
|
||||
#define ERR_CF LOG_STREAM(err, log_config)
|
||||
|
||||
namespace dialogs
|
||||
{
|
||||
|
||||
int advance_unit_dialog(const map_location &loc)
|
||||
{
|
||||
const unit& u = *resources::units->find(loc);
|
||||
std::vector<unit_const_ptr> previews;
|
||||
|
||||
for(const std::string& advance : u.advances_to()) {
|
||||
preferences::encountered_units().insert(advance);
|
||||
previews.push_back(get_advanced_unit(u, advance));
|
||||
}
|
||||
|
||||
size_t num_real_advances = previews.size();
|
||||
bool always_display = false;
|
||||
|
||||
for(const config& advance : u.get_modification_advances()) {
|
||||
if(advance["always_display"]) {
|
||||
always_display = true;
|
||||
}
|
||||
previews.push_back(get_amla_unit(u, advance));
|
||||
}
|
||||
|
||||
if(previews.size() > 1 || always_display) {
|
||||
gui2::tunit_advance dlg(previews, num_real_advances);
|
||||
|
||||
dlg.show(CVideo::get_singleton());
|
||||
|
||||
if(dlg.get_retval() == gui2::twindow::OK) {
|
||||
return dlg.get_selected_index();
|
||||
}
|
||||
|
||||
// This should be unreachable, since canceling is disabled for the dialog
|
||||
assert(false && "Unit advance dialog was cancelled, which should be impossible.");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool animate_unit_advancement(const map_location &loc, size_t choice, const bool &fire_event, const bool animate)
|
||||
{
|
||||
const events::command_disabler cmd_disabler;
|
||||
|
||||
unit_map::iterator u = resources::units->find(loc);
|
||||
if (u == resources::units->end()) {
|
||||
LOG_DP << "animate_unit_advancement suppressed: invalid unit\n";
|
||||
return false;
|
||||
} else if (!u->advances()) {
|
||||
LOG_DP << "animate_unit_advancement suppressed: unit does not advance\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::vector<std::string>& options = u->advances_to();
|
||||
std::vector<config> mod_options = u->get_modification_advances();
|
||||
|
||||
if(choice >= options.size() + mod_options.size()) {
|
||||
LOG_DP << "animate_unit_advancement suppressed: invalid option\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// When the unit advances, it fades to white, and then switches
|
||||
// to the new unit, then fades back to the normal color
|
||||
|
||||
if (animate && !resources::screen->video().update_locked()) {
|
||||
unit_animator animator;
|
||||
bool with_bars = true;
|
||||
animator.add_animation(&*u,"levelout", u->get_location(), map_location(), 0, with_bars);
|
||||
animator.start_animations();
|
||||
animator.wait_for_end();
|
||||
}
|
||||
|
||||
if(choice < options.size()) {
|
||||
// chosen_unit is not a reference, since the unit may disappear at any moment.
|
||||
std::string chosen_unit = options[choice];
|
||||
::advance_unit(loc, chosen_unit, fire_event);
|
||||
} else {
|
||||
const config &mod_option = mod_options[choice - options.size()];
|
||||
::advance_unit(loc, "", fire_event, &mod_option);
|
||||
}
|
||||
|
||||
u = resources::units->find(loc);
|
||||
resources::screen->invalidate_unit();
|
||||
|
||||
if (animate && u != resources::units->end() && !resources::screen->video().update_locked()) {
|
||||
unit_animator animator;
|
||||
animator.add_animation(&*u, "levelin", u->get_location(), map_location(), 0, true);
|
||||
animator.start_animations();
|
||||
animator.wait_for_end();
|
||||
animator.set_all_standing();
|
||||
resources::screen->invalidate(loc);
|
||||
resources::screen->draw();
|
||||
events::pump();
|
||||
}
|
||||
|
||||
resources::screen->invalidate_all();
|
||||
resources::screen->draw();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void show_unit_list(display& gui)
|
||||
{
|
||||
gui2::tunit_list dlg(gui);
|
||||
|
||||
dlg.show(gui.video());
|
||||
|
||||
if(dlg.get_retval() == gui2::twindow::OK) {
|
||||
const map_location& loc = dlg.get_location_to_scroll_to();
|
||||
|
||||
gui.scroll_to_tile(loc, game_display::WARP);
|
||||
gui.select_hex(loc);
|
||||
}
|
||||
}
|
||||
|
||||
void show_objectives(const std::string &scenarioname, const std::string &objectives)
|
||||
{
|
||||
static const std::string no_objectives(_("No objectives available"));
|
||||
gui2::show_transient_message(resources::screen->video(), scenarioname,
|
||||
(objectives.empty() ? no_objectives : objectives), "", true);
|
||||
}
|
||||
|
||||
static void network_transmission_dialog(CVideo& video, gui2::tnetwork_transmission::connection_data& conn, const std::string& msg1, const std::string& msg2)
|
||||
{
|
||||
if (video.faked()) {
|
||||
while (!conn.finished()) {
|
||||
conn.poll();
|
||||
SDL_Delay(1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
gui2::tnetwork_transmission(conn, msg1, msg2).show(video);
|
||||
}
|
||||
}
|
||||
|
||||
struct read_wesnothd_connection_data : public gui2::tnetwork_transmission::connection_data
|
||||
{
|
||||
read_wesnothd_connection_data(twesnothd_connection& conn) : conn_(conn) {}
|
||||
size_t total() override { return conn_.bytes_to_read(); }
|
||||
virtual size_t current() override { return conn_.bytes_read(); }
|
||||
virtual bool finished() override { return conn_.has_data_received(); }
|
||||
virtual void cancel() override { }
|
||||
virtual void poll() override { conn_.poll(); }
|
||||
twesnothd_connection& conn_;
|
||||
};
|
||||
|
||||
bool network_receive_dialog(CVideo& video, const std::string& msg, config& cfg, twesnothd_connection& wesnothd_connection)
|
||||
{
|
||||
read_wesnothd_connection_data gui_data(wesnothd_connection);
|
||||
network_transmission_dialog(video, gui_data, msg, _("Waiting"));
|
||||
return wesnothd_connection.receive_data(cfg);
|
||||
}
|
||||
|
||||
struct connect_wesnothd_connection_data : public gui2::tnetwork_transmission::connection_data
|
||||
{
|
||||
connect_wesnothd_connection_data(twesnothd_connection& conn) : conn_(conn) {}
|
||||
virtual bool finished() override { return conn_.handshake_finished(); }
|
||||
virtual void cancel() override { }
|
||||
virtual void poll() override { conn_.poll(); }
|
||||
twesnothd_connection& conn_;
|
||||
};
|
||||
|
||||
std::unique_ptr<twesnothd_connection> network_connect_dialog(CVideo& video, const std::string& msg, const std::string& hostname, int port)
|
||||
{
|
||||
std::unique_ptr<twesnothd_connection> res(new twesnothd_connection(hostname, std::to_string(port)));
|
||||
connect_wesnothd_connection_data gui_data(*res);
|
||||
network_transmission_dialog(video, gui_data, msg, _("Connecting"));
|
||||
return std::move(res);
|
||||
|
||||
}
|
||||
|
||||
} // end namespace dialogs
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 2003 - 2016 by David White <dave@whitevine.net>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
#ifndef DIALOGS_H_INCLUDED
|
||||
#define DIALOGS_H_INCLUDED
|
||||
|
||||
class attack_type;
|
||||
class config;
|
||||
class display;
|
||||
class game_display;
|
||||
class unit;
|
||||
class unit_map;
|
||||
class unit_type;
|
||||
class terrain_type;
|
||||
class twesnothd_connection;
|
||||
#include "map/location.hpp"
|
||||
#include "construct_dialog.hpp"
|
||||
#include "units/ptr.hpp"
|
||||
#include "ai/lua/aspect_advancements.hpp"
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
namespace dialogs {
|
||||
|
||||
|
||||
/**
|
||||
* Lets the user to select a unit advancement. This should always be used
|
||||
* from WML events, advance_unit can only be used safely for normal levels.
|
||||
*/
|
||||
int advance_unit_dialog(const map_location &loc);
|
||||
|
||||
/**
|
||||
* Actually levels a unit up. This is the other part of the low-level
|
||||
* interface to the advancing code (along with advance_unit_dialog). This needs
|
||||
* to be used to implement advances from any nonstandard situation. It does
|
||||
* not add a replay.
|
||||
*/
|
||||
bool animate_unit_advancement(const map_location &loc, size_t choice, const bool &fire_event = true, const bool animate = true);
|
||||
|
||||
void show_objectives(const std::string& scenarioname, const std::string &objectives);
|
||||
|
||||
void show_unit_list(display& gui);
|
||||
|
||||
bool network_receive_dialog(CVideo& video, const std::string& msg, config& cfg, twesnothd_connection& wesnothd_connection);
|
||||
std::unique_ptr<twesnothd_connection> network_connect_dialog(CVideo& video, const std::string& msg, const std::string& hostname, int port);
|
||||
|
||||
} //end namespace dialogs
|
||||
|
||||
#endif
|
|
@ -34,10 +34,10 @@
|
|||
#include "gui/dialogs/editor/custom_tod.hpp"
|
||||
#include "gui/dialogs/message.hpp"
|
||||
#include "gui/dialogs/transient_message.hpp"
|
||||
#include "gui/dialogs/unit_list.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
#include "dialogs.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "reports.hpp"
|
||||
|
||||
|
@ -1155,7 +1155,7 @@ void editor_controller::rename_unit()
|
|||
|
||||
void editor_controller::unit_list()
|
||||
{
|
||||
dialogs::show_unit_list(*gui_);
|
||||
gui2::show_unit_list(*gui_);
|
||||
}
|
||||
|
||||
void editor_controller::cut_selection()
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
#include "carryover.hpp"
|
||||
#include "config.hpp"
|
||||
#include "dialogs.hpp"
|
||||
#include "formula/string_utils.hpp"
|
||||
#include "saved_game.hpp"
|
||||
#include "game_config.hpp"
|
||||
|
|
|
@ -143,7 +143,7 @@ static std::unique_ptr<twesnothd_connection> open_connection(CVideo& video, cons
|
|||
shown_hosts.insert(hostpair(host, port));
|
||||
|
||||
config data;
|
||||
sock = dialogs::network_connect_dialog(video, _("Connecting to Server..."), host, port);
|
||||
sock = gui2::tnetwork_transmission::wesnothd_connect_dialog(video, _("Connecting to Server..."), host, port);
|
||||
do {
|
||||
|
||||
if (!sock) {
|
||||
|
@ -151,7 +151,7 @@ static std::unique_ptr<twesnothd_connection> open_connection(CVideo& video, cons
|
|||
}
|
||||
|
||||
data.clear();
|
||||
dialogs::network_receive_dialog(video, "", data, *sock);
|
||||
gui2::tnetwork_transmission::wesnothd_receive_dialog(video, "", data, *sock);
|
||||
//mp::check_response(data_res, data);
|
||||
|
||||
if (data.has_child("reject") || data.has_attribute("version")) {
|
||||
|
@ -181,7 +181,7 @@ static std::unique_ptr<twesnothd_connection> open_connection(CVideo& video, cons
|
|||
}
|
||||
shown_hosts.insert(hostpair(host, port));
|
||||
sock.release();
|
||||
sock = dialogs::network_connect_dialog(video, _("Connecting to Server..."), host, port);
|
||||
sock = gui2::tnetwork_transmission::wesnothd_connect_dialog(video, _("Connecting to Server..."), host, port);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -218,7 +218,7 @@ static std::unique_ptr<twesnothd_connection> open_connection(CVideo& video, cons
|
|||
sp["selective_ping"] = true;
|
||||
}
|
||||
sock->send_data(response);
|
||||
dialogs::network_receive_dialog(video, "login response", data, *sock);
|
||||
gui2::tnetwork_transmission::wesnothd_receive_dialog(video, "login response", data, *sock);
|
||||
config *warning = &data.child("warning");
|
||||
|
||||
if(*warning) {
|
||||
|
@ -298,7 +298,7 @@ static std::unique_ptr<twesnothd_connection> open_connection(CVideo& video, cons
|
|||
|
||||
// Once again send our request...
|
||||
sock->send_data(response);
|
||||
dialogs::network_receive_dialog(video, "", data, *sock);
|
||||
gui2::tnetwork_transmission::wesnothd_receive_dialog(video, "", data, *sock);
|
||||
|
||||
|
||||
error = &data.child("error");
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "multiplayer_connect.hpp"
|
||||
|
||||
#include "ai/configuration.hpp"
|
||||
#include "dialogs.hpp"
|
||||
#include "construct_dialog.hpp"
|
||||
#include "display_chat_manager.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
#include "gettext.hpp"
|
||||
|
|
|
@ -14,11 +14,12 @@
|
|||
|
||||
#include "global.hpp"
|
||||
|
||||
#include "dialogs.hpp"
|
||||
#include "construct_dialog.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "game_config_manager.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
#include "gui/dialogs/transient_message.hpp"
|
||||
#include "gui/dialogs/network_transmission.hpp"
|
||||
#include "image.hpp"
|
||||
#include "log.hpp"
|
||||
#include "marked-up_text.hpp"
|
||||
|
@ -627,7 +628,7 @@ bool wait::download_level_data()
|
|||
bool has_scenario_and_controllers = false;
|
||||
while (!has_scenario_and_controllers) {
|
||||
config revc;
|
||||
bool data_res = dialogs::network_receive_dialog(
|
||||
bool data_res = gui2::tnetwork_transmission::wesnothd_receive_dialog(
|
||||
video(), _("Getting game data..."), revc, *wesnothd_connection_);
|
||||
|
||||
if (!data_res) {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "flg_manager.hpp"
|
||||
#include "multiplayer_ui.hpp"
|
||||
#include "widgets/combo.hpp"
|
||||
#include "show_dialog.hpp" //gui::preview_pane
|
||||
|
||||
namespace mp {
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
#include "mp_game_utils.hpp"
|
||||
#include "multiplayer.hpp"
|
||||
#include "connect_engine.hpp"
|
||||
#include "dialogs.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "savegame.hpp"
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include "gui/widgets/window.hpp"
|
||||
#include "log.hpp"
|
||||
#include "serialization/string_utils.hpp"
|
||||
#include "video.hpp"
|
||||
#include "wesnothd_connection.hpp"
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
@ -94,4 +96,53 @@ void tnetwork_transmission::post_show(twindow& /*window*/)
|
|||
connection_->cancel();
|
||||
}
|
||||
|
||||
void tnetwork_transmission::wesnothd_dialog(CVideo& video, gui2::tnetwork_transmission::connection_data& conn, const std::string& msg1, const std::string& msg2)
|
||||
{
|
||||
if (video.faked()) {
|
||||
while (!conn.finished()) {
|
||||
conn.poll();
|
||||
SDL_Delay(1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
gui2::tnetwork_transmission(conn, msg1, msg2).show(video);
|
||||
}
|
||||
}
|
||||
|
||||
struct read_wesnothd_connection_data : public gui2::tnetwork_transmission::connection_data
|
||||
{
|
||||
read_wesnothd_connection_data(twesnothd_connection& conn) : conn_(conn) {}
|
||||
size_t total() override { return conn_.bytes_to_read(); }
|
||||
virtual size_t current() override { return conn_.bytes_read(); }
|
||||
virtual bool finished() override { return conn_.has_data_received(); }
|
||||
virtual void cancel() override { }
|
||||
virtual void poll() override { conn_.poll(); }
|
||||
twesnothd_connection& conn_;
|
||||
};
|
||||
|
||||
bool tnetwork_transmission::wesnothd_receive_dialog(CVideo& video, const std::string& msg, config& cfg, twesnothd_connection& wesnothd_connection)
|
||||
{
|
||||
read_wesnothd_connection_data gui_data(wesnothd_connection);
|
||||
wesnothd_dialog(video, gui_data, msg, _("Waiting"));
|
||||
return wesnothd_connection.receive_data(cfg);
|
||||
}
|
||||
|
||||
struct connect_wesnothd_connection_data : public gui2::tnetwork_transmission::connection_data
|
||||
{
|
||||
connect_wesnothd_connection_data(twesnothd_connection& conn) : conn_(conn) {}
|
||||
virtual bool finished() override { return conn_.handshake_finished(); }
|
||||
virtual void cancel() override { }
|
||||
virtual void poll() override { conn_.poll(); }
|
||||
twesnothd_connection& conn_;
|
||||
};
|
||||
|
||||
std::unique_ptr<twesnothd_connection> tnetwork_transmission::wesnothd_connect_dialog(CVideo& video, const std::string& msg, const std::string& hostname, int port)
|
||||
{
|
||||
std::unique_ptr<twesnothd_connection> res(new twesnothd_connection(hostname, std::to_string(port)));
|
||||
connect_wesnothd_connection_data gui_data(*res);
|
||||
wesnothd_dialog(video, gui_data, msg, _("Connecting"));
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include <boost/optional.hpp>
|
||||
#include "events.hpp"
|
||||
|
||||
class twesnothd_connection;
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
|
@ -34,6 +36,7 @@ namespace gui2
|
|||
class tnetwork_transmission : public tdialog
|
||||
{
|
||||
public:
|
||||
//A wrapper of eigher a twesnothd_connection or a network_asio::connection
|
||||
class connection_data
|
||||
{
|
||||
public:
|
||||
|
@ -44,7 +47,12 @@ public:
|
|||
virtual void poll() = 0;
|
||||
virtual ~connection_data() {}
|
||||
};
|
||||
|
||||
static bool wesnothd_receive_dialog(CVideo& video, const std::string& msg, config& cfg, twesnothd_connection& wesnothd_connection);
|
||||
static std::unique_ptr<twesnothd_connection> wesnothd_connect_dialog(CVideo& video, const std::string& msg, const std::string& hostname, int port);
|
||||
|
||||
private:
|
||||
static void wesnothd_dialog(CVideo& video, gui2::tnetwork_transmission::connection_data& conn, const std::string& msg1, const std::string& msg2);
|
||||
connection_data* connection_;
|
||||
|
||||
class pump_monitor : public events::pump_monitor
|
||||
|
|
|
@ -210,4 +210,18 @@ void tunit_list::post_show(twindow& window)
|
|||
}
|
||||
}
|
||||
|
||||
void show_unit_list(display& gui)
|
||||
{
|
||||
gui2::tunit_list dlg(gui);
|
||||
|
||||
dlg.show(gui.video());
|
||||
|
||||
if (dlg.get_retval() == gui2::twindow::OK) {
|
||||
const map_location& loc = dlg.get_location_to_scroll_to();
|
||||
|
||||
gui.scroll_to_tile(loc, display::WARP);
|
||||
gui.select_hex(loc);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ namespace gui2
|
|||
|
||||
class ttext_;
|
||||
|
||||
void show_unit_list(display& gui);
|
||||
|
||||
class tunit_list : public tdialog
|
||||
{
|
||||
typedef std::vector<unit_const_ptr> unit_ptr_vector;
|
||||
|
|
|
@ -68,7 +68,7 @@ const team & play_controller::hotkey_handler::viewing_team() const { return play
|
|||
bool play_controller::hotkey_handler::viewing_team_is_playing() const { return gui()->viewing_team() == gui()->playing_team(); }
|
||||
|
||||
void play_controller::hotkey_handler::objectives(){
|
||||
menu_handler_.objectives(gui()->viewing_team()+1);
|
||||
menu_handler_.objectives();
|
||||
}
|
||||
|
||||
void play_controller::hotkey_handler::show_statistics(){
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include "ai/manager.hpp"
|
||||
#include "chat_command_handler.hpp"
|
||||
#include "config_assign.hpp"
|
||||
#include "dialogs.hpp"
|
||||
#include "display_chat_manager.hpp"
|
||||
#include "filechooser.hpp"
|
||||
#include "formatter.hpp"
|
||||
|
@ -53,6 +52,7 @@
|
|||
#include "gui/dialogs/edit_text.hpp"
|
||||
#include "gui/dialogs/game_stats.hpp"
|
||||
#include "gui/dialogs/unit_create.hpp"
|
||||
#include "gui/dialogs/unit_list.hpp"
|
||||
#include "gui/dialogs/unit_recall.hpp"
|
||||
#include "gui/dialogs/unit_recruit.hpp"
|
||||
#include "gui/widgets/settings.hpp"
|
||||
|
@ -118,20 +118,18 @@ gui::floating_textbox& menu_handler::get_textbox(){
|
|||
return textbox_info_;
|
||||
}
|
||||
|
||||
void menu_handler::objectives(int side_num)
|
||||
void menu_handler::objectives()
|
||||
{
|
||||
if (!gamestate().lua_kernel_) {
|
||||
return ;
|
||||
}
|
||||
|
||||
config cfg;
|
||||
cfg["side"] = std::to_string(side_num);
|
||||
cfg["side"] = gui_->viewing_side();
|
||||
gamestate().lua_kernel_->run_wml_action("show_objectives", vconfig(cfg),
|
||||
game_events::queued_event("_from_interface", "", map_location(),
|
||||
map_location(), config()));
|
||||
team ¤t_team = teams()[side_num - 1];
|
||||
dialogs::show_objectives(pc_.get_scenario_name(), current_team.objectives());
|
||||
current_team.reset_objectives_changed();
|
||||
pc_.show_objectives();
|
||||
}
|
||||
|
||||
void menu_handler::show_statistics(int side_num)
|
||||
|
@ -149,7 +147,7 @@ void menu_handler::show_statistics(int side_num)
|
|||
|
||||
void menu_handler::unit_list()
|
||||
{
|
||||
dialogs::show_unit_list(*gui_);
|
||||
gui2::show_unit_list(*gui_);
|
||||
}
|
||||
|
||||
void menu_handler::status_table()
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
gui::floating_textbox& get_textbox();
|
||||
void set_gui(game_display* gui) { gui_ = gui; }
|
||||
|
||||
void objectives(int side_num);
|
||||
void objectives();
|
||||
void show_statistics(int side_num);
|
||||
void unit_list();
|
||||
void status_table();
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "actions/undo.hpp" // for undo_list
|
||||
#include "config.hpp" // for config
|
||||
#include "cursor.hpp" // for set, CURSOR_TYPE::NORMAL, etc
|
||||
#include "dialogs.hpp" // for units_list_preview_pane, etc
|
||||
#include "game_board.hpp" // for game_board, etc
|
||||
#include "game_config.hpp" // for red_to_green
|
||||
#include "game_events/manager.hpp"
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include "actions/vision.hpp"
|
||||
#include "ai/manager.hpp"
|
||||
#include "ai/testing.hpp"
|
||||
#include "dialogs.hpp"
|
||||
#include "display_chat_manager.hpp"
|
||||
#include "formula/string_utils.hpp"
|
||||
#include "game_events/manager.hpp"
|
||||
|
@ -1261,3 +1260,11 @@ play_controller::scoped_savegame_snapshot::~scoped_savegame_snapshot()
|
|||
{
|
||||
controller_.saved_game_.remove_snapshot();
|
||||
}
|
||||
|
||||
void play_controller::show_objectives() const
|
||||
{
|
||||
const team& t = gamestate().board_.teams()[gui_->viewing_team()];
|
||||
static const std::string no_objectives(_("No objectives available"));
|
||||
gui2::show_transient_message(gui_->video(), get_scenario_name(), (t.objectives().empty() ? no_objectives : t.objectives()), "", true);
|
||||
t.reset_objectives_changed();
|
||||
}
|
||||
|
|
|
@ -219,17 +219,17 @@ public:
|
|||
|
||||
virtual bool is_replay() { return false; }
|
||||
|
||||
t_string get_scenario_name()
|
||||
t_string get_scenario_name() const
|
||||
{
|
||||
return level_["name"].t_str();
|
||||
}
|
||||
|
||||
bool get_disallow_recall()
|
||||
bool get_disallow_recall() const
|
||||
{
|
||||
return level_["disallow_recall"].to_bool();
|
||||
}
|
||||
|
||||
std::string theme()
|
||||
std::string theme() const
|
||||
{
|
||||
return level_["theme"].str();
|
||||
}
|
||||
|
@ -267,6 +267,7 @@ public:
|
|||
virtual bool is_networked_mp() const { return false; }
|
||||
virtual void send_to_wesnothd(const config&, const std::string& = "unknown") const { }
|
||||
virtual bool recieve_from_wesnothd(config&) const { return false; }
|
||||
void show_objectives() const;
|
||||
protected:
|
||||
struct scoped_savegame_snapshot
|
||||
{
|
||||
|
|
|
@ -15,11 +15,10 @@
|
|||
|
||||
#include "playmp_controller.hpp"
|
||||
|
||||
#include "dialogs.hpp"
|
||||
|
||||
#include "actions/undo.hpp"
|
||||
#include "display_chat_manager.hpp"
|
||||
#include "game_end_exceptions.hpp"
|
||||
#include "gui/dialogs/network_transmission.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "hotkey/hotkey_handler_mp.hpp"
|
||||
#include "log.hpp"
|
||||
|
@ -281,7 +280,7 @@ void playmp_controller::wait_for_upload()
|
|||
network_reader_.set_source(playturn_network_adapter::get_source_from_config(cfg));
|
||||
while(true) {
|
||||
try {
|
||||
const bool res = dialogs::network_receive_dialog(
|
||||
const bool res = gui2::tnetwork_transmission::wesnothd_receive_dialog(
|
||||
gui_->video(), _("Waiting for next scenario..."), cfg, mp_info_->wesnothd_connection);
|
||||
|
||||
if(res) {
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "ai/game_info.hpp"
|
||||
#include "ai/testing.hpp"
|
||||
#include "config_assign.hpp"
|
||||
#include "dialogs.hpp"
|
||||
#include "display_chat_manager.hpp"
|
||||
#include "game_end_exceptions.hpp"
|
||||
#include "game_events/manager.hpp"
|
||||
|
@ -612,8 +611,7 @@ void playsingle_controller::check_objectives()
|
|||
const team &t = gamestate().board_.teams()[gui_->viewing_team()];
|
||||
|
||||
if (!is_regular_game_end() && !is_browsing() && t.objectives_changed()) {
|
||||
dialogs::show_objectives(get_scenario_name().str(), t.objectives());
|
||||
t.reset_objectives_changed();
|
||||
show_objectives();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
#include "actions/undo.hpp"
|
||||
#include "config_assign.hpp"
|
||||
#include "dialogs.hpp"
|
||||
#include "display_chat_manager.hpp"
|
||||
#include "floating_label.hpp"
|
||||
#include "game_display.hpp"
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "global.hpp"
|
||||
|
||||
#include "actions/attack.hpp" // for battle_context_unit_stats, etc
|
||||
#include "actions/advancement.hpp" // for advance_unit_at, etc
|
||||
#include "actions/move.hpp" // for clear_shroud
|
||||
#include "actions/vision.hpp" // for clear_shroud
|
||||
#include "ai/composite/ai.hpp" // for ai_composite
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "team.hpp"
|
||||
#include "play_controller.hpp"
|
||||
#include "actions/create.hpp"
|
||||
#include "actions/advancement.hpp"
|
||||
#include "actions/attack.hpp"
|
||||
#include "actions/move.hpp"
|
||||
#include "actions/undo.hpp"
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include <boost/test/unit_test_suite.hpp>
|
||||
|
||||
|
||||
#include "dialogs.hpp"
|
||||
#include "key.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "savegame.hpp"
|
||||
|
|
Loading…
Add table
Reference in a new issue