adding version selector

adding version selector
This commit is contained in:
Alister
2021-11-27 23:28:33 +00:00
parent c28b9b67fa
commit 138c29cee2
5 changed files with 324 additions and 24 deletions

View File

@@ -0,0 +1,37 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#include <noggit/ui/VersionSelector.h>
#include <noggit/ui/main_window.hpp>
namespace noggit
{
namespace ui
{
versionSelector::versionSelector(main_window* parent) : QDialog(parent)
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
Ui::VersionSelector versionSelector;
versionSelector.setupUi(this);
activateWindow();
connect(versionSelector.select_shadowlands_version, &QPushButton::clicked
, [=]
{
parent->setEnabled(true);
parent->build_menu(true);
hide();
}
);
connect(versionSelector.select_wrath_version, &QPushButton::clicked
, [=]
{
parent->setEnabled(true);
parent->build_menu(false);
hide();
}
);
}
}
}

View File

@@ -0,0 +1,18 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#pragma once
#include <QtWidgets/QDialog>
#include <ui_VersionSelector.h>
namespace noggit
{
namespace ui
{
struct main_window;
class versionSelector : public QDialog
{
public:
versionSelector(main_window* parent = nullptr);
};
}
}

View File

@@ -0,0 +1,202 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>VersionSelector</class>
<widget class="QWidget" name="VersionSelector">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>563</width>
<height>214</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="windowTitle">
<string>Version Selector</string>
</property>
<property name="windowIcon">
<iconset>
<normalon>:/icon</normalon>
</iconset>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="minimumSize">
<size>
<width>0</width>
<height>18</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Noggit Red Version Selector</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<item>
<widget class="QLabel" name="wrath_logo">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap>:/wrath_logo</pixmap>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Patch 3.3.5</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="select_wrath_version">
<property name="text">
<string>Select</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="leftMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<item>
<widget class="QLabel" name="shadowlands_logo">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap>:/shadowlands_logo</pixmap>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Patch 9.1.5</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="select_shadowlands_version">
<property name="text">
<string>Select</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="minimumSize">
<size>
<width>0</width>
<height>18</height>
</size>
</property>
<property name="text">
<string>World of Warcraft is (C) Blizzard Entertainment</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../../../resources/resources.qrc"/>
</resources>
<connections/>
</ui>

View File

@@ -15,7 +15,7 @@
#include <noggit/ui/font_awesome.hpp>
#include <noggit/ui/FramelessWindow.hpp>
#include <noggit/Red/UiCommon/StackedWidget.hpp>
#include <BlizzardDatabase.h>
#include <QtGui/QCloseEvent>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QListWidget>
@@ -158,10 +158,11 @@ namespace noggit
createBookmarkList();
_about = new about(this);
_menuBar = menuBar();
_settings = new settings(this);
setEnabled(false);
_version_selector = new versionSelector(this);
_menuBar = menuBar();
QSettings settings;
@@ -173,6 +174,8 @@ namespace noggit
setMenuWidget(widget);
}
_menuBar->setNativeMenuBar(settings.value("nativeMenubar", true).toBool());
auto file_menu (_menuBar->addMenu ("&Noggit"));
@@ -193,6 +196,14 @@ namespace noggit
}
);
auto version_action(file_menu->addAction("Version"));
QObject::connect(version_action, &QAction::triggered
, [this]
{
_version_selector->show();
}
);
auto mapmenu_action (file_menu->addAction ("Exit"));
QObject::connect ( mapmenu_action, &QAction::triggered
, [this]
@@ -203,8 +214,7 @@ namespace noggit
_menuBar->adjustSize();
build_menu();
_version_selector->show();
}
void main_window::check_uid_then_enter_map
@@ -300,7 +310,7 @@ namespace noggit
LogError << "Map with ID " << mapID << " not found. Failed loading." << std::endl;
}
void main_window::build_menu()
void main_window::build_menu(bool isShadowlands)
{
_stack_widget = new StackedWidget(this);
_stack_widget->setAutoResize(true);
@@ -346,7 +356,7 @@ namespace noggit
layout->addWidget (entry_points_tabs);
build_map_lists();
build_map_lists(isShadowlands);
qulonglong bookmark_index (0);
for (auto entry : mBookmarks)
@@ -408,7 +418,7 @@ namespace noggit
_map_wizard_connection = connect(_map_creation_wizard, &noggit::Red::MapCreationWizard::Ui::MapCreationWizard::map_dbc_updated
,[=]
{
build_map_lists();
build_map_lists(isShadowlands);
}
);
@@ -421,7 +431,7 @@ namespace noggit
_minimap->adjustSize();
}
void noggit::ui::main_window::build_map_lists()
void noggit::ui::main_window::build_map_lists(bool isShadowlands)
{
std::array<QListWidget*, 5> type_to_table
@@ -432,19 +442,50 @@ namespace noggit
table->clear();
}
for (DBCFile::Iterator i = gMapDB.begin(); i != gMapDB.end(); ++i)
{
MapEntry e;
e.mapID = i->getInt(MapDB::MapID);
e.name = i->getLocalizedString(MapDB::Name);
e.areaType = i->getUInt(MapDB::AreaType);
if(isShadowlands)
{
std::string dbcFileDirectory = std::string("./workspace/dbfilesclient");
std::string dbdFileDirectory = std::string("./workspace/definitions");
if (e.areaType < 0 || e.areaType > 4 || !World::IsEditableWorld(e.mapID))
continue;
const auto& build = BlizzardDatabaseLib::Structures::Build("9.1.0.39584");
const auto& table = std::string("map");
auto item (new QListWidgetItem (QString::number(e.mapID) + " - " + QString::fromUtf8 (e.name.c_str()), type_to_table[e.areaType]));
item->setData (Qt::UserRole, QVariant (e.mapID));
}
auto blizzardDatabase = BlizzardDatabaseLib::BlizzardDatabase(dbcFileDirectory, dbdFileDirectory);
auto mapTable = blizzardDatabase.LoadTable(table, build);
auto iterator = mapTable.Records();
while (iterator.HasRecords())
{
auto record = iterator.Next();
MapEntry e;
e.mapID = record.RecordId;
e.name = record.Columns["MapName_lang"].Value;
e.areaType = std::stoi(record.Columns["InstanceType"].Value);
if (e.areaType < 0 || e.areaType > 4)
continue;
auto item(new QListWidgetItem(QString::number(e.mapID) + " - " + QString::fromUtf8(e.name.c_str()), type_to_table[e.areaType]));
item->setData(Qt::UserRole, QVariant(e.mapID));
}
}
else
{
for (DBCFile::Iterator i = gMapDB.begin(); i != gMapDB.end(); ++i)
{
MapEntry e;
e.mapID = i->getInt(MapDB::MapID);
e.name = i->getLocalizedString(MapDB::Name);
e.areaType = i->getUInt(MapDB::AreaType);
if (e.areaType < 0 || e.areaType > 4 || !World::IsEditableWorld(e.mapID))
continue;
auto item(new QListWidgetItem(QString::number(e.mapID) + " - " + QString::fromUtf8(e.name.c_str()), type_to_table[e.areaType]));
item->setData(Qt::UserRole, QVariant(e.mapID));
}
}
}

View File

@@ -11,6 +11,8 @@
#include <string>
#include <unordered_set>
#include <noggit/ui/VersionSelector.h>
class StackedWidget;
namespace noggit
@@ -30,12 +32,12 @@ namespace noggit
void prompt_exit(QCloseEvent* event);
void prompt_uid_fix_failure();
void build_map_lists();
void build_map_lists(bool isShadowlands);
QMenuBar* _menuBar;
std::unordered_set<QWidget*> displayed_widgets;
void build_menu(bool isShadowlands);
signals:
void exit_prompt_opened();
void map_selected(int map_id);
@@ -57,7 +59,6 @@ namespace noggit
);
void createBookmarkList();
void build_menu();
struct MapEntry
{
@@ -84,6 +85,7 @@ namespace noggit
QWidget* _null_widget;
MapView* _map_view;
StackedWidget* _stack_widget;
versionSelector* _version_selector;
noggit::Red::MapCreationWizard::Ui::MapCreationWizard* _map_creation_wizard;
QMetaObject::Connection _map_wizard_connection;