gzdoom-gles/src/menu/playermenu.cpp

577 lines
14 KiB
C++
Raw Normal View History

2016-03-01 15:47:10 +00:00
/*
** playermenu.cpp
** The player setup menu
**
**---------------------------------------------------------------------------
** Copyright 2001-2010 Randy Heit
** Copyright 2010 Christoph Oelckers
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3. The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**---------------------------------------------------------------------------
**
*/
#include "menu/menu.h"
#include "v_video.h"
#include "v_font.h"
#include "gi.h"
#include "gstrings.h"
#include "d_player.h"
#include "d_event.h"
#include "d_gui.h"
#include "c_dispatch.h"
#include "teaminfo.h"
#include "v_palette.h"
#include "r_state.h"
#include "r_data/r_translate.h"
#include "v_text.h"
EXTERN_CVAR (String, playerclass)
EXTERN_CVAR (String, name)
EXTERN_CVAR (Int, team)
EXTERN_CVAR (Float, autoaim)
EXTERN_CVAR(Bool, neverswitchonpickup)
EXTERN_CVAR (Bool, cl_run)
//=============================================================================
//
//
//
//=============================================================================
class DPlayerMenu : public DListMenu
{
DECLARE_CLASS(DPlayerMenu, DListMenu)
2017-02-17 15:53:36 +00:00
public:
2016-03-01 15:47:10 +00:00
int PlayerClassIndex;
FPlayerClass *PlayerClass;
TArray<int> PlayerColorSets;
TArray<int> PlayerSkins;
int mRotation;
void PickPlayerClass ();
void UpdateColorsets();
void UpdateSkins();
void UpdateTranslation();
public:
DPlayerMenu() {}
void Init(DMenu *parent, DListMenuDescriptor *desc);
2016-03-01 15:47:10 +00:00
bool Responder (event_t *ev);
};
IMPLEMENT_CLASS(DPlayerMenu, false, false)
2016-03-01 15:47:10 +00:00
//=============================================================================
//
//
//
//=============================================================================
enum EPDFlags
{
ListMenuItemPlayerDisplay_PDF_ROTATION = 0x10001,
ListMenuItemPlayerDisplay_PDF_SKIN = 0x10002,
ListMenuItemPlayerDisplay_PDF_CLASS = 0x10003,
ListMenuItemPlayerDisplay_PDF_MODE = 0x10004,
ListMenuItemPlayerDisplay_PDF_TRANSLATE = 0x10005,
};
2016-03-01 15:47:10 +00:00
void DPlayerMenu::Init(DMenu *parent, DListMenuDescriptor *desc)
2016-03-01 15:47:10 +00:00
{
DMenuItemBase *li;
2016-03-01 15:47:10 +00:00
Super::Init(parent, desc);
PickPlayerClass();
mRotation = 0;
li = GetItem(NAME_Playerdisplay);
if (li != NULL)
{
li->SetValue(ListMenuItemPlayerDisplay_PDF_ROTATION, 0);
li->SetValue(ListMenuItemPlayerDisplay_PDF_MODE, 1);
li->SetValue(ListMenuItemPlayerDisplay_PDF_TRANSLATE, 1);
li->SetValue(ListMenuItemPlayerDisplay_PDF_CLASS, players[consoleplayer].userinfo.GetPlayerClassNum());
2016-03-01 15:47:10 +00:00
if (PlayerClass != NULL && !(GetDefaultByType (PlayerClass->Type)->flags4 & MF4_NOSKIN) &&
players[consoleplayer].userinfo.GetPlayerClassNum() != -1)
{
li->SetValue(ListMenuItemPlayerDisplay_PDF_SKIN, players[consoleplayer].userinfo.GetSkin());
2016-03-01 15:47:10 +00:00
}
}
li = GetItem(NAME_Playerbox);
if (li != NULL)
{
li->SetString(0, name);
}
li = GetItem(NAME_Team);
if (li != NULL)
{
li->SetString(0, "None");
for(unsigned i=0;i<Teams.Size(); i++)
{
li->SetString(i+1, Teams[i].GetName());
}
li->SetValue(0, team == TEAM_NONE? 0 : team + 1);
}
int mycolorset = players[consoleplayer].userinfo.GetColorSet();
int color = players[consoleplayer].userinfo.GetColor();
UpdateColorsets();
li = GetItem(NAME_Red);
if (li != NULL)
{
li->Enable(mycolorset == -1);
li->SetValue(0, RPART(color));
}
li = GetItem(NAME_Green);
if (li != NULL)
{
li->Enable(mycolorset == -1);
li->SetValue(0, GPART(color));
}
li = GetItem(NAME_Blue);
if (li != NULL)
{
li->Enable(mycolorset == -1);
li->SetValue(0, BPART(color));
}
li = GetItem(NAME_Class);
if (li != NULL)
{
if (PlayerClasses.Size() == 1)
{
li->SetString(0, GetPrintableDisplayName(PlayerClasses[0].Type));
li->SetValue(0, 0);
}
else
{
// [XA] Remove the "Random" option if the relevant gameinfo flag is set.
if(!gameinfo.norandomplayerclass)
li->SetString(0, "Random");
for(unsigned i=0; i< PlayerClasses.Size(); i++)
{
const char *cls = GetPrintableDisplayName(PlayerClasses[i].Type);
li->SetString(gameinfo.norandomplayerclass ? i : i+1, cls);
}
int pclass = players[consoleplayer].userinfo.GetPlayerClassNum();
li->SetValue(0, gameinfo.norandomplayerclass && pclass >= 0 ? pclass : pclass + 1);
}
}
UpdateSkins();
li = GetItem(NAME_Gender);
if (li != NULL)
{
li->SetValue(0, players[consoleplayer].userinfo.GetGender());
}
li = GetItem(NAME_Autoaim);
if (li != NULL)
{
li->SetValue(0, (int)autoaim);
}
li = GetItem(NAME_Switch);
if (li != NULL)
{
li->SetValue(0, neverswitchonpickup);
}
li = GetItem(NAME_AlwaysRun);
if (li != NULL)
{
li->SetValue(0, cl_run);
}
if (mDesc->mSelectedItem < 0) mDesc->mSelectedItem = 1;
}
//=============================================================================
//
//
//
//=============================================================================
bool DPlayerMenu::Responder (event_t *ev)
{
if (ev->type == EV_GUI_Event && ev->subtype == EV_GUI_Char && ev->data1 == ' ')
{
// turn the player sprite around
mRotation = 8 - mRotation;
DMenuItemBase *li = GetItem(NAME_Playerdisplay);
2016-03-01 15:47:10 +00:00
if (li != NULL)
{
li->SetValue(ListMenuItemPlayerDisplay_PDF_ROTATION, mRotation);
2016-03-01 15:47:10 +00:00
}
return true;
}
return Super::Responder(ev);
}
//=============================================================================
//
2017-02-17 22:56:22 +00:00
// done
2016-03-01 15:47:10 +00:00
//
//=============================================================================
void DPlayerMenu::UpdateTranslation()
{
int PlayerColor = players[consoleplayer].userinfo.GetColor();
int PlayerSkin = players[consoleplayer].userinfo.GetSkin();
int PlayerColorset = players[consoleplayer].userinfo.GetColorSet();
if (PlayerClass != NULL)
{
PlayerSkin = R_FindSkin (Skins[PlayerSkin].Name, int(PlayerClass - &PlayerClasses[0]));
R_GetPlayerTranslation(PlayerColor, GetColorSet(PlayerClass->Type, PlayerColorset),
&Skins[PlayerSkin], translationtables[TRANSLATION_Players][MAXPLAYERS]);
2016-03-01 15:47:10 +00:00
}
}
//=============================================================================
//
2017-02-17 22:56:22 +00:00
// done
2016-03-01 15:47:10 +00:00
//
//=============================================================================
void DPlayerMenu::PickPlayerClass()
{
2017-02-17 17:21:59 +00:00
int pclass = 0;
// [GRB] Pick a class from player class list
if (PlayerClasses.Size () > 1)
2016-03-01 15:47:10 +00:00
{
2017-02-17 17:21:59 +00:00
pclass = players[consoleplayer].userinfo.GetPlayerClassNum();
2016-03-01 15:47:10 +00:00
2017-02-17 17:21:59 +00:00
if (pclass < 0)
{
pclass = (MenuTime>>7) % PlayerClasses.Size ();
2016-03-01 15:47:10 +00:00
}
}
2017-02-17 17:21:59 +00:00
PlayerClassIndex = pclass;
2016-03-01 15:47:10 +00:00
PlayerClass = &PlayerClasses[PlayerClassIndex];
UpdateTranslation();
}
//=============================================================================
//
//
//
//=============================================================================
2017-02-17 17:21:59 +00:00
DEFINE_ACTION_FUNCTION(DPlayerMenu, ColorChanged)
{
PARAM_SELF_PROLOGUE(DPlayerMenu);
PARAM_INT(r);
PARAM_INT(g);
PARAM_INT(b);
// only allow if the menu is active to prevent abuse.
if (self == DMenu::CurrentMenu)
{
2017-02-17 22:56:22 +00:00
char command[24];
2017-02-17 17:21:59 +00:00
players[consoleplayer].userinfo.ColorChanged(MAKERGB(r, g, b));
2017-02-17 22:56:22 +00:00
mysnprintf(command, countof(command), "color \"%02x %02x %02x\"", r, g, b);
C_DoCommand(command);
2017-02-17 17:21:59 +00:00
}
return 0;
}
2016-03-01 15:47:10 +00:00
//=============================================================================
//
2017-02-17 22:56:22 +00:00
// done
2016-03-01 15:47:10 +00:00
//
//=============================================================================
void DPlayerMenu::UpdateColorsets()
{
DMenuItemBase *li = GetItem(NAME_Color);
2016-03-01 15:47:10 +00:00
if (li != NULL)
{
int sel = 0;
EnumColorSets(PlayerClass->Type, &PlayerColorSets);
2016-03-01 15:47:10 +00:00
li->SetString(0, "Custom");
for(unsigned i=0;i<PlayerColorSets.Size(); i++)
{
FPlayerColorSet *colorset = GetColorSet(PlayerClass->Type, PlayerColorSets[i]);
2016-03-01 15:47:10 +00:00
li->SetString(i+1, colorset->Name);
}
int mycolorset = players[consoleplayer].userinfo.GetColorSet();
if (mycolorset != -1)
{
for(unsigned i=0;i<PlayerColorSets.Size(); i++)
{
if (PlayerColorSets[i] == mycolorset)
{
sel = i+1;
}
}
}
li->SetValue(0, sel);
}
}
//=============================================================================
//
2017-02-17 22:56:22 +00:00
// done
2016-03-01 15:47:10 +00:00
//
//=============================================================================
void DPlayerMenu::UpdateSkins()
{
int sel = 0;
int skin;
DMenuItemBase *li = GetItem(NAME_Skin);
2016-03-01 15:47:10 +00:00
if (li != NULL)
{
if (GetDefaultByType (PlayerClass->Type)->flags4 & MF4_NOSKIN ||
players[consoleplayer].userinfo.GetPlayerClassNum() == -1)
{
li->SetString(0, "Base");
li->SetValue(0, 0);
skin = 0;
}
else
{
PlayerSkins.Clear();
for (unsigned i = 0; i < Skins.Size(); i++)
2016-03-01 15:47:10 +00:00
{
if (PlayerClass->CheckSkin(i))
{
int j = PlayerSkins.Push(i);
li->SetString(j, Skins[i].Name);
2016-03-01 15:47:10 +00:00
if (players[consoleplayer].userinfo.GetSkin() == i)
{
sel = j;
}
}
}
li->SetValue(0, sel);
skin = PlayerSkins[sel];
}
li = GetItem(NAME_Playerdisplay);
if (li != NULL)
{
li->SetValue(ListMenuItemPlayerDisplay_PDF_SKIN, skin);
2016-03-01 15:47:10 +00:00
}
}
UpdateTranslation();
}
//=============================================================================
//
2017-02-17 19:02:26 +00:00
// access to the player config is done natively, so that broader access
// functions do not need to be exported.
2016-03-01 15:47:10 +00:00
//
//=============================================================================
2017-02-17 19:02:26 +00:00
DEFINE_ACTION_FUNCTION(DPlayerMenu, PlayerNameChanged)
2016-03-01 15:47:10 +00:00
{
2017-02-17 19:02:26 +00:00
PARAM_SELF_PROLOGUE(DPlayerMenu);
PARAM_STRING(s);
const char *pp = s;
FString command("name \"");
2016-03-01 15:47:10 +00:00
2017-02-17 19:02:26 +00:00
if (self == DMenu::CurrentMenu)
{
2016-03-01 15:47:10 +00:00
// Escape any backslashes or quotation marks before sending the name to the console.
2017-02-17 19:02:26 +00:00
for (auto p = pp; *p != '\0'; ++p)
2016-03-01 15:47:10 +00:00
{
if (*p == '"' || *p == '\\')
{
command << '\\';
}
command << *p;
}
command << '"';
2017-02-17 19:02:26 +00:00
C_DoCommand(command);
2016-03-01 15:47:10 +00:00
}
2017-02-17 19:02:26 +00:00
return 0;
2016-03-01 15:47:10 +00:00
}
//=============================================================================
//
//
//
//=============================================================================
2017-02-17 19:02:26 +00:00
DEFINE_ACTION_FUNCTION(DPlayerMenu, ColorSetChanged)
2016-03-01 15:47:10 +00:00
{
2017-02-17 19:02:26 +00:00
PARAM_SELF_PROLOGUE(DPlayerMenu);
PARAM_INT(sel);
if (self == DMenu::CurrentMenu)
2016-03-01 15:47:10 +00:00
{
2017-02-17 19:02:26 +00:00
players[consoleplayer].userinfo.ColorSetChanged(sel);
2017-02-17 22:56:22 +00:00
char command[24];
mysnprintf(command, countof(command), "colorset %d", sel);
C_DoCommand(command);
2016-03-01 15:47:10 +00:00
}
2017-02-17 19:02:26 +00:00
return 0;
2016-03-01 15:47:10 +00:00
}
//=============================================================================
//
//
//
//=============================================================================
2017-02-17 19:02:26 +00:00
DEFINE_ACTION_FUNCTION(DPlayerMenu, ClassChanged)
{
PARAM_SELF_PROLOGUE(DPlayerMenu);
2017-02-17 22:56:22 +00:00
PARAM_INT(sel);
PARAM_POINTER(cls, FPlayerClass);
2017-02-17 19:02:26 +00:00
if (self == DMenu::CurrentMenu)
{
2017-02-17 22:56:22 +00:00
players[consoleplayer].userinfo.PlayerClassNumChanged(gameinfo.norandomplayerclass ? sel : sel - 1);
cvar_set("playerclass", sel == 0 && !gameinfo.norandomplayerclass ? "Random" : GetPrintableDisplayName(cls->Type).GetChars());
2017-02-17 19:02:26 +00:00
}
return 0;
}
2016-03-01 15:47:10 +00:00
//=============================================================================
//
//
//
//=============================================================================
2017-02-17 19:02:26 +00:00
DEFINE_ACTION_FUNCTION(DPlayerMenu, SkinChanged)
{
PARAM_SELF_PROLOGUE(DPlayerMenu);
PARAM_INT(sel);
2017-02-17 19:02:26 +00:00
if (self == DMenu::CurrentMenu)
{
players[consoleplayer].userinfo.SkinNumChanged(sel);
2017-02-17 22:56:22 +00:00
cvar_set("skin", Skins[sel].Name);
2017-02-17 19:02:26 +00:00
}
return 0;
}
2016-03-01 15:47:10 +00:00
//=============================================================================
//
//
//
//=============================================================================
2017-02-17 17:21:59 +00:00
DEFINE_ACTION_FUNCTION(DPlayerMenu, AutoaimChanged)
{
PARAM_SELF_PROLOGUE(DPlayerMenu);
PARAM_FLOAT(val);
// only allow if the menu is active to prevent abuse.
if (self == DMenu::CurrentMenu)
{
autoaim = float(val);
}
return 0;
}
2017-02-17 19:02:26 +00:00
2016-03-01 15:47:10 +00:00
//=============================================================================
//
//
//
//=============================================================================
2017-02-17 19:02:26 +00:00
DEFINE_ACTION_FUNCTION(DPlayerMenu, TeamChanged)
2016-03-01 15:47:10 +00:00
{
2017-02-17 19:02:26 +00:00
PARAM_SELF_PROLOGUE(DPlayerMenu);
PARAM_INT(val);
// only allow if the menu is active to prevent abuse.
if (self == DMenu::CurrentMenu)
2016-03-01 15:47:10 +00:00
{
2017-02-17 19:02:26 +00:00
team = val == 0 ? TEAM_NONE : val - 1;
}
return 0;
}
2016-03-01 15:47:10 +00:00
2017-02-17 19:02:26 +00:00
//=============================================================================
//
//
//
//=============================================================================
2016-03-01 15:47:10 +00:00
2017-02-17 19:02:26 +00:00
DEFINE_ACTION_FUNCTION(DPlayerMenu, GenderChanged)
{
PARAM_SELF_PROLOGUE(DPlayerMenu);
PARAM_INT(v);
// only allow if the menu is active to prevent abuse.
if (self == DMenu::CurrentMenu)
{
cvar_set("gender", v == 0 ? "male" : v == 1 ? "female" : "other");
}
return 0;
}
2016-03-01 15:47:10 +00:00
2017-02-17 19:02:26 +00:00
//=============================================================================
//
//
//
//=============================================================================
2016-03-01 15:47:10 +00:00
2017-02-17 19:02:26 +00:00
DEFINE_ACTION_FUNCTION(DPlayerMenu, SwitchOnPickupChanged)
{
PARAM_SELF_PROLOGUE(DPlayerMenu);
PARAM_INT(v);
// only allow if the menu is active to prevent abuse.
if (self == DMenu::CurrentMenu)
{
neverswitchonpickup = !!v;
}
return 0;
}
2016-03-01 15:47:10 +00:00
2017-02-17 19:02:26 +00:00
//=============================================================================
//
//
//
//=============================================================================
2016-03-01 15:47:10 +00:00
2017-02-17 19:02:26 +00:00
DEFINE_ACTION_FUNCTION(DPlayerMenu, AlwaysRunChanged)
{
PARAM_SELF_PROLOGUE(DPlayerMenu);
PARAM_INT(v);
// only allow if the menu is active to prevent abuse.
if (self == DMenu::CurrentMenu)
{
cl_run = !!v;
2016-03-01 15:47:10 +00:00
}
2017-02-17 19:02:26 +00:00
return 0;
2016-03-01 15:47:10 +00:00
}
2017-02-17 19:02:26 +00:00
2017-02-17 15:53:36 +00:00
DEFINE_FIELD(DPlayerMenu, mRotation)
2017-02-17 17:21:59 +00:00
DEFINE_FIELD_NAMED(DPlayerMenu, PlayerClass, mPlayerClass)
2017-02-17 19:02:26 +00:00
DEFINE_FIELD(DPlayerMenu, PlayerColorSets)
2017-02-17 21:12:56 +00:00
DEFINE_FIELD_NAMED(DPlayerMenu, PlayerSkins, mPlayerSkins)
2017-02-17 19:58:11 +00:00
DEFINE_FIELD(DPlayerMenu, PlayerClassIndex)