Skip to content

Commit 3f5bd30

Browse files
committed
C# / Lua: UIMenuItem will now handle all the text formatting scaleform side.
Lua: fixed Label / label typos
1 parent f0c4490 commit 3f5bd30

24 files changed

Lines changed: 189 additions & 234 deletions

MenuExample/MenuExample.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public async void ExampleMenu()
5050
#region Big Message
5151

5252
UIMenuItem bigMessageItem = new UIMenuItem("~g~Big~s~ Message ~r~Examples~s~", "Select me to switch to the BigMessage menu!");
53+
bigMessageItem.KeepTextColorWhite = true;
5354
bigMessageItem.SetCustomLeftBadge("scaleformui", "kitty");
5455
bigMessageItem.SetCustomRightBadge("scaleformui", "kitty");
5556

@@ -153,8 +154,7 @@ public async void ExampleMenu()
153154
UIMenuCheckboxItem ketchupItem = new UIMenuCheckboxItem("~g~Scrolling animation enabled? ~b~in a very long label to ~o~test the text scrolling feature!", UIMenuCheckboxStyle.Tick, enabled, "Do you wish to enable the scrolling animation?");
154155
long _paneldui = API.CreateDui("https://i.imgur.com/mH0Y65C.gif", 288, 160);
155156
API.CreateRuntimeTextureFromDuiHandle(txd, "panelbackground", API.GetDuiHandle(_paneldui));
156-
//UIMissionDetailsPanel sidePanel = new UIMissionDetailsPanel(PanelSide.Right, "Side Panel", false, "scaleformui", "bannerbackground");
157-
UIMissionDetailsPanel sidePanel = new UIMissionDetailsPanel(PanelSide.Right, "Side Panel", SColor.HUD_Freemode, "scaleformui", "bannerbackground");
157+
UIMissionDetailsPanel sidePanel = new UIMissionDetailsPanel(PanelSide.Right, "Side Panel", false, "scaleformui", "bannerbackground");
158158
UIFreemodeDetailsItem detailItem1 = new UIFreemodeDetailsItem("Left Label", "RIGHT LABEL", ScaleformFonts.SIGNPAINTER_HOUSESCRIPT, ScaleformFonts.GTAV_TAXI_DIGITAL, BadgeIcon.BRIEFCASE, SColor.FromRandomValues());
159159
UIFreemodeDetailsItem detailItem2 = new UIFreemodeDetailsItem("Left Label", "RIGHT LABEL", ScaleformFonts.SIGNPAINTER_HOUSESCRIPT, ScaleformFonts.GTAV_TAXI_DIGITAL, BadgeIcon.MISSION_STAR, SColor.FromRandomValues());
160160
UIFreemodeDetailsItem detailItem3 = new UIFreemodeDetailsItem("Left Label", "RIGHT LABEL", ScaleformFonts.SIGNPAINTER_HOUSESCRIPT, ScaleformFonts.GTAV_TAXI_DIGITAL, BadgeIcon.ARMOR, SColor.FromRandomValues());

ScaleformUI_Csharp/Menus/Pause Menus/Elements/Columns/PM_Column.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public virtual void RemoveSlot(int idx)
9797
if (Items.Count > 0)
9898
{
9999
if (idx == this.index)
100-
index = idx >= Items.Count ? Items.Count - 1 : idx >= 0 && idx < Items.Count ? idx - 1 : 0;
100+
index = idx >= Items.Count ? Items.Count - 1 : idx >= 0 && idx < Items.Count ? idx : 0;
101101
else
102102
{
103103
if (selectedItem < Items.Count)

ScaleformUI_Csharp/Menus/Pause Menus/Elements/Columns/SettingsListColumn.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,9 @@ internal void SendItemToScaleform(int i, bool update = false, bool newItem = fal
163163
{
164164
case 1:
165165
UIMenuDynamicListItem dit = (UIMenuDynamicListItem)item;
166-
var curString = dit.Selected ? (dit.CurrentListItem.StartsWith("~") ? dit.CurrentListItem : "~s~" + dit.CurrentListItem).ToString().Replace("~w~", "~l~").Replace("~s~", "~l~") : (dit.CurrentListItem.StartsWith("~") ? dit.CurrentListItem : "~s~" + dit.CurrentListItem).ToString().Replace("~l~", "~s~");
167-
if (!dit.Enabled)
168-
curString = curString.ReplaceRstarColorsWith("~c~");
169-
PushScaleformMovieMethodParameterString(curString);
166+
BeginTextCommandScaleformString("CELL_EMAIL_BCON");
167+
AddTextComponentScaleform(dit.CurrentListItem);
168+
EndTextCommandScaleformString_2();
170169
break;
171170
case 2:
172171
UIMenuCheckboxItem check = (UIMenuCheckboxItem)item;
@@ -189,7 +188,9 @@ internal void SendItemToScaleform(int i, bool update = false, bool newItem = fal
189188
break;
190189
}
191190
PushScaleformMovieFunctionParameterBool(item.Enabled);
192-
PushScaleformMovieMethodParameterString(item._formatLeftLabel);
191+
BeginTextCommandScaleformString("CELL_EMAIL_BCON");
192+
AddTextComponentScaleform(item.Label);
193+
EndTextCommandScaleformString_2();
193194
PushScaleformMovieFunctionParameterBool(item.BlinkDescription);
194195
switch (item)
195196
{
@@ -249,7 +250,9 @@ internal void SendItemToScaleform(int i, bool update = false, bool newItem = fal
249250
default:
250251
PushScaleformMovieFunctionParameterInt(item.MainColor.ArgbValue);
251252
PushScaleformMovieFunctionParameterInt(item.HighlightColor.ArgbValue);
252-
PushScaleformMovieMethodParameterString(item._formatRightLabel);
253+
BeginTextCommandScaleformString("CELL_EMAIL_BCON");
254+
AddTextComponentScaleform(item.RightLabel);
255+
EndTextCommandScaleformString_2();
253256
PushScaleformMovieFunctionParameterInt((int)item.LeftBadge);
254257
PushScaleformMovieMethodParameterString(item.customLeftBadge.Key);
255258
PushScaleformMovieMethodParameterString(item.customLeftBadge.Value);
@@ -260,6 +263,7 @@ internal void SendItemToScaleform(int i, bool update = false, bool newItem = fal
260263
PushScaleformMovieMethodParameterString(item.rightLabelFont.FontName);
261264
break;
262265
}
266+
PushScaleformMovieFunctionParameterBool(item.KeepTextColorWhite);
263267
EndScaleformMovieMethod();
264268
}
265269

@@ -417,7 +421,6 @@ public override void Select()
417421
{
418422
it.Checked = !it.Checked;
419423
it.CheckboxEventTrigger();
420-
SelectItem();
421424
break;
422425
}
423426
case UIMenuListItem it:
@@ -441,19 +444,19 @@ public override void GoBack()
441444
public async override void MouseScroll(int dir)
442445
{
443446
if (!visible) return;
444-
CurrentItem.Selected = false;
447+
CurrentItem._selected = false;
445448
do
446449
{
450+
await BaseScript.Delay(0);
447451
index += dir;
448452
if(index < 0)
449453
index = Items.Count - 1;
450454
if (index >= Items.Count)
451455
index = 0;
452-
await BaseScript.Delay(0);
453456
}
454457
while (CurrentItem is UIMenuSeparatorItem sp && sp.Jumpable);
455458
API.AddTextEntry("PAUSEMENU_Current_Description", CurrentItem.Description);
456-
CurrentItem.Selected = true;
459+
CurrentItem._selected = true;
457460
IndexChangedEvent();
458461
}
459462

ScaleformUI_Csharp/Menus/Pause Menus/Elements/Columns/SubmenuLeftColumn.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ public override void SetDataSlot(int index)
3636
PushScaleformMovieFunctionParameterInt(0);
3737
PushScaleformMovieFunctionParameterInt(0);
3838
PushScaleformMovieFunctionParameterBool(item.Enabled);
39-
PushScaleformMovieMethodParameterString(item._formatLeftLabel);
39+
BeginTextCommandScaleformString("CELL_EMAIL_BCON");
40+
AddTextComponentScaleform(item.Label);
41+
EndTextCommandScaleformString_2();
4042
PushScaleformMovieFunctionParameterBool(false);
4143
PushScaleformMovieFunctionParameterInt(item.MainColor.ArgbValue);
4244
PushScaleformMovieFunctionParameterInt(item.HighlightColor.ArgbValue);
43-
PushScaleformMovieMethodParameterString(item._internalItem._formatRightLabel);
45+
BeginTextCommandScaleformString("CELL_EMAIL_BCON");
46+
AddTextComponentScaleform(item._internalItem.RightLabel);
47+
EndTextCommandScaleformString_2();
4448
PushScaleformMovieFunctionParameterInt((int)item._internalItem.LeftBadge);
4549
PushScaleformMovieMethodParameterString(item._internalItem.customLeftBadge.Key);
4650
PushScaleformMovieMethodParameterString(item._internalItem.customLeftBadge.Value);
@@ -65,11 +69,15 @@ public override void UpdateSlot(int index)
6569
PushScaleformMovieFunctionParameterInt(0);
6670
PushScaleformMovieFunctionParameterInt(0);
6771
PushScaleformMovieFunctionParameterBool(item.Enabled);
68-
PushScaleformMovieMethodParameterString(item._formatLeftLabel);
72+
BeginTextCommandScaleformString("CELL_EMAIL_BCON");
73+
AddTextComponentScaleform(item.Label);
74+
EndTextCommandScaleformString_2();
6975
PushScaleformMovieFunctionParameterBool(false);
7076
PushScaleformMovieFunctionParameterInt(item.MainColor.ArgbValue);
7177
PushScaleformMovieFunctionParameterInt(item.HighlightColor.ArgbValue);
72-
PushScaleformMovieMethodParameterString(item._internalItem._formatRightLabel);
78+
BeginTextCommandScaleformString("CELL_EMAIL_BCON");
79+
AddTextComponentScaleform(item._internalItem.RightLabel);
80+
EndTextCommandScaleformString_2();
7381
PushScaleformMovieFunctionParameterInt((int)item._internalItem.LeftBadge);
7482
PushScaleformMovieMethodParameterString(item._internalItem.customLeftBadge.Key);
7583
PushScaleformMovieMethodParameterString(item._internalItem.customLeftBadge.Value);

ScaleformUI_Csharp/Menus/UIMenu/Items/UIMenuItem.cs

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ public enum BadgeIcon
208208
public class UIMenuItem : PauseMenuItem
209209
{
210210
internal int _itemId = 0;
211-
internal string _formatLeftLabel = "";
212-
internal string _formatRightLabel = "";
211+
//internal string _formatLeftLabel = "";
212+
//internal string _formatRightLabel = "";
213213
internal bool _selected = false;
214214
private string _label = "";
215215
private string _rightLabel = "";
@@ -222,6 +222,10 @@ public class UIMenuItem : PauseMenuItem
222222
internal ItemFont rightLabelFont = ScaleformFonts.CHALET_LONDON_NINETEENSIXTY;
223223
internal KeyValuePair<string, string> customLeftBadge = new KeyValuePair<string, string>("", "");
224224
internal KeyValuePair<string, string> customRightBadge = new KeyValuePair<string, string>("", "");
225+
/// <summary>
226+
/// This will override all the text color formatting to a pure white color both when highlighted and not.
227+
/// </summary>
228+
public bool KeepTextColorWhite = false;
225229

226230
/// <summary>
227231
/// The item color when not highlighted
@@ -359,24 +363,7 @@ public override bool Selected
359363
{
360364
_selected = value;
361365
if (value)
362-
{
363-
if (Enabled)
364-
{
365-
_formatLeftLabel = _formatLeftLabel.Replace("~w~", "~l~").Replace("~s~", "~l~");
366-
if (!string.IsNullOrWhiteSpace(_formatRightLabel))
367-
_formatRightLabel = _formatRightLabel.Replace("~w~", "~l~").Replace("~s~", "~l~");
368-
}
369366
Highlighted?.Invoke(Parent, this);
370-
}
371-
else
372-
{
373-
if (Enabled)
374-
{
375-
_formatLeftLabel = _formatLeftLabel.Replace("~l~", "~s~");
376-
if (!string.IsNullOrWhiteSpace(_formatRightLabel))
377-
_formatRightLabel = _formatRightLabel.Replace("~l~", "~s~");
378-
}
379-
}
380367
if (Parent != null && Parent.Visible)
381368
Parent.SendItemToScaleform(Parent.MenuItems.IndexOf(this), true);
382369
if (ParentColumn != null && ParentColumn.visible)
@@ -422,17 +409,6 @@ public virtual bool Enabled
422409
set
423410
{
424411
_enabled = value;
425-
if (!value)
426-
{
427-
_formatLeftLabel = _formatLeftLabel.ReplaceRstarColorsWith("~c~");
428-
if(this is UIMenuItem)
429-
_formatRightLabel = _formatRightLabel.ReplaceRstarColorsWith("~c~");
430-
}
431-
else
432-
{
433-
Label = _label;
434-
RightLabel = _rightLabel;
435-
}
436412
if (Parent != null && Parent.Visible)
437413
Parent.SendItemToScaleform(Parent.MenuItems.IndexOf(this), true);
438414
if (ParentColumn != null && ParentColumn.visible)
@@ -450,14 +426,12 @@ internal virtual void ItemActivate(UIMenu sender)
450426
/// <summary>
451427
/// Returns this item's label.
452428
/// </summary>
453-
public virtual string Label
429+
public new virtual string Label
454430
{
455431
get => _label;
456432
set
457433
{
458434
_label = value;
459-
_formatLeftLabel = value.StartsWith("~") ? value : "~s~" + value;
460-
_formatLeftLabel = !_enabled ? _formatLeftLabel.ReplaceRstarColorsWith("~c~") : _selected ? _formatLeftLabel.Replace("~w~", "~l~").Replace("~s~", "~l~") : _formatLeftLabel.Replace("~l~", "~s~");
461435
if (Parent != null && Parent.Visible)
462436
Parent.SendItemToScaleform(Parent.MenuItems.IndexOf(this), true);
463437
if (ParentColumn != null && ParentColumn.visible)
@@ -543,8 +517,6 @@ public virtual string RightLabel
543517
private set
544518
{
545519
_rightLabel = value;
546-
_formatRightLabel = value.StartsWith("~") ? value : "~s~" + value;
547-
_formatRightLabel = !_enabled ? _formatRightLabel.ReplaceRstarColorsWith("~c~") : _selected ? _formatRightLabel .Replace("~w~", "~l~").Replace("~s~", "~l~") : _formatRightLabel .Replace("~l~", "~s~");
548520
if (Parent != null && Parent.Visible)
549521
Parent.SendItemToScaleform(Parent.MenuItems.IndexOf(this), true);
550522
if (ParentColumn != null && ParentColumn.visible)

ScaleformUI_Csharp/Menus/UIMenu/SidePanels/DetailsPanel/UIMissionDetailsPanel.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using ScaleformUI.Elements;
2+
using System.Drawing;
23

34
namespace ScaleformUI.Menu
45
{
@@ -94,6 +95,27 @@ public void AddItem(UIFreemodeDetailsItem item)
9495
}
9596
}
9697

98+
public void Clear()
99+
{
100+
Title = "";
101+
TextureDict = "";
102+
TextureName = "";
103+
Items.Clear();
104+
if (ParentItem is not null && ParentItem.Parent != null && ParentItem.Parent.Visible)
105+
{
106+
Main.scaleformUI.CallFunction("SET_PANEL_DATA_SLOT_EMPTY");
107+
}
108+
}
109+
110+
public void Refresh()
111+
{
112+
if (ParentItem is not null && ParentItem.Parent != null && ParentItem.Parent.Visible)
113+
{
114+
int it = ParentItem.Parent.MenuItems.IndexOf(ParentItem);
115+
ParentItem.Parent.SendSidePanelToScaleform(it);
116+
}
117+
}
118+
97119
/// <summary>
98120
/// Removes an item from the scription of the panel
99121
/// </summary>

ScaleformUI_Csharp/Menus/UIMenu/UIMenu.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ public void RemoveItemAt(int idx)
643643
if (MenuItems.Count > 0)
644644
{
645645
if (idx == _currentSelection)
646-
_currentSelection = idx >= MenuItems.Count ? MenuItems.Count - 1 : idx > 0 && idx < MenuItems.Count - 1 ? idx - 1 : 0;
646+
_currentSelection = idx >= MenuItems.Count ? MenuItems.Count - 1 : idx > 0 && idx < MenuItems.Count - 1 ? idx : 0;
647647
else
648648
{
649649
if (selectedItem < MenuItems.Count)
@@ -1964,10 +1964,9 @@ internal void SendItemToScaleform(int i, bool update = false, bool newItem = fal
19641964
{
19651965
case 1:
19661966
UIMenuDynamicListItem dit = (UIMenuDynamicListItem)item;
1967-
var curString = dit.Selected ? (dit.CurrentListItem.StartsWith("~") ? dit.CurrentListItem : "~s~" + dit.CurrentListItem).ToString().Replace("~w~", "~l~").Replace("~s~", "~l~") : (dit.CurrentListItem.StartsWith("~") ? dit.CurrentListItem : "~s~" + dit.CurrentListItem).ToString().Replace("~l~", "~s~");
1968-
if (!dit.Enabled)
1969-
curString = curString.ReplaceRstarColorsWith("~c~");
1970-
PushScaleformMovieMethodParameterString(curString);
1967+
BeginTextCommandScaleformString("CELL_EMAIL_BCON");
1968+
AddTextComponentScaleform(dit.CurrentListItem);
1969+
EndTextCommandScaleformString_2();
19711970
break;
19721971
case 2:
19731972
UIMenuCheckboxItem check = (UIMenuCheckboxItem)item;
@@ -1990,7 +1989,9 @@ internal void SendItemToScaleform(int i, bool update = false, bool newItem = fal
19901989
break;
19911990
}
19921991
PushScaleformMovieFunctionParameterBool(item.Enabled);
1993-
PushScaleformMovieMethodParameterString(item._formatLeftLabel);
1992+
BeginTextCommandScaleformString("CELL_EMAIL_BCON");
1993+
AddTextComponentScaleform(item.Label);
1994+
EndTextCommandScaleformString_2();
19941995
PushScaleformMovieFunctionParameterBool(item.BlinkDescription);
19951996
switch (item)
19961997
{
@@ -2055,7 +2056,9 @@ internal void SendItemToScaleform(int i, bool update = false, bool newItem = fal
20552056
default:
20562057
PushScaleformMovieFunctionParameterInt(item.MainColor.ArgbValue);
20572058
PushScaleformMovieFunctionParameterInt(item.HighlightColor.ArgbValue);
2058-
PushScaleformMovieMethodParameterString(item._formatRightLabel);
2059+
BeginTextCommandScaleformString("CELL_EMAIL_BCON");
2060+
AddTextComponentScaleform(item.RightLabel);
2061+
EndTextCommandScaleformString_2();
20592062
PushScaleformMovieFunctionParameterInt((int)item.LeftBadge);
20602063
PushScaleformMovieMethodParameterString(item.customLeftBadge.Key);
20612064
PushScaleformMovieMethodParameterString(item.customLeftBadge.Value);
@@ -2066,6 +2069,7 @@ internal void SendItemToScaleform(int i, bool update = false, bool newItem = fal
20662069
PushScaleformMovieMethodParameterString(item.rightLabelFont.FontName);
20672070
break;
20682071
}
2072+
PushScaleformMovieFunctionParameterBool(item.KeepTextColorWhite);
20692073
EndScaleformMovieMethod();
20702074
}
20712075

ScaleformUI_Lua/src/Menus/PauseMenus/Elements/Columns/MissionListColumn.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function MissionListColumn:SendItemToScaleform(i, update, newItem, isSlot)
139139
if update then str = "UPDATE_SLOT" end
140140
if newItem then str = "SET_DATA_SLOT_SPLICE" end
141141
if isSlot then str = "ADD_SLOT" end
142-
ScaleformUI.Scaleforms._pauseMenu._pause:CallFunction(str, self.position, i, 0,i, item.type, 0, item.Enabled, item.Label, item.MainColor, item.HighlightColor, item.LeftIcon, item.RightIcon, item.LeftIconColor, item.RightIconColor, item.customLeftIcon.TXD, item.customLeftIcon.TXN, item.customRightIcon.TXD, item.customRightIcon.TXN, item.RightIconChecked, item.Jumpable)
142+
ScaleformUI.Scaleforms._pauseMenu._pause:CallFunction(str, self.position, i, 0,i, item.type, 0, item.Enabled, item.label, item.MainColor, item.HighlightColor, item.LeftIcon, item.RightIcon, item.LeftIconColor, item.RightIconColor, item.customLeftIcon.TXD, item.customLeftIcon.TXN, item.customRightIcon.TXD, item.customRightIcon.TXN, item.RightIconChecked, item.Jumpable)
143143
if self.position == 0 and i == self.index then
144144
if item.Panel ~= nil then
145145
item.Panel:UpdatePanel()
@@ -155,7 +155,7 @@ function MissionListColumn:RemoveItem(item)
155155
return
156156
end
157157
for k,v in pairs(self.Items) do
158-
if v.Label == item.Label then
158+
if v:Label () == item:Label() then
159159
self:RemoveSlot(k)
160160
end
161161
end

0 commit comments

Comments
 (0)