mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-28 13:47:58 +03:00
Implemented MP map picker
This commit is contained in:
parent
acbd802790
commit
956cd59385
2 changed files with 245 additions and 31 deletions
|
@ -21,12 +21,17 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "cl_ui.h"
|
#include "cl_ui.h"
|
||||||
|
#include "../qcommon/localization.h"
|
||||||
|
|
||||||
class MpMapPickerItem : public UIListCtrlItem
|
class MpMapPickerItem : public UIListCtrlItem
|
||||||
{
|
{
|
||||||
str m_string;
|
str m_string;
|
||||||
|
// Added in 2.0
|
||||||
|
str m_directory;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
MpMapPickerItem(const str& string, const str& directory);
|
||||||
|
|
||||||
int getListItemValue(int which) const override;
|
int getListItemValue(int which) const override;
|
||||||
griditemtype_t getListItemType(int which) const override;
|
griditemtype_t getListItemType(int which) const override;
|
||||||
str getListItemString(int which) const override;
|
str getListItemString(int which) const override;
|
||||||
|
@ -43,94 +48,300 @@ CLASS_DECLARATION(USignal, MpMapPickerClass, NULL) {
|
||||||
|
|
||||||
MpMapPickerClass::MpMapPickerClass()
|
MpMapPickerClass::MpMapPickerClass()
|
||||||
{
|
{
|
||||||
// FIXME: stub
|
window = new UIFloatingWindow();
|
||||||
|
window->Create(
|
||||||
|
NULL,
|
||||||
|
UIRect2D((cls.glconfig.vidWidth - 300) / 2, (cls.glconfig.vidHeight - 200) / 2, 300, 200),
|
||||||
|
"Select a Map",
|
||||||
|
UColor(0.15f, 0.195f, 0.278f),
|
||||||
|
UHudColor
|
||||||
|
);
|
||||||
|
window->setFont("facfont-20");
|
||||||
|
window->PassEventToWidget("closebutton", new Event(EV_Widget_Disable));
|
||||||
|
window->PassEventToWidget("minimizebutton", new Event(EV_Widget_Disable));
|
||||||
|
window->Connect(this, W_Deactivated, W_Deactivated);
|
||||||
|
|
||||||
|
listbox = new UIListCtrl();
|
||||||
|
listbox->InitFrame(window->getChildSpace(), window->getChildSpace()->getClientFrame(), 0);
|
||||||
|
listbox->SetDrawHeader(false);
|
||||||
|
listbox->setFont("facfont-20");
|
||||||
|
listbox->FrameInitialized();
|
||||||
|
listbox->AddColumn(Sys_LV_CL_ConvertString("Select a Map"), 0, 400, false, false);
|
||||||
|
|
||||||
|
listbox->Connect(this, EV_UIListBase_ItemDoubleClicked, EV_UIListBase_ItemDoubleClicked);
|
||||||
|
listbox->Connect(this, EV_UIListBase_ItemSelected, EV_UIListBase_ItemSelected);
|
||||||
|
listbox->AllowActivate(true);
|
||||||
|
|
||||||
|
// Added in 2.0
|
||||||
|
// Don't localize elements
|
||||||
|
listbox->SetDontLocalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
MpMapPickerClass::~MpMapPickerClass()
|
MpMapPickerClass::~MpMapPickerClass()
|
||||||
{
|
{
|
||||||
// FIXME: stub
|
if (listbox) {
|
||||||
|
delete listbox;
|
||||||
|
listbox = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window) {
|
||||||
|
delete window;
|
||||||
|
window = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MpMapPickerClass::Setup(const char *root_directory, const char *current_directory)
|
void MpMapPickerClass::Setup(const char *root_directory, const char *current_directory, const char *game_type)
|
||||||
{
|
{
|
||||||
// FIXME: stub
|
Initialize(root_directory, current_directory, game_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MpMapPickerClass::Initialize(const char *root_directory, const char *current_directory)
|
void MpMapPickerClass::Initialize(const char *root_directory, const char *current_directory, const char *game_type)
|
||||||
{
|
{
|
||||||
// FIXME: stub
|
rootDirectory = root_directory;
|
||||||
|
if (rootDirectory.length() > 1 && rootDirectory[rootDirectory.length() - 1] != '/') {
|
||||||
|
rootDirectory += "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
currentDirectory = current_directory;
|
||||||
|
if (currentDirectory.length() > 1 && currentDirectory[currentDirectory.length() - 1] != '/') {
|
||||||
|
currentDirectory += "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game_type) {
|
||||||
|
gameType = game_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetupFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MpMapPickerClass::GotoParentDirectory(void)
|
void MpMapPickerClass::GotoParentDirectory(void)
|
||||||
{
|
{
|
||||||
// FIXME: stub
|
uintptr_t i;
|
||||||
|
|
||||||
|
if (currentDirectory == rootDirectory) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = currentDirectory.length() - 2; i > 0; i--) {
|
||||||
|
if (currentDirectory[i] == '/') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentDirectory[i] == '/') {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentDirectory = str(currentDirectory, 0, i);
|
||||||
|
|
||||||
|
// refresh files
|
||||||
|
SetupFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MpMapPickerClass::GotoSubDirectory(str subdir)
|
void MpMapPickerClass::GotoSubDirectory(str subdir)
|
||||||
{
|
{
|
||||||
// FIXME: stub
|
currentDirectory += subdir + "/";
|
||||||
|
|
||||||
|
// refresh files
|
||||||
|
SetupFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MpMapPickerClass::SetupFiles(void)
|
void MpMapPickerClass::SetupFiles(void)
|
||||||
{
|
{
|
||||||
// FIXME: stub
|
char **filenames;
|
||||||
|
int numfiles;
|
||||||
|
int i;
|
||||||
|
char mapname[128];
|
||||||
|
bool bTugOfWar = false, bObjective = false, bLiberation = false;
|
||||||
|
|
||||||
|
listbox->DeleteAllItems();
|
||||||
|
|
||||||
|
if (gameType == "tow") {
|
||||||
|
bTugOfWar = true;
|
||||||
|
} else if (gameType == "obj") {
|
||||||
|
bObjective = true;
|
||||||
|
} else if (gameType == "lib") {
|
||||||
|
bLiberation = true;
|
||||||
|
} else {
|
||||||
|
// retrieve directories
|
||||||
|
filenames = FS_ListFiles(rootDirectory, ".bsp", qfalse, &numfiles);
|
||||||
|
|
||||||
|
for (i = 0; i < numfiles; i++) {
|
||||||
|
const char *filename = filenames[i];
|
||||||
|
|
||||||
|
strcpy(mapname, filename);
|
||||||
|
mapname[strlen(mapname) - 4] = 0;
|
||||||
|
|
||||||
|
if (COM_IsMapValid(mapname)) {
|
||||||
|
listbox->AddItem(new MpMapPickerItem(mapname, rootDirectory));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FS_FreeFileList(filenames);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentDirectory.length()) {
|
||||||
|
if (currentDirectory == "maps/-/") {
|
||||||
|
SetupSecondaryFiles(currentDirectory, bTugOfWar, bObjective, bLiberation);
|
||||||
|
} else {
|
||||||
|
SetupSecondaryFiles("maps/obj/", bTugOfWar, bObjective, bLiberation);
|
||||||
|
SetupSecondaryFiles("maps/lib/", bTugOfWar, bObjective, bLiberation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
listbox->SortByColumn(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MpMapPickerClass::FileSelected(str& currentDirectory, str& partialName, str& fullname)
|
void MpMapPickerClass::SetupSecondaryFiles(const char *path, bool bTugOfWar, bool bObjective, bool bLiberation)
|
||||||
{
|
{
|
||||||
// FIXME: stub
|
char **filenames;
|
||||||
|
int numfiles;
|
||||||
|
int i;
|
||||||
|
char mapname[128];
|
||||||
|
char string[1024];
|
||||||
|
|
||||||
|
filenames = FS_ListFiles(path, ".bsp", qfalse, &numfiles);
|
||||||
|
|
||||||
|
for (i = 0; i < numfiles; i++) {
|
||||||
|
const char *filename = filenames[i];
|
||||||
|
const char *token;
|
||||||
|
|
||||||
|
strcpy(mapname, filename);
|
||||||
|
mapname[strlen(mapname) - 4] = 0;
|
||||||
|
|
||||||
|
if (!COM_IsMapValid(mapname)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bTugOfWar || bObjective || bLiberation) {
|
||||||
|
bool bHasMP = false, bHasTOW = false, bHasLib = false;
|
||||||
|
|
||||||
|
strcpy(string, mapname);
|
||||||
|
|
||||||
|
for (token = strtok(string, "_"); token; token = strtok(NULL, "_")) {
|
||||||
|
if (bObjective) {
|
||||||
|
if (!Q_stricmp(token, "obj")) {
|
||||||
|
listbox->AddItem(new MpMapPickerItem(mapname, path));
|
||||||
|
} else if (!Q_stricmp(token, "ship")) {
|
||||||
|
listbox->AddItem(new MpMapPickerItem(mapname, path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bTugOfWar) {
|
||||||
|
if (!Q_stricmp(token, "MP")) {
|
||||||
|
bHasMP = true;
|
||||||
|
}
|
||||||
|
if (!Q_stricmp(token, "TOW")) {
|
||||||
|
bHasTOW = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bHasMP && bHasTOW) {
|
||||||
|
listbox->AddItem(new MpMapPickerItem(mapname, path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bLiberation) {
|
||||||
|
if (!Q_stricmp(token, "MP")) {
|
||||||
|
bHasMP = true;
|
||||||
|
}
|
||||||
|
if (!Q_stricmp(token, "LIB")) {
|
||||||
|
bHasLib = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bHasMP && bHasLib) {
|
||||||
|
listbox->AddItem(new MpMapPickerItem(mapname, path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!Q_stricmp(mapname, "obj_team2") || !Q_stricmp(mapname, "obj_team4")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
listbox->AddItem(new MpMapPickerItem(mapname, path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FS_FreeFileList(filenames);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MpMapPickerClass::FileSelected(const str& currentDirectory, const str& partialName, const str& fullname)
|
||||||
|
{
|
||||||
|
FileChosen(currentDirectory, partialName, fullname);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MpMapPickerClass::FileSelected(Event *ev)
|
void MpMapPickerClass::FileSelected(Event *ev)
|
||||||
{
|
{
|
||||||
// FIXME: stub
|
if (!listbox->getCurrentItem()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uii.Snd_PlaySound("sound/menu/apply.wav");
|
||||||
|
|
||||||
|
str name = listbox->GetItem(listbox->getCurrentItem())->getListItemString(0);
|
||||||
|
|
||||||
|
FileSelected(currentDirectory, name, currentDirectory + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MpMapPickerClass::FileChosen(str& currentDirectory, str& partialName, str& fullname)
|
void MpMapPickerClass::FileChosen(const str& currentDirectory, const str& partialName, const str& fullname)
|
||||||
{
|
{
|
||||||
// FIXME: stub
|
const char *pszFilename;
|
||||||
|
str sCommand;
|
||||||
|
|
||||||
|
pszFilename = fullname.c_str();
|
||||||
|
sCommand = va("ui_dmmap %s\n", pszFilename + 5);
|
||||||
|
|
||||||
|
Cbuf_AddText(sCommand);
|
||||||
|
CloseWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MpMapPickerClass::FileChosen(Event *ev)
|
void MpMapPickerClass::FileChosen(Event *ev)
|
||||||
{
|
{
|
||||||
// FIXME: stub
|
if (!listbox->getCurrentItem()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uii.Snd_PlaySound("sound/menu/apply.wav");
|
||||||
|
|
||||||
|
str name = listbox->GetItem(listbox->getCurrentItem())->getListItemString(0);
|
||||||
|
|
||||||
|
FileChosen(currentDirectory, name, currentDirectory + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MpMapPickerClass::CloseWindow(void)
|
void MpMapPickerClass::CloseWindow(void)
|
||||||
{
|
{
|
||||||
// FIXME: stub
|
PostEvent(EV_Remove, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MpMapPickerClass::OnDeactivated(Event *ev)
|
void MpMapPickerClass::OnDeactivated(Event *ev)
|
||||||
{
|
{
|
||||||
// FIXME: stub
|
CloseWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
MpMapPickerItem::MpMapPickerItem(const str& string, const str& directory)
|
||||||
|
{
|
||||||
|
m_string = string;
|
||||||
|
m_directory = directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MpMapPickerItem::getListItemValue(int which) const
|
int MpMapPickerItem::getListItemValue(int which) const
|
||||||
{
|
{
|
||||||
// FIXME: stub
|
return atoi(m_string);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
griditemtype_t MpMapPickerItem::getListItemType(int which) const
|
griditemtype_t MpMapPickerItem::getListItemType(int which) const
|
||||||
{
|
{
|
||||||
// FIXME: stub
|
|
||||||
return griditemtype_t::TYPE_STRING;
|
return griditemtype_t::TYPE_STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
str MpMapPickerItem::getListItemString(int which) const
|
str MpMapPickerItem::getListItemString(int which) const
|
||||||
{
|
{
|
||||||
// FIXME: stub
|
return m_string;
|
||||||
return str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MpMapPickerItem::DrawListItem(int iColumn, const UIRect2D& drawRect, bool bSelected, UIFont *pFont)
|
void MpMapPickerItem::DrawListItem(int iColumn, const UIRect2D& drawRect, bool bSelected, UIFont *pFont) {}
|
||||||
{
|
|
||||||
// FIXME: stub
|
|
||||||
}
|
|
||||||
|
|
||||||
qboolean MpMapPickerItem::IsHeaderEntry() const
|
qboolean MpMapPickerItem::IsHeaderEntry() const
|
||||||
{
|
{
|
||||||
// FIXME: stub
|
|
||||||
return qfalse;
|
return qfalse;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,27 +30,30 @@ class MpMapPickerClass : public USignal
|
||||||
UIListCtrl *listbox;
|
UIListCtrl *listbox;
|
||||||
str currentDirectory;
|
str currentDirectory;
|
||||||
str rootDirectory;
|
str rootDirectory;
|
||||||
|
str gameType;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CLASS_PROTOTYPE(MpMapPickerClass);
|
CLASS_PROTOTYPE(MpMapPickerClass);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SetupFiles(void);
|
void SetupFiles(void);
|
||||||
|
void SetupSecondaryFiles(const char *path, bool bTugOfWar, bool bObjective, bool bLiberation);
|
||||||
void GotoParentDirectory(void);
|
void GotoParentDirectory(void);
|
||||||
void GotoSubDirectory(str subdir);
|
void GotoSubDirectory(str subdir);
|
||||||
void Initialize(const char *root_directory, const char *current_directory);
|
void Initialize(const char *root_directory, const char *current_directory, const char *game_type);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void CloseWindow(void);
|
void CloseWindow(void);
|
||||||
void FileSelected(Event *ev);
|
void FileSelected(Event *ev);
|
||||||
virtual void FileSelected(str& currentDirectory, str& partialName, str& fullname);
|
virtual void FileSelected(const str& currentDirectory, const str& partialName, const str& fullname);
|
||||||
void FileChosen(Event *ev);
|
void FileChosen(Event *ev);
|
||||||
virtual void FileChosen(str& currentDirectory, str& partialName, str& fullname);
|
virtual void FileChosen(const str& currentDirectory, const str& partialName, const str& fullname);
|
||||||
void OnDeactivated(Event *ev);
|
void OnDeactivated(Event *ev);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MpMapPickerClass();
|
MpMapPickerClass();
|
||||||
~MpMapPickerClass();
|
~MpMapPickerClass();
|
||||||
|
|
||||||
void Setup(const char *root_directory, const char *current_directory);
|
// game_type was added in 2.0
|
||||||
|
void Setup(const char *root_directory, const char *current_directory, const char *game_type = NULL);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue