Skip to content

Commit

Permalink
Add test button to title screen in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Sep 17, 2016
1 parent c9cbdb2 commit 97899f8
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
15 changes: 15 additions & 0 deletions data/_main.cfg
Expand Up @@ -53,12 +53,27 @@
[/textdomain]
#endif

# We do a little preprocesser buggery to make the test scenarios accessible
# in debug mode, but excluding the unit test scenarios.
#ifdef DEBUG
#define TEST_SCENARIO
#enddef
#endif

#ifdef TEST
#define TEST_SCENARIO
#enddef
#endif

#ifdef TEST_SCENARIO
{scenario-test.cfg}
{scenario-leaders.cfg}
{scenario-movethrough.cfg}
{ai/scenarios/}
{ai/micro_ais/scenarios/}
#endif

#ifdef TEST
#define DONT_RELOAD_CORE
#enddef

Expand Down
1 change: 1 addition & 0 deletions data/gui/window/title_screen.cfg
Expand Up @@ -251,6 +251,7 @@ where
{_GUI_BUTTON "tutorial" _"Tutorial" _"Start a tutorial to familiarize yourself with the game"}
{_GUI_BUTTON "campaign" _"Campaigns" _"Start a new single player campaign"}
{_GUI_BUTTON "multiplayer" _"Multiplayer" _"Play multiplayer (hotseat, LAN, or Internet), or a single scenario against the AI"}
{_GUI_BUTTON "tests" _"Tests" _"Run a test scenario"}
{_GUI_BUTTON "load" _"Load" _"Load a saved game"}
{_GUI_BUTTON "addons" _"Add-ons" _"Download usermade campaigns, eras, or map packs"}
{_GUI_BUTTON "cores" _"Cores" _"Select the game core data"}
Expand Down
25 changes: 15 additions & 10 deletions src/game_launcher.cpp
Expand Up @@ -460,6 +460,20 @@ bool game_launcher::init_lua_script()
return !error;
}

void game_launcher::set_test(const std::string& id)
{
state_ = saved_game();
state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::TEST;
state_.classification().campaign_define = "TEST_SCENARIO";

state_.mp_settings().mp_era = "era_default";
state_.mp_settings().show_connect = false;

state_.set_carryover_sides_start(
config_of("next_scenario", id)
);
}

bool game_launcher::play_test()
{
static bool first_time = true;
Expand All @@ -472,18 +486,9 @@ bool game_launcher::play_test()

first_time = false;

state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::TEST;
set_test(test_scenario_);
state_.classification().campaign_define = "TEST";

state_.mp_settings().mp_era = "era_default";
state_.mp_settings().show_connect = false;

state_.set_carryover_sides_start(
config_of("next_scenario", test_scenario_)
);



game_config_manager::get()->
load_game_config_for_game(state_.classification());

Expand Down
1 change: 1 addition & 0 deletions src/game_launcher.hpp
Expand Up @@ -71,6 +71,7 @@ class game_launcher
void clear_loaded_game();
bool load_game();
void set_tutorial();
void set_test(const std::string& id);

std::string jump_to_campaign_id() const;
bool new_campaign();
Expand Down
21 changes: 21 additions & 0 deletions src/gui/dialogs/title_screen.cpp
Expand Up @@ -31,6 +31,7 @@
#include "gui/dialogs/lua_interpreter.hpp"
#include "game_config_manager.hpp"
#include "gui/dialogs/core_selection.hpp"
#include "gui/dialogs/simple_item_selector.hpp"
#include "gui/dialogs/multiplayer/mp_method_selection.hpp"
#include "gui/dialogs/multiplayer/mp_host_game_prompt.hpp"
#include "gui/dialogs/message.hpp"
Expand Down Expand Up @@ -379,6 +380,22 @@ void ttitle_screen::pre_show(twindow& window)
return;
}
});
register_button(window, "tests", hotkey::HOTKEY_NULL, [this](twindow& window) {
std::vector<std::string> options;
for(const config &sc : game_config_manager::get()->game_config().child_range("test")) {
const std::string &id = sc["id"];
options.push_back(id);
}
std::sort(options.begin(), options.end());
gui2::tsimple_item_selector dlg(_("Choose Test"), "", options);
dlg.show(game_.video());
int choice = dlg.selected_index();
if(choice >= 0) {
game_.set_test(options[choice]);
result_ = LAUNCH_GAME;
window.close();
}
});
register_button(window, "editor", hotkey::TITLE_SCREEN__EDITOR,
std::bind(&ttitle_screen::basic_callback, this, std::ref(window), MAP_EDITOR));
register_button(window, "cores", hotkey::TITLE_SCREEN__CORES, [this](twindow&) {
Expand Down Expand Up @@ -423,6 +440,10 @@ void ttitle_screen::pre_show(twindow& window)
find_widget<tbutton>(&window, "cores", false).set_visible(twindow::tvisible::invisible);
}

if(!game_config::debug) {
find_widget<tbutton>(&window, "tests", false).set_visible(twindow::tvisible::invisible);
}

window.connect_signal<event::SDL_VIDEO_RESIZE>(std::bind(&ttitle_screen::on_resize, this, std::ref(window)));
}

Expand Down

0 comments on commit 97899f8

Please sign in to comment.