Skip to content

Commit 6832b89

Browse files
committed
1.2.6-pre.1²
1 parent ab35720 commit 6832b89

File tree

12 files changed

+101
-103
lines changed

12 files changed

+101
-103
lines changed

LevelUP/Client/CharacterView.cs

Lines changed: 101 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
using System;
12
using System.Threading.Tasks;
23
using Vintagestory.API.Client;
34
using Vintagestory.API.Common;
5+
using Vintagestory.API.Config;
46

57
namespace LevelUP.Client;
68

@@ -9,7 +11,7 @@ class CharacterView
911
Instance instance;
1012

1113
GuiDialogCharacterBase characterView;
12-
private GuiComposer levelTabComposer;
14+
private GuiElementContainer levelContainer;
1315

1416
byte page = 0;
1517

@@ -35,99 +37,109 @@ public void Init(Instance _instance)
3537

3638
private void ComposeLevelTab(GuiComposer composer)
3739
{
38-
switch (page)
39-
{
40-
case 0: ComposeFirstPage(composer); break;
40+
// Bounds instanciation
41+
ElementBounds insetBounds;
42+
ElementBounds leftColumn = ElementBounds.Fixed(0.0, 0.0, 300.0, 30.0);
43+
ElementBounds clippingBounds;
44+
ElementBounds listBounds;
45+
ElementBounds containerBounds = ElementBounds.Fixed(0.0, 10.0, 82.0, 82);
46+
containerBounds = containerBounds.FlatCopy();
47+
double insetWidth = Math.Max(350.0, 350 * 0.5);
48+
double insetHeight = Math.Max(325.0, 425 - 160.0);
4149

42-
case 1: break;
43-
}
44-
composer.AddButton("Back", OnBackClicked, ElementBounds.Fixed(0.0, 300.0, 20.0, 15.0));
45-
composer.AddButton("Next", OnNextClicked, ElementBounds.Fixed(310.0, 300.0, 30.0, 15.0));
46-
47-
levelTabComposer = composer;
48-
// #region 3
49-
// // Leather Armor
50-
// composer.AddImage(ElementBounds.Fixed(0.0, 225.0, 385.0, 200.0), new AssetLocation("levelup:unknown.png"));
51-
// composer.AddRichtext(
52-
// $"{Lang.Get("levelup:leather_armor")}: {GetLevelByLevelName("LeatherArmor")}",
53-
// CairoFont.WhiteDetailText().WithLineHeightMultiplier(1.15),
54-
// ElementBounds.Fixed(0.0, 300.0, 385.0, 200.0)
55-
// );
56-
// // Chain Armor
57-
// composer.AddImage(ElementBounds.Fixed(100.0, 225.0, 385.0, 200.0), new AssetLocation("levelup:unknown.png"));
58-
// composer.AddRichtext(
59-
// $"{Lang.Get("levelup:chain_armor")}: {GetLevelByLevelName("ChainArmor")}",
60-
// CairoFont.WhiteDetailText().WithLineHeightMultiplier(1.15),
61-
// ElementBounds.Fixed(100.0, 300.0, 385.0, 200.0)
62-
// );
63-
// // Hunter
64-
// composer.AddImage(ElementBounds.Fixed(200.0, 225.0, 385.0, 200.0), new AssetLocation("levelup:unknown.png"));
65-
// composer.AddRichtext(
66-
// $"{Lang.Get("levelup:hunter")}: {GetLevelByLevelName("Hunter")}",
67-
// CairoFont.WhiteDetailText().WithLineHeightMultiplier(1.15),
68-
// ElementBounds.Fixed(200.0, 300.0, 385.0, 200.0)
69-
// );
70-
// // Farming
71-
// composer.AddImage(ElementBounds.Fixed(300.0, 225.0, 385.0, 200.0), new AssetLocation("levelup:unknown.png"));
72-
// composer.AddRichtext(
73-
// $"{Lang.Get("levelup:farming")}: {GetLevelByLevelName("Farming")}",
74-
// CairoFont.WhiteDetailText().WithLineHeightMultiplier(1.15),
75-
// ElementBounds.Fixed(300.0, 300.0, 385.0, 200.0)
76-
// );
77-
// #endregion
78-
// #region 4
79-
// // Cooking
80-
// composer.AddImage(ElementBounds.Fixed(0.0, 325.0, 385.0, 200.0), new AssetLocation("levelup:unknown.png"));
81-
// composer.AddRichtext(
82-
// $"{Lang.Get("levelup:cooking")}: {GetLevelByLevelName("Cooking")}",
83-
// CairoFont.WhiteDetailText().WithLineHeightMultiplier(1.15),
84-
// ElementBounds.Fixed(0.0, 400.0, 385.0, 200.0)
85-
// );
86-
// // Vitality
87-
// composer.AddImage(ElementBounds.Fixed(100.0, 325.0, 385.0, 200.0), new AssetLocation("levelup:unknown.png"));
88-
// composer.AddRichtext(
89-
// $"{Lang.Get("levelup:vitality")}: {GetLevelByLevelName("Vitality")}",
90-
// CairoFont.WhiteDetailText().WithLineHeightMultiplier(1.15),
91-
// ElementBounds.Fixed(100.0, 400.0, 385.0, 200.0)
92-
// );
93-
// #endregion
94-
}
50+
// Creating the dark background
51+
composer.AddInset(insetBounds = leftColumn.BelowCopy(0.0, -3.0).WithFixedSize(insetWidth, insetHeight - leftColumn.fixedY - leftColumn.fixedHeight));
52+
// Adding a scrollbar to it in the left side
53+
composer.AddVerticalScrollbar(OnNewScrollbarValue, ElementStdBounds.VerticalScrollbar(insetBounds), "LevelUP_Scrollbar");
54+
// Creating the Clip for the Scrollbar
55+
composer.BeginClip(clippingBounds = insetBounds.ForkContainingChild(10.0, 0.0, 10.0, 10.0));
56+
// Creating the container to add items in clip
57+
composer.AddContainer(listBounds = clippingBounds.ForkContainingChild(10.0, 10.0, 10.0, 10.0), "LevelUP_Levels_List");
58+
levelContainer = composer.GetContainer("LevelUP_Levels_List");
9559

96-
private void ComposeFirstPage(GuiComposer composer)
97-
{
98-
#region 1
99-
// Axe
100-
composer.AddImage(ElementBounds.Fixed(0.0, 25.0, 385.0, 200.0), new AssetLocation("levelup:axe.png"));
101-
SetComposerLevel(composer, ElementBounds.Fixed(0.0, 25.0, 385.0, 200.0), GetLevelByLevelName("Axe"));
102-
// Pickaxe
103-
composer.AddImage(ElementBounds.Fixed(150.0, 25.0, 385.0, 200.0), new AssetLocation("levelup:pickaxe.png"));
104-
SetComposerLevel(composer, ElementBounds.Fixed(150.0, 25.0, 385.0, 200.0), GetLevelByLevelName("Pickaxe"));
105-
// Shovel
106-
composer.AddImage(ElementBounds.Fixed(300.0, 25.0, 385.0, 200.0), new AssetLocation("levelup:shovel.png"));
107-
SetComposerLevel(composer, ElementBounds.Fixed(300.0, 25.0, 385.0, 200.0), GetLevelByLevelName("Shovel"));
60+
// Adding the levels images and texts
61+
#region axe
62+
levelContainer.Add(new GuiElementImage(instance.api, containerBounds, new AssetLocation("levelup:axe.png")));
63+
levelContainer.Add(new GuiElementStaticText(instance.api, $"{Lang.Get("levelup:axe")}: {GetLevelByLevelName("Axe")}", EnumTextOrientation.Left, containerBounds.RightCopy().ForkChildOffseted(0, 25, 500, 0), CairoFont.WhiteSmallText()));
64+
#endregion
65+
66+
#region pickaxe
67+
levelContainer.Add(new GuiElementImage(instance.api, containerBounds = containerBounds.BelowCopy(), new AssetLocation("levelup:pickaxe.png")));
68+
levelContainer.Add(new GuiElementStaticText(instance.api, $"{Lang.Get("levelup:pickaxe")}: {GetLevelByLevelName("Pickaxe")}", EnumTextOrientation.Left, containerBounds.RightCopy().ForkChildOffseted(0, 25, 500, 0), CairoFont.WhiteSmallText()));
69+
#endregion
70+
71+
#region shovel
72+
levelContainer.Add(new GuiElementImage(instance.api, containerBounds = containerBounds.BelowCopy(), new AssetLocation("levelup:shovel.png")));
73+
levelContainer.Add(new GuiElementStaticText(instance.api, $"{Lang.Get("levelup:shovel")}: {GetLevelByLevelName("Shovel")}", EnumTextOrientation.Left, containerBounds.RightCopy().ForkChildOffseted(0, 25, 500, 0), CairoFont.WhiteSmallText()));
74+
#endregion
75+
76+
#region knife
77+
levelContainer.Add(new GuiElementImage(instance.api, containerBounds = containerBounds.BelowCopy(), new AssetLocation("levelup:knife.png")));
78+
levelContainer.Add(new GuiElementStaticText(instance.api, $"{Lang.Get("levelup:knife")}: {GetLevelByLevelName("Knife")}", EnumTextOrientation.Left, containerBounds.RightCopy().ForkChildOffseted(0, 25, 500, 0), CairoFont.WhiteSmallText()));
79+
#endregion
80+
81+
#region bow
82+
levelContainer.Add(new GuiElementImage(instance.api, containerBounds = containerBounds.BelowCopy(), new AssetLocation("levelup:bow.png")));
83+
levelContainer.Add(new GuiElementStaticText(instance.api, $"{Lang.Get("levelup:bow")}: {GetLevelByLevelName("Bow")}", EnumTextOrientation.Left, containerBounds.RightCopy().ForkChildOffseted(0, 25, 500, 0), CairoFont.WhiteSmallText()));
84+
#endregion
85+
86+
#region spear
87+
levelContainer.Add(new GuiElementImage(instance.api, containerBounds = containerBounds.BelowCopy(), new AssetLocation("levelup:spear.png")));
88+
levelContainer.Add(new GuiElementStaticText(instance.api, $"{Lang.Get("levelup:spear")}: {GetLevelByLevelName("Spear")}", EnumTextOrientation.Left, containerBounds.RightCopy().ForkChildOffseted(0, 25, 500, 0), CairoFont.WhiteSmallText()));
89+
#endregion
90+
91+
#region hammer
92+
levelContainer.Add(new GuiElementImage(instance.api, containerBounds = containerBounds.BelowCopy(), new AssetLocation("levelup:hammer.png")));
93+
levelContainer.Add(new GuiElementStaticText(instance.api, $"{Lang.Get("levelup:hammer")}: {GetLevelByLevelName("Hammer")}", EnumTextOrientation.Left, containerBounds.RightCopy().ForkChildOffseted(0, 25, 500, 0), CairoFont.WhiteSmallText()));
94+
#endregion
95+
96+
#region sword
97+
levelContainer.Add(new GuiElementImage(instance.api, containerBounds = containerBounds.BelowCopy(), new AssetLocation("levelup:sword.png")));
98+
levelContainer.Add(new GuiElementStaticText(instance.api, $"{Lang.Get("levelup:sword")}: {GetLevelByLevelName("Sword")}", EnumTextOrientation.Left, containerBounds.RightCopy().ForkChildOffseted(0, 25, 500, 0), CairoFont.WhiteSmallText()));
99+
#endregion
100+
101+
#region shield
102+
levelContainer.Add(new GuiElementImage(instance.api, containerBounds = containerBounds.BelowCopy(), new AssetLocation("levelup:shield.png")));
103+
levelContainer.Add(new GuiElementStaticText(instance.api, $"{Lang.Get("levelup:shield")}: {GetLevelByLevelName("Shield")}", EnumTextOrientation.Left, containerBounds.RightCopy().ForkChildOffseted(0, 25, 500, 0), CairoFont.WhiteSmallText()));
104+
#endregion
105+
106+
#region farming
107+
levelContainer.Add(new GuiElementImage(instance.api, containerBounds = containerBounds.BelowCopy(), new AssetLocation("levelup:farming.png")));
108+
levelContainer.Add(new GuiElementStaticText(instance.api, $"{Lang.Get("levelup:farming")}: {GetLevelByLevelName("Farming")}", EnumTextOrientation.Left, containerBounds.RightCopy().ForkChildOffseted(0, 25, 500, 0), CairoFont.WhiteSmallText()));
109+
#endregion
110+
111+
#region cooking
112+
levelContainer.Add(new GuiElementImage(instance.api, containerBounds = containerBounds.BelowCopy(), new AssetLocation("levelup:cooking.png")));
113+
levelContainer.Add(new GuiElementStaticText(instance.api, $"{Lang.Get("levelup:cooking")}: {GetLevelByLevelName("Cooking")}", EnumTextOrientation.Left, containerBounds.RightCopy().ForkChildOffseted(0, 25, 500, 0), CairoFont.WhiteSmallText()));
108114
#endregion
109-
#region 2
110-
// Knife
111-
composer.AddImage(ElementBounds.Fixed(0.0, 125.0, 385.0, 200.0), new AssetLocation("levelup:unknown.png"));
112-
SetComposerLevel(composer, ElementBounds.Fixed(0.0, 125.0, 385.0, 200.0), GetLevelByLevelName("Knife"));
113-
// Bow
114-
composer.AddImage(ElementBounds.Fixed(150.0, 125.0, 385.0, 200.0), new AssetLocation("levelup:unknown.png"));
115-
SetComposerLevel(composer, ElementBounds.Fixed(150.0, 125.0, 385.0, 200.0), GetLevelByLevelName("Bow"));
116-
// Spear
117-
composer.AddImage(ElementBounds.Fixed(300.0, 125.0, 385.0, 200.0), new AssetLocation("levelup:unknown.png"));
118-
SetComposerLevel(composer, ElementBounds.Fixed(300.0, 125.0, 385.0, 200.0), GetLevelByLevelName("Spear"));
115+
116+
#region vitality
117+
levelContainer.Add(new GuiElementImage(instance.api, containerBounds = containerBounds.BelowCopy(), new AssetLocation("levelup:vitality.png")));
118+
levelContainer.Add(new GuiElementStaticText(instance.api, $"{Lang.Get("levelup:vitality")}: {GetLevelByLevelName("Vitality")}", EnumTextOrientation.Left, containerBounds.RightCopy().ForkChildOffseted(0, 25, 500, 0), CairoFont.WhiteSmallText()));
119119
#endregion
120-
#region 3
121-
// Hammer
122-
composer.AddImage(ElementBounds.Fixed(0.0, 225.0, 385.0, 200.0), new AssetLocation("levelup:unknown.png"));
123-
SetComposerLevel(composer, ElementBounds.Fixed(0.0, 225.0, 385.0, 200.0), GetLevelByLevelName("Hammer"));
124-
// Sword
125-
composer.AddImage(ElementBounds.Fixed(150.0, 225.0, 385.0, 200.0), new AssetLocation("levelup:unknown.png"));
126-
SetComposerLevel(composer, ElementBounds.Fixed(150.0, 225.0, 385.0, 200.0), GetLevelByLevelName("Sword"));
127-
// Shield
128-
composer.AddImage(ElementBounds.Fixed(300.0, 225.0, 385.0, 200.0), new AssetLocation("levelup:unknown.png"));
129-
SetComposerLevel(composer, ElementBounds.Fixed(300.0, 225.0, 385.0, 200.0), GetLevelByLevelName("Shield"));
120+
121+
#region leatherarmor
122+
levelContainer.Add(new GuiElementImage(instance.api, containerBounds = containerBounds.BelowCopy(), new AssetLocation("levelup:leather_armor.png")));
123+
levelContainer.Add(new GuiElementStaticText(instance.api, $"{Lang.Get("levelup:leather_armor")}: {GetLevelByLevelName("LeatherArmor")}", EnumTextOrientation.Left, containerBounds.RightCopy().ForkChildOffseted(0, 25, 500, 0), CairoFont.WhiteSmallText()));
130124
#endregion
125+
126+
#region chainarmor
127+
levelContainer.Add(new GuiElementImage(instance.api, containerBounds = containerBounds.BelowCopy(), new AssetLocation("levelup:chain_armor.png")));
128+
levelContainer.Add(new GuiElementStaticText(instance.api, $"{Lang.Get("levelup:chain_armor")}: {GetLevelByLevelName("ChainArmor")}", EnumTextOrientation.Left, containerBounds.RightCopy().ForkChildOffseted(0, 25, 500, 0), CairoFont.WhiteSmallText()));
129+
#endregion
130+
131+
// Finishing Clip for scrollbar
132+
composer.EndClip();
133+
134+
// Adding the size of scroll button
135+
GuiElementScrollbar scrollBar = composer.GetScrollbar("LevelUP_Scrollbar");
136+
scrollBar.SetHeights((float)containerBounds.fixedHeight, (float)(clippingBounds.fixedHeight * 3.5));
137+
}
138+
139+
private void OnNewScrollbarValue(float value)
140+
{
141+
levelContainer.Bounds.fixedY = 0f - value;
142+
levelContainer.Bounds.CalcWorldBounds();
131143
}
132144

133145
private int GetLevelByLevelName(string levelName) => instance.api.World.Player.Entity.WatchedAttributes.GetInt($"LevelUP_Level_{levelName}");
@@ -166,18 +178,4 @@ private static void SetComposerLevel(GuiComposer composer, ElementBounds positio
166178

167179
Debug.Log("Ops, you reached the gui limit :P ");
168180
}
169-
170-
private bool OnBackClicked()
171-
{
172-
page--;
173-
if (page < 0) page = 0;
174-
return true;
175-
}
176-
177-
private bool OnNextClicked()
178-
{
179-
page++;
180-
if (page > 1) page = 1;
181-
return true;
182-
}
183181
}
1009 Bytes
Loading
1009 Bytes
Loading
1009 Bytes
Loading
1009 Bytes
Loading
1009 Bytes
Loading
1009 Bytes
Loading
1009 Bytes
Loading
1009 Bytes
Loading
1009 Bytes
Loading
1009 Bytes
Loading
1009 Bytes
Loading

0 commit comments

Comments
 (0)