File indexing completed on 2024-04-28 05:38:04
0001 /*************************************************************************** 0002 * Copyright (C) 2015 by Renaud Guezennec * 0003 * https://rolisteam.org/contact * 0004 * * 0005 * rolisteam is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 0021 #include "rwidgets/docks/vmaptoolbar.h" 0022 #include "controller/view_controller/vectorialmapcontroller.h" 0023 0024 #include "common_widgets/colorbutton.h" 0025 #include <QAction> 0026 #include <QActionGroup> 0027 #include <QLabel> 0028 #include <QToolButton> 0029 0030 VmapTopBar::VmapTopBar(VectorialMapController* ctrl, QWidget* parent) : QToolBar(parent), m_ctrl(ctrl) 0031 { 0032 setObjectName("VmapTopBar"); 0033 setWindowTitle(tr("TopBar for VMap")); 0034 initActions(); 0035 setupUi(); 0036 0037 connect(m_ctrl, &VectorialMapController::localGMChanged, this, 0038 [this](bool b) 0039 { 0040 setEnabled(b); 0041 setVisible(b); 0042 }); 0043 0044 if(m_ctrl) 0045 { 0046 setEnabled(m_ctrl->localGM()); 0047 setVisible(m_ctrl->localGM()); 0048 } 0049 } 0050 0051 VmapTopBar::~VmapTopBar() 0052 { 0053 qDebug() << "Destructor topbar;"; 0054 } 0055 0056 void VmapTopBar::initActions() 0057 { 0058 if(!m_ctrl) 0059 return; 0060 0061 m_showSquareAct= new QAction(QIcon::fromTheme("grid"), tr("Square Grid"), this); 0062 m_showSquareAct->setObjectName("grid_square"); 0063 m_showSquareAct->setCheckable(true); 0064 0065 m_showHexagonAct= new QAction(QIcon::fromTheme("hexa_grid"), tr("Hexagonal Grid"), this); 0066 m_showSquareAct->setObjectName("grid_hexa"); 0067 m_showHexagonAct->setCheckable(true); 0068 0069 auto group= new QActionGroup(this); 0070 group->setExclusionPolicy(QActionGroup::ExclusionPolicy::ExclusiveOptional); 0071 group->addAction(m_showSquareAct); 0072 group->addAction(m_showHexagonAct); 0073 0074 connect(group, &QActionGroup::triggered, this, 0075 [this](QAction* action) 0076 { 0077 m_ctrl->setGridVisibility(action->isChecked()); 0078 if(action == m_showSquareAct) 0079 m_ctrl->setGridPattern(Core::GridPattern::SQUARE); 0080 else 0081 m_ctrl->setGridPattern(Core::GridPattern::HEXAGON); 0082 }); 0083 0084 m_gridAboveAct= new QAction(QIcon::fromTheme("grid_above"), tr("Grid Above"), this); 0085 m_gridAboveAct->setObjectName("grid_above"); 0086 m_gridAboveAct->setCheckable(true); 0087 0088 connect(m_gridAboveAct, &QAction::triggered, m_ctrl, &VectorialMapController::setGridAbove); 0089 0090 m_onlyGmPermAct= new QAction(QIcon::fromTheme("red_round"), tr("Permission: GM only"), this); 0091 m_onlyGmPermAct->setObjectName("permission_gm"); 0092 m_onlyGmPermAct->setData(QVariant::fromValue(Core::PermissionMode::GM_ONLY)); 0093 m_onlyGmPermAct->setCheckable(true); 0094 //addAction(m_onlyGmPermAct); 0095 0096 m_characterOnlyPermAct= new QAction(QIcon::fromTheme("orange_round"), tr("Permission: PC Move"), this); 0097 m_characterOnlyPermAct->setObjectName("permission_pc"); 0098 m_characterOnlyPermAct->setData(QVariant::fromValue(Core::PermissionMode::PC_MOVE)); 0099 m_characterOnlyPermAct->setCheckable(true); 0100 //addAction(m_characterOnlyPermAct); 0101 0102 m_allPermAct= new QAction(QIcon::fromTheme("green_round"), tr("Permission: All"), this); 0103 m_allPermAct->setObjectName("permission_all"); 0104 m_allPermAct->setData(QVariant::fromValue(Core::PermissionMode::PC_ALL)); 0105 m_allPermAct->setCheckable(true); 0106 //addAction(m_allPermAct); 0107 0108 group= new QActionGroup(this); 0109 group->setExclusionPolicy(QActionGroup::ExclusionPolicy::Exclusive); 0110 group->addAction(m_onlyGmPermAct); 0111 group->addAction(m_characterOnlyPermAct); 0112 group->addAction(m_allPermAct); 0113 0114 connect(group, &QActionGroup::triggered, this, 0115 [this](QAction* action) { m_ctrl->setPermission(action->data().value<Core::PermissionMode>()); }); 0116 0117 auto updatePerm= [this](Core::PermissionMode perm) 0118 { 0119 m_onlyGmPermAct->setChecked(perm == Core::PermissionMode::GM_ONLY); 0120 m_characterOnlyPermAct->setChecked(perm == Core::PermissionMode::PC_MOVE); 0121 m_allPermAct->setChecked(perm == Core::PermissionMode::PC_ALL); 0122 }; 0123 connect(m_ctrl, &VectorialMapController::permissionChanged, this, updatePerm); 0124 updatePerm(m_ctrl->permission()); 0125 0126 m_hiddenAct= new QAction(QIcon::fromTheme("mask"), tr("Visibility: Hidden"), this); 0127 m_hiddenAct->setObjectName("Visibility_hidden"); 0128 m_hiddenAct->setData(QVariant::fromValue(Core::VisibilityMode::HIDDEN)); 0129 m_hiddenAct->setCheckable(true); 0130 //addAction(m_hiddenAct); 0131 0132 m_fogAct= new QAction(QIcon::fromTheme("fogofwar"), tr("Visibility: Fog"), this); 0133 m_fogAct->setObjectName("Visibility_fow"); 0134 m_fogAct->setData(QVariant::fromValue(Core::VisibilityMode::FOGOFWAR)); 0135 m_fogAct->setCheckable(true); 0136 //addAction(m_fogAct); 0137 0138 m_allAct= new QAction(QIcon::fromTheme("eye"), tr("Visibility: All"), this); 0139 m_allAct->setObjectName("Visibility_all"); 0140 m_allAct->setData(QVariant::fromValue(Core::VisibilityMode::ALL)); 0141 m_allAct->setCheckable(true); 0142 //addAction(m_allAct); 0143 0144 group= new QActionGroup(this); 0145 group->setExclusionPolicy(QActionGroup::ExclusionPolicy::Exclusive); 0146 group->addAction(m_hiddenAct); 0147 group->addAction(m_fogAct); 0148 group->addAction(m_allAct); 0149 0150 connect(group, &QActionGroup::triggered, this, 0151 [this](QAction* action) { m_ctrl->setVisibility(action->data().value<Core::VisibilityMode>()); }); 0152 0153 auto updateVisiblility= [this](Core::VisibilityMode perm) 0154 { 0155 m_hiddenAct->setChecked(perm == Core::VisibilityMode::HIDDEN); 0156 m_fogAct->setChecked(perm == Core::VisibilityMode::FOGOFWAR); 0157 m_allAct->setChecked(perm == Core::VisibilityMode::ALL); 0158 }; 0159 updateVisiblility(m_ctrl->visibility()); 0160 connect(m_ctrl, &VectorialMapController::visibilityChanged, this, updateVisiblility); 0161 0162 m_groundAct= new QAction(QIcon::fromTheme("ground_layer"), tr("Current Layer: Ground"), this); 0163 m_groundAct->setObjectName("layer_ground"); 0164 //addAction(m_groundAct); 0165 m_groundAct->setData(QVariant::fromValue(Core::Layer::GROUND)); 0166 m_groundAct->setCheckable(true); 0167 0168 m_objectAct= new QAction(QIcon::fromTheme("object_layer"), tr("Current Layer: Object"), this); 0169 m_objectAct->setObjectName("layer_object"); 0170 //addAction(m_objectAct); 0171 m_objectAct->setData(QVariant::fromValue(Core::Layer::OBJECT)); 0172 m_objectAct->setCheckable(true); 0173 0174 m_characterAct= new QAction(QIcon::fromTheme("character_layer"), tr("Current Layer: Character"), this); 0175 m_characterAct->setObjectName("layer_character"); 0176 //addAction(m_characterAct); 0177 m_characterAct->setData(QVariant::fromValue(Core::Layer::CHARACTER_LAYER)); 0178 m_characterAct->setCheckable(true); 0179 0180 m_gameMasterAct= new QAction(QIcon::fromTheme("gm_icon"), tr("Current Layer: GameMaster"), this); 0181 m_gameMasterAct->setObjectName("layer_gm"); 0182 //addAction(m_gameMasterAct); 0183 m_gameMasterAct->setData(QVariant::fromValue(Core::Layer::GAMEMASTER_LAYER)); 0184 m_gameMasterAct->setCheckable(true); 0185 0186 group= new QActionGroup(this); 0187 group->setExclusionPolicy(QActionGroup::ExclusionPolicy::Exclusive); 0188 group->addAction(m_groundAct); 0189 group->addAction(m_objectAct); 0190 group->addAction(m_characterAct); 0191 group->addAction(m_gameMasterAct); 0192 0193 connect(group, &QActionGroup::triggered, this, 0194 [this](QAction* action) { m_ctrl->setLayer(action->data().value<Core::Layer>()); }); 0195 0196 auto updateLayer= [this](Core::Layer layer) 0197 { 0198 m_groundAct->setChecked(layer == Core::Layer::GROUND); 0199 m_objectAct->setChecked(layer == Core::Layer::OBJECT); 0200 m_characterAct->setChecked(layer == Core::Layer::CHARACTER_LAYER); 0201 m_gameMasterAct->setChecked(layer == Core::Layer::GAMEMASTER_LAYER); 0202 }; 0203 connect(m_ctrl, &VectorialMapController::layerChanged, this, updateLayer); 0204 updateLayer(m_ctrl->layer()); 0205 0206 m_hideOtherAct= new QAction(QIcon::fromTheme("hideotherlayers"), tr("hide other layers"), this); 0207 m_hideOtherAct->setObjectName("hide_layer"); 0208 //addAction(m_hideOtherAct); 0209 m_hideOtherAct->setCheckable(true); 0210 0211 m_characterVisionAct= new QAction(QIcon::fromTheme("sight"), tr("Character Vision"), this); 0212 m_characterVisionAct->setCheckable(true); 0213 m_characterVisionAct->setObjectName("character_vision"); 0214 //addAction(m_characterVisionAct); 0215 m_showTransparentAct= new QAction(QIcon::fromTheme("sun"), tr("Show Transparent Item"), this); 0216 m_showTransparentAct->setCheckable(true); 0217 m_showTransparentAct->setObjectName("show_transparent"); 0218 //addAction(m_showTransparentAct); 0219 0220 m_showPcName= new QAction(QIcon::fromTheme("pcName"), tr("Show/Hide PC name", "PC = playable character"), this); 0221 m_showPcName->setObjectName("show_pc_name"); 0222 //addAction(m_showPcName); 0223 m_showNpcName 0224 = new QAction(QIcon::fromTheme("npcName"), tr("Show/Hide NPC name", "NPC = non-playable character"), this); 0225 m_showNpcName->setObjectName("show_npc_name"); 0226 //addAction(m_showNpcName); 0227 m_showNpcNumber= new QAction(QIcon::fromTheme("npcNumber"), tr("Show/Hide NPC number"), this); 0228 m_showNpcNumber->setObjectName("show_npc_number"); 0229 //addAction(m_showNpcNumber); 0230 m_showState= new QAction(QIcon::fromTheme("stateName"), tr("Show/Hide State"), this); // 0231 m_showState->setObjectName("show_states"); 0232 //addAction(m_showState); 0233 m_showHealthBar= new QAction(QIcon::fromTheme("healthBar"), tr("Show/Hide Health Bar"), this); 0234 m_showHealthBar->setObjectName("show_health"); 0235 //addAction(m_showHealthBar); 0236 m_showInit= new QAction(QIcon::fromTheme("initScore"), tr("Show/Hide Initiative"), this); 0237 m_showInit->setObjectName("show_initScore"); 0238 //addAction(m_showInit); 0239 0240 m_showPcName->setCheckable(true); 0241 m_showNpcName->setCheckable(true); 0242 m_showNpcNumber->setCheckable(true); 0243 m_showState->setCheckable(true); 0244 m_showHealthBar->setCheckable(true); 0245 m_showInit->setCheckable(true); 0246 0247 connect(m_showPcName, &QAction::triggered, m_ctrl, &VectorialMapController::setPcNameVisible); 0248 connect(m_showNpcName, &QAction::triggered, m_ctrl, &VectorialMapController::setNpcNameVisible); 0249 connect(m_showNpcNumber, &QAction::triggered, m_ctrl, &VectorialMapController::setNpcNumberVisible); 0250 connect(m_showState, &QAction::triggered, m_ctrl, &VectorialMapController::setStateLabelVisible); 0251 connect(m_showHealthBar, &QAction::triggered, m_ctrl, &VectorialMapController::setHealthBarVisible); 0252 connect(m_showInit, &QAction::triggered, m_ctrl, &VectorialMapController::setInitScoreVisible); 0253 connect(m_characterVisionAct, &QAction::triggered, m_ctrl, &VectorialMapController::setCharacterVision); 0254 0255 m_showPcName->setChecked(m_ctrl->pcNameVisible()); 0256 m_showNpcName->setChecked(m_ctrl->npcNameVisible()); 0257 m_showNpcNumber->setChecked(m_ctrl->npcNumberVisible()); 0258 m_showState->setChecked(m_ctrl->stateLabelVisible()); 0259 m_showHealthBar->setChecked(m_ctrl->healthBarVisible()); 0260 m_showInit->setChecked(m_ctrl->initScoreVisible()); 0261 } 0262 0263 void VmapTopBar::setupUi() 0264 { 0265 if(!m_ctrl) 0266 return; 0267 // bg 0268 m_bgSelector= new ColorButton(); 0269 m_bgSelector->setColor(m_ctrl->backgroundColor()); 0270 addWidget(m_bgSelector); 0271 connect(m_bgSelector, &ColorButton::colorChanged, m_ctrl, &VectorialMapController::setBackgroundColor); 0272 addSeparator(); 0273 0274 // grid 0275 auto btn= new QToolButton(); 0276 btn->setDefaultAction(m_showSquareAct); 0277 addWidget(btn); 0278 0279 btn= new QToolButton(); 0280 btn->setDefaultAction(m_showHexagonAct); 0281 addWidget(btn); 0282 0283 btn= new QToolButton(); 0284 btn->setDefaultAction(m_gridAboveAct); 0285 addWidget(btn); 0286 0287 m_gridUnit= new QComboBox(); 0288 QStringList listUnit; 0289 listUnit << QStringLiteral("m") << QStringLiteral("km") << QStringLiteral("cm") << QStringLiteral("mi") 0290 << QStringLiteral("yd") << tr("inch") << tr("foot") << tr("px"); 0291 m_gridUnit->addItems(listUnit); 0292 // connect(m_gridUnit, &QComboBox::currentIndexChanged, m_ctrl, &VectorialMapController::setScaleUnit); 0293 0294 m_gridSize= new QSpinBox(this); 0295 m_gridSize->setRange(1, std::numeric_limits<int>::max()); 0296 connect(m_gridSize, QOverload<int>::of(&QSpinBox::valueChanged), m_ctrl, &VectorialMapController::setGridSize); 0297 m_gridSize->setValue(m_ctrl->gridSize()); 0298 0299 m_scaleSize= new QDoubleSpinBox(this); 0300 m_scaleSize->setRange(0.1, std::numeric_limits<double>::max()); 0301 connect(m_scaleSize, QOverload<qreal>::of(&QDoubleSpinBox::valueChanged), m_ctrl, 0302 &VectorialMapController::setGridScale); 0303 m_scaleSize->setValue(m_ctrl->gridScale()); 0304 0305 addWidget(m_gridSize); 0306 addWidget(new QLabel(tr("px"))); 0307 addWidget(m_scaleSize); 0308 addWidget(m_gridUnit); 0309 0310 addSeparator(); 0311 // permission 0312 btn= new QToolButton(); 0313 btn->setDefaultAction(m_onlyGmPermAct); 0314 addWidget(btn); 0315 0316 btn= new QToolButton(); 0317 btn->setDefaultAction(m_characterOnlyPermAct); 0318 addWidget(btn); 0319 0320 btn= new QToolButton(); 0321 btn->setDefaultAction(m_allPermAct); 0322 addWidget(btn); 0323 0324 addSeparator(); 0325 // visibility 0326 btn= new QToolButton(); 0327 btn->setDefaultAction(m_hiddenAct); 0328 addWidget(btn); 0329 btn= new QToolButton(); 0330 btn->setDefaultAction(m_fogAct); 0331 addWidget(btn); 0332 btn= new QToolButton(); 0333 btn->setDefaultAction(m_allAct); 0334 addWidget(btn); 0335 0336 addSeparator(); 0337 // layer 0338 btn= new QToolButton(); 0339 btn->setDefaultAction(m_groundAct); 0340 addWidget(btn); 0341 btn= new QToolButton(); 0342 btn->setDefaultAction(m_objectAct); 0343 addWidget(btn); 0344 0345 btn= new QToolButton(); 0346 btn->setDefaultAction(m_characterAct); 0347 addWidget(btn); 0348 0349 btn= new QToolButton(); 0350 btn->setDefaultAction(m_gameMasterAct); 0351 addWidget(btn); 0352 0353 btn= new QToolButton(); 0354 btn->setDefaultAction(m_hideOtherAct); 0355 addWidget(btn); 0356 0357 addSeparator(); 0358 // character vision 0359 btn= new QToolButton(); 0360 btn->setDefaultAction(m_characterVisionAct); 0361 addWidget(btn); 0362 0363 btn= new QToolButton(); 0364 btn->setDefaultAction(m_showTransparentAct); 0365 addWidget(btn); 0366 0367 connect(m_hideOtherAct, &QAction::triggered, m_ctrl, &VectorialMapController::hideOtherLayers); 0368 0369 addSeparator(); 0370 0371 btn= new QToolButton(); 0372 btn->setDefaultAction(m_showPcName); 0373 addWidget(btn); 0374 btn= new QToolButton(); 0375 btn->setDefaultAction(m_showNpcName); 0376 addWidget(btn); 0377 btn= new QToolButton(); 0378 btn->setDefaultAction(m_showNpcNumber); 0379 addWidget(btn); 0380 btn= new QToolButton(); 0381 btn->setDefaultAction(m_showState); 0382 addWidget(btn); 0383 btn= new QToolButton(); 0384 btn->setDefaultAction(m_showHealthBar); 0385 addWidget(btn); 0386 btn= new QToolButton(); 0387 btn->setDefaultAction(m_showInit); 0388 addWidget(btn); 0389 } 0390 0391 void VmapTopBar::updateUI() 0392 { 0393 // if(nullptr != m_vmap) 0394 { 0395 setEnabled(true); 0396 // m_bgSelector->setColor(m_vmap->getBackGroundColor()); 0397 /* m_showGridAct->setChecked(m_vmap->getOption(VisualItem::ShowGrid).toBool()); 0398 m_gridSize->setValue(m_vmap->getOption(VisualItem::GridSize).toInt()); 0399 m_currentLayer->setCurrentIndex(static_cast<int>(m_vmap->currentLayer())); 0400 m_showCharacterVision->setChecked(m_vmap->getOption(VisualItem::EnableCharacterVision).toBool()); 0401 m_gridUnit->setCurrentIndex(m_vmap->getOption(VisualItem::Unit).toInt()); 0402 m_currentPermission->setCurrentIndex(m_vmap->getOption(VisualItem::PermissionMode).toInt()); 0403 m_currentVisibility->setCurrentIndex(m_vmap->getOption(VisualItem::VisibilityMode).toInt()); 0404 m_gridPattern->setCurrentIndex(m_vmap->getOption(VisualItem::GridPattern).toInt()); 0405 m_collision->setChecked(m_vmap->getOption(VisualItem::CollisionStatus).toBool()); 0406 m_showOnlyItemsFromThisLayer->setChecked(m_vmap->getOption(VisualItem::HideOtherLayers).toBool()); 0407 m_currentLayer->setCurrentIndex(m_vmap->getOption(VisualItem::MapLayer).toInt()); 0408 m_gridAbove->setChecked(m_vmap->getOption(VisualItem::GridAbove).toBool()); 0409 m_scaleSize->setValue(m_vmap->getOption(VisualItem::Scale).toReal());*/ 0410 } 0411 /* else 0412 { 0413 setEnabled(false); 0414 }*/ 0415 }