Author: sapient
Date: Fri Jun 22 04:36:12 2007
New Revision: 18367
URL: http://svn.gna.org/viewcvs/wesnoth?rev=18367&view=rev
Log:
patch #749: Ingame Add-on removal support
* also fix some cross platform issues
* also remove an unnecessary style copy
Modified:
trunk/changelog
trunk/src/construct_dialog.cpp
trunk/src/construct_dialog.hpp
trunk/src/game.cpp
trunk/src/show_dialog.cpp
trunk/src/show_dialog.hpp
trunk/src/titlescreen.cpp
Modified: trunk/changelog
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=18367&r1=18366&r2=18367&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Fri Jun 22 04:36:12 2007
@@ -51,6 +51,7 @@
* the movement hint use multiline, colors and bigger font to display
terrain defense and turns to reach
* restore search of no-team-only map labels
+ * ability to delete Add-Ons
* Miscellaneous and bugfixes
* fix bug #4299: word wrap for menus with very long option strings
* various bugfixes and code cleanups
Modified: trunk/src/construct_dialog.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/construct_dialog.cpp?rev=18367&r1=18366&r2=18367&view=diff
==============================================================================
--- trunk/src/construct_dialog.cpp (original)
+++ trunk/src/construct_dialog.cpp Fri Jun 22 04:36:12 2007
@@ -54,10 +54,10 @@
// This is where the connections between styles and the panel images
// in the data tree gets made.
-const struct style dialog::default_style = {"opaque", 0};
-const struct style dialog::message_style = {"translucent65", 3};
-const struct style dialog::titlescreen_style = {"translucent54", 0};
-const struct style dialog::hotkeys_style = {"menu2", 0};
+const struct style dialog::default_style("opaque", 0);
+const struct style dialog::message_style("translucent65", 3);
+const struct style dialog::titlescreen_style("translucent54", 0);
+const struct style dialog::hotkeys_style("menu2", 0);
//static initialization
const std::string dialog::no_help("");
Modified: trunk/src/construct_dialog.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/construct_dialog.hpp?rev=18367&r1=18366&r2=18367&view=diff
==============================================================================
--- trunk/src/construct_dialog.hpp (original)
+++ trunk/src/construct_dialog.hpp Fri Jun 22 04:36:12 2007
@@ -27,8 +27,9 @@
namespace gui {
struct style {
+ style(std::string const& p, int br) : panel(p), blur_radius(br) {}
std::string panel;
- int blur_radius;
+ int blur_radius;
};
struct dialog_process_info
Modified: trunk/src/game.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game.cpp?rev=18367&r1=18366&r2=18367&view=diff
==============================================================================
--- trunk/src/game.cpp (original)
+++ trunk/src/game.cpp Fri Jun 22 04:36:12 2007
@@ -98,7 +98,8 @@
bool new_campaign();
bool play_multiplayer();
- void download_campaigns();
+ void manage_addons();
+ void download_campaigns(std::string host);
bool change_language();
void show_help();
@@ -888,17 +889,126 @@
namespace
{
-void game_controller::download_campaigns()
-{
- std::string host = preferences::campaign_server();
-
- const int res = gui::show_dialog(disp(),NULL,_("Connect to Server"),
+ // Manage add-ons
+ void game_controller::manage_addons()
+ {
+ int res;
+
+ gui::dialog d(disp(),_("Connect to Server"),
_("You will now connect to a server to download add-ons."),
- gui::OK_CANCEL,NULL,NULL,_("Server: "),&host);
- if(res != 0) {
- return;
- }
-
+ gui::OK_CANCEL);
+ d.set_textbox(_("Server: "), preferences::campaign_server());
+ d.add_button( new gui::dialog_button(disp().video(), _("Remove
Add-ons"),
+ gui::button::TYPE_PRESS, 2), gui::dialog::BUTTON_EXTRA);
+ res = d.show();
+ const std::string host = d.textbox_text();
+
+ if (res == 0 ) // Get Add-Ons
+ {
+ download_campaigns(host);
+ }
+ else if (res == 2) // Manage Add-Ons
+ {
+
+ std::vector<std::string> addons;
+
+ const std::string campaign_dir = get_user_data_dir() +
"/data/campaigns/";
+
+ get_files_in_dir(campaign_dir, &addons, NULL,
FILE_NAME_ONLY);
+
+ // Strip the ".cfg" extension and replace "_" with " "
for display.
+ std::vector<std::string>::iterator i = addons.begin();
+ while(i != addons.end())
+ {
+ std::string::size_type pos = i->rfind(".cfg",
i->size());
+ if(pos == std::string::npos) {
+ i = addons.erase(i);
+ } else {
+ i->erase(pos);
+ std::replace(i->begin(), i->end(), '_',
' ');
+ i++;
+ }
+ }
+
+
+ if (addons.empty())
+ {
+ gui::show_error_message(disp(), _("You have no
Add-ons installed."));
+ return;
+ }
+
+ gui::menu::basic_sorter sorter;
+ sorter.set_alpha_sort(1);
+
+
+ int index = 0;
+
+ do
+ {
+ gui::dialog addon_dialog(disp(), _("Remove
Add-ons"), _("Choose the add-on to remove."),
+ gui::OK_CANCEL);
+ gui::menu::imgsel_style &addon_style =
gui::menu::bluebg_style;
+
+ gui::menu *addon_menu = new
gui::menu(disp().video(), addons, false, -1,
+ gui::dialog::max_menu_width,
&sorter, &addon_style, false);
+ addon_dialog.set_menu(addon_menu);
+ index = addon_dialog.show();
+
+ if(index < 0) return;
+
+ const std::string confirm_message =
+ "Are you sure you want to remove the
add-on \'"
+ + addons.at(index)
+ + "?\'";
+ res = gui::show_dialog(
+ disp(),
+ NULL,
+ _("Confirm"),
+ confirm_message,
+ gui::YES_NO);
+ } while (res != 0);
+
+ bool delete_success = true;
+
+ //Put underscores back in the name and remove the addon
+ std::string filename = addons.at(index);
+ std::replace(filename.begin(), filename.end(), ' ',
'_');
+ delete_success &= delete_directory(campaign_dir +
filename + ".cfg");
+ if (delete_success)
+ {
+ delete_success &= delete_directory(campaign_dir
+ filename);
+ }
+
+ //Report results
+ if (delete_success)
+ {
+ //force a reload of configuration information
+ const bool old_cache = use_caching_;
+ use_caching_ = false;
+ old_defines_map_.clear();
+ refresh_game_cfg();
+ use_caching_ = old_cache;
+ ::init_textdomains(game_config_);
+ paths_manager_.set_paths(game_config_);
+ clear_binary_paths_cache();
+
+ std::string success_message = "Add-on \'" +
addons.at(index) + "\' deleted.";
+
+ gui::show_dialog(disp(), NULL, _("Add-on
deleted"), success_message,
+ gui::OK_ONLY);
+ }
+ else
+ {
+ gui::show_dialog(disp(), NULL, _("Error"),
_("Add-on could not be deleted -- a file was not found."),
+ gui::OK_ONLY);
+ }
+ }
+ else // Cancel or unexpected result
+ return;
+ }
+
+void game_controller::download_campaigns(std::string host)
+{
const std::vector<std::string> items = utils::split(host, ':');
if(items.empty()) {
return;
@@ -1908,7 +2018,7 @@
help::show_help(game.disp());
continue;
} else if(res == gui::GET_ADDONS) {
- game.download_campaigns();
+ game.manage_addons();
continue;
} else if(res == gui::BEG_FOR_UPLOAD) {
game.show_upload_begging();
Modified: trunk/src/show_dialog.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/show_dialog.cpp?rev=18367&r1=18366&r2=18367&view=diff
==============================================================================
--- trunk/src/show_dialog.cpp (original)
+++ trunk/src/show_dialog.cpp Fri Jun 22 04:36:12 2007
@@ -58,7 +58,8 @@
const int ButtonHPadding = 10;
const int ButtonVPadding = 10;
-const struct style dialog_frame::default_style = {"opaque", false};
+static const struct style &default_style = dialog::default_style; //{"opaque",
false}
+
const int dialog_frame::title_border_w = 10;
const int dialog_frame::title_border_h = 5;
Modified: trunk/src/show_dialog.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/show_dialog.hpp?rev=18367&r1=18366&r2=18367&view=diff
==============================================================================
--- trunk/src/show_dialog.hpp (original)
+++ trunk/src/show_dialog.hpp Fri Jun 22 04:36:12 2007
@@ -57,7 +57,6 @@
class dialog_frame {
public:
//Static members
- static const struct style default_style;
static const int title_border_w, title_border_h;
int vertical_padding() const;
Modified: trunk/src/titlescreen.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/titlescreen.cpp?rev=18367&r1=18366&r2=18367&view=diff
==============================================================================
--- trunk/src/titlescreen.cpp (original)
+++ trunk/src/titlescreen.cpp Fri Jun 22 04:36:12 2007
@@ -257,7 +257,7 @@
N_("TitleScreen
button^Campaign"),
N_("TitleScreen
button^Multiplayer"),
N_("TitleScreen button^Load"),
- N_("TitleScreen button^Get
Add-ons"),
+ N_("TitleScreen button^Add-ons"),
N_("TitleScreen
button^Language"),
N_("TitleScreen
button^Preferences"),
N_("Credits"),
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits