mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 14:51:51 +00:00
- scriptified DPlayerMenu::MouseEvent.
This commit is contained in:
parent
416911587e
commit
f4e9cd0009
4 changed files with 119 additions and 76 deletions
|
@ -91,7 +91,6 @@ public:
|
|||
void Init(DMenu *parent, DListMenuDescriptor *desc);
|
||||
bool Responder (event_t *ev);
|
||||
bool MenuEvent (int mkey, bool fromcontroller);
|
||||
bool MouseEvent(int type, int x, int y);
|
||||
};
|
||||
|
||||
IMPLEMENT_CLASS(DPlayerMenu, false, false)
|
||||
|
@ -278,30 +277,18 @@ void DPlayerMenu::UpdateTranslation()
|
|||
|
||||
void DPlayerMenu::PickPlayerClass()
|
||||
{
|
||||
int pclass = 0;
|
||||
// [GRB] Pick a class from player class list
|
||||
if (PlayerClasses.Size () > 1)
|
||||
{
|
||||
pclass = players[consoleplayer].userinfo.GetPlayerClassNum();
|
||||
|
||||
/*
|
||||
// What's the point of this? Aren't we supposed to edit the
|
||||
// userinfo?
|
||||
if (players[consoleplayer].mo != NULL)
|
||||
{
|
||||
PlayerClassIndex = players[consoleplayer].CurrentPlayerClass;
|
||||
}
|
||||
else
|
||||
*/
|
||||
{
|
||||
int pclass = 0;
|
||||
// [GRB] Pick a class from player class list
|
||||
if (PlayerClasses.Size () > 1)
|
||||
if (pclass < 0)
|
||||
{
|
||||
pclass = players[consoleplayer].userinfo.GetPlayerClassNum();
|
||||
|
||||
if (pclass < 0)
|
||||
{
|
||||
pclass = (MenuTime>>7) % PlayerClasses.Size ();
|
||||
}
|
||||
pclass = (MenuTime>>7) % PlayerClasses.Size ();
|
||||
}
|
||||
PlayerClassIndex = pclass;
|
||||
}
|
||||
PlayerClassIndex = pclass;
|
||||
PlayerClass = &PlayerClasses[PlayerClassIndex];
|
||||
UpdateTranslation();
|
||||
}
|
||||
|
@ -314,14 +301,25 @@ void DPlayerMenu::PickPlayerClass()
|
|||
|
||||
void DPlayerMenu::SendNewColor (int red, int green, int blue)
|
||||
{
|
||||
char command[24];
|
||||
|
||||
players[consoleplayer].userinfo.ColorChanged(MAKERGB(red,green,blue));
|
||||
mysnprintf (command, countof(command), "color \"%02x %02x %02x\"", red, green, blue);
|
||||
C_DoCommand (command);
|
||||
UpdateTranslation();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
players[consoleplayer].userinfo.ColorChanged(MAKERGB(r, g, b));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
//
|
||||
|
@ -456,10 +454,7 @@ void DPlayerMenu::ColorSetChanged (DMenuItemBase *li)
|
|||
if (green != NULL) green->Enable(mycolorset == -1);
|
||||
if (blue != NULL) blue->Enable(mycolorset == -1);
|
||||
|
||||
char command[24];
|
||||
players[consoleplayer].userinfo.ColorSetChanged(mycolorset);
|
||||
mysnprintf(command, countof(command), "colorset %d", mycolorset);
|
||||
C_DoCommand(command);
|
||||
UpdateTranslation();
|
||||
}
|
||||
}
|
||||
|
@ -545,6 +540,17 @@ void DPlayerMenu::AutoaimChanged (DMenuItemBase *li)
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
//=============================================================================
|
||||
//
|
||||
//
|
||||
|
@ -648,49 +654,5 @@ bool DPlayerMenu::MenuEvent (int mkey, bool fromcontroller)
|
|||
return Super::MenuEvent(mkey, fromcontroller);
|
||||
}
|
||||
|
||||
|
||||
bool DPlayerMenu::MouseEvent(int type, int x, int y)
|
||||
{
|
||||
int v;
|
||||
DMenuItemBase *li = mFocusControl;
|
||||
bool res = Super::MouseEvent(type, x, y);
|
||||
if (li == NULL) li = mFocusControl;
|
||||
if (li != NULL)
|
||||
{
|
||||
// Check if the colors have changed
|
||||
FName current = li->GetAction(NULL);
|
||||
switch(current)
|
||||
{
|
||||
case NAME_Red:
|
||||
if (li->GetValue(0, &v))
|
||||
{
|
||||
uint32 color = players[consoleplayer].userinfo.GetColor();
|
||||
SendNewColor (v, GPART(color), BPART(color));
|
||||
}
|
||||
break;
|
||||
|
||||
case NAME_Green:
|
||||
if (li->GetValue(0, &v))
|
||||
{
|
||||
uint32 color = players[consoleplayer].userinfo.GetColor();
|
||||
SendNewColor (RPART(color), v, BPART(color));
|
||||
}
|
||||
break;
|
||||
|
||||
case NAME_Blue:
|
||||
if (li->GetValue(0, &v))
|
||||
{
|
||||
uint32 color = players[consoleplayer].userinfo.GetColor();
|
||||
SendNewColor (RPART(color), GPART(color), v);
|
||||
}
|
||||
break;
|
||||
case NAME_Autoaim:
|
||||
AutoaimChanged(li);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
DEFINE_FIELD(DPlayerMenu, mRotation)
|
||||
DEFINE_FIELD_NAMED(DPlayerMenu, PlayerClass, mPlayerClass)
|
||||
|
|
|
@ -163,6 +163,13 @@ FString GetPrintableDisplayName(PClassActor *cls)
|
|||
return cls->DisplayName;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(APlayerPawn, GetPrintableDisplayName)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_CLASS(type, AActor);
|
||||
ACTION_RETURN_STRING(type->DisplayName);
|
||||
}
|
||||
|
||||
bool ValidatePlayerClass(PClassActor *ti, const char *name)
|
||||
{
|
||||
if (ti == NULL)
|
||||
|
@ -654,6 +661,13 @@ DEFINE_ACTION_FUNCTION(_PlayerInfo, GetNeverSwitch)
|
|||
ACTION_RETURN_BOOL(self->userinfo.GetNeverSwitch());
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(_PlayerInfo, GetColor)
|
||||
{
|
||||
PARAM_SELF_STRUCT_PROLOGUE(player_t);
|
||||
ACTION_RETURN_INT(self->userinfo.GetColor());
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// APlayerPawn
|
||||
|
|
|
@ -1,8 +1,74 @@
|
|||
|
||||
|
||||
class PlayerMenu : ListMenu native
|
||||
{
|
||||
native int mRotation;
|
||||
native PlayerClass mPlayerClass;
|
||||
|
||||
protected native void AutoaimChanged(float val);
|
||||
protected native void ColorChanged(int red, int green, int blue);
|
||||
|
||||
protected void UpdateTranslation()
|
||||
{
|
||||
Translation.SetPlayerTranslation(TRANSLATION_Players, MAXPLAYERS, consoleplayer, mPlayerClass);
|
||||
}
|
||||
|
||||
protected void SendNewColor (int red, int green, int blue)
|
||||
{
|
||||
ColorChanged(red, green, blue);
|
||||
UpdateTranslation();
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
override bool MouseEvent(int type, int x, int y)
|
||||
{
|
||||
let li = mFocusControl;
|
||||
bool res = Super.MouseEvent(type, x, y);
|
||||
if (li == NULL) li = mFocusControl;
|
||||
if (li != NULL)
|
||||
{
|
||||
// Check if the colors have changed
|
||||
Name ctrl = li.GetAction();
|
||||
bool resv;
|
||||
int v;
|
||||
[resv, v]= li.GetValue(0);
|
||||
switch(ctrl)
|
||||
{
|
||||
case 'Red':
|
||||
if (resv)
|
||||
{
|
||||
Color colr = players[consoleplayer].GetColor();
|
||||
SendNewColor (v, colr.g, colr.b);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Green':
|
||||
if (resv)
|
||||
{
|
||||
Color colr = players[consoleplayer].GetColor();
|
||||
SendNewColor (colr.r, v, colr.b);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Blue':
|
||||
if (resv)
|
||||
{
|
||||
Color colr = players[consoleplayer].GetColor();
|
||||
SendNewColor (colr.r, colr.g, v);
|
||||
}
|
||||
break;
|
||||
case 'Autoaim':
|
||||
AutoaimChanged(v);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
|
@ -12,9 +78,7 @@ class PlayerMenu : ListMenu native
|
|||
|
||||
override void Drawer ()
|
||||
{
|
||||
|
||||
Super.Drawer();
|
||||
|
||||
String str = "PRESS " .. TEXTCOLOR_WHITE .. "SPACE";
|
||||
screen.DrawText (SmallFont, Font.CR_GOLD, 320 - 32 - 32 - SmallFont.StringWidth (str)/2, 50 + 48 + 70, str, DTA_Clean, true);
|
||||
str = mRotation ? "TO SEE FRONT" : "TO SEE BACK";
|
||||
|
|
|
@ -136,6 +136,8 @@ class PlayerPawn : Actor native
|
|||
native int GetMaxHealth();
|
||||
native bool ResetAirSupply (bool playgasp = false);
|
||||
native void CheckWeaponSwitch(class<Inventory> item);
|
||||
native static String GetPrintableDisplayName(Class<Actor> cls);
|
||||
|
||||
}
|
||||
|
||||
class PlayerChunk : PlayerPawn
|
||||
|
@ -308,6 +310,7 @@ userinfo_t userinfo;
|
|||
native void SetLogNumber (int text);
|
||||
native void SetLogText (String text);
|
||||
native String GetUserName();
|
||||
native Color GetColor();
|
||||
native bool GetNeverSwitch();
|
||||
native void DropWeapon();
|
||||
native void BringUpWeapon();
|
||||
|
|
Loading…
Reference in a new issue