mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-27 03:26:04 +00:00
Implement a surrender dialog
This records a surrender command in replays and quits the game.
This commit is contained in:
parent
9cdd0242d5
commit
024b2e7e9b
132
data/gui/window/surrender_quit.cfg
Normal file
132
data/gui/window/surrender_quit.cfg
Normal file
@ -0,0 +1,132 @@
|
||||
#textdomain wesnoth-lib
|
||||
###
|
||||
### Definition of the window to ask for deleting a savegame file
|
||||
###
|
||||
|
||||
[window]
|
||||
id = "surrender_quit"
|
||||
description = "Confirmation for surrendering and/or quitting a game"
|
||||
|
||||
[resolution]
|
||||
definition = "default"
|
||||
|
||||
automatic_placement = true
|
||||
vertical_placement = "center"
|
||||
horizontal_placement = "center"
|
||||
|
||||
[tooltip]
|
||||
id = "tooltip"
|
||||
[/tooltip]
|
||||
|
||||
[helptip]
|
||||
id = "tooltip"
|
||||
[/helptip]
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
[label]
|
||||
id = "lblTitle"
|
||||
definition = "title"
|
||||
|
||||
label = _ "Surrender and/or quit game"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
[label]
|
||||
id = "lblMessage"
|
||||
definition = "default"
|
||||
|
||||
label = _ "Do you want to surrender and/or quit the game?"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
[button]
|
||||
id = "quit_and_surrender"
|
||||
definition = "default"
|
||||
|
||||
label = _ "Quit and surrender"
|
||||
return_value = 1
|
||||
[/button]
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[button]
|
||||
id = "quit_without_surrender"
|
||||
definition = "default"
|
||||
|
||||
label = _ "Quit without surrender"
|
||||
return_value = 2
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[button]
|
||||
id = "cancel"
|
||||
definition = "default"
|
||||
|
||||
label = _ "Cancel"
|
||||
return_value = 3
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/resolution]
|
||||
|
||||
[/window]
|
@ -659,6 +659,7 @@
|
||||
<Unit filename="../../src/gui/dialogs/statistics_dialog.hpp" />
|
||||
<Unit filename="../../src/gui/dialogs/story_viewer.cpp" />
|
||||
<Unit filename="../../src/gui/dialogs/story_viewer.hpp" />
|
||||
<Unit filename="../../src/gui/dialogs/surrender_quit.cpp" />
|
||||
<Unit filename="../../src/gui/dialogs/terrain_layers.cpp" />
|
||||
<Unit filename="../../src/gui/dialogs/terrain_layers.hpp" />
|
||||
<Unit filename="../../src/gui/dialogs/theme_list.cpp" />
|
||||
|
@ -1965,6 +1965,13 @@
|
||||
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Debug|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
|
||||
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Release|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\gui\dialogs\surrender_quit.cpp">
|
||||
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
|
||||
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='ReleaseDEBUG|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
|
||||
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
|
||||
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Debug|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
|
||||
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Release|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\gui\dialogs\terrain_layers.cpp">
|
||||
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
|
||||
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='ReleaseDEBUG|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
|
||||
@ -4120,4 +4127,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -662,6 +662,9 @@
|
||||
<ClCompile Include="..\..\src\gui\dialogs\story_viewer.cpp">
|
||||
<Filter>Gui\Dialogs</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\gui\dialogs\surrender_quit.cpp">
|
||||
<Filter>Gui\Dialogs</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\gui\dialogs\terrain_layers.cpp">
|
||||
<Filter>Gui\Dialogs</Filter>
|
||||
</ClCompile>
|
||||
@ -3046,4 +3049,4 @@
|
||||
<Filter>Tests\Utils</Filter>
|
||||
</CustomBuild>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -233,6 +233,7 @@ gui/dialogs/simple_item_selector.cpp
|
||||
gui/dialogs/sp_options_configure.cpp
|
||||
gui/dialogs/statistics_dialog.cpp
|
||||
gui/dialogs/story_viewer.cpp
|
||||
gui/dialogs/surrender_quit.cpp
|
||||
gui/dialogs/terrain_layers.cpp
|
||||
gui/dialogs/theme_list.cpp
|
||||
gui/dialogs/title_screen.cpp
|
||||
|
43
src/gui/dialogs/surrender_quit.cpp
Normal file
43
src/gui/dialogs/surrender_quit.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
Copyright (C) 2017 - 2018 by Amir Hassan <amir@viel-zu.org>
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "gui/dialogs/surrender_quit.hpp"
|
||||
#include "../widgets/settings.hpp"
|
||||
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
namespace dialogs
|
||||
{
|
||||
|
||||
/*WIKI
|
||||
* @page = GUIWindowDefinitionWML
|
||||
* @order = 2_surrender_quit
|
||||
*
|
||||
* == Surrender and/or quit a game ==
|
||||
*
|
||||
* This shows the dialog to confirm surrender and/or quitting the game
|
||||
*
|
||||
*/
|
||||
|
||||
REGISTER_DIALOG(surrender_quit)
|
||||
|
||||
|
||||
surrender_quit::surrender_quit()
|
||||
{
|
||||
set_restore(true);
|
||||
}
|
||||
|
||||
} // namespace dialogs
|
||||
} // namespace gui2
|
37
src/gui/dialogs/surrender_quit.hpp
Normal file
37
src/gui/dialogs/surrender_quit.hpp
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
Copyright (C) 2017 - 2018 by Amir Hassan <amir@viel-zu.org>
|
||||
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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gui/dialogs/modal_dialog.hpp"
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
namespace dialogs
|
||||
{
|
||||
|
||||
class surrender_quit : public modal_dialog
|
||||
{
|
||||
public:
|
||||
surrender_quit();
|
||||
|
||||
/** The execute function. See @ref modal_dialog for more information. */
|
||||
DEFINE_SIMPLE_EXECUTE_WRAPPER(surrender_quit)
|
||||
|
||||
private:
|
||||
/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
|
||||
virtual const std::string& window_id() const override;
|
||||
};
|
||||
} // namespace dialogs
|
||||
} // namespace gui2
|
@ -116,6 +116,7 @@ public:
|
||||
virtual void zoom_out() {}
|
||||
virtual void zoom_default() {}
|
||||
virtual void map_screenshot() {}
|
||||
virtual void surrender_quit_game() {}
|
||||
|
||||
virtual void set_button_state() {}
|
||||
virtual void recalculate_minimap() {}
|
||||
|
@ -425,6 +425,12 @@ void playmp_controller::maybe_linger()
|
||||
}
|
||||
}
|
||||
|
||||
void playmp_controller::surrender(int side_number) {
|
||||
undo_stack().clear();
|
||||
resources::recorder->add_surrender(side_number);
|
||||
turn_data_.send_data();
|
||||
}
|
||||
|
||||
void playmp_controller::pull_remote_choice()
|
||||
{
|
||||
// when using a remote user choice undoing must be impossible because that network traffic cannot be undone
|
||||
|
@ -33,6 +33,7 @@ public:
|
||||
|
||||
void pull_remote_choice() override;
|
||||
void send_user_choice() override;
|
||||
void surrender(int side_number);
|
||||
|
||||
class hotkey_handler;
|
||||
|
||||
|
@ -16,6 +16,9 @@
|
||||
#include "game_end_exceptions.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "video.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "playmp_controller.hpp"
|
||||
#include "gui/dialogs/surrender_quit.hpp"
|
||||
#include "gui/dialogs/message.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
|
||||
@ -59,5 +62,26 @@ bool quit_confirmation::show_prompt(const std::string& message)
|
||||
|
||||
bool quit_confirmation::default_prompt()
|
||||
{
|
||||
return show_prompt(_("Do you really want to quit?"));
|
||||
playmp_controller* pmc = dynamic_cast<playmp_controller*>(resources::controller);
|
||||
|
||||
if(!(pmc == nullptr || pmc->is_linger_mode() || pmc->is_observer())) {
|
||||
gui2::dialogs::surrender_quit sq;
|
||||
sq.show();
|
||||
int retval = sq.get_retval();
|
||||
if(retval == 1)
|
||||
{
|
||||
pmc->surrender(display::get_singleton()->viewing_team());
|
||||
return true;
|
||||
}
|
||||
else if(retval == 2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return show_prompt(_("Do you really want to quit?"));
|
||||
}
|
||||
}
|
||||
|
@ -226,6 +226,12 @@ void replay::add_start()
|
||||
cmd.add_child("start");
|
||||
}
|
||||
|
||||
void replay::add_surrender(int side_number)
|
||||
{
|
||||
config& cmd = add_nonundoable_command();
|
||||
cmd.add_child("surrender")["side_number"] = side_number;
|
||||
}
|
||||
|
||||
void replay::add_countdown_update(int value, int team)
|
||||
{
|
||||
config& cmd = add_command();
|
||||
@ -732,6 +738,10 @@ REPLAY_RETURN do_replay_handle(bool one_move)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (cfg->child("surrender"))
|
||||
{
|
||||
//prevent sending of a synced command for surrender
|
||||
}
|
||||
else if (const config &label_config = cfg->child("label"))
|
||||
{
|
||||
terrain_label label(game_display::get_singleton()->labels(), label_config);
|
||||
|
@ -52,6 +52,7 @@ public:
|
||||
|
||||
|
||||
void add_start();
|
||||
void add_surrender(int side_number);
|
||||
void add_countdown_update(int value,int team);
|
||||
|
||||
void add_synced_command(const std::string& name, const config& command);
|
||||
|
@ -978,6 +978,19 @@ bool game::is_legal_command(const simple_wml::node& command, const socket_ptr& u
|
||||
if(command.child("speak")) {
|
||||
return true;
|
||||
}
|
||||
if(command.child("surrender")) {
|
||||
const simple_wml::string_span& sn = command.child("surrender")->attr("side_number");
|
||||
if(sn.is_null()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t side_number = sn.to_int();
|
||||
if(side_number >= sides_.size() || sides_[side_number] != user) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// AKA it's generated by get_user_input for example [global_variable]
|
||||
if(is_player && command.has_attr("dependent") && command.has_attr("from_side")) {
|
||||
@ -1057,6 +1070,8 @@ bool game::process_turn(simple_wml::document& data, const socket_ptr& user)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (command->child("surrender")) {
|
||||
send_and_record_server_message(username(user) + " has surrendered.");
|
||||
} else if(is_current_player(user) && (*command).child("end_turn")) {
|
||||
turn_ended = end_turn();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user