|
| 1 | +class RWArtifactsMenu : ZFGenericMenu { |
| 2 | + const menuW = 960; |
| 3 | + const menuH = 540; |
| 4 | + Font smallFont; // A font to use for text. |
| 5 | + Font descrFont; |
| 6 | + ZFImage background; // A background image. |
| 7 | + ArtifactsMenuHandler handler; |
| 8 | + |
| 9 | + array<ArtifactButton> artifactButtons; |
| 10 | + array<ZFLabel> DescriptionLabels; |
| 11 | + int currLabelLine; |
| 12 | + |
| 13 | + override void Init(Menu parent) { |
| 14 | + Super.Init(parent); // Call GenericMenu's 'Init' function to do some required initialization. |
| 15 | + SetBaseResolution ((menuW, menuH)); |
| 16 | + smallFont = Font.GetFont("SmallFont"); // Get the smallfont. |
| 17 | + descrFont = Font.GetFont("mdesfont"); |
| 18 | + handler = new('ArtifactsMenuHandler'); |
| 19 | + handler.collector = RwHudArtifactStatsCollector.Create(); |
| 20 | + handler.link = self; |
| 21 | + // Add a background. |
| 22 | + background = ZFImage.Create((0, 0),(menuW, menuH),"graphics/ZForms/PlayerInvMenuPanel.png", ZFImage.AlignType_Center); |
| 23 | + background.Pack(mainFrame); // Add the image element into the main frame. |
| 24 | + |
| 25 | + let TitleLabel = ZFLabel.Create( (0, 30), (menuW - menuW/10, smallFont.GetHeight() * 2), |
| 26 | + text: "ARTIFACTS", |
| 27 | + fnt: smallFont, Alignment: AlignType_HCenter, wrap: true, autoSize: true, textScale: 2., textColor: Font.CR_WHITE); |
| 28 | + TitleLabel.Pack(mainFrame); |
| 29 | + |
| 30 | + let equippedLabel = ZFLabel.Create( (0, 125), (menuW/3, smallFont.GetHeight() * 2), |
| 31 | + text: "Equipped:", |
| 32 | + fnt: smallFont, Alignment: 2, wrap: true, autoSize: true, textScale: 2., textColor: Font.CR_WHITE); |
| 33 | + equippedLabel.Pack(mainFrame); |
| 34 | + |
| 35 | + let plr = RwPlayer(players[consoleplayer].mo); |
| 36 | + currentHeight = 160; |
| 37 | + // Weapon in hands: |
| 38 | + if (RandomizedWeapon(players[consoleplayer].ReadyWeapon)) { |
| 39 | + addArtifactButton(RandomizedWeapon(players[consoleplayer].ReadyWeapon)); |
| 40 | + } |
| 41 | + // Armor |
| 42 | + if (plr.CurrentEquippedArmor) { |
| 43 | + addArtifactButton(plr.CurrentEquippedArmor); |
| 44 | + } |
| 45 | + // Backpack: |
| 46 | + if (plr.CurrentEquippedBackpack) { |
| 47 | + addArtifactButton(plr.CurrentEquippedBackpack); |
| 48 | + } |
| 49 | + |
| 50 | + // for (let sid = 0; sid < RwPlayerStats.totalStatsCount; sid++) { |
| 51 | + // addLevelUpButton(sid); |
| 52 | + // } |
| 53 | + } |
| 54 | + |
| 55 | + override void Ticker() { |
| 56 | + super.Ticker(); |
| 57 | + } |
| 58 | + |
| 59 | + int currentHeight; |
| 60 | + const buttonMargin = 6; |
| 61 | + private void addArtifactButton(Inventory itm) { |
| 62 | + let newButton = ArtifactButton.Make(handler, 150, currentHeight, itm); |
| 63 | + currentHeight += newButton.box.size.y + buttonMargin; |
| 64 | + // Add the button element into the main frame. |
| 65 | + artifactButtons.Push(newButton); |
| 66 | + newButton.Pack(mainFrame); |
| 67 | + } |
| 68 | + |
| 69 | + void clearDescriptionLabels() { |
| 70 | + for (let i = 0; i < DescriptionLabels.Size(); i++) { |
| 71 | + DescriptionLabels[i].Unpack(); |
| 72 | + } |
| 73 | + currLabelLine = 0; |
| 74 | + DescriptionLabels.Resize(0); |
| 75 | + } |
| 76 | + |
| 77 | + void pushSeparator() { |
| 78 | + pushDescription("-----------------------------------", Font.CR_DARKGRAY); |
| 79 | + } |
| 80 | + |
| 81 | + const descrCenterX = 360; |
| 82 | + void pushDescription(string text, int color, double scale = 1., int alignment = AlignType_HCenter) { |
| 83 | + let lbl = ZFLabel.Create( |
| 84 | + (descrCenterX, 100 + (descrFont.GetHeight() + 3) * currLabelLine), (570, descrFont.GetHeight() + 4), |
| 85 | + text: text, // will be overwritten |
| 86 | + fnt: descrFont, Alignment: alignment, wrap: false, autoSize: false, textScale: scale, textColor: color); |
| 87 | + DescriptionLabels.Push(lbl); |
| 88 | + lbl.Pack(mainFrame); |
| 89 | + currLabelLine++; |
| 90 | + } |
| 91 | + |
| 92 | + const rightColumnOffset = 100; |
| 93 | + void pushTwoColumnsDescription(string textLeft, string textRight, int color) { |
| 94 | + let yCoord = 100 + (descrFont.GetHeight() + 3) * currLabelLine; |
| 95 | + let leftWidth = 280; |
| 96 | + let lbl = ZFLabel.Create( |
| 97 | + (descrCenterX+rightColumnOffset, yCoord), (leftWidth, descrFont.GetHeight() + 4), |
| 98 | + text: textLeft, // will be overwritten |
| 99 | + fnt: descrFont, Alignment: AlignType_CenterLeft, wrap: false, autoSize: false, textScale: 1., textColor: color); |
| 100 | + DescriptionLabels.Push(lbl); |
| 101 | + lbl.Pack(mainFrame); |
| 102 | + lbl = ZFLabel.Create( |
| 103 | + (descrCenterX+rightColumnOffset+leftWidth, yCoord), (250, descrFont.GetHeight() + 4), |
| 104 | + text: textRight, // will be overwritten |
| 105 | + fnt: descrFont, Alignment: AlignType_CenterLeft, wrap: false, autoSize: false, textScale: 1., textColor: color); |
| 106 | + DescriptionLabels.Push(lbl); |
| 107 | + lbl.Pack(mainFrame); |
| 108 | + currLabelLine++; |
| 109 | + } |
| 110 | + |
| 111 | + enum AlignType { |
| 112 | + AlignType_Left = 1, |
| 113 | + AlignType_HCenter = 2, |
| 114 | + AlignType_Right = 3, |
| 115 | + |
| 116 | + AlignType_Top = 1 << 4, |
| 117 | + AlignType_VCenter = 2 << 4, |
| 118 | + AlignType_Bottom = 3 << 4, |
| 119 | + |
| 120 | + AlignType_TopLeft = AlignType_Top | AlignType_Left, |
| 121 | + AlignType_TopCenter = AlignType_Top | AlignType_HCenter, |
| 122 | + AlignType_TopRight = AlignType_Top | AlignType_Right, |
| 123 | + |
| 124 | + AlignType_CenterLeft = AlignType_VCenter | AlignType_Left, |
| 125 | + AlignType_Center = AlignType_VCenter | AlignType_HCenter, |
| 126 | + AlignType_CenterRight = AlignType_VCenter | AlignType_Right, |
| 127 | + |
| 128 | + AlignType_BottomLeft = AlignType_Bottom | AlignType_Left, |
| 129 | + AlignType_BottomCenter = AlignType_Bottom | AlignType_HCenter, |
| 130 | + AlignType_BottomRight = AlignType_Bottom | AlignType_Right, |
| 131 | + } |
| 132 | +} |
0 commit comments