|
| 1 | +/* Command Row |
| 2 | + * |
| 3 | + * From: https://github.com/PokemonAutomation/ |
| 4 | + * |
| 5 | + */ |
| 6 | + |
| 7 | +#include <QHBoxLayout> |
| 8 | +#include "Common/Qt/Options/ConfigWidget.h" |
| 9 | +#include "CommonFramework/GlobalSettingsPanel.h" |
| 10 | +#include "CommonFramework/Options/Environment/ThemeSelectorOption.h" |
| 11 | +#include "CommonFramework/Recording/StreamHistoryOption.h" |
| 12 | +#include "ML_ImageDisplayCommandRow.h" |
| 13 | + |
| 14 | +//#include <iostream> |
| 15 | +//using std::cout; |
| 16 | +//using std::endl; |
| 17 | + |
| 18 | +namespace PokemonAutomation{ |
| 19 | +namespace ML{ |
| 20 | + |
| 21 | + |
| 22 | +ImageDisplayCommandRow::~ImageDisplayCommandRow(){ |
| 23 | + m_session.remove_listener(*this); |
| 24 | +} |
| 25 | +ImageDisplayCommandRow::ImageDisplayCommandRow( |
| 26 | + QWidget& parent, |
| 27 | + VideoOverlaySession& session |
| 28 | +) |
| 29 | + : QWidget(&parent) |
| 30 | + , m_session(session) |
| 31 | + , m_last_known_focus(false) |
| 32 | + , m_last_known_state(ProgramState::STOPPED) |
| 33 | +{ |
| 34 | + QHBoxLayout* command_row = new QHBoxLayout(this); |
| 35 | + command_row->setContentsMargins(0, 0, 0, 0); |
| 36 | + |
| 37 | + command_row->addWidget(new QLabel("<b>Console Type:</b>", this), 2); |
| 38 | + command_row->addSpacing(5); |
| 39 | + |
| 40 | + QHBoxLayout* row = new QHBoxLayout(); |
| 41 | + command_row->addLayout(row, 12); |
| 42 | + |
| 43 | + |
| 44 | +#if 0 |
| 45 | + row->addWidget(new QLabel("<b>Keyboard Input:</b>", this), 2); |
| 46 | + row->addSpacing(5); |
| 47 | +#endif |
| 48 | + |
| 49 | + row->addStretch(100); |
| 50 | + |
| 51 | + m_status = new QLabel(this); |
| 52 | +// m_status->setVisible(false); |
| 53 | + row->addWidget(m_status); |
| 54 | + row->addSpacing(5); |
| 55 | + |
| 56 | +// row->addWidget(new QLabel("<b>Overlays:<b>", this)); |
| 57 | + |
| 58 | + m_overlay_boxes = new QCheckBox("Boxes", this); |
| 59 | + m_overlay_boxes->setChecked(session.enabled_boxes()); |
| 60 | + row->addWidget(m_overlay_boxes); |
| 61 | + |
| 62 | + m_overlay_text = new QCheckBox("Text", this); |
| 63 | + m_overlay_text->setHidden(true); // Nothing uses text overlay yet. |
| 64 | + m_overlay_text->setChecked(session.enabled_text()); |
| 65 | + row->addWidget(m_overlay_text); |
| 66 | + |
| 67 | + if (PreloadSettings::instance().DEVELOPER_MODE){ |
| 68 | + m_overlay_images = new QCheckBox("Masks", this); |
| 69 | + m_overlay_images->setChecked(session.enabled_images()); |
| 70 | + row->addWidget(m_overlay_images); |
| 71 | + } |
| 72 | + |
| 73 | + m_overlay_log = new QCheckBox("Log", this); |
| 74 | + m_overlay_log->setChecked(session.enabled_log()); |
| 75 | + row->addWidget(m_overlay_log); |
| 76 | + |
| 77 | + m_overlay_stats = new QCheckBox("Stats", this); |
| 78 | + m_overlay_stats->setChecked(session.enabled_stats()); |
| 79 | + row->addWidget(m_overlay_stats); |
| 80 | + |
| 81 | + row->addSpacing(5); |
| 82 | + |
| 83 | + m_load_profile_button = new QPushButton("Load Profile", this); |
| 84 | + row->addWidget(m_load_profile_button, 2); |
| 85 | + |
| 86 | + m_save_profile_button = new QPushButton("Save Profile", this); |
| 87 | + row->addWidget(m_save_profile_button, 2); |
| 88 | + |
| 89 | + m_screenshot_button = new QPushButton("Screenshot", this); |
| 90 | +// m_screenshot_button->setToolTip("Take a screenshot of the console and save to disk."); |
| 91 | + row->addWidget(m_screenshot_button, 2); |
| 92 | + |
| 93 | + |
| 94 | +// m_test_button = new QPushButton("Test Button", this); |
| 95 | +// row->addWidget(m_test_button, 3); |
| 96 | + |
| 97 | + update_ui(); |
| 98 | + |
| 99 | + connect( |
| 100 | + m_overlay_boxes, &QCheckBox::clicked, |
| 101 | + this, [this](bool checked){ m_session.set_enabled_boxes(checked); } |
| 102 | + ); |
| 103 | +#if QT_VERSION < 0x060700 |
| 104 | + connect( |
| 105 | + m_overlay_text, &QCheckBox::stateChanged, |
| 106 | + this, [this](bool checked){ m_session.set_enabled_text(checked); } |
| 107 | + ); |
| 108 | + connect( |
| 109 | + m_overlay_images, &QCheckBox::stateChanged, |
| 110 | + this, [this](bool checked){ m_session.set_enabled_images(checked); } |
| 111 | + ); |
| 112 | + connect( |
| 113 | + m_overlay_log, &QCheckBox::stateChanged, |
| 114 | + this, [this](bool checked){ m_session.set_enabled_log(checked); } |
| 115 | + ); |
| 116 | + connect( |
| 117 | + m_overlay_stats, &QCheckBox::stateChanged, |
| 118 | + this, [this](bool checked){ m_session.set_enabled_stats(checked); } |
| 119 | + ); |
| 120 | +#else |
| 121 | + connect( |
| 122 | + m_overlay_text, &QCheckBox::checkStateChanged, |
| 123 | + this, [this](Qt::CheckState state){ m_session.set_enabled_text(state == Qt::Checked); } |
| 124 | + ); |
| 125 | + if (PreloadSettings::instance().DEVELOPER_MODE){ |
| 126 | + connect( |
| 127 | + m_overlay_images, &QCheckBox::checkStateChanged, |
| 128 | + this, [this](Qt::CheckState state){ m_session.set_enabled_images(state == Qt::Checked); } |
| 129 | + ); |
| 130 | + } |
| 131 | + connect( |
| 132 | + m_overlay_log, &QCheckBox::checkStateChanged, |
| 133 | + this, [this](Qt::CheckState state){ m_session.set_enabled_log(state == Qt::Checked); } |
| 134 | + ); |
| 135 | + connect( |
| 136 | + m_overlay_stats, &QCheckBox::checkStateChanged, |
| 137 | + this, [this](Qt::CheckState state){ m_session.set_enabled_stats(state == Qt::Checked); } |
| 138 | + ); |
| 139 | +#endif |
| 140 | + connect( |
| 141 | + m_load_profile_button, &QPushButton::clicked, |
| 142 | + this, [this](bool) { emit load_profile(); } |
| 143 | + ); |
| 144 | + connect( |
| 145 | + m_save_profile_button, &QPushButton::clicked, |
| 146 | + this, [this](bool) { emit save_profile(); } |
| 147 | + ); |
| 148 | + connect( |
| 149 | + m_screenshot_button, &QPushButton::clicked, |
| 150 | + this, [this](bool){ emit screenshot_requested(); } |
| 151 | + ); |
| 152 | + |
| 153 | +#if (QT_VERSION_MAJOR == 6) && (QT_VERSION_MINOR >= 8) |
| 154 | + if (IS_BETA_VERSION || PreloadSettings::instance().DEVELOPER_MODE){ |
| 155 | + m_video_button = new QPushButton("Video Capture", this); |
| 156 | + command_row->addWidget(m_video_button, 2); |
| 157 | + if (GlobalSettings::instance().STREAM_HISTORY->enabled()){ |
| 158 | + connect( |
| 159 | + m_video_button, &QPushButton::clicked, |
| 160 | + this, [this](bool){ emit video_requested(); } |
| 161 | + ); |
| 162 | + }else{ |
| 163 | + m_video_button->setEnabled(false); |
| 164 | + m_video_button->setToolTip("Please turn on Stream History to enable video capture."); |
| 165 | + } |
| 166 | + } |
| 167 | +#endif |
| 168 | + |
| 169 | + m_session.add_listener(*this); |
| 170 | +} |
| 171 | + |
| 172 | +void ImageDisplayCommandRow::on_key_press(const QKeyEvent& key){ |
| 173 | + if (!m_last_known_focus){ |
| 174 | + m_session.add_log("Keyboard Command Suppressed: Not in focus.", COLOR_RED); |
| 175 | + return; |
| 176 | + } |
| 177 | +} |
| 178 | +void ImageDisplayCommandRow::on_key_release(const QKeyEvent& key){} |
| 179 | + |
| 180 | +void ImageDisplayCommandRow::set_focus(bool focused){ |
| 181 | + if (m_last_known_focus == focused){ |
| 182 | + return; |
| 183 | + } |
| 184 | + m_last_known_focus = focused; |
| 185 | + update_ui(); |
| 186 | +} |
| 187 | + |
| 188 | +void ImageDisplayCommandRow::update_ui(){ |
| 189 | +// cout << "ImageDisplayCommandRow::update_ui(): focus = " << m_last_known_focus << endl; |
| 190 | + |
| 191 | + bool stopped = m_last_known_state == ProgramState::STOPPED; |
| 192 | + m_load_profile_button->setEnabled(stopped); |
| 193 | + |
| 194 | + if (!m_last_known_focus){ |
| 195 | + m_status->setText( |
| 196 | + QString::fromStdString( |
| 197 | + "Keyboard: " + html_color_text("⬤", COLOR_PURPLE) |
| 198 | + ) |
| 199 | + ); |
| 200 | + return; |
| 201 | + } |
| 202 | + |
| 203 | + m_status->setText( |
| 204 | + QString::fromStdString( |
| 205 | + "Keyboard: " + html_color_text("⬤", COLOR_DARKGREEN) |
| 206 | + ) |
| 207 | + ); |
| 208 | +} |
| 209 | + |
| 210 | +void ImageDisplayCommandRow::on_state_changed(ProgramState state){ |
| 211 | + m_last_known_state = state; |
| 212 | + update_ui(); |
| 213 | +} |
| 214 | + |
| 215 | + |
| 216 | +void ImageDisplayCommandRow::on_overlay_enabled_boxes(bool enabled){ |
| 217 | + QMetaObject::invokeMethod(this, [this, enabled]{ |
| 218 | + this->m_overlay_boxes->setChecked(enabled); |
| 219 | + }, Qt::QueuedConnection); |
| 220 | +} |
| 221 | +void ImageDisplayCommandRow::on_overlay_enabled_text(bool enabled){ |
| 222 | + QMetaObject::invokeMethod(this, [this, enabled]{ |
| 223 | + this->m_overlay_text->setChecked(enabled); |
| 224 | + }, Qt::QueuedConnection); |
| 225 | +} |
| 226 | +void ImageDisplayCommandRow::on_overlay_enabled_images(bool enabled){ |
| 227 | + QMetaObject::invokeMethod(this, [this, enabled]{ |
| 228 | + this->m_overlay_images->setChecked(enabled); |
| 229 | + }, Qt::QueuedConnection); |
| 230 | +} |
| 231 | +void ImageDisplayCommandRow::on_overlay_enabled_log(bool enabled){ |
| 232 | + QMetaObject::invokeMethod(this, [this, enabled]{ |
| 233 | + this->m_overlay_log->setChecked(enabled); |
| 234 | + }, Qt::QueuedConnection); |
| 235 | +} |
| 236 | +void ImageDisplayCommandRow::on_overlay_enabled_stats(bool enabled){ |
| 237 | + QMetaObject::invokeMethod(this, [this, enabled]{ |
| 238 | + this->m_overlay_stats->setChecked(enabled); |
| 239 | + }, Qt::QueuedConnection); |
| 240 | +} |
| 241 | +void ImageDisplayCommandRow::ready_changed(bool ready){ |
| 242 | +// cout << "ImageDisplayCommandRow::ready_changed(): " << ready << endl; |
| 243 | + QMetaObject::invokeMethod(this, [this]{ |
| 244 | + update_ui(); |
| 245 | + }, Qt::QueuedConnection); |
| 246 | +} |
| 247 | + |
| 248 | + |
| 249 | + |
| 250 | + |
| 251 | +} |
| 252 | +} |
| 253 | + |
| 254 | + |
| 255 | + |
| 256 | + |
| 257 | + |
| 258 | + |
| 259 | + |
| 260 | + |
| 261 | + |
| 262 | + |
| 263 | + |
| 264 | + |
0 commit comments