Skip to content

Commit

Permalink
More functionality for fonts added. Handling of colors moved out from…
Browse files Browse the repository at this point in the history
… UiElement
  • Loading branch information
gaston11276 committed Dec 15, 2021
1 parent 016a1f5 commit ce29c6b
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 35 deletions.
1 change: 1 addition & 0 deletions Fivemui.Client/Fivemui.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="FivemuiService.cs" />
<Compile Include="UiElement\Editbox.cs" />
<Compile Include="UiElement\Fonts.cs" />
<Compile Include="UiElement\UiInput.cs" />
<Compile Include="UiElement\UiElementFiveM.cs" />
<Compile Include="UiElement\Textbox.cs" />
Expand Down
17 changes: 17 additions & 0 deletions Fivemui.Client/UiElement/Fonts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gaston11276.Fivemui
{
public enum Font
{
ChaletLondon = 0,
HouseScript = 1,
Monospace = 2,
CharletComprimeColonge = 4,
Pricedown = 7
}
}
64 changes: 55 additions & 9 deletions Fivemui.Client/UiElement/Textbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ namespace Gaston11276.Fivemui
public class Textbox : UiElementFiveM
{
Argb textColor;

Argb textColorDefault;
Argb textColorDisabled;
private int fontIndex = 0;
private float fontSize = 0.3f;
protected int textFlags;
protected string text;
private float textWidth;
Expand All @@ -21,6 +24,8 @@ public Textbox()
Type = UiElementType.Textbox;
textFlags = 0;
textColor = new Argb(0xFFFFFFFF);
textColorDefault = textColor;
textColorDisabled = new Argb(0x80FFFFFF);
text = "";
needRefresh = true;

Expand Down Expand Up @@ -64,9 +69,14 @@ public void SetFont(string fontName, int fontSize)
TextChanged();
}

public void SetFont(int fontIndex)
public void SetFontSize(float fontSize)
{
SetTextFont(fontIndex);
this.fontSize = fontSize;
}

public void SetFont(Font font)
{
this.fontIndex = (int)font;
TextChanged();
}

Expand All @@ -93,30 +103,65 @@ public void SetTextColor(int ARGB)
textColor.SetARGB(ARGB);
}

public override void OnDisabled()
{
textColor = textColorDisabled;
colorBackground = colorDisabled;

foreach (fpVoid OnDisable in onDisableCallbacks)
{
OnDisable();
}
}

public override void OffDisabled()
{
textColor = textColorDefault;
colorBackground = color;

foreach (fpVoid OffDisable in offDisableCallbacks)
{
OffDisable();
}
}

protected override float GetContentWidth()
{
BeginTextCommandWidth("STRING");
SetTextScale(1f, fontSize);
SetTextFont(fontIndex);
AddTextComponentString(this.text);
textWidth = EndTextCommandGetWidth(false) * 0.3f;
textWidth = EndTextCommandGetWidth(false);
return textWidth;
}
protected override float GetContentHeight()
{
textHeight = 0.3f * 0.03f;
float sy = screenResolutionX / screenResolutionY;
textHeight = (1f/sy)*GetTextScaleHeight(fontSize, (int)fontIndex);
return textHeight;
}

public override void Draw()
{
UiRectangle textRectangle = new UiRectangle();

base.Draw();

if ((flags & HIDDEN) != 0 || (textFlags & TRANSPARENT) != 0)
if ((flags & HIDDEN) != 0)// || (textFlags & TRANSPARENT) != 0)
{
return;
}

BeginTextCommandDisplayText("STRING");
SetTextScale(1f, 0.3f);
SetTextScale(1f, fontSize);
SetTextFont(fontIndex);

if ((textFlags & UiElementTextbox.TEXT_OUTLINE) != 0)
{
SetTextOutline();
}

SetTextCentre(true);

float textX = 0f;
if (this.hGravity == HGravity.Left)
Expand All @@ -131,13 +176,14 @@ public override void Draw()
}
else if (this.hGravity == HGravity.Right)
{
//SetTextRightJustify(true);
SetTextJustification(2);
SetTextWrap(drawingRectangle.Left(), drawingRectangle.Right());
textX = drawingRectangle.Right() - (Padding.Right() * screenBoundaries.Width());
}

float y_adjust = -0.012f;
float text_x = textX;
float text_y = drawingRectangle.CenterY() + y_adjust;
float text_y = drawingRectangle.Top() + (textHeight * 0.15f);

SetTextColour(textColor.GetRed(), textColor.GetGreen(), textColor.GetBlue(), textColor.GetAlpha());
AddTextComponentString(this.text);
Expand Down
72 changes: 51 additions & 21 deletions Fivemui.Client/UiElement/UiElementFiveM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,24 @@ public class UiElementFiveM: UiElement, IUiElement
static public ILogger Logger;
public Guid Id;
public delegate void fpGuid(Guid id);
protected List<fpGuid> callbacksOnSelectId;
protected List<fpGuid> callbacksOnSelectId = new List<fpGuid>();
protected List<fpVoid> callbacksOffSelect = new List<fpVoid>();
protected List<fpVoid> onDisableCallbacks = new List<fpVoid>();
protected List<fpVoid> offDisableCallbacks = new List<fpVoid>();

protected Argb color;
protected Argb colorFocus;
protected Argb colorSelected;
protected Argb colorDisabled;

public UiElementFiveM()
{
Type = UiElementType.Rectangle;
callbacksOnSelectId = new List<fpGuid>();

color = new Argb(100, 20, 20, 20);
colorFocus = new Argb(100, 200, 200, 100);
colorSelected = new Argb(100, 100, 100, 200);
colorDisabled = new Argb(50, 20, 20, 20);
}

public void SetLogger(ILogger Logger)
Expand All @@ -35,46 +47,62 @@ public void RegisterOnSelectIdCallback(fpGuid OnSelectId)
callbacksOnSelectId.Add(OnSelectId);
}

protected override void OnFocus()
public void RegisterOffSelect(fpVoid OffSelect)
{
callbacksOffSelect.Add(OffSelect);
}

public override void OnFocus()
{
if ((flags & SELECTED) == 0)
{
currentColorBackground = colorFocus;
colorBackground = colorFocus;
}
}

protected override void OffFocus()
public override void OffFocus()
{
if ((flags & SELECTED) == 0)
{
currentColorBackground = colorBackground;
colorBackground = color;
}
}

protected override void OnSelect()
public override void OnSelect()
{
currentColorBackground = colorSelected;
colorBackground = colorSelected;
OnSelectId(Id);
}

protected override void OffSelect()
public override void OffSelect()
{
currentColorBackground = colorBackground;
colorBackground = color;
foreach (fpVoid OffSelect in callbacksOffSelect)
{
OffSelect();
}
}

public new void OnDisabled()
public override void OnDisabled()
{
currentColorBackground = colorDisabled;
colorBackground = colorDisabled;
foreach (fpVoid OnDisable in onDisableCallbacks)
{
OnDisable();
}
}

public new void OffDisabled()
public override void OffDisabled()
{
currentColorBackground = colorBackground;
colorBackground = color;
foreach (fpVoid OffDisable in offDisableCallbacks)
{
OffDisable();
}
}

protected override void RunOnSelectCallbacks()
public void OnSelectId(Guid Id)
{
base.RunOnSelectCallbacks();

foreach (fpGuid OnSelectId in callbacksOnSelectId)
{
OnSelectId(Id);
Expand All @@ -97,11 +125,13 @@ public bool GetSelection(ref UiElement selectedElement)
public void Enable()
{
ClearFlags(DISABLED);
OffDisabled();
}

public void Disable()
{
SetFlags(DISABLED);
OnDisabled();
}

public void Select()
Expand All @@ -127,10 +157,10 @@ public override void Draw()
drawingRectangle.CenterY(),
drawingRectangle.Width(),
drawingRectangle.Height(),
currentColorBackground.GetRed(),
currentColorBackground.GetGreen(),
currentColorBackground.GetBlue(),
currentColorBackground.GetAlpha());
colorBackground.GetRed(),
colorBackground.GetGreen(),
colorBackground.GetBlue(),
colorBackground.GetAlpha());
}


Expand Down
6 changes: 2 additions & 4 deletions Fivemui.Client/UiElement/WindowManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using CitizenFX.Core;
using CitizenFX.Core.Native;
using NFive.SDK.Client.Interface;
using Gaston11276.Fivemui.Client.Overlays;
Expand All @@ -14,24 +15,21 @@ namespace Gaston11276.Fivemui
public delegate void fpOnMouseMove(float x, float y);
public delegate void fpOnMouseButton(int state, int button, float x, float y);
public delegate void fpOnKey(int state, int keycode);
public delegate void fpPedHash(PedHash pedHash);

public static class WindowManager
{
static public int delayMs = 10;
//static public List<Window> windows = new List<Window>();

public static List<fpOnKey> inputsOnKey = new List<fpOnKey>();
public static List<fpOnMouseMove> inputsOnMouseMove = new List<fpOnMouseMove>();
public static List<fpOnMouseButton> inputsOnMouseButton = new List<fpOnMouseButton>();

static public fpDelay Delay;

//static public IOverlayManager overlayManager;
static public FivemuiOverlay overlay;
static UiElementFiveM mainElement = new UiElementFiveM();

//static bool holdFocus;

public static void Init()
{
mainElement.SetFlags(UiElement.TRANSPARENT);
Expand Down
Binary file modified SimpleUi.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion nfive.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: gaston11276/fivemui
version: 0.1.0
version: 1.0.0
description: NFive Plugin
author: gaston11276
license: LGPL-3.0-or-later
Expand Down

0 comments on commit ce29c6b

Please sign in to comment.