Code: Select all
class LADCharacterMenu : GenericMenu
{
const RES_WIDTH = 320;
const RES_HEIGHT = 200;
bool bIsEnabled;
PlayerInfo mPlayer;
KeyBindings mBindings;
int menuKeyDelay;
int menuKeyCode;
int currentSelection;
int filterButtonsX;
int filterButtonsY;
int paperdollX;
int paperdollY;
int itemBGWidth;
int itemBGHeight;
int itemBGPadding;
int itemListX;
int itemListY;
int itemListPaddingX;
int itemDetailsX;
int itemDetailsY;
int itemDetailsWidth;
int itemDetailsHeight;
int bottomBarLines;
int bottomBarPadding;
override void Init(Menu parent)
{
PlayerInfo p = players[consoleplayer];
if (p) let mo = p.mo;
if (playeringame[consoleplayer] && mo && gamestate == GS_LEVEL)
{
bIsEnabled = true;
mPlayer = p;
// setup coordinates
itemBGPadding = 8;
itemListPaddingX = 64;
// top stuff
filterButtonsX = itemListPaddingX / CleanXfac;
filterButtonsY = 32 / CleanYfac;
// item list
itemListX = itemListPaddingX / CleanXfac;
itemListY = 128 / CleanYfac;
itemBGWidth = 150;
itemBGHeight = Screen.GetHeight();
// paperdoll
TextureID bodyTex = TexMan.CheckForTexture("graphics/ui/charactermenu/paperdoll/caucasian_male_body.png", TexMan.Type_MiscPatch);
int bodyTexWidth, bodyTexHeight;
if (bodyTex.IsValid()) [bodyTexWidth, bodyTexHeight] = TexMan.GetSize(bodyTex);
// find how much space is left after the item stuff
int px = itemBGWidth + itemBGPadding;
paperDollX = (px + (Screen.GetWidth() / CleanXfac)) / 2;
paperDollX -= (bodyTexWidth / 2);
paperDollY = 32 / CleanYfac;
itemDetailsWidth = 224;
itemDetailsHeight = 64;
itemDetailsX = (px + (Screen.GetWidth() / CleanXfac)) / 2;;
itemDetailsX -= (itemDetailsWidth / 2);
itemDetailsY = Screen.GetHeight() / CleanYfac;
itemDetailsY -= itemDetailsHeight + 24;
// bottom bar
bottomBarLines = 2;
bottomBarPadding = 2;
Super.Init(parent);
}
// add a delay before being able to press the "open menu" key again
menuKeyDelay = 1;
}
override bool OnInputEvent(InputEvent ev)
{
// record the bounded key that was used to open the menu
if (menuKeyCode == 0)
{
menuKeyCode = ev.KeyChar;
}
return Super.OnInputEvent(ev);
}
override bool OnUIEvent(UIEvent ev)
{
// the "open menu" key was pressed
if (ev.Type == UIEvent.Type_KeyDown && ev.KeyChar == menuKeyCode && menuKeyDelay == 0)
{
GoBack();
}
if (ev.Type == ev.Type_MouseMove)
{
int mx = ev.MouseX;
int my = ev.MouseY;
// set the boundaries for the item selection window
int winx, winw, winy, winh;
winx = itemListX * CleanXfac;
winw = winx + ((itemBGWidth - itemBGPadding - itemBGPadding) * CleanXfac);
if (mx > winx && mx < winw)
{
// subtract the item Y position with the mouse coordinates
my = clamp(my, 0, Screen.GetHeight() - (((SmallFont.GetHeight() * (bottomBarLines + 1)) + (bottomBarPadding * 2)) * CleanYfac));
int selectY = (my - (itemListY * CleanYfac)) / ((SmallFont.GetHeight() + 1) * CleanYfac);
let pmo = LADPlayer(mPlayer.mo);
// be sure selection is always within bounds
let sia = LADItem.GetSortedItemArray(pmo);
if (sia && selectY > sia.items.Size() - 1) selectY = sia.Items.Size() - 1;
if (selectY < 0) selectY = 0;
currentSelection = selectY;
}
}
return Super.OnUIEvent(ev);
}
override bool MouseEvent(int type, int x, int y)
{
/*
// convert x/y from screen to virtual coordinates, according to CleanX/Yfac use in DrawTexture
x = ((x - (Screen.GetWidth() / 2)) / CleanXfac) + 160;
y = ((y - (Screen.GetHeight() / 2)) / CleanYfac) + 100;
return true;
*/
if (type == MOUSE_Release)
{
// check boundaries before allowing click
int mx = x, my = y;
int winx, winw, winy, winh;
winx = itemListX * CleanXfac;
winw = winx + ((itemBGWidth - itemBGPadding - itemBGPadding) * CleanXfac);
if (mx > winx && mx < winw)
{
if (MenuEvent(MKEY_Enter, true))
{
return true;
}
}
}
return Super.MouseEvent(type, x, y);
}
override bool MenuEvent (int mkey, bool fromcontroller)
{
let pmo = LADPlayer(mPlayer.mo);
if (pmo) LADCharacter character = LADCharacter(pmo.FindInventory("LADCharacter"));
if (!character) return false;
let sia = LADItem.GetSortedItemArray(pmo);
if (!sia) return false;
if (sia.items.Size() == 0) return false;
switch (mkey)
{
case MKEY_Up:
currentSelection--;
if (currentSelection < 0) currentSelection = sia.items.Size() - 1;
return true;
case MKEY_Down:
currentSelection++;
if (currentSelection > sia.items.Size() - 1) currentSelection = 0;
return true;
case MKEY_Enter:
// find which slot this item is in
let itemPtr = sia.items[currentSelection];
// find slot THE FUCKING MANUAL WAY because Find() is blocked
int slot;
for (int i = 0; i < character.myItems.Size(); i++)
{
if (character.myItems[i] == itemPtr)
{
slot = i;
continue;
}
}
if (!LADItem.bIsItemEquippedAtSlot(pmo, slot))
{
EventHandler.SendNetworkEvent("EV_EquipItem", slot);
}
else
{
EventHandler.SendNetworkEvent("EV_UnequipItem", slot);
}
return true;
case MKEY_Back:
GoBack();
return true;
default:
return false;
}
}
override void Drawer(void)
{
if (!bIsEnabled) return;
if (!mPlayer || mPlayer != players[consoleplayer]) return;
let pmo = LADPlayer(mPlayer.mo);
if (!pmo) return;
// paperdoll
TextureID bodyTex= TexMan.CheckForTexture("graphics/ui/charactermenu/paperdoll/caucasian_male_body.png", TexMan.Type_MiscPatch);
if (bodyTex.IsValid())
{
Screen.DrawTexture (bodyTex, false,
paperdollX * CleanXfac,
paperdollY * CleanYfac,
DTA_CleanNoMove, true);
}
// items
// background
Screen.Dim(Color(0, 0, 0), 0.4,
(itemListX - itemBGPadding) * CleanXfac,
0 * CleanYfac,
itemBGWidth * CleanXfac,
itemBGHeight);
// top stuff
Screen.DrawText(SmallFont, Font.CR_WHITE,
filterButtonsX * CleanXfac,
filterButtonsY * CleanYfac,
"< My Inventory >\n"
"Sort by: Name", DTA_CleanNoMove, true);
// inventory list
let sia = LADItem.GetSortedItemArray(pmo);
if (sia && sia.items.Size() > 0)
{
// inventory selection highlight
Screen.Dim(Color(255, 255, 255), 0.8,
itemListX * CleanXfac,
(itemListY + ((SmallFont.GetHeight() * currentSelection) + currentSelection)) * CleanYfac,
(itemBGWidth - itemBGPadding - itemBGPadding) * CleanXfac,
SmallFont.GetHeight() * CleanYfac);
// inventory list
Screen.DrawText(SmallFont, Font.CR_WHITE,
itemListX * CleanXfac,
itemListY * CleanYfac,
LADItem.GetSortedItemsString(pmo), DTA_CleanNoMove, true);
}
// item details
// background
Screen.Dim(Color(0, 0, 0), 0.4,
itemDetailsX * CleanXfac,
itemDetailsY * CleanYfac,
itemDetailsWidth * CleanXfac,
itemDetailsHeight * CleanYfac);
// details
String details;
details = "Item Detail Stuff";
Screen.DrawText(SmallFont, Font.CR_WHITE,
((itemDetailsX + (itemDetailsWidth / 2)) - (SmallFont.StringWidth(details) / 2)) * CleanXfac,
itemDetailsY * CleanYfac,
details, DTA_CleanNoMove, true);
// bottom bar stuff
String ts = Bumi.GetTimeString(true, Bumi.DATE_SHORT);
String ds = Bumi.GetDateString(Bumi.DATE_LONG);
String bottomText = String.Format("%s\n%s", ts, ds);
// draw background
Screen.Dim(Color(0, 0, 0), 0.4,
0 * CleanXfac,
Screen.GetHeight() - ((SmallFont.GetHeight() * bottomBarLines) + (bottomBarPadding * 2)) * CleanYfac,
Screen.GetWidth() * CleanXfac,
((SmallFont.GetHeight() * bottomBarLines) + (bottomBarPadding * 2)) * CleanYfac);
// draw date and time
Screen.DrawText(SmallFont, Font.CR_WHITE,
bottomBarPadding * CleanXfac,
Screen.GetHeight() - ((SmallFont.GetHeight() * bottomBarLines) + bottomBarPadding) * CleanYfac,
bottomText, DTA_CleanNoMove, true);
Super.Drawer();
}
override void Ticker(void)
{
if (!mPlayer || mPlayer != players[consoleplayer])
{
CloseCharacterMenu();
return;
}
if (!bIsEnabled)
{
CloseCharacterMenu();
return;
}
// menuKeyCode is 0, which means the menu was most probably opened via the console or some
// other unconventional means.
// Don't allow this because proper input functionality will be broken
if (menuKeycode == 0)
{
//CloseCharacterMenu();
return;
}
if (menuKeyDelay > 0) menuKeyDelay--;
}
void CloseCharacterMenu(void)
{
Close();
}
void GoBack(void)
{
CloseCharacterMenu();
}
}