1
- using System . Text ;
2
1
using System . Threading . Tasks ;
3
2
using Vintagestory . API . Client ;
4
- using Vintagestory . API . Config ;
3
+ using Vintagestory . API . Common ;
5
4
6
5
namespace LevelUP . Client ;
7
6
@@ -10,6 +9,9 @@ class CharacterView
10
9
Instance instance ;
11
10
12
11
GuiDialogCharacterBase characterView ;
12
+ private GuiComposer levelTabComposer ;
13
+
14
+ byte page = 0 ;
13
15
14
16
public void Init ( Instance _instance )
15
17
{
@@ -31,45 +33,151 @@ public void Init(Instance _instance)
31
33
} ) ;
32
34
}
33
35
34
- // Compose the gui page for the level tab
35
36
private void ComposeLevelTab ( GuiComposer composer )
36
37
{
37
- composer . AddRichtext ( GetText ( ) , CairoFont . WhiteDetailText ( ) . WithLineHeightMultiplier ( 1.15 ) , ElementBounds . Fixed ( 0.0 , 25.0 , 385.0 , 200.0 ) ) ;
38
+ switch ( page )
39
+ {
40
+ case 0 : ComposeFirstPage ( composer ) ; break ;
41
+
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
+ }
95
+
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" ) ) ;
108
+ #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" ) ) ;
119
+ #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" ) ) ;
130
+ #endregion
38
131
}
39
132
40
- // Creates the full text for level tab
41
- private string GetText ( )
133
+ private int GetLevelByLevelName ( string levelName ) => instance . api . World . Player . Entity . WatchedAttributes . GetInt ( $ "LevelUP_Level_{ levelName } ") ;
134
+
135
+ private static void SetComposerLevel ( GuiComposer composer , ElementBounds position , int level )
42
136
{
43
- int hunterLevel = instance . api . World . Player . Entity . WatchedAttributes . GetInt ( "LevelUP_Level_Hunter" ) ;
44
- int bowLevel = instance . api . World . Player . Entity . WatchedAttributes . GetInt ( "LevelUP_Level_Bow" ) ;
45
- int knifeLevel = instance . api . World . Player . Entity . WatchedAttributes . GetInt ( "LevelUP_Level_Knife" ) ;
46
- int spearLevel = instance . api . World . Player . Entity . WatchedAttributes . GetInt ( "LevelUP_Level_Spear" ) ;
47
- int axeLevel = instance . api . World . Player . Entity . WatchedAttributes . GetInt ( "LevelUP_Level_Axe" ) ;
48
- int pickaxeLevel = instance . api . World . Player . Entity . WatchedAttributes . GetInt ( "LevelUP_Level_Pickaxe" ) ;
49
- int shovelLevel = instance . api . World . Player . Entity . WatchedAttributes . GetInt ( "LevelUP_Level_Shovel" ) ;
50
- int hammerLevel = instance . api . World . Player . Entity . WatchedAttributes . GetInt ( "LevelUP_Level_Hammer" ) ;
51
- int swordLevel = instance . api . World . Player . Entity . WatchedAttributes . GetInt ( "LevelUP_Level_Sword" ) ;
52
- int shieldLevel = instance . api . World . Player . Entity . WatchedAttributes . GetInt ( "LevelUP_Level_Shield" ) ;
53
- int farmingLevel = instance . api . World . Player . Entity . WatchedAttributes . GetInt ( "LevelUP_Level_Farming" ) ;
54
- int cookingLevel = instance . api . World . Player . Entity . WatchedAttributes . GetInt ( "LevelUP_Level_Cooking" ) ;
55
- int vitalityLevel = instance . api . World . Player . Entity . WatchedAttributes . GetInt ( "LevelUP_Level_Vitality" ) ;
56
- int leatherArmorLevel = instance . api . World . Player . Entity . WatchedAttributes . GetInt ( "LevelUP_Level_LeatherArmor" ) ;
57
- int chainArmorLevel = instance . api . World . Player . Entity . WatchedAttributes . GetInt ( "LevelUP_Level_ChainArmor" ) ;
137
+ // Single Digits
138
+ if ( level < 10 )
139
+ // Creating the imagem
140
+ composer . AddImage ( position , new AssetLocation ( $ "levelup:{ level } .png") ) ;
141
+ // Double Digits
142
+ else if ( level < 100 )
143
+ {
144
+ string levelStr = level . ToString ( ) ;
145
+ int firstDigit = int . Parse ( levelStr [ 0 ] . ToString ( ) ) ;
146
+ int secondDigit = int . Parse ( levelStr [ 1 ] . ToString ( ) ) ;
147
+
148
+ // First digit instanciation
149
+ ElementBounds firstDigitPosition = ElementBounds . Fixed (
150
+ position . fixedX - 15 ,
151
+ position . fixedY ,
152
+ position . fixedWidth ,
153
+ position . fixedHeight
154
+ ) ;
155
+ composer . AddImage ( firstDigitPosition , new AssetLocation ( $ "levelup:{ firstDigit } .png") ) ;
156
+
157
+ // Second digit instanciation
158
+ ElementBounds secondDigitPosition = ElementBounds . Fixed (
159
+ position . fixedX + 15 ,
160
+ position . fixedY ,
161
+ position . fixedWidth ,
162
+ position . fixedHeight
163
+ ) ;
164
+ composer . AddImage ( secondDigitPosition , new AssetLocation ( $ "levelup:{ secondDigit } .png") ) ;
165
+ }
166
+
167
+ Debug . Log ( "Ops, you reached the gui limit :P " ) ;
168
+ }
169
+
170
+ private bool OnBackClicked ( )
171
+ {
172
+ page -- ;
173
+ if ( page < 0 ) page = 0 ;
174
+ return true ;
175
+ }
58
176
59
- StringBuilder fulldesc = new ( ) ;
60
- fulldesc . AppendLine ( Lang . Get ( "levelup:character_levels" ) ) ;
61
- fulldesc . AppendLine ( $ "-- { Lang . Get ( "levelup:tools_levels" ) } --") ;
62
- fulldesc . AppendLine ( $ "{ Lang . Get ( "levelup:axe" ) } : { axeLevel } { Lang . Get ( "levelup:pickaxe" ) } : { pickaxeLevel } { Lang . Get ( "levelup:shovel" ) } : { shovelLevel } ") ;
63
- fulldesc . AppendLine ( $ "{ Lang . Get ( "levelup:bow" ) } : { bowLevel } { Lang . Get ( "levelup:spear" ) } : { spearLevel } { Lang . Get ( "levelup:knife" ) } : { knifeLevel } ") ;
64
- fulldesc . AppendLine ( $ "{ Lang . Get ( "levelup:armors" ) } : { hammerLevel } { Lang . Get ( "levelup:sword" ) } : { swordLevel } { Lang . Get ( "levelup:shield" ) } : { shieldLevel } ") ;
65
- fulldesc . AppendLine ( $ "-- { Lang . Get ( "levelup:armor_levels" ) } --") ;
66
- fulldesc . AppendLine ( $ "{ Lang . Get ( "levelup:leather_armor" ) } : { leatherArmorLevel } ") ;
67
- fulldesc . AppendLine ( $ "{ Lang . Get ( "chain_armor" ) } : { chainArmorLevel } ") ;
68
- fulldesc . AppendLine ( $ "-- { Lang . Get ( "levelup:specialist_levels" ) } --") ;
69
- fulldesc . AppendLine ( $ "{ Lang . Get ( "levelup:hunter" ) } : { hunterLevel } ") ;
70
- fulldesc . AppendLine ( $ "{ Lang . Get ( "levelup:farming" ) } : { farmingLevel } ") ;
71
- fulldesc . AppendLine ( $ "{ Lang . Get ( "levelup:cooking" ) } : { cookingLevel } ") ;
72
- fulldesc . AppendLine ( $ "{ Lang . Get ( "levelup:vitality" ) } : { vitalityLevel } ") ;
73
- return fulldesc . ToString ( ) ;
177
+ private bool OnNextClicked ( )
178
+ {
179
+ page ++ ;
180
+ if ( page > 1 ) page = 1 ;
181
+ return true ;
74
182
}
75
183
}
0 commit comments