mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-27 09:28:15 +00:00
rebase commit: implemented a surrender dialog that records a surrender command in replays and quits the game
This commit is contained in:
parent
efa91bd9e8
commit
4dda0ad9b2
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]
|
@ -657,6 +657,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" />
|
||||
|
@ -1944,6 +1944,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>
|
||||
@ -4088,4 +4095,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>
|
||||
@ -3022,4 +3025,4 @@
|
||||
<Filter>Tests\Utils</Filter>
|
||||
</CustomBuild>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -243,6 +243,7 @@ gui/dialogs/unit_recall.cpp
|
||||
gui/dialogs/unit_recruit.cpp
|
||||
gui/dialogs/wml_error.cpp
|
||||
gui/dialogs/wml_message.cpp
|
||||
gui/dialogs/surrender_quit.cpp
|
||||
gui/widgets/addon_list.cpp
|
||||
gui/widgets/button.cpp
|
||||
gui/widgets/chatbox.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) 2008 - 2017 by Jörg Hinrichs <joerg.hinrichs@alice-dsl.de>
|
||||
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) 2008 - 2017 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() {}
|
||||
|
@ -71,7 +71,7 @@ bool playmp_controller::hotkey_handler::can_execute_command(const hotkey::hotkey
|
||||
case hotkey::HOTKEY_STOP_NETWORK:
|
||||
res = is_observer();
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
return playsingle_controller::hotkey_handler::can_execute_command(cmd, index);
|
||||
}
|
||||
return res;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -597,15 +597,12 @@ void playsingle_controller::play_network_turn()
|
||||
ERR_NG << "Networked team encountered by playsingle_controller." << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void playsingle_controller::handle_generic_event(const std::string& name){
|
||||
if (name == "ai_user_interact"){
|
||||
play_slice(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void playsingle_controller::end_turn(){
|
||||
if (linger_)
|
||||
end_turn_ = END_TURN_REQUIRED;
|
||||
|
@ -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(resources::screen->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(resources::screen->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);
|
||||
|
@ -867,6 +867,19 @@ bool game::is_legal_command(const simple_wml::node& command, const socket_ptr us
|
||||
if (!command.one_child()) return false;
|
||||
// Chatting is never an illegal command.
|
||||
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;
|
||||
|
||||
int side_number = sn.to_int();
|
||||
if(side_number < 0 || static_cast<size_t>(side_number) >= sides_.size() || sides_[side_number] != user) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_player && command.has_attr("dependent") && command.has_attr("from_side"))
|
||||
//AKA it's generated by get_user_input for example [global_variable]
|
||||
{
|
||||
@ -940,6 +953,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