The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
mp_report.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2008 - 2025
3 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY.
11
12 See the COPYING file for more details.
13*/
14
15#define GETTEXT_DOMAIN "wesnoth-lib"
16
17#include <functional>
18
20
21#include "gettext.hpp"
26
27namespace gui2::dialogs
28{
29
30REGISTER_DIALOG(mp_report)
31
32// static t_string std::array causes a core dump on start
33const std::array<std::string, 3> mp_report::occurrence_locations = {"Lobby", "Whisper", "Game"};
34
35mp_report::mp_report(std::string& report_text)
36 : modal_dialog(window_id())
37 , report_text_(report_text)
38 , reportee_empty_(true)
39 , report_reason_empty_(true)
40{
41}
42
44{
45 std::vector<config> occurrence_location_entries;
46 occurrence_location_entries.emplace_back("label", _("Lobby"));
47 occurrence_location_entries.emplace_back("label", _("Whisper"));
48 occurrence_location_entries.emplace_back("label", _("Game"));
49
50 find_widget<menu_button>("occurrence_location").set_values(occurrence_location_entries);
51
52 button& ok = find_widget<button>("ok");
53 ok.set_active(false);
54
55 text_box& reportee = find_widget<text_box>("reportee");
56 reportee.on_modified([this](const auto& box) { reportee_changed(box.text()); });
57
58 text_box& report_reason = find_widget<text_box>("report_reason");
59 report_reason.on_modified([this](const auto& box) { report_reason_changed(box.text()); });
60
62}
63
65{
67 {
68 const text_box& reportee = find_widget<const text_box>("reportee");
69 const text_box& report_reason = find_widget<const text_box>("report_reason");
70 const menu_button& occurrence_location = find_widget<const menu_button>("occurrence_location");
71 const std::string additional_information = find_widget<const text_box>("additional_information").get_value();
72
73 std::ostringstream report;
74 report << "Reporting player '" << reportee.get_value() << "' for reason '" << report_reason.get_value() << "'."
75 << " Location of occurrence is '" << occurrence_locations[occurrence_location.get_value()] << "'.";
76 if(additional_information.size() > 0)
77 {
78 report << " Additional information provided: '" << additional_information << "'.";
79 }
80 report_text_ = report.str();
81 }
82}
83
84void mp_report::reportee_changed(const std::string& text)
85{
86 reportee_empty_ = text.empty();
87
88 button& ok = find_widget<button>("ok");
90}
91
92void mp_report::report_reason_changed(const std::string& text)
93{
94 report_reason_empty_ = text.empty();
95
96 button& ok = find_widget<button>("ok");
98}
99
100} // namespace dialogs
Simple push button.
Definition button.hpp:36
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition button.cpp:64
Abstract base class for all modal dialogs.
mp_report(std::string &report_text_)
Definition mp_report.cpp:35
static const std::array< std::string, 3 > occurrence_locations
Definition mp_report.hpp:42
virtual void post_show() override
Actions to be taken after the window has been shown.
Definition mp_report.cpp:64
void report_reason_changed(const std::string &text)
Definition mp_report.cpp:92
std::string & report_text_
Definition mp_report.hpp:39
virtual void pre_show() override
Actions to be taken before showing the window.
Definition mp_report.cpp:43
void reportee_changed(const std::string &text)
Definition mp_report.cpp:84
virtual unsigned get_value() const override
Inherited from selectable_item.
void on_modified(const Func &f)
Registers a NOTIFY_MODIFIED handler.
std::string get_value() const
A widget that allows the user to input text in single line.
Definition text_box.hpp:125
void set_exit_hook(exit_hook mode, const Func &hook)
Sets the window's exit hook.
Definition window.hpp:435
int get_retval()
Definition window.hpp:394
static std::string _(const char *str)
Definition gettext.hpp:100
This file contains the window object, this object is a top level container which has the event manage...
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
@ OK
Dialog was closed with the OK button.
Definition retval.hpp:35