#include "settingstab.h" #include "ui_settingstab.h" #include #include static std::vector toChampionNameList(const std::vector& scs) { std::vector out; out.reserve(scs.size()); std::transform(scs.begin(), scs.end(), std::insert_iterator(out, out.begin()), [](const StageSettings::SelectedChamp& sc) { return sc.name; }); return out; } SettingsTab::SettingsTab(QWidget *parent) : QWidget(parent), ui(new Ui::SettingsTab) { ui->setupUi(this); } SettingsTab::~SettingsTab() { delete ui; } void SettingsTab::setup(Config::PositionConfig& conf, DataDragon* dd) { this->conf = &conf; this->dd = dd; ui->banstage->setDataDragon(dd); ui->pickstage->setDataDragon(dd); // load config ui->banstage->loadConfig(conf.ban); ui->pickstage->loadConfig(conf.pick); } std::vector SettingsTab::getChamps(LolAutoAccept::State s) const { return getStage(s)->getChampions(); } bool SettingsTab::getState(LolAutoAccept::State s) const { auto stage = getStage(s); return stage->getState(); } void SettingsTab::setChamps(LolAutoAccept::State s, const std::vector& c) { getStage(s)->setChampions(c); } void SettingsTab::setState(LolAutoAccept::State s, bool b) { auto stage = getStage(s); return stage->setState(b); } Position SettingsTab::getPosition() const { return position; } void SettingsTab::banToggled(bool b) { conf->ban.enabled = b; emit toggled(position, LolAutoAccept::State::BAN, b); } void SettingsTab::banChampsChanged() { conf->ban.champs = toChampionNameList(ui->banstage->getChampions()); emit changed(position, LolAutoAccept::State::BAN); } void SettingsTab::pickToggled(bool b) { conf->pick.enabled = b; emit toggled(position, LolAutoAccept::State::PICK, b); } void SettingsTab::pickChampsChanged() { auto champs = ui->pickstage->getChampions(); auto champnames = toChampionNameList(champs); conf->pick.champs.swap(champnames); emit changed(position, LolAutoAccept::State::BAN); } StageSettings* SettingsTab::getStage(LolAutoAccept::State s) const { switch(s) { case LolAutoAccept::State::BAN: return ui->banstage; case LolAutoAccept::State::PICK: return ui->pickstage; default: break; } assert(false); // "invalid" stage (Lobby or Game) return nullptr; }