kokars
kokars
CC#
Created by kokars on 5/24/2023 in #help
❔ List string variables
Hello, I'm really new to C# and would like to get help. How is the correct way to give variable for each case name? So it would display like - "WOOD x1" "STONE x2" etc... My code is below. This is for Rust game plugin.
private void CreateButtons(BasePlayer player, BaseContainer parent, BuildingPrivlidge tc)
{
// Title
TextContainer.Create(parent, Anchor.TopLeft, new Offset(60f, -50f, 210f, -3f))
.WithSize(15)
.WithText("BASE UPGRADE")
.WithOutline(m_OutlineWhite);


List<string> u_ButtonNames = new List<string> { "WOOD " + "(resource)", "STONE " + "(resource)", "METAL " + "(resource)", "HQM " + "(resource)" };

// Button Container
ImageContainer.Create(parent, Anchor.FullStretch, new Offset(5f, 5f, -5f, -25f))
.WithStyle(m_PanelStyle)
.WithLayoutGroup(u_ButtonLayout, u_ButtonNames, 0, (int i, string t, BaseContainer buttons, Anchor anchor, Offset offset) =>
{
ImageContainer.Create(buttons, anchor, offset)
.WithStyle(m_ButtonStyle)
.WithChildren(header =>
{
TextContainer.Create(header, Anchor.FullStretch, Offset.zero)
.WithText(t)
.WithAlignment(TextAnchor.MiddleCenter);

ButtonContainer.Create(header, Anchor.FullStretch, Offset.zero)
.WithColor(Color.Clear)
.WithCallback(m_CallbackHandler, arg =>
{
switch (t)
{
case "WOOD": rust.RunClientCommand(player, "chat.say", "/up 1"); break;
case "STONE": rust.RunClientCommand(player, "chat.say", "/up 2"); break;
case "METAL": rust.RunClientCommand(player, "chat.say", "/up 3"); break;
case "HQM": rust.RunClientCommand(player, "chat.say", "/up 4"); break;
}
}, $"{player.UserIDString}.{t}");
});
});
}
private void CreateButtons(BasePlayer player, BaseContainer parent, BuildingPrivlidge tc)
{
// Title
TextContainer.Create(parent, Anchor.TopLeft, new Offset(60f, -50f, 210f, -3f))
.WithSize(15)
.WithText("BASE UPGRADE")
.WithOutline(m_OutlineWhite);


List<string> u_ButtonNames = new List<string> { "WOOD " + "(resource)", "STONE " + "(resource)", "METAL " + "(resource)", "HQM " + "(resource)" };

// Button Container
ImageContainer.Create(parent, Anchor.FullStretch, new Offset(5f, 5f, -5f, -25f))
.WithStyle(m_PanelStyle)
.WithLayoutGroup(u_ButtonLayout, u_ButtonNames, 0, (int i, string t, BaseContainer buttons, Anchor anchor, Offset offset) =>
{
ImageContainer.Create(buttons, anchor, offset)
.WithStyle(m_ButtonStyle)
.WithChildren(header =>
{
TextContainer.Create(header, Anchor.FullStretch, Offset.zero)
.WithText(t)
.WithAlignment(TextAnchor.MiddleCenter);

ButtonContainer.Create(header, Anchor.FullStretch, Offset.zero)
.WithColor(Color.Clear)
.WithCallback(m_CallbackHandler, arg =>
{
switch (t)
{
case "WOOD": rust.RunClientCommand(player, "chat.say", "/up 1"); break;
case "STONE": rust.RunClientCommand(player, "chat.say", "/up 2"); break;
case "METAL": rust.RunClientCommand(player, "chat.say", "/up 3"); break;
case "HQM": rust.RunClientCommand(player, "chat.say", "/up 4"); break;
}
}, $"{player.UserIDString}.{t}");
});
});
}
250 replies