forked from TomGrobbe/MenuAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuCheckboxItem.cs
More file actions
147 lines (133 loc) · 4.86 KB
/
MenuCheckboxItem.cs
File metadata and controls
147 lines (133 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CitizenFX.Core;
using static CitizenFX.Core.Native.API;
using static CitizenFX.Core.Native.Function;
using static CitizenFX.Core.Native.Hash;
namespace MenuAPI
{
public class MenuCheckboxItem : MenuItem
{
public bool Checked { get; set; } = false;
public CheckboxStyle Style { get; set; } = CheckboxStyle.Tick;
public enum CheckboxStyle
{
#if FIVEM
Cross,
#endif
Tick
}
/// <summary>
/// Creates a basic <see cref="MenuCheckboxItem"/>.
/// </summary>
/// <param name="text"></param>
public MenuCheckboxItem(string text) : this(text, null) { }
/// <summary>
/// Creates a basic <see cref="MenuCheckboxItem"/> and sets the checked state to <param name="_checked"></param>'s state.
/// </summary>
/// <param name="text"></param>
/// <param name="_checked"></param>
public MenuCheckboxItem(string text, bool _checked) : this(text, null, _checked) { }
/// <summary>
/// Creates a basic <see cref="MenuCheckboxItem"/> and adds an item description.
/// </summary>
/// <param name="text"></param>
/// <param name="description"></param>
public MenuCheckboxItem(string text, string description) : this(text, description, false) { }
/// <summary>
/// Creates a new <see cref="MenuCheckboxItem"/> with all parameters set.
/// </summary>
/// <param name="text"></param>
/// <param name="description"></param>
/// <param name="_checked"></param>
public MenuCheckboxItem(string text, string description, bool _checked) : base(text, description)
{
Checked = _checked;
}
int GetSpriteColour()
{
return Enabled ? 255 : 109;
}
#if FIVEM
string GetSpriteName()
{
if (Checked)
{
if (Style == CheckboxStyle.Tick)
{
if (Selected)
{
return "shop_box_tickb";
}
return "shop_box_tick";
}
else
{
if (Selected)
{
return "shop_box_crossb";
}
return "shop_box_cross";
}
}
else
{
if (base.Selected)
{
return "shop_box_blankb";
}
return "shop_box_blank";
}
}
#endif
float GetSpriteX()
{
#if FIVEM
bool leftSide = false;
bool leftAligned = ParentMenu.LeftAligned;
return leftSide ? (leftAligned ? (20f / MenuController.ScreenWidth) : GetSafeZoneSize() - ((Width - 20f) / MenuController.ScreenWidth)) : (leftAligned ? (Width - 20f) / MenuController.ScreenWidth : (GetSafeZoneSize() - (20f / MenuController.ScreenWidth)));
#endif
#if REDM
return (Width - 30f) / MenuController.ScreenWidth;
#endif
}
internal override void Draw(int offset)
{
RightIcon = Icon.NONE;
Label = null;
base.Draw(offset);
#if FIVEM
SetScriptGfxAlign(76, 84);
SetScriptGfxAlignParams(0f, 0f, 0f, 0f);
#endif
float yOffset = ParentMenu.MenuItemsYOffset + 1f - (RowHeight * MathUtil.Clamp(ParentMenu.Size, 0, ParentMenu.MaxItemsOnScreen));
#if FIVEM
string name = GetSpriteName();
#endif
float spriteY = (ParentMenu.Position.Value + ((Index - offset) * RowHeight) + (20f) + yOffset) / MenuController.ScreenHeight;
float spriteX = GetSpriteX();
#if FIVEM
float spriteHeight = 45f / MenuController.ScreenHeight;
float spriteWidth = 45f / MenuController.ScreenWidth;
#endif
int color = GetSpriteColour();
#if FIVEM
DrawSprite("commonmenu", name, spriteX, spriteY, spriteWidth, spriteHeight, 0f, color, color, color, 255);
ResetScriptGfxAlign();
#endif
#if REDM
float spriteHeight = 24f / MenuController.ScreenHeight;
float spriteWidth = 16f / MenuController.ScreenWidth;
Call(DRAW_SPRITE, "menu_textures", "SELECTION_BOX_SQUARE", spriteX, spriteY, spriteWidth, spriteHeight, 0f, color, color, color, 255);
if (Checked)
{
int[] sc = Enabled ? (Selected ? new int[3] { 255, 255, 255 } : new int[3] { 181, 17, 18 }) : (Selected ? new int[3] { 109, 109, 109 } : new int[3] { 110, 10, 10 });
Call(DRAW_SPRITE, "generic_textures", "TICK", spriteX, spriteY, spriteWidth, spriteHeight, 0f, sc[0], sc[1], sc[2], 255);
}
#endif
}
}
}