Skip to content

Commit

Permalink
Android port by Alessandro Pira
Browse files Browse the repository at this point in the history
  • Loading branch information
AI0867 committed Jul 2, 2013
1 parent a44b709 commit ee68c38
Show file tree
Hide file tree
Showing 40 changed files with 102 additions and 29 deletions.
10 changes: 9 additions & 1 deletion src/events.cpp
Expand Up @@ -298,10 +298,18 @@ void pump()
}
}
std::vector<SDL_Event>::iterator ev_end = events.end();
int draw_processed = 0;

for(ev_it = events.begin(); ev_it != ev_end; ++ev_it){
SDL_Event &event = *ev_it;
switch(event.type) {
// ___AP___
if (event.type == DRAW_EVENT) {
if (draw_processed)
continue;
draw_processed = 1;
}

switch(event.type) {
case SDL_ACTIVEEVENT: {
SDL_ActiveEvent& ae = reinterpret_cast<SDL_ActiveEvent&>(event);
if((ae.state & SDL_APPMOUSEFOCUS) != 0 || (ae.state & SDL_APPINPUTFOCUS) != 0) {
Expand Down
14 changes: 11 additions & 3 deletions src/game.cpp
Expand Up @@ -337,8 +337,13 @@ static void init_locale() {
#if defined _WIN32 || defined __APPLE__
setlocale(LC_ALL, "English");
#else
std::setlocale(LC_ALL, "C");
std::setlocale(LC_MESSAGES, "");
#if defined ANDROID
setlocale(LC_ALL, "C");
setlocale(LC_MESSAGES, "");
#else
std::setlocale(LC_ALL, "C");
std::setlocale(LC_MESSAGES, "");
#endif
#endif
const std::string& intl_dir = get_intl_dir();
bindtextdomain (PACKAGE, intl_dir.c_str());
Expand Down Expand Up @@ -589,12 +594,15 @@ void init_custom_malloc();
}
#endif


#ifdef ANDROID
int SDL_main(int argc, char** argv)
#else
#ifdef __native_client__
int wesnoth_main(int argc, char** argv)
#else
int main(int argc, char** argv)
#endif
#endif
{

#ifdef HAVE_VISUAL_LEAK_DETECTOR
Expand Down
5 changes: 4 additions & 1 deletion src/game_controller.cpp
Expand Up @@ -954,9 +954,12 @@ bool game_controller::play_multiplayer()

if(dlg.get_retval() == gui2::twindow::OK) {
res = dlg.get_choice();
//___AP___ removed "start local server" option
#ifdef ANDROID
if (res >= 2) res += 1;
#endif
} else {
return false;

}

if (res == 2 && preferences::mp_server_warning_disabled() < 2)
Expand Down
40 changes: 34 additions & 6 deletions src/game_preferences_display.cpp
Expand Up @@ -110,7 +110,12 @@ class preferences_dialog : public gui::preview_pane
scroll_slider_, chat_lines_slider_,
buffer_size_slider_, idle_anim_slider_, autosavemax_slider_, advanced_slider_;
gui::list_slider<double> turbo_slider_;
gui::button fullscreen_button_, turbo_button_, show_ai_moves_button_,
gui::button
// ___AP___
#ifndef ANDROID
fullscreen_button_, show_color_cursors_button_,
#endif
turbo_button_, show_ai_moves_button_,
interrupt_when_ally_sighted_button_,
show_grid_button_, save_replays_button_, delete_saves_button_,
show_lobby_joins_button1_,
Expand All @@ -123,7 +128,7 @@ class preferences_dialog : public gui::preview_pane
friends_remove_button_, show_floating_labels_button_,
turn_dialog_button_, whiteboard_on_start_button_,
hide_whiteboard_button_, turn_bell_button_, show_team_colors_button_,
show_color_cursors_button_, show_haloing_button_, video_mode_button_,
show_haloing_button_, video_mode_button_,
theme_button_, hotkeys_button_,
advanced_button_, sound_button_,
music_button_, chat_timestamp_button_,
Expand Down Expand Up @@ -168,8 +173,11 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
advanced_slider_(disp.video()),
turbo_slider_(disp.video()),


// ___AP___
#ifndef ANDROID
fullscreen_button_(disp.video(), _("Full screen"), gui::button::TYPE_CHECK),
show_color_cursors_button_(disp.video(), _("Show color cursors"), gui::button::TYPE_CHECK),
#endif
turbo_button_(disp.video(), _("Accelerated speed"), gui::button::TYPE_CHECK),
show_ai_moves_button_(disp.video(), _("Skip AI moves"), gui::button::TYPE_CHECK),
interrupt_when_ally_sighted_button_(disp.video(), _("Interrupt move when an ally is sighted"), gui::button::TYPE_CHECK),
Expand All @@ -194,7 +202,6 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
hide_whiteboard_button_(disp.video(), _("Hide allies’ plans by default"), gui::button::TYPE_CHECK),
turn_bell_button_(disp.video(), _("Turn bell"), gui::button::TYPE_CHECK),
show_team_colors_button_(disp.video(), _("Show team colors"), gui::button::TYPE_CHECK),
show_color_cursors_button_(disp.video(), _("Show color cursors"), gui::button::TYPE_CHECK),
show_haloing_button_(disp.video(), _("Show haloing effects"), gui::button::TYPE_CHECK),
video_mode_button_(disp.video(), _("Change Resolution")),
theme_button_(disp.video(), _("Theme")),
Expand Down Expand Up @@ -311,8 +318,11 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
chat_timestamp_button_.set_check(chat_timestamping());
chat_timestamp_button_.set_help_string(_("Add a timestamp to chat messages"));

// ___AP___
#ifndef ANDROID
fullscreen_button_.set_check(fullscreen());
fullscreen_button_.set_help_string(_("Choose whether the game should run full screen or in a window"));
#endif

turbo_button_.set_check(turbo());
turbo_button_.set_help_string(_("Make units move and fight faster"));
Expand Down Expand Up @@ -419,8 +429,11 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
show_team_colors_button_.set_check(show_side_colors());
show_team_colors_button_.set_help_string(_("Show a colored circle around the base of each unit to show which side it is on"));

// ___AP___
#ifndef ANDROID
show_color_cursors_button_.set_check(use_color_cursors());
show_color_cursors_button_.set_help_string(_("Use colored mouse cursors (may be slower)"));
#endif

show_haloing_button_.set_check(show_haloes());
show_haloing_button_.set_help_string(_("Use graphical special effects (may be slower)"));
Expand All @@ -445,7 +458,10 @@ handler_vector preferences_dialog::handler_members()
h.push_back(&autosavemax_slider_);
h.push_back(&buffer_size_slider_);
h.push_back(&advanced_slider_);
// ___AP___
#ifndef ANDROID
h.push_back(&fullscreen_button_);
#endif
h.push_back(&turbo_button_);
h.push_back(&idle_anim_button_);
h.push_back(&standing_anim_button_);
Expand Down Expand Up @@ -475,7 +491,10 @@ handler_vector preferences_dialog::handler_members()
h.push_back(&turn_bell_button_);
h.push_back(&UI_sound_button_);
h.push_back(&show_team_colors_button_);
// ___AP___
#ifndef ANDROID
h.push_back(&show_color_cursors_button_);
#endif
h.push_back(&show_haloing_button_);
h.push_back(&video_mode_button_);
h.push_back(&theme_button_);
Expand Down Expand Up @@ -558,9 +577,12 @@ void preferences_dialog::update_location(SDL_Rect const &rect)

// Display tab
ypos = rect.y + top_border;
// ___AP___
#ifndef ANDROID
fullscreen_button_.set_location(rect.x, ypos);

ypos += item_interline; show_color_cursors_button_.set_location(rect.x, ypos);
#endif

ypos += item_interline; show_floating_labels_button_.set_location(rect.x, ypos);
ypos += item_interline; show_haloing_button_.set_location(rect.x, ypos);
ypos += item_interline; show_team_colors_button_.set_location(rect.x, ypos);
Expand Down Expand Up @@ -770,12 +792,15 @@ void preferences_dialog::process_event()
if (theme_button_.pressed())
show_theme_dialog(disp_);
parent->clear_buttons();
// ___AP___
#ifndef ANDROID
if (fullscreen_button_.pressed())
throw video_mode_change_exception(fullscreen_button_.checked()
? video_mode_change_exception::MAKE_FULLSCREEN
: video_mode_change_exception::MAKE_WINDOWED);
if (show_color_cursors_button_.pressed())
set_color_cursors(show_color_cursors_button_.checked());
#endif
if (show_haloing_button_.pressed())
set_show_haloes(show_haloing_button_.checked());
if (show_team_colors_button_.pressed())
Expand Down Expand Up @@ -1152,9 +1177,12 @@ void preferences_dialog::set_selection(int index)

const bool hide_display = tab_ != DISPLAY_TAB;
show_floating_labels_button_.hide(hide_display);
show_color_cursors_button_.hide(hide_display);
show_haloing_button_.hide(hide_display);
// ___AP___
#ifndef ANDROID
show_color_cursors_button_.hide(hide_display);
fullscreen_button_.hide(hide_display);
#endif
idle_anim_button_.hide(hide_display);
idle_anim_slider_label_.hide(hide_display);
idle_anim_slider_label_.enable(idle_anim());
Expand Down
1 change: 1 addition & 0 deletions src/gui/dialogs/title_screen.cpp
Expand Up @@ -351,6 +351,7 @@ void ttitle_screen::pre_show(CVideo& video, twindow& window)
/***** Set the logo *****/
tprogress_bar* logo =
find_widget<tprogress_bar>(&window, "logo", false, false);

if(logo) {
/*
* A 'singleton' value, since the progress bar only needs to progress
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 5 additions & 1 deletion src/lua/llex.c → src/lua/llex.cpp
Expand Up @@ -178,9 +178,13 @@ static void buffreplace (LexState *ls, char from, char to) {

static void trydecpoint (LexState *ls, SemInfo *seminfo) {
/* format error: try to update decimal point separator */
struct lconv *cv = localeconv();
char old = ls->decpoint;
#if defined ANDROID
ls->decpoint = '.';
#else
struct lconv *cv = localeconv();
ls->decpoint = (cv ? cv->decimal_point[0] : '.');
#endif
buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */
if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) {
/* format error with correct decimal point: no more options */
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 21 additions & 6 deletions src/preferences.cpp
Expand Up @@ -34,6 +34,12 @@

#include <sys/stat.h> // for setting the permissions of the preferences file

#ifdef ANDROID // ___AP___
extern "C" {
void SDL_ANDROID_getScreenSize(int *, int *);
}
#endif

static lg::log_domain log_config("config");
#define ERR_CFG LOG_STREAM(err , log_config)

Expand All @@ -42,7 +48,7 @@ static lg::log_domain log_filesystem("filesystem");

namespace {

bool color_cursors = false;
bool color_cursors = true;

bool no_preferences_save = false;

Expand Down Expand Up @@ -212,7 +218,15 @@ std::pair<int,int> resolution()
//res.second &= ~3;
return res;
} else {
#ifdef ANDROID // ___AP___
int sdlw, sdlh;
SDL_ANDROID_getScreenSize(&sdlw, &sdlh);
std::pair<int,int> res(std::max(sdlw, min_allowed_width()),
std::max(sdlh, min_allowed_height()));
return res;
#else
return std::pair<int,int>(1024,768);
#endif
}
}

Expand Down Expand Up @@ -382,7 +396,7 @@ void set_UI_volume(int vol)

bool turn_bell()
{
return get("turn_bell", true);
return get("turn_bell", false); // ___AP___
}

bool set_turn_bell(bool ison)
Expand All @@ -406,7 +420,7 @@ bool set_turn_bell(bool ison)

bool UI_sound_on()
{
return get("UI_sound", true);
return get("UI_sound", false); // ___AP___
}

bool set_UI_sound(bool ison)
Expand All @@ -430,12 +444,12 @@ bool set_UI_sound(bool ison)

bool message_bell()
{
return get("message_bell", true);
return get("message_bell", false); // ___AP___
}

bool sound_on()
{
return get("sound", true);
return get("sound", false); // ___AP___
}

bool set_sound(bool ison) {
Expand All @@ -458,7 +472,7 @@ bool set_sound(bool ison) {

bool music_on()
{
return get("music", true);
return get("music", false); // ___AP___
}

bool set_music(bool ison) {
Expand Down Expand Up @@ -705,6 +719,7 @@ bool use_color_cursors()

void _set_color_cursors(bool value)
{
value = true; // ___AP___
preferences::set("color_cursors", value);
color_cursors = value;
}
Expand Down
11 changes: 6 additions & 5 deletions src/preferences_display.cpp
Expand Up @@ -51,7 +51,7 @@ display_manager::display_manager(display* d)
set_turbo_speed(turbo_speed());
set_fullscreen(fullscreen());
set_scroll_to_action(scroll_to_action());
set_color_cursors(preferences::get("color_cursors", false));
set_color_cursors(preferences::get("color_cursors", true)); // ___AP___
}

display_manager::~display_manager()
Expand All @@ -75,10 +75,11 @@ bool detect_video_settings(CVideo& video, std::pair<int,int>& resolution, int& b

typedef std::pair<int, int> res_t;
std::vector<res_t> res_list;
res_list.push_back(res_t(1024, 768));
res_list.push_back(res_t(1024, 600));
res_list.push_back(res_t(800, 600));
// ___AP___ reversed order
res_list.push_back(res_t(800, 480));
res_list.push_back(res_t(800, 600));
res_list.push_back(res_t(1024, 600));
res_list.push_back(res_t(1024, 768));

bpp = video.modePossible(resolution.first, resolution.second,
DefaultBPP, video_flags, true);
Expand Down Expand Up @@ -124,7 +125,7 @@ void set_fullscreen(CVideo& video, const bool ison)
gui2::show_transient_message(video,"",_("The video mode could not be changed. Your window manager must be set to 16 bits per pixel to run the game in windowed mode. Your display must support 1024x768x16 to run the game full screen."));
}
// We reinit color cursors, because SDL on Mac seems to forget the SDL_Cursor
set_color_cursors(preferences::get("color_cursors", false));
set_color_cursors(preferences::get("color_cursors", true)); // ___AP___
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/serialization/parser.cpp
Expand Up @@ -158,6 +158,7 @@ void parser::parse_element()
error(_("Unterminated [element] tag"));
// Add the element
current_element = &(elements.top().cfg->add_child(elname));

elements.push(element(current_element, elname, tok_->get_start_line(), tok_->get_file()));
if (validator_){
validator_->open_tag(elname,tok_->get_start_line(),
Expand Down Expand Up @@ -187,6 +188,7 @@ void parser::parse_element()
tok_->get_file());
}
}

elements.push(element(current_element, elname, tok_->get_start_line(), tok_->get_file()));
break;

Expand All @@ -212,6 +214,7 @@ void parser::parse_element()
validator_->validate(*el.cfg,el.name,el.start_line,el.file);
validator_->close_tag();
}

elements.pop();
break;
default:
Expand Down Expand Up @@ -321,10 +324,12 @@ void parser::parse_variable()
}

finish:
if (buffer.translatable())
cfg[*curvar] = t_string(buffer);
else
if (buffer.translatable()) {
t_string tmp = t_string(buffer);
cfg[*curvar] = tmp;
} else {
cfg[*curvar] = buffer.value();
}
if(validator_){
validator_->validate_key (cfg,*curvar,buffer.value(),
tok_->get_start_line (),
Expand Down
2 changes: 1 addition & 1 deletion src/tstring.cpp
Expand Up @@ -66,7 +66,7 @@ t_string_base::walker::walker(const t_string_base& string) :
}
}

#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(ANDROID) // ___AP___
/*
* From the IRC log of 23.07.2010
* 07:52 <silene> Upth: what did it break?
Expand Down

0 comments on commit ee68c38

Please sign in to comment.