Skip to content

Commit 99df009

Browse files
committed
WIP on items menu.
1 parent 4ae5381 commit 99df009

File tree

7 files changed

+268
-3
lines changed

7 files changed

+268
-3
lines changed

credits/minecraftia_font/CREDITS.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Submitted: Jimmy
2+
Author: Jimmy, Andrew Tyler of textcraft.net, Mojang
3+
Original font: Minecraft's in-game font
72.7 KB
Loading

mdesfont.lmp

9.27 KB
Binary file not shown.

zscript.zsc

+7-3
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,18 @@ version "4.10.0"
7171
#include "zscript/player/player_item_pickup.zs"
7272
#include "zscript/player/press_to_pickup_handler.zs"
7373
#include "zscript/player/scrap_item.zs"
74-
#include "zscript/player/menus/levelup_menu/levelup_button.zs"
75-
#include "zscript/player/menus/levelup_menu/handler.zs"
76-
#include "zscript/player/menus/levelup_menu/menu.zs"
7774
#include "zscript/player/player_stats/player_stats.zs"
7875
#include "zscript/player/player_stats/experience.zs"
7976
#include "zscript/player/player_stats/stats_effects.zs"
8077
#include "zscript/player/player_stats/stats_increase.zs"
8178
#include "zscript/player/player_stats/stats_strings.zs"
79+
// Player menus
80+
#include "zscript/player/menus/artifacts_menu/artifact_button.zs"
81+
#include "zscript/player/menus/artifacts_menu/handler.zs"
82+
#include "zscript/player/menus/artifacts_menu/menu.zs"
83+
#include "zscript/player/menus/levelup_menu/levelup_button.zs"
84+
#include "zscript/player/menus/levelup_menu/handler.zs"
85+
#include "zscript/player/menus/levelup_menu/menu.zs"
8286

8387
#include "zscript/rarmor/ablue.zs"
8488
#include "zscript/rarmor/aenergy.zs"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
class ArtifactButton : ZFButton {
2+
3+
int drawnButtonW, drawnButtonH;
4+
Inventory artifact;
5+
6+
static ArtifactButton Make(ZFHandler handler, int x, int y, Inventory itm) {
7+
// Textures for the button
8+
ZFBoxTextures buttonIdle, buttonHover, buttonClick;
9+
if (itm) {
10+
buttonIdle = ZFBoxTextures.CreateSingleTexture(GetItemSpriteAsTextureName(itm), true); // ZFBoxTextures.CreateSingleTexture("graphics/ZForms/SmallButtonIdle.png", true);
11+
buttonHover = ZFBoxTextures.CreateSingleTexture(GetItemSpriteAsTextureName(itm), true);
12+
buttonClick = ZFBoxTextures.CreateSingleTexture(GetItemSpriteAsTextureName(itm), true);
13+
}
14+
15+
let newButton = new('ArtifactButton');
16+
[newButton.drawnButtonW, newButton.drawnButtonH] = GetItemSpriteSize(itm);
17+
newButton.drawnButtonW *= 2;
18+
newButton.drawnButtonH *= 2;
19+
newButton.config("", handler, '', buttonIdle, buttonHover, buttonClick, holdInterval: TICRATE/3);
20+
// Real width is the width of the drawn button plus the width of the text.
21+
x -= newButton.drawnButtonW/2;
22+
newButton.setBox((x, y), (newButton.drawnButtonW + 5 + newButton.fnt.StringWidth(newButton.text), newButton.drawnButtonH));
23+
newButton.artifact = itm;
24+
return newButton;
25+
}
26+
27+
override void drawer() {
28+
ZFBoxTextures textures = textures[curButtonState];
29+
// Notice: overriding drawn button width here
30+
if (artifact) {
31+
drawBox((0, 0), (drawnButtonW, box.size.y), textures, true);
32+
}
33+
textColor = Font.CR_GOLD;
34+
}
35+
36+
string getDescription() {
37+
return "";
38+
}
39+
40+
static string GetItemSpriteAsTextureName(Inventory item) {
41+
return TexMan.GetName(item.SpawnState.GetSpriteTexture(0));
42+
}
43+
44+
static int, int GetItemSpriteSize(Inventory item) {
45+
int w, h;
46+
[w, h] = TexMan.GetSize(item.SpawnState.GetSpriteTexture(0));
47+
return w, h;
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
class ArtifactsMenuHandler : ZFHandler
2+
{
3+
// The menu this command handler belongs to.
4+
// We need this to be able to do anything with our menu.
5+
RWArtifactsMenu link;
6+
RwHudArtifactStatsCollector collector;
7+
8+
override void buttonClickCommand(ZFButton caller, string command) {
9+
let aBtn = artifactButton(caller);
10+
if (aBtn && aBtn.artifact) {
11+
collector.CollectStatsFromAffixableItem(aBtn.artifact, null);
12+
if (RandomizedWeapon(aBtn.artifact)) {
13+
setDescriptionForWeapon(RandomizedWeapon(aBtn.artifact));
14+
} else if (RandomizedArmor(aBtn.artifact)) {
15+
setDescriptionForArmor(RandomizedArmor(aBtn.artifact));
16+
} else if (RwBackpack(aBtn.artifact)) {
17+
setDescriptionForBackpack(RwBackpack(aBtn.artifact));
18+
}
19+
}
20+
}
21+
22+
override void elementHoverChanged(ZFElement caller, string command, bool unhovered) {
23+
if (LevelUpButton(caller)) {
24+
}
25+
}
26+
27+
void pushAllCollectorLines() {
28+
for (let i = 0; i < collector.statLines.Size(); i++) {
29+
let line = collector.statLines[i];
30+
if (line.isSeparator) {
31+
link.pushSeparator();
32+
continue;
33+
}
34+
if (line.rightLabel.Length() > 0) {
35+
link.pushTwoColumnsDescription(line.mainLabel, line.rightLabel, line.mainColor);
36+
continue;
37+
}
38+
link.pushDescription(line.mainLabel, line.mainColor, 0.75);
39+
}
40+
}
41+
42+
void setDescriptionForWeapon(RandomizedWeapon wpn) {
43+
link.clearDescriptionLabels();
44+
// MyCustomHUD.PickColorForAffixableItem()
45+
link.pushDescription(wpn.nameWithAppliedAffixes,
46+
MyCustomHUD.PickColorForAffixableItem(wpn), 1.25);
47+
link.pushDescription("Level "..wpn.generatedQuality.." "..MyCustomHUD.getRarityName(wpn.appliedAffixes.Size()).." "..wpn.rwbaseName,
48+
MyCustomHUD.PickColorForAffixableItem(wpn), 0.75);
49+
50+
link.pushSeparator();
51+
pushAllCollectorLines();
52+
}
53+
54+
void setDescriptionForArmor(RandomizedArmor armr) {
55+
link.clearDescriptionLabels();
56+
// MyCustomHUD.PickColorForAffixableItem()
57+
link.pushDescription(armr.nameWithAppliedAffixes,
58+
MyCustomHUD.PickColorForAffixableItem(armr), 1.25);
59+
link.pushDescription("Level "..armr.generatedQuality.." "..MyCustomHUD.getRarityName(armr.appliedAffixes.Size()).." "..armr.rwbaseName,
60+
MyCustomHUD.PickColorForAffixableItem(armr), 0.75);
61+
62+
link.pushSeparator();
63+
pushAllCollectorLines();
64+
}
65+
66+
void setDescriptionForBackpack(RwBackpack bkpk) {
67+
link.clearDescriptionLabels();
68+
// MyCustomHUD.PickColorForAffixableItem()
69+
link.pushDescription(bkpk.nameWithAppliedAffixes,
70+
MyCustomHUD.PickColorForAffixableItem(bkpk), 1.25);
71+
link.pushDescription("Level "..bkpk.generatedQuality.." "..MyCustomHUD.getRarityName(bkpk.appliedAffixes.Size()).." "..bkpk.rwbaseName,
72+
MyCustomHUD.PickColorForAffixableItem(bkpk), 0.75);
73+
74+
link.pushSeparator();
75+
pushAllCollectorLines();
76+
}
77+
}
+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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

Comments
 (0)