Showing preview only (224K chars total). Download the full file or copy to clipboard to get everything.
Repository: Guad/NativeUI
Branch: master
Commit: 1c6bfd48a6bc
Files: 39
Total size: 212.4 KB
Directory structure:
gitextract_bxv95l5f/
├── .appveyor.yml
├── .gitattributes
├── .gitignore
├── LICENSE.md
├── MenuExample/
│ ├── MenuExample.cs
│ ├── MenuExample.csproj
│ └── packages.config
├── NativeUI/
│ ├── BigMessage.cs
│ ├── Controls.cs
│ ├── Elements/
│ │ ├── Sprite.cs
│ │ ├── TimerBars.cs
│ │ ├── UIResRectangle.cs
│ │ └── UIResText.cs
│ ├── InstructionalButton.cs
│ ├── Items/
│ │ ├── IListItem.cs
│ │ ├── UIMenuCheckboxItem.cs
│ │ ├── UIMenuColoredItem.cs
│ │ ├── UIMenuDynamicListItem.cs
│ │ ├── UIMenuItem.cs
│ │ ├── UIMenuListItem.cs
│ │ └── UIMenuSliderItem.cs
│ ├── MenuPool.cs
│ ├── NativeUI.csproj
│ ├── NativeUI.nuspec
│ ├── PauseMenu/
│ │ ├── TabInteractiveListItem.cs
│ │ ├── TabItem.cs
│ │ ├── TabItemSimpleList.cs
│ │ ├── TabMissionSelectItem.cs
│ │ ├── TabSubmenuItem.cs
│ │ ├── TabTextItem.cs
│ │ └── TabView.cs
│ ├── PointExtensions.cs
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ ├── Screen.cs
│ ├── StringMeasurer.cs
│ ├── UIMenu.cs
│ └── packages.config
├── NativeUI.sln
└── README.md
================================================
FILE CONTENTS
================================================
================================================
FILE: .appveyor.yml
================================================
version: "1.9.1.{build}"
image: Visual Studio 2017
assembly_info:
patch: true
file: Properties\AssemblyInfo.cs
assembly_version: "{version}"
assembly_file_version: "{version}"
init:
- ps: if ($env:APPVEYOR_REPO_TAG -eq "true") { Update-AppveyorBuild -Version "$($env:APPVEYOR_REPO_TAG_NAME)" }
install:
- git submodule update --init --recursive
- nuget restore %APPVEYOR_PROJECT_NAME%.sln
build_script:
- msbuild %APPVEYOR_PROJECT_NAME%.sln /t:Build /p:Configuration=Release
- nuget pack %APPVEYOR_PROJECT_NAME%\%APPVEYOR_PROJECT_NAME%.nuspec
after_build:
- 7z a %APPVEYOR_PROJECT_NAME%.7z %APPVEYOR_BUILD_FOLDER%\NativeUI\bin\x64\Release\*
artifacts:
- path: "%APPVEYOR_PROJECT_NAME%.7z"
name: File for Final Users
- path: '**\%APPVEYOR_PROJECT_NAME%.*.nupkg'
name: NuGet Package for Developers
deploy:
release: $(APPVEYOR_BUILD_VERSION)
provider: GitHub
auth_token:
secure: "DkvKC8KRj8AipGu/oWW/J2e6jMWt2xXQfKU7oefFMsp0ZMfzz+OR9Y9XpML+ZmG4"
artifact: /.*\.7z|nupkg/
draft: false
prerelease: false
on:
branch: master
appveyor_repo_tag: true
================================================
FILE: .gitattributes
================================================
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
================================================
FILE: .gitignore
================================================
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
================================================
FILE: LICENSE.md
================================================
MIT License
Copyright (c) 2016 Guad
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: MenuExample/MenuExample.cs
================================================
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using GTA;
using NativeUI;
public class MenuExample : Script
{
private bool ketchup = false;
private string dish = "Banana";
private MenuPool _menuPool;
public void AddMenuKetchup(UIMenu menu)
{
var newitem = new UIMenuCheckboxItem("Add ketchup?", ketchup, "Do you wish to add ketchup?");
menu.AddItem(newitem);
menu.OnCheckboxChange += (sender, item, checked_) =>
{
if (item == newitem)
{
ketchup = checked_;
UI.Notify("~r~Ketchup status: ~b~" + ketchup);
}
};
}
public void AddMenuFoods(UIMenu menu)
{
var foods = new List<dynamic>
{
"Banana",
"Apple",
"Pizza",
"Quartilicious",
0xF00D, // Dynamic!
};
var newitem = new UIMenuListItem("Food", foods, 0);
menu.AddItem(newitem);
menu.OnListChange += (sender, item, index) =>
{
if (item == newitem)
{
dish = item.Items[index].ToString();
UI.Notify("Preparing ~b~" + dish + "~w~...");
}
};
}
public void AddMenuCook(UIMenu menu)
{
var newitem = new UIMenuItem("Cook!", "Cook the dish with the appropiate ingredients and ketchup.");
newitem.SetLeftBadge(UIMenuItem.BadgeStyle.Star);
newitem.SetRightBadge(UIMenuItem.BadgeStyle.Tick);
menu.AddItem(newitem);
menu.OnItemSelect += (sender, item, index) =>
{
if (item == newitem)
{
string output = ketchup ? "You have ordered ~b~{0}~w~ ~r~with~w~ ketchup." : "You have ordered ~b~{0}~w~ ~r~without~w~ ketchup.";
UI.ShowSubtitle(String.Format(output, dish));
}
};
menu.OnIndexChange += (sender, index) =>
{
if (sender.MenuItems[index] == newitem)
newitem.SetLeftBadge(UIMenuItem.BadgeStyle.None);
};
}
public void AddMenuAnotherMenu(UIMenu menu)
{
var submenu = _menuPool.AddSubMenu(menu, "Another Menu");
for (int i = 0; i < 20; i++)
submenu.AddItem(new UIMenuItem("PageFiller", "Sample description that takes more than one line. Moreso, it takes way more than two lines since it's so long. Wow, check out this length!"));
}
public MenuExample()
{
_menuPool = new MenuPool();
var mainMenu = new UIMenu("Native UI", "~b~NATIVEUI SHOWCASE");
_menuPool.Add(mainMenu);
AddMenuKetchup(mainMenu);
AddMenuFoods(mainMenu);
AddMenuCook(mainMenu);
AddMenuAnotherMenu(mainMenu);
_menuPool.RefreshIndex();
Tick += (o, e) => _menuPool.ProcessMenus();
KeyDown += (o, e) =>
{
if (e.KeyCode == Keys.F5 && !_menuPool.IsAnyMenuOpen()) // Our menu on/off switch
mainMenu.Visible = !mainMenu.Visible;
};
}
}
================================================
FILE: MenuExample/MenuExample.csproj
================================================
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{79D9A09F-1999-4148-9BA0-20AEBA9B3C8B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MenuExample</RootNamespace>
<AssemblyName>MenuExample</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="ScriptHookVDotNet2, Version=2.10.12.0, Culture=neutral, processorArchitecture=AMD64">
<HintPath>..\packages\ScriptHookVDotNet2.2.10.12\lib\net48\ScriptHookVDotNet2.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MenuExample.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NativeUI\NativeUI.csproj">
<Project>{f3e16ed9-dbf7-4e7b-b04b-9b24b11891d3}</Project>
<Name>NativeUI</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
================================================
FILE: MenuExample/packages.config
================================================
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ScriptHookVDotNet2" version="2.10.12" targetFramework="net48" />
</packages>
================================================
FILE: NativeUI/BigMessage.cs
================================================
using System;
using System.Runtime.Remoting.Messaging;
using GTA;
using GTA.Native;
namespace NativeUI
{
public class BigMessageHandler
{
private Scaleform _sc;
private int _start;
private int _timer;
public BigMessageHandler()
{
}
public void Load()
{
if (_sc != null) return;
_sc = new Scaleform("MP_BIG_MESSAGE_FREEMODE");
var timeout = 1000;
var start = DateTime.Now;
while (!Function.Call<bool>(Hash.HAS_SCALEFORM_MOVIE_LOADED, _sc.Handle) && DateTime.Now.Subtract(start).TotalMilliseconds < timeout) Script.Yield();
}
public void Dispose()
{
Function.Call(Hash.SET_SCALEFORM_MOVIE_AS_NO_LONGER_NEEDED, new OutputArgument(_sc.Handle));
_sc = null;
}
public void ShowMissionPassedMessage(string msg, int time = 5000)
{
Load();
_start = Game.GameTime;
_sc.CallFunction("SHOW_MISSION_PASSED_MESSAGE", msg, "", 100, true, 0, true);
_timer = time;
}
public void ShowColoredShard(string msg, string desc, HudColor textColor, HudColor bgColor, int time = 5000)
{
Load();
_start = Game.GameTime;
_sc.CallFunction("SHOW_SHARD_CENTERED_MP_MESSAGE", msg, desc, (int)bgColor, (int)textColor);
_timer = time;
}
public void ShowOldMessage(string msg, int time = 5000)
{
Load();
_start = Game.GameTime;
_sc.CallFunction("SHOW_MISSION_PASSED_MESSAGE", msg);
_timer = time;
}
public void ShowSimpleShard(string title, string subtitle, int time = 5000)
{
Load();
_start = Game.GameTime;
_sc.CallFunction("SHOW_SHARD_CREW_RANKUP_MP_MESSAGE", title, subtitle);
_timer = time;
}
public void ShowRankupMessage(string msg, string subtitle, int rank, int time = 5000)
{
Load();
_start = Game.GameTime;
_sc.CallFunction("SHOW_BIG_MP_MESSAGE", msg, subtitle, rank, "", "");
_timer = time;
}
public void ShowWeaponPurchasedMessage(string bigMessage, string weaponName, WeaponHash weapon, int time = 5000)
{
Load();
_start = Game.GameTime;
_sc.CallFunction("SHOW_WEAPON_PURCHASED", bigMessage, weaponName, unchecked((int)weapon), "", 100);
_timer = time;
}
public void ShowMpMessageLarge(string msg, int time = 5000)
{
Load();
_start = Game.GameTime;
_sc.CallFunction("SHOW_CENTERED_MP_MESSAGE_LARGE", msg, "test", 100, true, 100);
_sc.CallFunction("TRANSITION_IN");
_timer = time;
}
public void ShowCustomShard(string funcName, params object[] paremeters)
{
Load();
_sc.CallFunction(funcName, paremeters);
}
internal void Update()
{
if (_sc == null) return;
_sc.Render2D();
if (_start != 0 && Game.GameTime - _start > _timer)
{
_sc.CallFunction("TRANSITION_OUT");
_start = 0;
Dispose();
}
}
}
public class BigMessageThread : Script
{
public static BigMessageHandler MessageInstance { get; set; }
public BigMessageThread()
{
MessageInstance = new BigMessageHandler();
Tick += (sender, args) =>
{
MessageInstance.Update();
};
}
}
public enum HudColor
{
HUD_COLOUR_PURE_WHITE = 0,
HUD_COLOUR_WHITE = 1,
HUD_COLOUR_BLACK = 2,
HUD_COLOUR_GREY = 3,
HUD_COLOUR_GREYLIGHT = 4,
HUD_COLOUR_GREYDARK = 5,
HUD_COLOUR_RED = 6,
HUD_COLOUR_REDLIGHT = 7,
HUD_COLOUR_REDDARK = 8,
HUD_COLOUR_BLUE = 9,
HUD_COLOUR_BLUELIGHT = 10,
HUD_COLOUR_BLUEDARK = 11,
HUD_COLOUR_YELLOW = 12,
HUD_COLOUR_YELLOWLIGHT = 13,
HUD_COLOUR_YELLOWDARK = 14,
HUD_COLOUR_ORANGE = 15,
HUD_COLOUR_ORANGELIGHT = 16,
HUD_COLOUR_ORANGEDARK = 17,
HUD_COLOUR_GREEN = 18,
HUD_COLOUR_GREENLIGHT = 19,
HUD_COLOUR_GREENDARK = 20,
HUD_COLOUR_PURPLE = 21,
HUD_COLOUR_PURPLELIGHT = 22,
HUD_COLOUR_PURPLEDARK = 23,
HUD_COLOUR_PINK = 24,
HUD_COLOUR_RADAR_HEALTH = 25,
HUD_COLOUR_RADAR_ARMOUR = 26,
HUD_COLOUR_RADAR_DAMAGE = 27,
HUD_COLOUR_NET_PLAYER1 = 28,
HUD_COLOUR_NET_PLAYER2 = 29,
HUD_COLOUR_NET_PLAYER3 = 30,
HUD_COLOUR_NET_PLAYER4 = 31,
HUD_COLOUR_NET_PLAYER5 = 32,
HUD_COLOUR_NET_PLAYER6 = 33,
HUD_COLOUR_NET_PLAYER7 = 34,
HUD_COLOUR_NET_PLAYER8 = 35,
HUD_COLOUR_NET_PLAYER9 = 36,
HUD_COLOUR_NET_PLAYER10 = 37,
HUD_COLOUR_NET_PLAYER11 = 38,
HUD_COLOUR_NET_PLAYER12 = 39,
HUD_COLOUR_NET_PLAYER13 = 40,
HUD_COLOUR_NET_PLAYER14 = 41,
HUD_COLOUR_NET_PLAYER15 = 42,
HUD_COLOUR_NET_PLAYER16 = 43,
HUD_COLOUR_NET_PLAYER17 = 44,
HUD_COLOUR_NET_PLAYER18 = 45,
HUD_COLOUR_NET_PLAYER19 = 46,
HUD_COLOUR_NET_PLAYER20 = 47,
HUD_COLOUR_NET_PLAYER21 = 48,
HUD_COLOUR_NET_PLAYER22 = 49,
HUD_COLOUR_NET_PLAYER23 = 50,
HUD_COLOUR_NET_PLAYER24 = 51,
HUD_COLOUR_NET_PLAYER25 = 52,
HUD_COLOUR_NET_PLAYER26 = 53,
HUD_COLOUR_NET_PLAYER27 = 54,
HUD_COLOUR_NET_PLAYER28 = 55,
HUD_COLOUR_NET_PLAYER29 = 56,
HUD_COLOUR_NET_PLAYER30 = 57,
HUD_COLOUR_NET_PLAYER31 = 58,
HUD_COLOUR_NET_PLAYER32 = 59,
HUD_COLOUR_SIMPLEBLIP_DEFAULT = 60,
HUD_COLOUR_MENU_BLUE = 61,
HUD_COLOUR_MENU_GREY_LIGHT = 62,
HUD_COLOUR_MENU_BLUE_EXTRA_DARK = 63,
HUD_COLOUR_MENU_YELLOW = 64,
HUD_COLOUR_MENU_YELLOW_DARK = 65,
HUD_COLOUR_MENU_GREEN = 66,
HUD_COLOUR_MENU_GREY = 67,
HUD_COLOUR_MENU_GREY_DARK = 68,
HUD_COLOUR_MENU_HIGHLIGHT = 69,
HUD_COLOUR_MENU_STANDARD = 70,
HUD_COLOUR_MENU_DIMMED = 71,
HUD_COLOUR_MENU_EXTRA_DIMMED = 72,
HUD_COLOUR_BRIEF_TITLE = 73,
HUD_COLOUR_MID_GREY_MP = 74,
HUD_COLOUR_NET_PLAYER1_DARK = 75,
HUD_COLOUR_NET_PLAYER2_DARK = 76,
HUD_COLOUR_NET_PLAYER3_DARK = 77,
HUD_COLOUR_NET_PLAYER4_DARK = 78,
HUD_COLOUR_NET_PLAYER5_DARK = 79,
HUD_COLOUR_NET_PLAYER6_DARK = 80,
HUD_COLOUR_NET_PLAYER7_DARK = 81,
HUD_COLOUR_NET_PLAYER8_DARK = 82,
HUD_COLOUR_NET_PLAYER9_DARK = 83,
HUD_COLOUR_NET_PLAYER10_DARK = 84,
HUD_COLOUR_NET_PLAYER11_DARK = 85,
HUD_COLOUR_NET_PLAYER12_DARK = 86,
HUD_COLOUR_NET_PLAYER13_DARK = 87,
HUD_COLOUR_NET_PLAYER14_DARK = 88,
HUD_COLOUR_NET_PLAYER15_DARK = 89,
HUD_COLOUR_NET_PLAYER16_DARK = 90,
HUD_COLOUR_NET_PLAYER17_DARK = 91,
HUD_COLOUR_NET_PLAYER18_DARK = 92,
HUD_COLOUR_NET_PLAYER19_DARK = 93,
HUD_COLOUR_NET_PLAYER20_DARK = 94,
HUD_COLOUR_NET_PLAYER21_DARK = 95,
HUD_COLOUR_NET_PLAYER22_DARK = 96,
HUD_COLOUR_NET_PLAYER23_DARK = 97,
HUD_COLOUR_NET_PLAYER24_DARK = 98,
HUD_COLOUR_NET_PLAYER25_DARK = 99,
HUD_COLOUR_NET_PLAYER26_DARK = 100,
HUD_COLOUR_NET_PLAYER27_DARK = 101,
HUD_COLOUR_NET_PLAYER28_DARK = 102,
HUD_COLOUR_NET_PLAYER29_DARK = 103,
HUD_COLOUR_NET_PLAYER30_DARK = 104,
HUD_COLOUR_NET_PLAYER31_DARK = 105,
HUD_COLOUR_NET_PLAYER32_DARK = 106,
HUD_COLOUR_BRONZE = 107,
HUD_COLOUR_SILVER = 108,
HUD_COLOUR_GOLD = 109,
HUD_COLOUR_PLATINUM = 110,
HUD_COLOUR_GANG1 = 111,
HUD_COLOUR_GANG2 = 112,
HUD_COLOUR_GANG3 = 113,
HUD_COLOUR_GANG4 = 114,
HUD_COLOUR_SAME_CREW = 115,
HUD_COLOUR_FREEMODE = 116,
HUD_COLOUR_PAUSE_BG = 117,
HUD_COLOUR_FRIENDLY = 118,
HUD_COLOUR_ENEMY = 119,
HUD_COLOUR_LOCATION = 120,
HUD_COLOUR_PICKUP = 121,
HUD_COLOUR_PAUSE_SINGLEPLAYER = 122,
HUD_COLOUR_FREEMODE_DARK = 123,
HUD_COLOUR_INACTIVE_MISSION = 124,
HUD_COLOUR_DAMAGE = 125,
HUD_COLOUR_PINKLIGHT = 126,
HUD_COLOUR_PM_MITEM_HIGHLIGHT = 127,
HUD_COLOUR_SCRIPT_VARIABLE = 128,
HUD_COLOUR_YOGA = 129,
HUD_COLOUR_TENNIS = 130,
HUD_COLOUR_GOLF = 131,
HUD_COLOUR_SHOOTING_RANGE = 132,
HUD_COLOUR_FLIGHT_SCHOOL = 133,
HUD_COLOUR_NORTH_BLUE = 134,
HUD_COLOUR_SOCIAL_CLUB = 135,
HUD_COLOUR_PLATFORM_BLUE = 136,
HUD_COLOUR_PLATFORM_GREEN = 137,
HUD_COLOUR_PLATFORM_GREY = 138,
HUD_COLOUR_FACEBOOK_BLUE = 139,
HUD_COLOUR_INGAME_BG = 140,
HUD_COLOUR_DARTS = 141,
HUD_COLOUR_WAYPOINT = 142,
HUD_COLOUR_MICHAEL = 143,
HUD_COLOUR_FRANKLIN = 144,
HUD_COLOUR_TREVOR = 145,
HUD_COLOUR_GOLF_P1 = 146,
HUD_COLOUR_GOLF_P2 = 147,
HUD_COLOUR_GOLF_P3 = 148,
HUD_COLOUR_GOLF_P4 = 149,
HUD_COLOUR_WAYPOINTLIGHT = 150,
HUD_COLOUR_WAYPOINTDARK = 151,
HUD_COLOUR_PANEL_LIGHT = 152,
HUD_COLOUR_MICHAEL_DARK = 153,
HUD_COLOUR_FRANKLIN_DARK = 154,
HUD_COLOUR_TREVOR_DARK = 155,
HUD_COLOUR_OBJECTIVE_ROUTE = 156,
HUD_COLOUR_PAUSEMAP_TINT = 157,
HUD_COLOUR_PAUSE_DESELECT = 158,
HUD_COLOUR_PM_WEAPONS_PURCHASABLE = 159,
HUD_COLOUR_PM_WEAPONS_LOCKED = 160,
HUD_COLOUR_END_SCREEN_BG = 161,
HUD_COLOUR_CHOP = 162,
HUD_COLOUR_PAUSEMAP_TINT_HALF = 163,
HUD_COLOUR_NORTH_BLUE_OFFICIAL = 164,
HUD_COLOUR_SCRIPT_VARIABLE_2 = 165,
HUD_COLOUR_H = 166,
HUD_COLOUR_HDARK = 167,
HUD_COLOUR_T = 168,
HUD_COLOUR_TDARK = 169,
HUD_COLOUR_HSHARD = 170,
HUD_COLOUR_CONTROLLER_MICHAEL = 171,
HUD_COLOUR_CONTROLLER_FRANKLIN = 172,
HUD_COLOUR_CONTROLLER_TREVOR = 173,
HUD_COLOUR_CONTROLLER_CHOP = 174,
HUD_COLOUR_VIDEO_EDITOR_VIDEO = 175,
HUD_COLOUR_VIDEO_EDITOR_AUDIO = 176,
HUD_COLOUR_VIDEO_EDITOR_TEXT = 177,
HUD_COLOUR_HB_BLUE = 178,
HUD_COLOUR_HB_YELLOW = 179,
}
}
================================================
FILE: NativeUI/Controls.cs
================================================
using GTA;
using GTA.Native;
using System.Collections.Generic;
using System.Linq;
namespace NativeUI
{
/// <summary>
/// Class that provides tools to handle the game controls.
/// </summary>
public static class Controls
{
/// <summary>
/// All of the controls required for using a keyboard.
/// </summary>
private static readonly Control[] NecessaryControlsKeyboard = new Control[]
{
Control.FrontendAccept,
Control.FrontendAxisX,
Control.FrontendAxisY,
Control.FrontendDown,
Control.FrontendUp,
Control.FrontendLeft,
Control.FrontendRight,
Control.FrontendCancel,
Control.FrontendSelect,
Control.CursorScrollDown,
Control.CursorScrollUp,
Control.CursorX,
Control.CursorY,
Control.MoveUpDown,
Control.MoveLeftRight,
Control.Sprint,
Control.Jump,
Control.Enter,
Control.VehicleExit,
Control.VehicleAccelerate,
Control.VehicleBrake,
Control.VehicleMoveLeftRight,
Control.VehicleFlyYawLeft,
Control.FlyLeftRight,
Control.FlyUpDown,
Control.VehicleFlyYawRight,
Control.VehicleHandbrake,
};
/// <summary>
/// All of the controls required for using a keyboard.
/// </summary>
private static readonly Control[] NecessaryControlsGamePad = NecessaryControlsKeyboard.Concat(new Control[]
{
Control.LookUpDown,
Control.LookLeftRight,
Control.Aim,
Control.Attack,
})
.ToArray();
/// <summary>
/// Toggles the availability of the controls.
/// It does not disable the basic movement and frontend controls.
/// </summary>
/// <param name="toggle">If we want to enable or disable the controls.</param>
public static void Toggle(bool toggle)
{
// If we want to enable the controls
if (toggle)
{
// Enable all of them
Game.EnableAllControlsThisFrame(2);
}
// If we don't need them
else
{
// Disable all of the controls
Game.DisableAllControlsThisFrame(2);
// Now, re-enable the controls that are required for the game
// First, pick the right controls for gamepad or keyboard and mouse
Control[] list = Game.CurrentInputMode == InputMode.GamePad ? NecessaryControlsGamePad : NecessaryControlsKeyboard;
// Then, enable all of the controls for that input mode
foreach (Control control in list)
{
Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, (int)control);
}
}
}
}
}
================================================
FILE: NativeUI/Elements/Sprite.cs
================================================
using System;
using System.Drawing;
using System.IO;
using System.Reflection;
using GTA;
using GTA.Native;
namespace NativeUI
{
public class Sprite
{
public Point Position;
public Size Size;
public Color Color;
public bool Visible;
public float Heading;
public string TextureDict
{
get { return _textureDict; }
set
{
_textureDict = value;
//if(_autoload && !Function.Call<bool>(Hash.HAS_STREAMED_TEXTURE_DICT_LOADED, value))
//Function.Call(Hash.REQUEST_STREAMED_TEXTURE_DICT, value, true);
}
}
public string TextureName;
private string _textureDict;
/// <summary>
/// Creates a game sprite object from a texture dictionary and texture name.
/// </summary>
/// <param name="textureDict"></param>
/// <param name="textureName"></param>
/// <param name="position"></param>
/// <param name="size"></param>
/// <param name="heading"></param>
/// <param name="color"></param>
public Sprite(string textureDict, string textureName, Point position, Size size, float heading, Color color) //BASE
{
//if (!Function.Call<bool>(Hash.HAS_STREAMED_TEXTURE_DICT_LOADED, textureDict))
//Function.Call(Hash.REQUEST_STREAMED_TEXTURE_DICT, textureDict, true);
TextureDict = textureDict;
TextureName = textureName;
Position = position;
Size = size;
Heading = heading;
Color = color;
Visible = true;
}
/// <summary>
/// Creates a game sprite object from a texture dictionary and texture name.
/// </summary>
/// <param name="textureDict"></param>
/// <param name="textureName"></param>
/// <param name="position"></param>
/// <param name="size"></param>
public Sprite(string textureDict, string textureName, Point position, Size size) : this(textureDict, textureName, position, size, 0f, Color.FromArgb(255, 255, 255, 255))
{
}
/// <summary>
/// Draws the sprite on a 1080-pixels height base.
/// </summary>
public void Draw()
{
if (!Visible) return;
if (!Function.Call<bool>(Hash.HAS_STREAMED_TEXTURE_DICT_LOADED, TextureDict))
Function.Call(Hash.REQUEST_STREAMED_TEXTURE_DICT, TextureDict, true);
int screenw = Game.ScreenResolution.Width;
int screenh = Game.ScreenResolution.Height;
const float height = 1080f;
float ratio = (float)screenw/screenh;
var width = height*ratio;
float w = (Size.Width / width);
float h = (Size.Height / height);
float x = (Position.X / width) + w * 0.5f;
float y = (Position.Y / height) + h * 0.5f;
Function.Call(Hash.DRAW_SPRITE, TextureDict, TextureName, x, y, w, h, Heading, Color.R, Color.G, Color.B, Color.A);
}
public static void Draw(string dict, string name, int xpos, int ypos, int boxWidth, int boxHeight, float rotation, Color color)
{
if (!Function.Call<bool>(Hash.HAS_STREAMED_TEXTURE_DICT_LOADED, dict))
Function.Call(Hash.REQUEST_STREAMED_TEXTURE_DICT, dict, true);
int screenw = Game.ScreenResolution.Width;
int screenh = Game.ScreenResolution.Height;
const float height = 1080f;
float ratio = (float)screenw / screenh;
var width = height * ratio;
float w = (boxWidth / width);
float h = (boxHeight / height);
float x = (xpos / width) + w * 0.5f;
float y = (ypos / height) + h * 0.5f;
Function.Call(Hash.DRAW_SPRITE, dict, name, x, y, w, h, rotation, color.R, color.G, color.B, color.A);
}
/// <summary>
/// Draw a custom texture from a file on a 1080-pixels height base.
/// </summary>
/// <param name="path">Path to texture file.</param>
/// <param name="position"></param>
/// <param name="size"></param>
public static void DrawTexture(string path, Point position, Size size, float rotation, Color color)
{
int screenw = Game.ScreenResolution.Width;
int screenh = Game.ScreenResolution.Height;
const float height = 1080f;
float ratio = (float)screenw / screenh;
float width = height * ratio;
float reduceX = UI.WIDTH / width;
float reduceY = UI.HEIGHT / height;
Point extra = new Point(0,0);
if (screenw == 1914 && screenh == 1052) //TODO: Fix this when ScriptHookVDotNet 1.2 comes out.
extra = new Point(15, 0);
UI.DrawTexture(path, 1, 1, 60,
new Point(Convert.ToInt32(position.X*reduceX) + extra.X, Convert.ToInt32(position.Y*reduceY) + extra.Y),
new PointF(0f, 0f),
new Size(Convert.ToInt32(size.Width * reduceX), Convert.ToInt32(size.Height * reduceY)),
rotation, color);
}
/// <summary>
/// Draw a custom texture from a file on a 1080-pixels height base.
/// </summary>
/// <param name="path">Path to texture file.</param>
/// <param name="position"></param>
/// <param name="size"></param>
public static void DrawTexture(string path, Point position, Size size)
{
int screenw = Game.ScreenResolution.Width;
int screenh = Game.ScreenResolution.Height;
const float height = 1080f;
float ratio = (float)screenw / screenh;
float width = height * ratio;
float reduceX = UI.WIDTH / width;
float reduceY = UI.HEIGHT / height;
Point extra = new Point(0, 0);
if (screenw == 1914 && screenh == 1052) //TODO: Fix this when ScriptHookVDotNet 1.2 comes out.
extra = new Point(15, 0);
UI.DrawTexture(path, 1, 1, 60,
new Point(Convert.ToInt32(position.X * reduceX) + extra.X, Convert.ToInt32(position.Y * reduceY) + extra.Y),
new PointF(0f, 0f),
new Size(Convert.ToInt32(size.Width * reduceX), Convert.ToInt32(size.Height * reduceY)),
0f, Color.White);
}
/// <summary>
/// Save an embedded resource to a temporary file.
/// </summary>
/// <param name="yourAssembly">Your executing assembly.</param>
/// <param name="fullResourceName">Resource name including your solution name. E.G MyMenuMod.banner.png</param>
/// <returns>Absolute path to the written file.</returns>
public static string WriteFileFromResources(Assembly yourAssembly, string fullResourceName)
{
string tmpPath = Path.GetTempFileName();
return WriteFileFromResources(yourAssembly, fullResourceName, tmpPath);
}
/// <summary>
/// Save an embedded resource to a concrete path.
/// </summary>
/// <param name="yourAssembly">Your executing assembly.</param>
/// <param name="fullResourceName">Resource name including your solution name. E.G MyMenuMod.banner.png</param>
/// <param name="savePath">Path to where save the file, including the filename.</param>
/// <returns>Absolute path to the written file.</returns>
public static string WriteFileFromResources(Assembly yourAssembly, string fullResourceName, string savePath)
{
using (Stream stream = yourAssembly.GetManifestResourceStream(fullResourceName))
{
if (stream != null)
{
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, Convert.ToInt32(stream.Length));
using (FileStream fileStream = File.Create(savePath))
{
fileStream.Write(buffer, 0, Convert.ToInt32(stream.Length));
fileStream.Close();
}
}
}
return Path.GetFullPath(savePath);
}
}
}
================================================
FILE: NativeUI/Elements/TimerBars.cs
================================================
using System.Collections.Generic;
using System.Drawing;
using GTA;
using Font = GTA.Font;
namespace NativeUI
{
public abstract class TimerBarBase
{
public string Label { get; set; }
public TimerBarBase(string label)
{
Label = label;
}
public virtual void Draw(int interval)
{
SizeF res = Screen.ResolutionMaintainRatio;
Point safe = Screen.SafezoneBounds;
UIResText.Draw(Label, (int)res.Width - safe.X - 180, (int)res.Height - safe.Y - (30 + (4 * interval)), Font.ChaletLondon, 0.3f, Color.White,
UIResText.Alignment.Right, false, false, 0);
Sprite.Draw("timerbars", "all_black_bg", (int)res.Width - safe.X - 298, (int)res.Height - safe.Y - (40 + (4 * interval)), 300, 37, 0f, Color.FromArgb(180, 255, 255, 255));
UI.HideHudComponentThisFrame(HudComponent.AreaName);
UI.HideHudComponentThisFrame(HudComponent.StreetName);
UI.HideHudComponentThisFrame(HudComponent.VehicleName);
}
}
public class TextTimerBar : TimerBarBase
{
public string Text { get; set; }
public TextTimerBar(string label, string text) : base(label)
{
Text = text;
}
public override void Draw(int interval)
{
SizeF res = Screen.ResolutionMaintainRatio;
Point safe = Screen.SafezoneBounds;
base.Draw(interval);
UIResText.Draw(Text, (int)res.Width - safe.X - 10, (int)res.Height - safe.Y - (42 + (4 * interval)), Font.ChaletLondon, 0.5f, Color.White,
UIResText.Alignment.Right, false, false, 0);
}
}
public class BarTimerBar : TimerBarBase
{
/// <summary>
/// Bar percentage. Goes from 0 to 1.
/// </summary>
public float Percentage { get; set; }
public Color BackgroundColor { get; set; }
public Color ForegroundColor { get; set; }
public BarTimerBar(string label) : base(label)
{
BackgroundColor = Color.DarkRed;
ForegroundColor = Color.Red;
}
public override void Draw(int interval)
{
SizeF res = Screen.ResolutionMaintainRatio;
Point safe = Screen.SafezoneBounds;
base.Draw(interval);
var start = new Point((int)res.Width - safe.X - 160, (int)res.Height - safe.Y - (28 + (4 * interval)));
UIResRectangle.Draw(start.X, start.Y, 150, 15, BackgroundColor);
UIResRectangle.Draw(start.X, start.Y, (int)(150 * Percentage), 15, ForegroundColor);
}
}
public class TimerBarPool
{
private static List<TimerBarBase> _bars = new List<TimerBarBase>();
public TimerBarPool()
{
_bars = new List<TimerBarBase>();
}
public List<TimerBarBase> ToList()
{
return _bars;
}
public void Add(TimerBarBase timer)
{
_bars.Add(timer);
}
public void Remove(TimerBarBase timer)
{
_bars.Remove(timer);
}
public void Draw()
{
for (int i = 0; i < _bars.Count; i++)
{
_bars[i].Draw(i * 10);
}
}
}
}
================================================
FILE: NativeUI/Elements/UIResRectangle.cs
================================================
using System.Drawing;
using GTA;
using GTA.Native;
namespace NativeUI
{
/// <summary>
/// A rectangle in 1080 pixels height system.
/// </summary>
public class UIResRectangle : UIRectangle
{
public UIResRectangle()
{ }
public UIResRectangle(Point pos, Size size) : base(pos, size)
{ }
public UIResRectangle(Point pos, Size size, Color color) : base(pos, size, color)
{ }
public override void Draw(Size offset)
{
if (!Enabled) return;
int screenw = Game.ScreenResolution.Width;
int screenh = Game.ScreenResolution.Height;
const float height = 1080f;
float ratio = (float)screenw / screenh;
var width = height * ratio;
float w = Size.Width/width;
float h = Size.Height/height;
float x = ((Position.X + offset.Width)/width) + w*0.5f;
float y = ((Position.Y + offset.Height)/height) + h*0.5f;
Function.Call(Hash.DRAW_RECT, x, y, w, h, Color.R, Color.G, Color.B, Color.A);
}
public static void Draw(int xPos, int yPos, int boxWidth, int boxHeight, Color color)
{
int screenw = Game.ScreenResolution.Width;
int screenh = Game.ScreenResolution.Height;
const float height = 1080f;
float ratio = (float)screenw / screenh;
var width = height * ratio;
float w = boxWidth / width;
float h = boxHeight / height;
float x = ((xPos) / width) + w * 0.5f;
float y = ((yPos) / height) + h * 0.5f;
Function.Call(Hash.DRAW_RECT, x, y, w, h, color.R, color.G, color.B, color.A);
}
}
}
================================================
FILE: NativeUI/Elements/UIResText.cs
================================================
using System;
using System.Drawing;
using GTA;
using GTA.Native;
using Font = GTA.Font;
namespace NativeUI
{
/// <summary>
/// A Text object in the 1080 pixels height base system.
/// </summary>
public class UIResText : UIText
{
public UIResText(string caption, Point position, float scale) : base(caption, position, scale)
{
TextAlignment = Alignment.Left;
}
public UIResText(string caption, Point position, float scale, Color color) : base(caption, position, scale, color)
{
TextAlignment = Alignment.Left;
}
public UIResText(string caption, Point position, float scale, Color color, Font font, Alignment justify) : base(caption, position, scale, color, font, false)
{
TextAlignment = justify;
}
public Alignment TextAlignment { get; set; }
/// <summary>
/// Push a long string into the stack.
/// </summary>
/// <param name="str"></param>
public static void AddLongString(string str)
{
var utf8ByteCount = System.Text.Encoding.UTF8.GetByteCount(str);
if (utf8ByteCount == str.Length)
{
AddLongStringForAscii(str);
}
else
{
AddLongStringForUtf8(str);
}
}
private static void AddLongStringForAscii(string input)
{
const int maxByteLengthPerString = 99;
for (int i = 0; i < input.Length; i += maxByteLengthPerString)
{
string substr = (input.Substring(i, Math.Min(maxByteLengthPerString, input.Length - i)));
Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, substr);
}
}
internal static void AddLongStringForUtf8(string input)
{
const int maxByteLengthPerString = 99;
if (maxByteLengthPerString < 0)
{
throw new ArgumentOutOfRangeException("maxLengthPerString");
}
if (string.IsNullOrEmpty(input) || maxByteLengthPerString == 0)
{
return;
}
var enc = System.Text.Encoding.UTF8;
var utf8ByteCount = enc.GetByteCount(input);
if (utf8ByteCount < maxByteLengthPerString)
{
Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, input);
return;
}
var startIndex = 0;
for (int i = 0; i < input.Length; i++)
{
var length = i - startIndex;
if (enc.GetByteCount(input.Substring(startIndex, length)) > maxByteLengthPerString)
{
string substr = (input.Substring(startIndex, length - 1));
Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, substr);
i -= 1;
startIndex = (startIndex + length - 1);
}
}
Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, input.Substring(startIndex, input.Length - startIndex));
}
[Obsolete("Use Screen.GetTextWidth instead.", true)]
public static float MeasureStringWidth(string str, Font font, float scale) => Screen.GetTextWidth(str, font, scale);
[Obsolete("Use Screen.GetTextWidth instead.", true)]
public static float MeasureStringWidthNoConvert(string str, Font font, float scale) => Screen.GetTextWidth(str, font, scale);
/// <summary>
/// Width of the text wrap box. Set to zero to disable.
/// </summary>
public int Wrap { get; set; } = 0;
/// <summary>
/// Size of the text wrap box.
/// </summary>
[Obsolete("Use UIResText.Wrap instead.", true)]
public Size WordWrap
{
get => new Size(Wrap, 0);
set => Wrap = value.Width;
}
public override void Draw(Size offset)
{
int screenw = Game.ScreenResolution.Width;
int screenh = Game.ScreenResolution.Height;
const float height = 1080f;
float ratio = (float)screenw / screenh;
var width = height * ratio;
float x = (Position.X) / width;
float y = (Position.Y) / height;
Function.Call(Hash.SET_TEXT_FONT, (int)Font);
Function.Call(Hash.SET_TEXT_SCALE, 1.0f, Scale);
Function.Call(Hash.SET_TEXT_COLOUR, Color.R, Color.G, Color.B, Color.A);
if (Shadow)
Function.Call(Hash.SET_TEXT_DROP_SHADOW);
if (Outline)
Function.Call(Hash.SET_TEXT_OUTLINE);
switch (TextAlignment)
{
case Alignment.Centered:
Function.Call(Hash.SET_TEXT_CENTRE, true);
break;
case Alignment.Right:
Function.Call(Hash.SET_TEXT_RIGHT_JUSTIFY, true);
Function.Call(Hash.SET_TEXT_WRAP, 0, x);
break;
}
if (Wrap != 0)
{
float xsize = (Position.X + Wrap) / width;
Function.Call(Hash.SET_TEXT_WRAP, x, xsize);
}
Function.Call(Hash._SET_TEXT_ENTRY, "jamyfafi");
AddLongString(Caption);
Function.Call(Hash._DRAW_TEXT, x, y);
}
public static void Draw(string caption, int xPos, int yPos, Font font, float scale, Color color, Alignment alignment, bool dropShadow, bool outline, int wordWrap)
{
int screenw = Game.ScreenResolution.Width;
int screenh = Game.ScreenResolution.Height;
const float height = 1080f;
float ratio = (float)screenw / screenh;
var width = height * ratio;
float x = (xPos) / width;
float y = (yPos) / height;
Function.Call(Hash.SET_TEXT_FONT, (int)font);
Function.Call(Hash.SET_TEXT_SCALE, 1.0f, scale);
Function.Call(Hash.SET_TEXT_COLOUR, color.R, color.G, color.B, color.A);
if (dropShadow)
Function.Call(Hash.SET_TEXT_DROP_SHADOW);
if (outline)
Function.Call(Hash.SET_TEXT_OUTLINE);
switch (alignment)
{
case Alignment.Centered:
Function.Call(Hash.SET_TEXT_CENTRE, true);
break;
case Alignment.Right:
Function.Call(Hash.SET_TEXT_RIGHT_JUSTIFY, true);
Function.Call(Hash.SET_TEXT_WRAP, 0, x);
break;
}
if (wordWrap != 0)
{
float xsize = (xPos + wordWrap) / width;
Function.Call(Hash.SET_TEXT_WRAP, x, xsize);
}
Function.Call(Hash._SET_TEXT_ENTRY, "jamyfafi");
AddLongString(caption);
Function.Call(Hash._DRAW_TEXT, x, y);
}
public enum Alignment
{
Left,
Centered,
Right,
}
}
}
================================================
FILE: NativeUI/InstructionalButton.cs
================================================
using GTA.Native;
namespace NativeUI
{
public class InstructionalButton
{
public string Text { get; set; }
public UIMenuItem ItemBind { get; private set; }
private readonly string _buttonString;
private readonly GTA.Control _buttonControl;
private readonly bool _usingControls;
/// <summary>
/// Add a dynamic button to the instructional buttons array.
/// Changes whether the controller is being used and changes depending on keybinds.
/// </summary>
/// <param name="control">GTA.Control that gets converted into a button.</param>
/// <param name="text">Help text that goes with the button.</param>
public InstructionalButton(GTA.Control control, string text)
{
Text = text;
_buttonControl = control;
_usingControls = true;
}
/// <summary>
/// Adds a keyboard button to the instructional buttons array.
/// </summary>
/// <param name="keystring">Custom keyboard button, like "I", or "O", or "F5".</param>
/// <param name="text">Help text that goes with the button.</param>
public InstructionalButton(string keystring, string text)
{
Text = text;
_buttonString = keystring;
_usingControls = false;
}
/// <summary>
/// Bind this button to an item, so it's only shown when that item is selected.
/// </summary>
/// <param name="item">Item to bind to.</param>
public void BindToItem(UIMenuItem item)
{
ItemBind = item;
}
public string GetButtonId()
{
return _usingControls ? Function.Call<string>(Hash._0x0499D7B09FC9B407, 2, (int) _buttonControl, 0) : "t_" + _buttonString;
}
}
}
================================================
FILE: NativeUI/Items/IListItem.cs
================================================
namespace NativeUI
{
public interface IListItem
{
string CurrentItem();
}
}
================================================
FILE: NativeUI/Items/UIMenuCheckboxItem.cs
================================================
using System;
using System.Drawing;
namespace NativeUI
{
public class UIMenuCheckboxItem : UIMenuItem
{
protected Sprite _checkedSprite;
/// <summary>
/// Triggered when the checkbox state is changed.
/// </summary>
public event ItemCheckboxEvent CheckboxEvent;
/// <summary>
/// Checkbox item with a toggleable checkbox.
/// </summary>
/// <param name="text">Item label.</param>
/// <param name="check">Boolean value whether the checkbox is checked.</param>
public UIMenuCheckboxItem(string text, bool check) : this(text, check, "")
{
}
/// <summary>
/// Checkbox item with a toggleable checkbox.
/// </summary>
/// <param name="text">Item label.</param>
/// <param name="check">Boolean value whether the checkbox is checked.</param>
/// <param name="description">Description for this item.</param>
public UIMenuCheckboxItem(string text, bool check, string description) : base(text, description)
{
const int y = 0;
_checkedSprite = new Sprite("commonmenu", "shop_box_blank", new Point(410, y + 95), new Size(50, 50));
Checked = check;
}
/// <summary>
/// Change or get whether the checkbox is checked.
/// </summary>
public bool Checked { get; set; }
/// <summary>
/// Change item's position.
/// </summary>
/// <param name="y">New Y value.</param>
public override void Position(int y)
{
base.Position(y);
_checkedSprite.Position = new Point(380 + Offset.X + Parent.WidthOffset, y + 138 + Offset.Y);
}
/// <summary>
/// Draw item.
/// </summary>
public override void Draw()
{
base.Draw();
_checkedSprite.Position = new Point(380 + Offset.X + Parent.WidthOffset, _checkedSprite.Position.Y);
if (Selected)
{
_checkedSprite.TextureName = Checked ? "shop_box_tickb" : "shop_box_blankb";
}
else
{
_checkedSprite.TextureName = Checked ? "shop_box_tick" : "shop_box_blank";
}
_checkedSprite.Draw();
}
public void CheckboxEventTrigger()
{
CheckboxEvent?.Invoke(this, Checked);
}
public override void SetRightBadge(BadgeStyle badge)
{
throw new Exception("UIMenuCheckboxItem cannot have a right badge.");
}
public override void SetRightLabel(string text)
{
throw new Exception("UIMenuListItem cannot have a right label.");
}
}
}
================================================
FILE: NativeUI/Items/UIMenuColoredItem.cs
================================================
using System.Drawing;
namespace NativeUI
{
public class UIMenuColoredItem : UIMenuItem
{
public Color MainColor { get; set; }
public Color HighlightColor { get; set; }
public Color TextColor { get; set; }
public Color HighlightedTextColor { get; set; }
public UIMenuColoredItem(string label, Color color, Color highlightColor) : base(label)
{
MainColor = color;
HighlightColor = highlightColor;
TextColor = Color.White;
HighlightedTextColor = Color.Black;
Init();
}
public UIMenuColoredItem(string label, string description, Color color, Color highlightColor) : base(label, description)
{
MainColor = color;
HighlightColor = highlightColor;
TextColor = Color.White;
HighlightedTextColor = Color.Black;
Init();
}
protected void Init()
{
_selectedSprite = new Sprite("commonmenu", "gradient_nav", new Point(0, 0), new Size(431, 38), 0, HighlightColor);
_rectangle = new UIResRectangle(new Point(0, 0), new Size(431, 38), Color.FromArgb(150, 0, 0, 0));
_text = new UIResText(Text, new Point(8, 0), 0.33f, Color.WhiteSmoke, GTA.Font.ChaletLondon, UIResText.Alignment.Left);
Description = Description;
_badgeLeft = new Sprite("commonmenu", "", new Point(0, 0), new Size(40, 40));
_badgeRight = new Sprite("commonmenu", "", new Point(0, 0), new Size(40, 40));
_labelText = new UIResText("", new Point(0, 0), 0.35f) { TextAlignment = UIResText.Alignment.Right };
}
public override void Draw()
{
_rectangle.Size = new Size(431 + Parent.WidthOffset, 38);
_selectedSprite.Size = new Size(431 + Parent.WidthOffset, 38);
if (Hovered && !Selected)
{
_rectangle.Color = Color.FromArgb(20, 255, 255, 255);
_rectangle.Draw();
}
if (Selected)
{
_selectedSprite.Color = HighlightColor;
_selectedSprite.Draw();
}
else
{
_selectedSprite.Color = MainColor;
_selectedSprite.Draw();
}
_text.Color = Enabled ? Selected ? HighlightedTextColor : TextColor : Color.FromArgb(163, 159, 148);
if (LeftBadge != BadgeStyle.None)
{
_text.Position = new Point(35 + Offset.X, _text.Position.Y);
_badgeLeft.TextureDict = BadgeToSpriteLib(LeftBadge);
_badgeLeft.TextureName = BadgeToSpriteName(LeftBadge, Selected);
_badgeLeft.Color = BadgeToColor(LeftBadge, Selected);
_badgeLeft.Draw();
}
else
{
_text.Position = new Point(8 + Offset.X, _text.Position.Y);
}
if (RightBadge != BadgeStyle.None)
{
_badgeRight.Position = new Point(385 + Offset.X + Parent.WidthOffset, _badgeRight.Position.Y);
_badgeRight.TextureDict = BadgeToSpriteLib(RightBadge);
_badgeRight.TextureName = BadgeToSpriteName(RightBadge, Selected);
_badgeRight.Color = BadgeToColor(RightBadge, Selected);
_badgeRight.Draw();
}
if (!string.IsNullOrWhiteSpace(RightLabel))
{
_labelText.Position = new Point(420 + Offset.X + Parent.WidthOffset, _labelText.Position.Y);
_labelText.Caption = RightLabel;
_labelText.Color = _text.Color = Enabled ? Selected ? HighlightedTextColor : TextColor : Color.FromArgb(163, 159, 148);
_labelText.Draw();
}
_text.Draw();
}
}
}
================================================
FILE: NativeUI/Items/UIMenuDynamicListItem.cs
================================================
using System;
using System.Drawing;
using Font = GTA.Font;
namespace NativeUI
{
public class UIMenuDynamicListItem : UIMenuItem, IListItem
{
public enum ChangeDirection
{
Left,
Right
}
public delegate string DynamicListItemChangeCallback(UIMenuDynamicListItem sender, ChangeDirection direction);
protected UIResText _itemText;
protected Sprite _arrowLeft;
protected Sprite _arrowRight;
public string CurrentListItem { get; internal set; }
public DynamicListItemChangeCallback Callback { get; set; }
/// <summary>
/// List item with items generated at runtime
/// </summary>
/// <param name="text">Label text</param>
public UIMenuDynamicListItem(string text, string startingItem, DynamicListItemChangeCallback changeCallback) : this(text, null, startingItem, changeCallback)
{
}
/// <summary>
/// List item with items generated at runtime
/// </summary>
/// <param name="text">Label text</param>
/// <param name="description">Item description</param>
public UIMenuDynamicListItem(string text, string description, string startingItem, DynamicListItemChangeCallback changeCallback) : base(text, description)
{
const int y = 0;
_arrowLeft = new Sprite("commonmenu", "arrowleft", new Point(110, 105 + y), new Size(30, 30));
_arrowRight = new Sprite("commonmenu", "arrowright", new Point(280, 105 + y), new Size(30, 30));
_itemText = new UIResText("", new Point(290, y + 104), 0.35f, Color.White, Font.ChaletLondon,
UIResText.Alignment.Right);
CurrentListItem = startingItem;
Callback = changeCallback;
}
/// <summary>
/// Change item's position.
/// </summary>
/// <param name="y">New Y position.</param>
public override void Position(int y)
{
_arrowLeft.Position = new Point(300 + Offset.X + Parent.WidthOffset, 147 + y + Offset.Y);
_arrowRight.Position = new Point(400 + Offset.X + Parent.WidthOffset, 147 + y + Offset.Y);
_itemText.Position = new Point(300 + Offset.X + Parent.WidthOffset, y + 147 + Offset.Y);
base.Position(y);
}
/// <summary>
/// Draw item.
/// </summary>
public override void Draw()
{
base.Draw();
string caption = CurrentListItem;
float offset = Screen.GetTextWidth(caption, _itemText.Font, _itemText.Scale);
_itemText.Color = Enabled ? Selected ? Color.Black : Color.WhiteSmoke : Color.FromArgb(163, 159, 148);
_itemText.Caption = caption;
_arrowLeft.Color = Enabled ? Selected ? Color.Black : Color.WhiteSmoke : Color.FromArgb(163, 159, 148);
_arrowRight.Color = Enabled ? Selected ? Color.Black : Color.WhiteSmoke : Color.FromArgb(163, 159, 148);
_arrowLeft.Position = new Point(375 - (int)offset + Offset.X + Parent.WidthOffset, _arrowLeft.Position.Y);
if (Selected)
{
_arrowLeft.Draw();
_arrowRight.Draw();
_itemText.Position = new Point(403 + Offset.X + Parent.WidthOffset, _itemText.Position.Y);
}
else
{
_itemText.Position = new Point(418 + Offset.X + Parent.WidthOffset, _itemText.Position.Y);
}
_itemText.Draw();
}
public override void SetRightBadge(BadgeStyle badge)
{
throw new Exception("UIMenuListItem cannot have a right badge.");
}
public override void SetRightLabel(string text)
{
throw new Exception("UIMenuListItem cannot have a right label.");
}
public string CurrentItem()
{
return CurrentListItem;
}
}
}
================================================
FILE: NativeUI/Items/UIMenuItem.cs
================================================
using System;
using System.Drawing;
namespace NativeUI
{
/// <summary>
/// Simple item with a label.
/// </summary>
public class UIMenuItem
{
protected UIResRectangle _rectangle;
protected UIResText _text;
protected Sprite _selectedSprite;
protected Sprite _badgeLeft;
protected Sprite _badgeRight;
protected UIResText _labelText;
private readonly Color _disabledColor = Color.FromArgb(163, 159, 148); // Why allocating memory for same color every time?
/// <summary>
/// Called when user selects the current item.
/// </summary>
public event ItemActivatedEvent Activated;
/// <summary>
/// Basic menu button.
/// </summary>
/// <param name="text">Button label.</param>
public UIMenuItem(string text) : this(text, "")
{
}
/// <summary>
/// Basic menu button.
/// </summary>
/// <param name="text">Button label.</param>
/// <param name="description">Description.</param>
public UIMenuItem(string text, string description)
{
Enabled = true;
_rectangle = new UIResRectangle(new Point(0, 0), new Size(431, 38), Color.FromArgb(20, 255, 255, 255)); // Color.FromArgb(150, 0, 0, 0)
_text = new UIResText(text, new Point(8, 0), 0.33f, Color.WhiteSmoke, GTA.Font.ChaletLondon, UIResText.Alignment.Left);
Description = description;
_selectedSprite = new Sprite("commonmenu", "gradient_nav", new Point(0, 0), new Size(431, 38));
_badgeLeft = new Sprite("commonmenu", "", new Point(0, 0), new Size(40, 40));
_badgeRight = new Sprite("commonmenu", "", new Point(0, 0), new Size(40, 40));
_labelText = new UIResText("", new Point(0, 0), 0.35f) {TextAlignment = UIResText.Alignment.Right};
}
/// <summary>
/// Whether this item is currently selected.
/// </summary>
public virtual bool Selected { get; set; }
/// <summary>
/// Whether this item is currently being hovered on with a mouse.
/// </summary>
public virtual bool Hovered { get; set; }
/// <summary>
/// This item's description.
/// </summary>
public virtual string Description { get; set; }
/// <summary>
/// Whether this item is enabled or disabled (text is greyed out and you cannot select it).
/// </summary>
public virtual bool Enabled { get; set; }
internal virtual void ItemActivate(UIMenu sender)
{
Activated?.Invoke(sender, this);
}
/// <summary>
/// Set item's position.
/// </summary>
/// <param name="y"></param>
public virtual void Position(int y)
{
_rectangle.Position = new Point(Offset.X, y + 144 + Offset.Y);
_selectedSprite.Position = new Point(0 + Offset.X, y + 144 + Offset.Y);
_text.Position = new Point(8 + Offset.X, y + 147 + Offset.Y);
_badgeLeft.Position = new Point(0 + Offset.X, y + 142 + Offset.Y);
_badgeRight.Position = new Point(385 + Offset.X, y + 142 + Offset.Y);
_labelText.Position = new Point(420 + Offset.X, y + 148 + Offset.Y);
}
/// <summary>
/// Draw this item.
/// </summary>
public virtual void Draw()
{
_rectangle.Size = new Size(431 + Parent.WidthOffset, 38);
_selectedSprite.Size = new Size(431 + Parent.WidthOffset, 38);
if (Hovered && !Selected)
{
//_rectangle.Color = Color.FromArgb(20, 255, 255, 255); // Why setting color every time? (I set it in ctor)
_rectangle.Draw();
}
if (Selected)
_selectedSprite.Draw();
_text.Color = Enabled ? (Selected ? Color.Black : Color.WhiteSmoke) : _disabledColor; // No alloc anymore there
if (LeftBadge == BadgeStyle.None)
{
_text.Position = new Point(8 + Offset.X, _text.Position.Y);
}
else
{
_text.Position = new Point(35 + Offset.X, _text.Position.Y);
_badgeLeft.TextureDict = BadgeToSpriteLib(LeftBadge);
_badgeLeft.TextureName = BadgeToSpriteName(LeftBadge, Selected);
_badgeLeft.Color = BadgeToColor(LeftBadge, Selected);
_badgeLeft.Draw();
}
if (RightBadge != BadgeStyle.None)
{
_badgeRight.Position = new Point(385 + Offset.X + Parent.WidthOffset, _badgeRight.Position.Y);
_badgeRight.TextureDict = BadgeToSpriteLib(RightBadge);
_badgeRight.TextureName = BadgeToSpriteName(RightBadge, Selected);
_badgeRight.Color = BadgeToColor(RightBadge, Selected);
_badgeRight.Draw();
}
if (!String.IsNullOrWhiteSpace(RightLabel))
{
_labelText.Position = new Point(420 + Offset.X + Parent.WidthOffset, _labelText.Position.Y);
_labelText.Caption = RightLabel;
_labelText.Color = _text.Color = Enabled ? (Selected ? Color.Black : Color.WhiteSmoke) : _disabledColor; // No alloc anymore there
_labelText.Draw();
}
_text.Draw();
}
/// <summary>
/// This item's offset.
/// </summary>
public Point Offset { get; set; }
/// <summary>
/// Returns this item's label.
/// </summary>
public string Text
{
get { return _text.Caption; }
set { _text.Caption = value; }
}
/// <summary>
/// Set the left badge. Set it to None to remove the badge.
/// </summary>
/// <param name="badge"></param>
public virtual void SetLeftBadge(BadgeStyle badge)
{
LeftBadge = badge;
}
/// <summary>
/// Set the right badge. Set it to None to remove the badge.
/// </summary>
/// <param name="badge"></param>
public virtual void SetRightBadge(BadgeStyle badge)
{
RightBadge = badge;
}
/// <summary>
/// Set the right label.
/// </summary>
/// <param name="text">Text as label. Set it to "" to remove the label.</param>
public virtual void SetRightLabel(string text)
{
RightLabel = text;
}
/// <summary>
/// Returns the current right label.
/// </summary>
public virtual string RightLabel { get; private set; }
/// <summary>
/// Returns the current left badge.
/// </summary>
public virtual BadgeStyle LeftBadge { get; private set; }
/// <summary>
/// Returns the current right badge.
/// </summary>
public virtual BadgeStyle RightBadge { get; private set; }
public enum BadgeStyle
{
None,
BronzeMedal,
GoldMedal,
SilverMedal,
Alert,
Crown,
Ammo,
Armour,
Barber,
Clothes,
Franklin,
Bike,
Car,
Gun,
Heart,
Makeup,
Mask,
Michael,
Star,
Tatoo,
Trevor,
Lock,
Tick,
Sale,
ArrowLeft,
ArrowRight,
Audio1,
Audio2,
Audio3,
AudioInactive,
AudioMute
}
internal static string BadgeToSpriteLib(BadgeStyle badge)
{
switch (badge)
{
case BadgeStyle.Sale:
return "mpshopsale";
case BadgeStyle.Audio1:
case BadgeStyle.Audio2:
case BadgeStyle.Audio3:
case BadgeStyle.AudioInactive:
case BadgeStyle.AudioMute:
return "mpleaderboard";
default:
return "commonmenu";
}
}
internal static string BadgeToSpriteName(BadgeStyle badge, bool selected)
{
switch (badge)
{
case BadgeStyle.None:
return "";
case BadgeStyle.BronzeMedal:
return "mp_medal_bronze";
case BadgeStyle.GoldMedal:
return "mp_medal_gold";
case BadgeStyle.SilverMedal:
return "medal_silver";
case BadgeStyle.Alert:
return "mp_alerttriangle";
case BadgeStyle.Crown:
return "mp_hostcrown";
case BadgeStyle.Ammo:
return selected ? "shop_ammo_icon_b" : "shop_ammo_icon_a";
case BadgeStyle.Armour:
return selected ? "shop_armour_icon_b" : "shop_armour_icon_a";
case BadgeStyle.Barber:
return selected ? "shop_barber_icon_b" : "shop_barber_icon_a";
case BadgeStyle.Clothes:
return selected ? "shop_clothing_icon_b" : "shop_clothing_icon_a";
case BadgeStyle.Franklin:
return selected ? "shop_franklin_icon_b" : "shop_franklin_icon_a";
case BadgeStyle.Bike:
return selected ? "shop_garage_bike_icon_b" : "shop_garage_bike_icon_a";
case BadgeStyle.Car:
return selected ? "shop_garage_icon_b" : "shop_garage_icon_a";
case BadgeStyle.Gun:
return selected ? "shop_gunclub_icon_b" : "shop_gunclub_icon_a";
case BadgeStyle.Heart:
return selected ? "shop_health_icon_b" : "shop_health_icon_a";
case BadgeStyle.Lock:
return "shop_lock";
case BadgeStyle.Makeup:
return selected ? "shop_makeup_icon_b" : "shop_makeup_icon_a";
case BadgeStyle.Mask:
return selected ? "shop_mask_icon_b" : "shop_mask_icon_a";
case BadgeStyle.Michael:
return selected ? "shop_michael_icon_b" : "shop_michael_icon_a";
case BadgeStyle.Star:
return "shop_new_star";
case BadgeStyle.Tatoo:
return selected ? "shop_tattoos_icon_b" : "shop_tattoos_icon_";
case BadgeStyle.Tick:
return "shop_tick_icon";
case BadgeStyle.Trevor:
return selected ? "shop_trevor_icon_b" : "shop_trevor_icon_a";
case BadgeStyle.Sale:
return "saleicon";
case BadgeStyle.ArrowLeft:
return "arrowleft";
case BadgeStyle.ArrowRight:
return "arrowright";
case BadgeStyle.Audio1:
return "leaderboard_audio_1";
case BadgeStyle.Audio2:
return "leaderboard_audio_2";
case BadgeStyle.Audio3:
return "leaderboard_audio_3";
case BadgeStyle.AudioInactive:
return "leaderboard_audio_inactive";
case BadgeStyle.AudioMute:
return "leaderboard_audio_mute";
default:
return "";
}
}
internal static Color BadgeToColor(BadgeStyle badge, bool selected)
{
switch (badge)
{
case BadgeStyle.Lock:
case BadgeStyle.Tick:
case BadgeStyle.Crown:
return selected ? Color.FromArgb(255, 0, 0, 0) : Color.FromArgb(255, 255, 255, 255);
default:
return Color.FromArgb(255, 255, 255, 255);
}
}
/// <summary>
/// Returns the menu this item is in.
/// </summary>
public UIMenu Parent { get; set; }
}
}
================================================
FILE: NativeUI/Items/UIMenuListItem.cs
================================================
using System;
using System.Collections.Generic;
using System.Drawing;
using GTA;
using Font = GTA.Font;
namespace NativeUI
{
public class UIMenuListItem : UIMenuItem, IListItem
{
protected UIResText _itemText;
protected Sprite _arrowLeft;
protected Sprite _arrowRight;
protected int _index;
protected List<object> _items;
/// <summary>
/// Triggered when the list is changed.
/// </summary>
public event ItemListEvent OnListChanged;
/// <summary>
/// Returns the current selected index.
/// </summary>
public int Index
{
get { return _index % Items.Count; }
set { _index = 100000000 - (100000000 % Items.Count) + value; }
}
/// <summary>
/// Returns the current selected index.
/// </summary>
public List<object> Items
{
get => _items;
set
{
Index = 0;
_items = value;
}
}
/// <summary>
/// List item, with left/right arrows.
/// </summary>
/// <param name="text">Item label.</param>
/// <param name="items">List that contains your items.</param>
/// <param name="index">Index in the list. If unsure user 0.</param>
public UIMenuListItem(string text, List<object> items, int index) : this(text, items, index, "")
{
}
/// <summary>
/// List item, with left/right arrows.
/// </summary>
/// <param name="text">Item label.</param>
/// <param name="items">List that contains your items.</param>
/// <param name="index">Index in the list. If unsure user 0.</param>
/// <param name="description">Description for this item.</param>
public UIMenuListItem(string text, List<object> items, int index, string description) : base(text, description)
{
const int y = 0;
_items = items;
_arrowLeft = new Sprite("commonmenu", "arrowleft", new Point(110, 105 + y), new Size(30, 30));
_arrowRight = new Sprite("commonmenu", "arrowright", new Point(280, 105 + y), new Size(30, 30));
_itemText = new UIResText("", new Point(290, y + 104), 0.35f, Color.White, Font.ChaletLondon,
UIResText.Alignment.Left) {TextAlignment = UIResText.Alignment.Right};
Index = index;
}
/// <summary>
/// Change item's position.
/// </summary>
/// <param name="y">New Y position.</param>
public override void Position(int y)
{
_arrowLeft.Position = new Point(300 + Offset.X + Parent.WidthOffset, 147 + y + Offset.Y);
_arrowRight.Position = new Point(400 + Offset.X + Parent.WidthOffset, 147 + y + Offset.Y);
_itemText.Position = new Point(300 + Offset.X + Parent.WidthOffset, y + 147 + Offset.Y);
base.Position(y);
}
/// <summary>
/// Find an item in the list and return it's index.
/// </summary>
/// <param name="item">Item to search for.</param>
/// <returns>Item index.</returns>
[Obsolete("Use UIMenuListItem.Items.FindIndex(p => ReferenceEquals(p, item)) instead.")]
public virtual int ItemToIndex(object item)
{
return Items.FindIndex(p => ReferenceEquals(p, item));
}
/// <summary>
/// Find an item by it's index and return the item.
/// </summary>
/// <param name="index">Item's index.</param>
/// <returns>Item</returns>
[Obsolete("Use UIMenuListItem.Items[Index] instead.")]
public virtual object IndexToItem(int index)
{
return Items[index];
}
/// <summary>
/// Draw item.
/// </summary>
public override void Draw()
{
base.Draw();
string caption = Items[Index].ToString();
float offset = Screen.GetTextWidth(caption, _itemText.Font, _itemText.Scale);
_itemText.Color = Enabled ? Selected ? Color.Black : Color.WhiteSmoke : Color.FromArgb(163, 159, 148);
_itemText.Caption = caption;
_arrowLeft.Color = Enabled ? Selected ? Color.Black : Color.WhiteSmoke : Color.FromArgb(163, 159, 148);
_arrowRight.Color = Enabled ? Selected ? Color.Black : Color.WhiteSmoke : Color.FromArgb(163, 159, 148);
_arrowLeft.Position = new Point(375 - (int)offset + Offset.X + Parent.WidthOffset, _arrowLeft.Position.Y);
if (Selected)
{
_arrowLeft.Draw();
_arrowRight.Draw();
_itemText.Position = new Point(403 + Offset.X + Parent.WidthOffset, _itemText.Position.Y);
}
else
{
_itemText.Position = new Point(418 + Offset.X + Parent.WidthOffset, _itemText.Position.Y);
}
_itemText.Draw();
}
internal virtual void ListChangedTrigger(int newindex)
{
OnListChanged?.Invoke(this, newindex);
}
public override void SetRightBadge(BadgeStyle badge)
{
throw new Exception("UIMenuListItem cannot have a right badge.");
}
public override void SetRightLabel(string text)
{
throw new Exception("UIMenuListItem cannot have a right label.");
}
[Obsolete("Use UIMenuListItem.Items[Index].ToString() instead.")]
public string CurrentItem()
{
return Items[Index].ToString();
}
}
}
================================================
FILE: NativeUI/Items/UIMenuSliderItem.cs
================================================
using System.Collections.Generic;
using System.Drawing;
namespace NativeUI
{
public class UIMenuSliderItem : UIMenuItem
{
protected Sprite _arrowLeft;
protected Sprite _arrowRight;
protected UIResRectangle _rectangleBackground;
protected UIResRectangle _rectangleSlider;
protected UIResRectangle _rectangleDivider;
protected int _value = 0;
protected int _max = 100;
protected int _multiplier = 5;
/// <summary>
/// Triggered when the slider is changed.
/// </summary>
public event ItemSliderEvent OnSliderChanged;
/// <summary>
/// The maximum value of the slider.
/// </summary>
public int Maximum
{
get
{
return _max;
}
set
{
_max = value;
if (_value > value)
{
_value = value;
}
}
}
/// <summary>
/// Curent value of the slider.
/// </summary>
public int Value
{
get
{
return _value;
}
set
{
if (value > _max)
_value = _max;
else if (value < 0)
_value = 0;
else
_value = value;
SliderChanged();
}
}
/// <summary>
/// The multiplier of the left and right navigation movements.
/// </summary>
public int Multiplier
{
get
{
return _multiplier;
}
set
{
_multiplier = value;
}
}
/// <summary>
/// List item, with slider.
/// </summary>
/// <param name="text">Item label.</param>
/// <param name="items">List that contains your items.</param>
/// <param name="index">Index in the list. If unsure user 0.</param>
public UIMenuSliderItem(string text) : this(text, "", false)
{
}
/// <summary>
/// List item, with slider.
/// </summary>
/// <param name="text">Item label.</param>
/// <param name="items">List that contains your items.</param>
/// <param name="index">Index in the list. If unsure user 0.</param>
/// <param name="description">Description for this item.</param>
public UIMenuSliderItem(string text, string description) : this(text, description, false)
{
}
/// <summary>
/// List item, with slider.
/// </summary>
/// <param name="text">Item label.</param>
/// <param name="items">List that contains your items.</param>
/// <param name="index">Index in the list. If unsure user 0.</param>
/// <param name="description">Description for this item.</param>
/// /// <param name="divider">Put a divider in the center of the slider</param>
public UIMenuSliderItem(string text, string description, bool divider) : base(text, description)
{
const int y = 0;
_arrowLeft = new Sprite("commonmenutu", "arrowleft", new Point(0, 105 + y), new Size(15, 15));
_arrowRight = new Sprite("commonmenutu", "arrowright", new Point(0, 105 + y), new Size(15, 15));
_rectangleBackground = new UIResRectangle(new Point(0, 0), new Size(150, 9), Color.FromArgb(255, 4, 32, 57));
_rectangleSlider = new UIResRectangle(new Point(0, 0), new Size(75, 9), Color.FromArgb(255, 57, 116, 200));
if (divider)
{
_rectangleDivider = new UIResRectangle(new Point(0, 0), new Size(2, 20), Color.WhiteSmoke);
}
else
{
_rectangleDivider = new UIResRectangle(new Point(0, 0), new Size(2, 20), Color.Transparent);
}
}
/// <summary>
/// Change item's position.
/// </summary>
/// <param name="y">New Y position.</param>
public override void Position(int y)
{
_rectangleBackground.Position = new Point(250 + Offset.X, y + 158 + Offset.Y);
_rectangleSlider.Position = new Point(250 + Offset.X, y + 158 + Offset.Y);
_rectangleDivider.Position = new Point(323 + Offset.X, y + 153 + Offset.Y);
_arrowLeft.Position = new Point(235 + Offset.X + Parent.WidthOffset, 155 + y + Offset.Y);
_arrowRight.Position = new Point(400 + Offset.X + Parent.WidthOffset, 155 + y + Offset.Y);
base.Position(y);
}
/// <summary>
/// Draw item.
/// </summary>
public override void Draw()
{
base.Draw();
_arrowLeft.Color = Enabled ? Selected ? Color.Black : Color.WhiteSmoke : Color.FromArgb(163, 159, 148);
_arrowRight.Color = Enabled ? Selected ? Color.Black : Color.WhiteSmoke : Color.FromArgb(163, 159, 148);
int offset = 176 + Offset.X + _rectangleBackground.Size.Width - _rectangleSlider.Size.Width;
_rectangleSlider.Position = new Point((int)(offset + (_value / (float)_max * 73)), _rectangleSlider.Position.Y);
if (Selected)
{
_arrowLeft.Draw();
_arrowRight.Draw();
}
else
{
}
_rectangleBackground.Draw();
_rectangleSlider.Draw();
_rectangleDivider.Draw();
}
internal virtual void SliderChanged()
{
OnSliderChanged?.Invoke(this, Value);
}
}
}
================================================
FILE: NativeUI/MenuPool.cs
================================================
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Control = GTA.Control;
namespace NativeUI
{
/// <summary>
/// Helper class that handles all of your Menus. After instatiating it, you will have to add your menu by using the Add method.
/// </summary>
public class MenuPool
{
public bool MouseEdgeEnabled { set { _menuList.ForEach(m => m.MouseEdgeEnabled = value); } }
public bool ControlDisablingEnabled { set { _menuList.ForEach(m => m.ControlDisablingEnabled = value); } }
public bool ResetCursorOnOpen { set { _menuList.ForEach(m => m.ResetCursorOnOpen = value); } }
public bool UseCursor { set { _menuList.ForEach(m => m.UseCursor = value); } }
public bool FormatDescriptions { set { _menuList.ForEach(m => m.FormatDescriptions = value); } }
public string AUDIO_LIBRARY { set { _menuList.ForEach(m => m.AUDIO_LIBRARY = value); } }
public string AUDIO_UPDOWN { set { _menuList.ForEach(m => m.AUDIO_UPDOWN = value); } }
public string AUDIO_SELECT { set { _menuList.ForEach(m => m.AUDIO_SELECT = value); } }
public string AUDIO_BACK { set { _menuList.ForEach(m => m.AUDIO_BACK = value); } }
public string AUDIO_ERROR { set { _menuList.ForEach(m => m.AUDIO_ERROR = value); } }
public int WidthOffset { set { _menuList.ForEach(m => m.SetMenuWidthOffset(value)); } }
public string CounterPretext { set { _menuList.ForEach(m => m.CounterPretext = value); } }
public bool DisableInstructionalButtons { set { _menuList.ForEach(m => m.DisableInstructionalButtons(value)); } }
public bool BannerInheritance = true;
public bool OffsetInheritance = true;
private readonly List<UIMenu> _menuList = new List<UIMenu>();
/// <summary>
/// Add your menu to the menu pool.
/// </summary>
/// <param name="menu"></param>
public void Add(UIMenu menu)
{
_menuList.Add(menu);
}
/// <summary>
/// Create and add a submenu to the menu pool.
/// Adds an item with the given text to the menu, creates a corresponding submenu, and binds the submenu to the item.
/// The submenu inherits its title from the menu, and its subtitle from the item text.
/// </summary>
/// <param name="menu">The parent menu to which the submenu must be added.</param>
/// <param name="text">The name of the submenu.</param>
/// <returns>The newly created submenu.</returns>
public UIMenu AddSubMenu(UIMenu menu, string text)
{
Point Offset = Point.Empty;
if (OffsetInheritance)
Offset = menu.Offset;
return AddSubMenu(menu, text, "", Offset);
}
/// <summary>
/// Create and add a submenu to the menu pool with a custom offset.
/// Adds an item with the given text to the menu, creates a corresponding submenu, and binds the submenu to the item.
/// The submenu inherits its title from the menu, and its subtitle from the item text.
/// </summary>
/// <param name="menu">The parent menu to which the submenu must be added.</param>
/// <param name="text">The name of the submenu</param>
/// <param name="offset">The offset of the menu</param>
/// <returns>The newly created submenu.</returns>
public UIMenu AddSubMenu(UIMenu menu, string text, Point offset)
{
return AddSubMenu(menu, text, "", offset);
}
/// <summary>
/// Create and add a submenu to the menu pool.
/// Adds an item with the given text and description to the menu, creates a corresponding submenu, and binds the submenu to the item.
/// The submenu inherits its title from the menu, and its subtitle from the item text.
/// </summary>
/// <param name="menu">The parent menu to which the submenu must be added.</param>
/// <param name="text">The name of the submenu.</param>
/// <param name="description">The name of the submenu.</param>
/// <returns>The newly created submenu.</returns>
public UIMenu AddSubMenu(UIMenu menu, string text, string description)
{
Point Offset = Point.Empty;
if (OffsetInheritance)
Offset = menu.Offset;
return AddSubMenu(menu, text, description, Offset);
}
/// <summary>
/// Create and add a submenu to the menu pool.
/// Adds an item with the given text and description to the menu, creates a corresponding submenu, and binds the submenu to the item.
/// The submenu inherits its title from the menu, and its subtitle from the item text.
/// </summary>
/// <param name="menu">The parent menu to which the submenu must be added.</param>
/// <param name="text">The name of the submenu.</param>
/// <param name="description">The name of the submenu.</param>
/// <returns>The newly created submenu.</returns>
public UIMenu AddSubMenu(UIMenu menu, string text, string description, Point offset)
{
UIMenuItem item = new UIMenuItem(text, description);
menu.AddItem(item);
UIMenu submenu = new UIMenu(menu.Title.Caption, text, offset);
if (BannerInheritance && menu.BannerTexture != null)
submenu.SetBannerType(submenu.BannerTexture);
else if (BannerInheritance && menu.BannerRectangle != null)
submenu.SetBannerType(submenu.BannerRectangle);
else if (BannerInheritance && menu.BannerSprite != null)
submenu.SetBannerType(menu.BannerSprite);
Add(submenu);
menu.BindMenuToItem(submenu, item);
return submenu;
}
/// <summary>
/// Refresh index of every menu in the pool.
/// Use this after you have finished constructing the entire menu pool.
/// </summary>
public void RefreshIndex()
{
foreach (UIMenu menu in _menuList) menu.RefreshIndex();
}
/// <summary>
/// Returns all of your menus.
/// </summary>
/// <returns></returns>
public List<UIMenu> ToList()
{
return _menuList;
}
/// <summary>
/// Processes all of your visible menus' controls.
/// </summary>
public void ProcessControl()
{
/*foreach (var menu in _menuList.Where(menu => menu.Visible)) // foreach works slower with List. Also why make a new enumerable every tick
{
menu.ProcessControl();
}*/
int count = _menuList.Count; // Cache count
for (int i = 0; i < count; i++)
{
if (_menuList[i].Visible)
_menuList[i].ProcessControl();
}
}
/// <summary>
/// Processes all of your visible menus' keys.
/// </summary>
/// <param name="key"></param>
public void ProcessKey(Keys key)
{
/*foreach (var menu in _menuList.Where(menu => menu.Visible))
{
menu.ProcessKey(key);
}*/
int count = _menuList.Count;
for (int i = 0; i < count; i++)
{
if (_menuList[i].Visible)
_menuList[i].ProcessKey(key);
}
}
/// <summary>
/// Processes all of your visible menus' mouses.
/// </summary>
public void ProcessMouse()
{
/*foreach (var menu in _menuList.Where(menu => menu.Visible))
{
menu.ProcessMouse();
}*/
int count = _menuList.Count;
for (int i = 0; i < count; i++)
{
if (_menuList[i].Visible)
_menuList[i].ProcessMouse();
}
}
/// <summary>
/// Draws all visible menus.
/// </summary>
public void Draw()
{
/*foreach (var menu in _menuList.Where(menu => menu.Visible))
{
menu.Draw();
}*/
int count = _menuList.Count;
for (int i = 0; i < count; i++)
{
if (_menuList[i].Visible)
_menuList[i].Draw();
}
}
/// <summary>
/// Checks if any menu is currently visible.
/// </summary>
/// <returns>true if at least one menu is visible, false if not.</returns>
public bool IsAnyMenuOpen()
{
return _menuList.Any(menu => menu.Visible);
}
/// <summary>
/// Process all of your menus' functions. Call this in a tick event.
/// </summary>
public void ProcessMenus()
{
ProcessControl();
ProcessMouse();
Draw();
}
/// <summary>
/// Closes all of your menus.
/// </summary>
public void CloseAllMenus()
{
foreach (var menu in _menuList.Where(menu => menu.Visible))
{
menu.Visible = false;
}
}
public void SetBannerType(Sprite bannerType)
{
_menuList.ForEach(m => m.SetBannerType(bannerType));
}
public void SetBannerType(UIResRectangle bannerType)
{
_menuList.ForEach(m => m.SetBannerType(bannerType));
}
public void SetBannerType(string bannerPath)
{
_menuList.ForEach(m => m.SetBannerType(bannerPath));
}
public void SetKey(UIMenu.MenuControls menuControl, Control control)
{
_menuList.ForEach(m => m.SetKey(menuControl, control));
}
public void SetKey(UIMenu.MenuControls menuControl, Control control, int controllerIndex)
{
_menuList.ForEach(m => m.SetKey(menuControl, control, controllerIndex));
}
public void SetKey(UIMenu.MenuControls menuControl, Keys control)
{
_menuList.ForEach(m => m.SetKey(menuControl, control));
}
public void ResetKey(UIMenu.MenuControls menuControl)
{
_menuList.ForEach(m => m.ResetKey(menuControl));
}
}
}
================================================
FILE: NativeUI/NativeUI.csproj
================================================
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F3E16ED9-DBF7-4E7B-B04B-9B24B11891D3}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NativeUI</RootNamespace>
<AssemblyName>NativeUI</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\x64\Release\NativeUI.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="ScriptHookVDotNet2, Version=2.10.12.0, Culture=neutral, processorArchitecture=AMD64">
<HintPath>..\packages\ScriptHookVDotNet2.2.10.12\lib\net48\ScriptHookVDotNet2.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BigMessage.cs" />
<Compile Include="Controls.cs" />
<Compile Include="InstructionalButton.cs" />
<Compile Include="Items\IListItem.cs" />
<Compile Include="Items\UIMenuDynamicListItem.cs" />
<Compile Include="Items\UIMenuSliderItem.cs" />
<Compile Include="MenuPool.cs" />
<Compile Include="PauseMenu\TabItem.cs" />
<Compile Include="PauseMenu\TabItemSimpleList.cs" />
<Compile Include="PauseMenu\TabMissionSelectItem.cs" />
<Compile Include="PauseMenu\TabInteractiveListItem.cs" />
<Compile Include="PauseMenu\TabSubmenuItem.cs" />
<Compile Include="PauseMenu\TabTextItem.cs" />
<Compile Include="PauseMenu\TabView.cs" />
<Compile Include="PointExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Elements\Sprite.cs" />
<Compile Include="Screen.cs" />
<Compile Include="StringMeasurer.cs" />
<Compile Include="Elements\TimerBars.cs" />
<Compile Include="UIMenu.cs" />
<Compile Include="Items\UIMenuCheckboxItem.cs" />
<Compile Include="Items\UIMenuColoredItem.cs" />
<Compile Include="Items\UIMenuItem.cs" />
<Compile Include="Items\UIMenuListItem.cs" />
<Compile Include="Elements\UIResRectangle.cs" />
<Compile Include="Elements\UIResText.cs" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />
</ItemGroup>
<ItemGroup>
<None Include="NativeUI.nuspec" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
================================================
FILE: NativeUI/NativeUI.nuspec
================================================
<?xml version="1.0"?>
<package >
<metadata>
<id>NativeUI</id>
<version>1.9</version>
<authors>Guad</authors>
<licenseUrl>https://github.com/Guad/NativeUI/blob/master/LICENSE.md</licenseUrl>
<projectUrl>https://github.com/Guad/NativeUI</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>NativeUI is a ScriptHookDotNet based library that helps you quickly and easily build Rockstar-like menus.</description>
<tags>gta gtav shvdn</tags>
<dependencies>
<dependency id="ScriptHookVDotNet2" version="2.10.7" />
</dependencies>
</metadata>
<files>
<file src="bin\x64\Release\NativeUI.dll" target="lib\net452" />
</files>
</package>
================================================
FILE: NativeUI/PauseMenu/TabInteractiveListItem.cs
================================================
using System;
using System.Collections.Generic;
using System.Drawing;
using GTA;
using GTA.Native;
using Font = GTA.Font;
namespace NativeUI.PauseMenu
{
public class TabInteractiveListItem : TabItem
{
public TabInteractiveListItem(string name, IEnumerable<UIMenuItem> items) : base(name)
{
DrawBg = false;
CanBeFocused = true;
Items = new List<UIMenuItem>(items);
IsInList = true;
_maxItem = MaxItemsPerView;
_minItem = 0;
}
public List<UIMenuItem> Items { get; set; }
public int Index { get; set; }
public bool IsInList { get; set; }
protected const int MaxItemsPerView = 15;
protected int _minItem;
protected int _maxItem;
public void MoveDown()
{
Index = (1000 - (1000 % Items.Count) + Index + 1) % Items.Count;
if (Items.Count <= MaxItemsPerView) return;
if (Index >= _maxItem)
{
_maxItem++;
_minItem++;
}
if (Index == 0)
{
_minItem = 0;
_maxItem = MaxItemsPerView;
}
}
public void MoveUp()
{
Index = (1000 - (1000 % Items.Count) + Index - 1) % Items.Count;
if (Items.Count <= MaxItemsPerView) return;
if (Index < _minItem)
{
_minItem--;
_maxItem--;
}
if (Index == Items.Count - 1)
{
_minItem = Items.Count - MaxItemsPerView;
_maxItem = Items.Count;
}
}
public void RefreshIndex()
{
Index = 0;
_maxItem = MaxItemsPerView;
_minItem = 0;
}
public override void ProcessControls()
{
if (!Visible) return;
if (JustOpened)
{
JustOpened = false;
return;
}
if (!Focused) return;
if (Items.Count == 0) return;
if (Game.IsControlJustPressed(0, Control.FrontendAccept) && Focused && Items[Index] is UIMenuCheckboxItem)
{
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
((UIMenuCheckboxItem)Items[Index]).Checked = !((UIMenuCheckboxItem)Items[Index]).Checked;
((UIMenuCheckboxItem)Items[Index]).CheckboxEventTrigger();
}
else if (Game.IsControlJustPressed(0, Control.FrontendAccept) && Focused)
{
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
Items[Index].ItemActivate(null);
}
if (Game.IsControlJustPressed(0, Control.FrontendLeft) && Focused && Items[Index] is UIMenuListItem)
{
var it = (UIMenuListItem)Items[Index];
it.Index--;
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "NAV_LEFT_RIGHT", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
it.ListChangedTrigger(it.Index);
}
if (Game.IsControlJustPressed(0, Control.FrontendRight) && Focused && Items[Index] is UIMenuListItem)
{
var it = (UIMenuListItem)Items[Index];
it.Index++;
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "NAV_LEFT_RIGHT", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
it.ListChangedTrigger(it.Index);
}
if (Game.IsControlJustPressed(0, Control.FrontendUp) || Game.IsControlJustPressed(0, Control.MoveUpOnly) || Game.IsControlJustPressed(0, Control.CursorScrollUp))
{
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
MoveUp();
}
else if (Game.IsControlJustPressed(0, Control.FrontendDown) || Game.IsControlJustPressed(0, Control.MoveDownOnly) || Game.IsControlJustPressed(0, Control.CursorScrollDown))
{
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
MoveDown();
}
}
public override void Draw()
{
if (!Visible) return;
base.Draw();
var res = Screen.ResolutionMaintainRatio;
var alpha = Focused ? 120 : 30;
var blackAlpha = Focused ? 200 : 100;
var fullAlpha = Focused ? 255 : 150;
var submenuWidth = (BottomRight.X - TopLeft.X);
var itemSize = new Size(submenuWidth, 40);
int i = 0;
for (int c = _minItem; c < Math.Min(Items.Count, _maxItem); c++)
{
var hovering = Screen.IsMouseInBounds(SafeSize.AddPoints(new Point(0, (itemSize.Height + 3) * i)),
itemSize);
var hasLeftBadge = Items[c].LeftBadge != UIMenuItem.BadgeStyle.None;
var hasRightBadge = Items[c].RightBadge != UIMenuItem.BadgeStyle.None;
var hasBothBadges = hasRightBadge && hasLeftBadge;
var hasAnyBadge = hasRightBadge || hasLeftBadge;
new UIResRectangle(SafeSize.AddPoints(new Point(0, (itemSize.Height + 3) * i)), itemSize, (Index == c && Focused) ? Color.FromArgb(fullAlpha, Color.White) : Focused && hovering ? Color.FromArgb(100, 50, 50, 50) : Color.FromArgb(blackAlpha, Color.Black)).Draw();
new UIResText(Items[c].Text, SafeSize.AddPoints(new Point((hasBothBadges ? 60 : hasAnyBadge ? 30 : 6), 5 + (itemSize.Height + 3) * i)), 0.35f, Color.FromArgb(fullAlpha, (Index == c && Focused) ? Color.Black : Color.White)).Draw();
if (hasLeftBadge && !hasRightBadge)
{
new Sprite(UIMenuItem.BadgeToSpriteLib(Items[c].LeftBadge),
UIMenuItem.BadgeToSpriteName(Items[c].LeftBadge, (Index == c && Focused)), SafeSize.AddPoints(new Point(-2, 1 + (itemSize.Height + 3) * i)), new Size(40, 40), 0f,
UIMenuItem.BadgeToColor(Items[c].LeftBadge, (Index == c && Focused))).Draw();
}
if (!hasLeftBadge && hasRightBadge)
{
new Sprite(UIMenuItem.BadgeToSpriteLib(Items[c].RightBadge),
UIMenuItem.BadgeToSpriteName(Items[c].RightBadge, (Index == c && Focused)), SafeSize.AddPoints(new Point(-2, 1 + (itemSize.Height + 3) * i)), new Size(40, 40), 0f,
UIMenuItem.BadgeToColor(Items[c].RightBadge, (Index == c && Focused))).Draw();
}
if (hasLeftBadge && hasRightBadge)
{
new Sprite(UIMenuItem.BadgeToSpriteLib(Items[c].LeftBadge),
UIMenuItem.BadgeToSpriteName(Items[c].LeftBadge, (Index == c && Focused)), SafeSize.AddPoints(new Point(-2, 1 + (itemSize.Height + 3) * i)), new Size(40, 40), 0f,
UIMenuItem.BadgeToColor(Items[c].LeftBadge, (Index == c && Focused))).Draw();
new Sprite(UIMenuItem.BadgeToSpriteLib(Items[c].RightBadge),
UIMenuItem.BadgeToSpriteName(Items[c].RightBadge, (Index == c && Focused)), SafeSize.AddPoints(new Point(25, 1 + (itemSize.Height + 3) * i)), new Size(40, 40), 0f,
UIMenuItem.BadgeToColor(Items[c].RightBadge, (Index == c && Focused))).Draw();
}
if (!string.IsNullOrEmpty(Items[c].RightLabel))
{
new UIResText(Items[c].RightLabel,
SafeSize.AddPoints(new Point(BottomRight.X - SafeSize.X - 5, 5 + (itemSize.Height + 3) * i)),
0.35f, Color.FromArgb(fullAlpha, (Index == c && Focused) ? Color.Black : Color.White),
Font.ChaletLondon, UIResText.Alignment.Right).Draw();
}
if (Items[c] is UIMenuCheckboxItem)
{
string textureName = "";
if (c == Index && Focused)
{
textureName = ((UIMenuCheckboxItem)Items[c]).Checked ? "shop_box_tickb" : "shop_box_blankb";
}
else
{
textureName = ((UIMenuCheckboxItem)Items[c]).Checked ? "shop_box_tick" : "shop_box_blank";
}
new Sprite("commonmenu", textureName, SafeSize.AddPoints(new Point(BottomRight.X - SafeSize.X - 60, -5 + (itemSize.Height + 3) * i)), new Size(50, 50)).Draw();
}
else if (Items[c] is UIMenuListItem)
{
var convItem = (UIMenuListItem)Items[c];
var yoffset = 5;
var basePos =
SafeSize.AddPoints(new Point(BottomRight.X - SafeSize.X - 30, yoffset + (itemSize.Height + 3) * i));
var arrowLeft = new Sprite("commonmenu", "arrowleft", basePos, new Size(30, 30));
var arrowRight = new Sprite("commonmenu", "arrowright", basePos, new Size(30, 30));
var itemText = new UIResText("", basePos, 0.35f, Color.White, Font.ChaletLondon,
UIResText.Alignment.Left)
{ TextAlignment = UIResText.Alignment.Right };
string caption = convItem.Items[convItem.Index].ToString();
float offset = Screen.GetTextWidth(caption, itemText.Font, itemText.Scale);
var selected = c == Index && Focused;
itemText.Color = convItem.Enabled ? selected ? Color.Black : Color.WhiteSmoke : Color.FromArgb(163, 159, 148);
itemText.Caption = caption;
arrowLeft.Color = convItem.Enabled ? selected ? Color.Black : Color.WhiteSmoke : Color.FromArgb(163, 159, 148);
arrowRight.Color = convItem.Enabled ? selected ? Color.Black : Color.WhiteSmoke : Color.FromArgb(163, 159, 148);
arrowLeft.Position =
SafeSize.AddPoints(new Point(BottomRight.X - SafeSize.X - 60 - (int)offset, yoffset + (itemSize.Height + 3)*i));
if (selected)
{
arrowLeft.Draw();
arrowRight.Draw();
itemText.Position = SafeSize.AddPoints(new Point(BottomRight.X - SafeSize.X - 30, yoffset + (itemSize.Height + 3) * i));
}
else
{
itemText.Position = SafeSize.AddPoints(new Point(BottomRight.X - SafeSize.X - 5, yoffset + (itemSize.Height + 3) * i));
}
itemText.Draw();
}
if (Focused && hovering && Game.IsControlJustPressed(0, Control.CursorAccept))
{
bool open = Index == c;
Index = (1000 - (1000 % Items.Count) + c) % Items.Count;
if (!open)
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
else
{
if (Items[Index] is UIMenuCheckboxItem)
{
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
((UIMenuCheckboxItem)Items[Index]).Checked = !((UIMenuCheckboxItem)Items[Index]).Checked;
((UIMenuCheckboxItem)Items[Index]).CheckboxEventTrigger();
}
else
{
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
Items[Index].ItemActivate(null);
}
}
}
i++;
}
}
}
}
================================================
FILE: NativeUI/PauseMenu/TabItem.cs
================================================
using System;
using System.Drawing;
namespace NativeUI.PauseMenu
{
public class TabItem
{
public TabItem(string name)
{
RockstarTile = new Sprite("pause_menu_sp_content", "rockstartilebmp", new Point(), new Size(64, 64), 0f, Color.FromArgb(40, 255, 255, 255));
Title = name;
DrawBg = true;
UseDynamicPositionment = true;
}
public virtual bool Visible { get; set; }
public virtual bool Focused { get; set; }
public string Title { get; set; }
public bool Active { get; set; }
public bool JustOpened { get; set; }
public bool CanBeFocused { get; set; }
public Point TopLeft { get; set; }
public Point BottomRight { get; set; }
public Point SafeSize { get; set; }
public bool UseDynamicPositionment { get; set; }
public TabView Parent { get; set; }
public event EventHandler Activated;
public event EventHandler DrawInstructionalButtons;
public bool DrawBg;
public bool FadeInWhenFocused { get; set; }
protected Sprite RockstarTile;
public void OnActivated()
{
Activated?.Invoke(this, EventArgs.Empty);
}
public virtual void ProcessControls()
{
}
public virtual void Draw()
{
if (!Visible) return;
var res = Screen.ResolutionMaintainRatio;
if (UseDynamicPositionment)
{
SafeSize = new Point(300, 240);
TopLeft = new Point(SafeSize.X, SafeSize.Y);
BottomRight = new Point((int)res.Width - SafeSize.X, (int)res.Height - SafeSize.Y);
}
var rectSize = new Size(BottomRight.SubtractPoints(TopLeft));
DrawInstructionalButtons?.Invoke(this, EventArgs.Empty);
if (DrawBg)
{
new UIResRectangle(TopLeft, rectSize,
Color.FromArgb((Focused || !FadeInWhenFocused) ? 200 : 120, 0, 0, 0)).Draw();
var tileSize = 100;
RockstarTile.Size = new Size(tileSize, tileSize);
var cols = rectSize.Width / tileSize;
var fils = 4;
for (int i = 0; i < cols * fils; i++)
{
RockstarTile.Position = TopLeft.AddPoints(new Point(tileSize * (i % cols), tileSize * (i / cols)));
RockstarTile.Color = Color.FromArgb((int)MiscExtensions.LinearFloatLerp(40, 0, i / cols, fils), 255, 255, 255);
RockstarTile.Draw();
}
}
}
}
}
================================================
FILE: NativeUI/PauseMenu/TabItemSimpleList.cs
================================================
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Font = GTA.Font;
namespace NativeUI.PauseMenu
{
public class TabItemSimpleList : TabItem
{
public TabItemSimpleList(string title, Dictionary<string, string> dict) : base(title)
{
Dictionary = dict;
DrawBg = false;
}
public Dictionary<string, string> Dictionary { get; set; }
public override void Draw()
{
base.Draw();
var res = Screen.ResolutionMaintainRatio;
var alpha = (Focused || !CanBeFocused) ? 180 : 60;
var blackAlpha = (Focused || !CanBeFocused) ? 200 : 90;
var fullAlpha = (Focused || !CanBeFocused) ? 255 : 150;
var rectSize = (int)(BottomRight.X - TopLeft.X);
for (int i = 0; i < Dictionary.Count; i++)
{
new UIResRectangle(new Point(TopLeft.X, TopLeft.Y + (40 * i)),
new Size(rectSize, 40), i % 2 == 0 ? Color.FromArgb(alpha, 0, 0, 0) : Color.FromArgb(blackAlpha, 0, 0, 0)).Draw();
var item = Dictionary.ElementAt(i);
new UIResText(item.Key, new Point(TopLeft.X + 6, TopLeft.Y + 5 + (40 * i)), 0.35f, Color.FromArgb(fullAlpha, Color.White)).Draw();
new UIResText(item.Value, new Point(BottomRight.X - 6, TopLeft.Y + 5 + (40 * i)), 0.35f, Color.FromArgb(fullAlpha, Color.White), Font.ChaletLondon, UIResText.Alignment.Right).Draw();
}
}
}
}
================================================
FILE: NativeUI/PauseMenu/TabMissionSelectItem.cs
================================================
using System;
using System.Collections.Generic;
using System.Drawing;
using GTA;
using GTA.Native;
using Font = GTA.Font;
namespace NativeUI.PauseMenu
{
public delegate void OnItemSelect(MissionInformation selectedItem);
public class MissionInformation
{
public MissionInformation(string name, IEnumerable<Tuple<string, string>> info)
{
Name = name;
ValueList = new List<Tuple<string, string>>(info);
}
public MissionInformation(string name, string description, IEnumerable<Tuple<string, string>> info)
{
Name = name;
Description = description;
ValueList = new List<Tuple<string, string>>(info);
}
public string Name { get; set; }
public string Description { get; set; }
public MissionLogo Logo { get; set; }
public List<Tuple<string, string>> ValueList { get; set; }
}
public class MissionLogo
{
/// <summary>
/// Create a logo from an external picture.
/// </summary>
/// <param name="filepath">Path to the picture</param>
public MissionLogo(string filepath)
{
FileName = filepath;
IsGameTexture = false;
}
/// <summary>
/// Create a mission logo from a game texture.
/// </summary>
/// <param name="textureDict">Name of the texture dictionary</param>
/// <param name="textureName">Name of the texture.</param>
public MissionLogo(string textureDict, string textureName)
{
FileName = textureName;
DictionaryName = textureDict;
IsGameTexture = true;
}
internal bool IsGameTexture;
internal string FileName { get; set; }
internal string DictionaryName { get; set; }
}
public class TabMissionSelectItem : TabItem
{
public TabMissionSelectItem(string name, IEnumerable<MissionInformation> list) : base(name)
{
base.FadeInWhenFocused = true;
base.DrawBg = false;
_noLogo = new Sprite("gtav_online", "rockstarlogo256", new Point(), new Size(512, 256));
_maxItem = MaxItemsPerView;
_minItem = 0;
CanBeFocused = true;
Heists = new List<MissionInformation>(list);
}
public event OnItemSelect OnItemSelect;
public List<MissionInformation> Heists { get; set; }
public int Index { get; set; }
protected const int MaxItemsPerView = 15;
protected int _minItem;
protected int _maxItem;
protected Sprite _noLogo { get; set; }
public override void ProcessControls()
{
if (!Focused) return;
if (Heists.Count == 0) return;
if (JustOpened)
{
JustOpened = false;
return;
}
if (Game.IsControlJustPressed(0, Control.PhoneSelect))
{
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
OnItemSelect?.Invoke(Heists[Index]);
}
if (Game.IsControlJustPressed(0, Control.FrontendUp) || Game.IsControlJustPressed(0, Control.MoveUpOnly))
{
Index = (1000 - (1000 % Heists.Count) + Index - 1) % Heists.Count;
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
if (Heists.Count <= MaxItemsPerView) return;
if (Index < _minItem)
{
_minItem--;
_maxItem--;
}
if (Index == Heists.Count - 1)
{
_minItem = Heists.Count - MaxItemsPerView;
_maxItem = Heists.Count;
}
}
else if (Game.IsControlJustPressed(0, Control.FrontendDown) || Game.IsControlJustPressed(0, Control.MoveDownOnly))
{
Index = (1000 - (1000 % Heists.Count) + Index + 1) % Heists.Count;
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
if (Heists.Count <= MaxItemsPerView) return;
if (Index >= _maxItem)
{
_maxItem++;
_minItem++;
}
if (Index == 0)
{
_minItem = 0;
_maxItem = MaxItemsPerView;
}
}
}
public override void Draw()
{
base.Draw();
if (Heists.Count == 0) return;
var res = Screen.ResolutionMaintainRatio;
var activeWidth = res.Width - SafeSize.X * 2;
var itemSize = new Size((int)activeWidth - 515, 40);
var alpha = Focused ? 120 : 30;
var blackAlpha = Focused ? 200 : 100;
var fullAlpha = Focused ? 255 : 150;
var counter = 0;
for (int i = _minItem; i < Math.Min(Heists.Count, _maxItem); i++)
{
new UIResRectangle(SafeSize.AddPoints(new Point(0, (itemSize.Height + 3) * counter)), itemSize, (Index == i && Focused) ? Color.FromArgb(fullAlpha, Color.White) : Color.FromArgb(blackAlpha, Color.Black)).Draw();
new UIResText(Heists[i].Name, SafeSize.AddPoints(new Point(6, 5 + (itemSize.Height + 3) * counter)), 0.35f, Color.FromArgb(fullAlpha, (Index == i && Focused) ? Color.Black : Color.White)).Draw();
counter++;
}
if (Heists[Index].Logo == null || string.IsNullOrEmpty(Heists[Index].Logo.FileName))
{
_noLogo.Position = new Point((int)res.Width - SafeSize.X - 512, SafeSize.Y);
_noLogo.Color = Color.FromArgb(blackAlpha, 0, 0, 0);
_noLogo.Draw();
}
else if (Heists[Index].Logo != null && Heists[Index].Logo.FileName != null && !Heists[Index].Logo.IsGameTexture)
{
var target = Heists[Index].Logo.FileName;
Sprite.DrawTexture(target, new Point((int)res.Width - SafeSize.X - 512, SafeSize.Y), new Size(512, 256));
}
else if (Heists[Index].Logo != null && Heists[Index].Logo.FileName != null &&
Heists[Index].Logo.IsGameTexture)
{
var newLogo = new Sprite(Heists[Index].Logo.DictionaryName, Heists[Index].Logo.FileName, new Point(), new Size(512, 256));
newLogo.Position = new Point((int)res.Width - SafeSize.X - 512, SafeSize.Y);
newLogo.Color = Color.FromArgb(blackAlpha, 0, 0, 0);
newLogo.Draw();
}
new UIResRectangle(new Point((int)res.Width - SafeSize.X - 512, SafeSize.Y + 256), new Size(512, 40), Color.FromArgb(fullAlpha, Color.Black)).Draw();
new UIResText(Heists[Index].Name, new Point((int)res.Width - SafeSize.X - 4, SafeSize.Y + 260), 0.5f, Color.FromArgb(fullAlpha, Color.White),
Font.HouseScript, UIResText.Alignment.Right).Draw();
for (int i = 0; i < Heists[Index].ValueList.Count; i++)
{
new UIResRectangle(new Point((int)res.Width - SafeSize.X - 512, SafeSize.Y + 256 + 40 + (40 * i)),
new Size(512, 40), i % 2 == 0 ? Color.FromArgb(alpha, 0, 0, 0) : Color.FromArgb(blackAlpha, 0, 0, 0)).Draw();
var text = Heists[Index].ValueList[i].Item1;
var label = Heists[Index].ValueList[i].Item2;
new UIResText(text, new Point((int)res.Width - SafeSize.X - 506, SafeSize.Y + 260 + 42 + (40 * i)), 0.35f, Color.FromArgb(fullAlpha, Color.White)).Draw();
new UIResText(label, new Point((int)res.Width - SafeSize.X - 6, SafeSize.Y + 260 + 42 + (40 * i)), 0.35f, Color.FromArgb(fullAlpha, Color.White), Font.ChaletLondon, UIResText.Alignment.Right).Draw();
}
if (!string.IsNullOrEmpty(Heists[Index].Description))
{
var propLen = Heists[Index].ValueList.Count;
new UIResRectangle(new Point((int)res.Width - SafeSize.X - 512, SafeSize.Y + 256 + 42 + 40 * propLen),
new Size(512, 2), Color.FromArgb(fullAlpha, Color.White)).Draw();
new UIResText(Heists[Index].Description,
new Point((int)res.Width - SafeSize.X - 508, SafeSize.Y + 256 + 45 + 40 * propLen + 4), 0.35f,
Color.FromArgb(fullAlpha, Color.White))
{
Wrap = 508,
}.Draw();
new UIResRectangle(new Point((int) res.Width - SafeSize.X - 512, SafeSize.Y + 256 + 44 + 40*propLen),
new Size(512, 45*(int)(Screen.GetTextWidth(Heists[Index].Description, Font.ChaletLondon, 0.35f)/500)),
Color.FromArgb(blackAlpha, 0, 0, 0)).Draw();
}
}
}
}
================================================
FILE: NativeUI/PauseMenu/TabSubmenuItem.cs
================================================
using System.Collections.Generic;
using System.Drawing;
using GTA;
using GTA.Native;
namespace NativeUI.PauseMenu
{
public class TabSubmenuItem : TabItem
{
private bool _focused;
public TabSubmenuItem(string name, IEnumerable<TabItem> items) : base(name)
{
DrawBg = false;
CanBeFocused = true;
Items = new List<TabItem>(items);
IsInList = true;
}
public void RefreshIndex()
{
foreach (var item in Items)
{
item.Focused = false;
item.Active = false;
item.Visible = false;
}
Index = (1000 - (1000 % Items.Count)) % Items.Count;
}
public List<TabItem> Items { get; set; }
public int Index { get; set; }
public bool IsInList { get; set; }
public override bool Focused
{
get { return _focused; }
set
{
_focused = value;
if (!value) Items[Index].Focused = false;
}
}
public override void ProcessControls()
{
if (JustOpened)
{
JustOpened = false;
return;
}
if (!Focused) return;
if (Game.IsControlJustPressed(0, Control.PhoneSelect) && Focused && Parent.FocusLevel == 1)
{
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
if (Items[Index].CanBeFocused && !Items[Index].Focused)
{
Parent.FocusLevel++;
Items[Index].JustOpened = true;
Items[Index].Focused = true;
}
else
{
Items[Index].OnActivated();
}
}
if (Game.IsControlJustPressed(0, Control.PhoneCancel) && Focused && Parent.FocusLevel > 1)
{
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "CANCEL", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
if (Items[Index].CanBeFocused && Items[Index].Focused)
{
Parent.FocusLevel--;
Items[Index].Focused = false;
}
}
if ((Game.IsControlJustPressed(0, Control.FrontendUp) || Game.IsControlJustPressed(0, Control.MoveUpOnly) || Game.IsControlJustPressed(0, Control.CursorScrollUp)) && Parent.FocusLevel == 1)
{
Index = (1000 - (1000 % Items.Count) + Index - 1) % Items.Count;
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
}
else if ((Game.IsControlJustPressed(0, Control.FrontendDown) || Game.IsControlJustPressed(0, Control.MoveDownOnly) || Game.IsControlJustPressed(0, Control.CursorScrollDown)) && Parent.FocusLevel == 1)
{
Index = (1000 - (1000 % Items.Count) + Index + 1) % Items.Count;
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
}
if (Items.Count > 0) Items[Index].ProcessControls();
}
public override void Draw()
{
if (!Visible) return;
base.Draw();
var res = Screen.ResolutionMaintainRatio;
var alpha = Focused ? 120 : 30;
var blackAlpha = Focused ? 200 : 100;
var fullAlpha = Focused ? 255 : 150;
var activeWidth = res.Width - SafeSize.X * 2;
var submenuWidth = (int)(activeWidth * 0.6818f);
var itemSize = new Size((int)activeWidth - (submenuWidth + 3), 40);
for (int i = 0; i < Items.Count; i++)
{
var hovering = Screen.IsMouseInBounds(SafeSize.AddPoints(new Point(0, (itemSize.Height + 3) * i)),
itemSize);
new UIResRectangle(SafeSize.AddPoints(new Point(0, (itemSize.Height + 3) * i)), itemSize, (Index == i && Focused) ? Color.FromArgb(fullAlpha, Color.White) : hovering && Focused ? Color.FromArgb(100, 50, 50, 50) : Color.FromArgb(blackAlpha, Color.Black)).Draw();
new UIResText(Items[i].Title, SafeSize.AddPoints(new Point(6, 5 + (itemSize.Height + 3) * i)), 0.35f, Color.FromArgb(fullAlpha, (Index == i && Focused) ? Color.Black : Color.White)).Draw();
if (Focused && hovering && Game.IsControlJustPressed(0, Control.CursorAccept))
{
Items[Index].Focused = false;
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
bool open = Index == i;
Index = (1000 - (1000 % Items.Count) + i) % Items.Count;
if (open)
{
if (Items[Index].CanBeFocused && !Items[Index].Focused)
{
Parent.FocusLevel = 2;
Items[Index].JustOpened = true;
Items[Index].Focused = true;
}
else
{
Items[Index].OnActivated();
}
}
else
{
Parent.FocusLevel = 1;
}
}
}
Items[Index].Visible = true;
Items[Index].FadeInWhenFocused = true;
//Items[Index].CanBeFocused = true;
if (!Items[Index].CanBeFocused)
Items[Index].Focused = Focused;
Items[Index].UseDynamicPositionment = false;
Items[Index].SafeSize = SafeSize.AddPoints(new Point((int)activeWidth - submenuWidth, 0));
Items[Index].TopLeft = SafeSize.AddPoints(new Point((int)activeWidth - submenuWidth, 0));
Items[Index].BottomRight = new Point((int)res.Width - SafeSize.X, (int)res.Height - SafeSize.Y);
Items[Index].Draw();
}
}
}
================================================
FILE: NativeUI/PauseMenu/TabTextItem.cs
================================================
using System.Drawing;
namespace NativeUI.PauseMenu
{
public class TabTextItem : TabItem
{
public string TextTitle { get; set; }
public string Text { get; set; }
public int WordWrap { get; set; }
public TabTextItem(string name, string title) : base(name)
{
TextTitle = title;
}
public TabTextItem(string name, string title, string text) : base(name)
{
TextTitle = title;
Text = text;
}
public override void Draw()
{
base.Draw();
var res = Screen.ResolutionMaintainRatio;
var alpha = (Focused || !CanBeFocused) ? 255 : 200;
if (!string.IsNullOrEmpty(TextTitle))
{
new UIResText(TextTitle, SafeSize.AddPoints(new Point(40, 20)), 1.5f, Color.FromArgb(alpha, Color.White)).Draw();
}
if (!string.IsNullOrEmpty(Text))
{
var ww = WordWrap == 0 ? BottomRight.X - TopLeft.X - 40 : WordWrap;
new UIResText(Text, SafeSize.AddPoints(new Point(40, 150)), 0.4f, Color.FromArgb(alpha, Color.White))
{
Wrap = ww
}.Draw();
}
}
}
}
================================================
FILE: NativeUI/PauseMenu/TabView.cs
================================================
using System;
using System.Collections.Generic;
using System.Drawing;
using GTA;
using GTA.Native;
using Font = GTA.Font;
namespace NativeUI.PauseMenu
{
public class TabView
{
public TabView(string title)
{
Title = title;
Tabs = new List<TabItem>();
Index = 0;
Name = Game.Player.Name;
TemporarilyHidden = false;
CanLeave = true;
}
public string Title { get; set; }
public Sprite Photo { get; set; }
public string Name { get; set; }
public string Money { get; set; }
public string MoneySubtitle { get; set; }
public List<TabItem> Tabs { get; set; }
public int FocusLevel { get; set; }
public bool TemporarilyHidden { get; set; }
public bool CanLeave { get; set; }
public bool HideTabs { get; set; }
internal readonly static string _browseTextLocalized = Game.GetGXTEntry("HUD_INPUT1C");
public event EventHandler OnMenuClose;
public bool Visible
{
get { return _visible; }
set
{
_visible = value;
if (value)
{
Function.Call(Hash._START_SCREEN_EFFECT, "MinigameTransitionIn", 0, true);
}
else
{
Function.Call(Hash._STOP_SCREEN_EFFECT, "MinigameTransitionIn");
}
}
}
public void AddTab(TabItem item)
{
Tabs.Add(item);
item.Parent = this;
}
public int Index;
private bool _visible;
private Scaleform _sc;
public void ShowInstructionalButtons()
{
if (_sc == null)
{
_sc = new Scaleform("instructional_buttons");
}
_sc.CallFunction("CLEAR_ALL");
_sc.CallFunction("TOGGLE_MOUSE_BUTTONS", 0);
_sc.CallFunction("CREATE_CONTAINER");
_sc.CallFunction("SET_DATA_SLOT", 0, Function.Call<string>(Hash._0x0499D7B09FC9B407, 2, (int)Control.PhoneSelect, 0), UIMenu._selectTextLocalized);
_sc.CallFunction("SET_DATA_SLOT", 1, Function.Call<string>(Hash._0x0499D7B09FC9B407, 2, (int)Control.PhoneCancel, 0), UIMenu._backTextLocalized);
_sc.CallFunction("SET_DATA_SLOT", 2, Function.Call<string>(Hash._0x0499D7B09FC9B407, 2, (int)Control.FrontendRb, 0), "");
_sc.CallFunction("SET_DATA_SLOT", 3, Function.Call<string>(Hash._0x0499D7B09FC9B407, 2, (int)Control.FrontendLb, 0), _browseTextLocalized);
}
public void DrawInstructionalButton(int slot, Control control, string text)
{
_sc.CallFunction("SET_DATA_SLOT", slot, Function.Call<string>(Hash._0x0499D7B09FC9B407, 2, (int)control, 0), text);
}
public void ProcessControls()
{
if (!Visible || TemporarilyHidden) return;
Function.Call(Hash.DISABLE_ALL_CONTROL_ACTIONS, 0);
if (Game.IsControlJustPressed(0, Control.PhoneLeft) && FocusLevel == 0)
{
Tabs[Index].Active = false;
Tabs[Index].Focused = false;
Tabs[Index].Visible = false;
Index = (1000 - (1000 % Tabs.Count) + Index - 1) % Tabs.Count;
Tabs[Index].Active = true;
Tabs[Index].Focused = false;
Tabs[Index].Visible = true;
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
}
else if (Game.IsControlJustPressed(0, Control.PhoneRight) && FocusLevel == 0)
{
Tabs[Index].Active = false;
Tabs[Index].Focused = false;
Tabs[Index].Visible = false;
Index = (1000 - (1000 % Tabs.Count) + Index + 1) % Tabs.Count;
Tabs[Index].Active = true;
Tabs[Index].Focused = false;
Tabs[Index].Visible = true;
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
}
else if (Game.IsControlJustPressed(0, Control.FrontendAccept) && FocusLevel == 0)
{
if (Tabs[Index].CanBeFocused)
{
Tabs[Index].Focused = true;
Tabs[Index].JustOpened = true;
FocusLevel = 1;
}
else
{
Tabs[Index].JustOpened = true;
Tabs[Index].OnActivated();
}
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
}
else if (Game.IsControlJustPressed(0, Control.PhoneCancel) && FocusLevel == 1)
{
Tabs[Index].Focused = false;
FocusLevel = 0;
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "BACK", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
}
else if (Game.IsControlJustPressed(0, Control.PhoneCancel) && FocusLevel == 0 && CanLeave)
{
Visible = false;
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "BACK", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
OnMenuClose?.Invoke(this, EventArgs.Empty);
}
if (!HideTabs)
{
if (Game.IsControlJustPressed(0, Control.FrontendLb))
{
Tabs[Index].Active = false;
Tabs[Index].Focused = false;
Tabs[Index].Visible = false;
Index = (1000 - (1000 % Tabs.Count) + Index - 1) % Tabs.Count;
Tabs[Index].Active = true;
Tabs[Index].Focused = false;
Tabs[Index].Visible = true;
FocusLevel = 0;
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
}
else if (Game.IsControlJustPressed(0, Control.FrontendRb))
{
Tabs[Index].Active = false;
Tabs[Index].Focused = false;
Tabs[Index].Visible = false;
Index = (1000 - (1000 % Tabs.Count) + Index + 1) % Tabs.Count;
Tabs[Index].Active = true;
Tabs[Index].Focused = false;
Tabs[Index].Visible = true;
FocusLevel = 0;
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
}
}
if (Tabs.Count > 0) Tabs[Index].ProcessControls();
}
public void RefreshIndex()
{
foreach (var item in Tabs)
{
item.Focused = false;
item.Active = false;
item.Visible = false;
}
Index = (1000 - (1000 % Tabs.Count)) % Tabs.Count;
Tabs[Index].Active = true;
Tabs[Index].Focused = false;
Tabs[Index].Visible = true;
FocusLevel = 0;
}
public void Update()
{
if (!Visible || TemporarilyHidden) return;
ShowInstructionalButtons();
Function.Call(Hash.HIDE_HUD_AND_RADAR_THIS_FRAME);
Function.Call(Hash._SHOW_CURSOR_THIS_FRAME);
var res = Screen.ResolutionMaintainRatio;
var safe = new Point(300, 180);
if (!HideTabs)
{
new UIResText(Title, new Point(safe.X, safe.Y - 80), 1f, Color.White, Font.ChaletComprimeCologne,
UIResText.Alignment.Left)
{
Shadow = true,
}.Draw();
if (Photo == null)
{
new Sprite("char_multiplayer", "char_multiplayer",
new Point((int)res.Width - safe.X - 64, safe.Y - 80), new Size(64, 64)).Draw();
}
else
{
Photo.Position = new Point((int)res.Width - safe.X - 100, safe.Y - 80);
Photo.Size = new Size(64, 64);
Photo.Draw();
}
new UIResText(Name, new Point((int)res.Width - safe.X - 70, safe.Y - 95), 0.7f, Color.White,
Font.ChaletComprimeCologne, UIResText.Alignment.Right)
{
Shadow = true,
}.Draw();
string t = Money;
if (string.IsNullOrEmpty(Money))
{
t = DateTime.Now.ToString();
}
new UIResText(t, new Point((int)res.Width - safe.X - 70, safe.Y - 60), 0.4f, Color.White,
Font.ChaletComprimeCologne, UIResText.Alignment.Right)
{
Shadow = true,
}.Draw();
string subt = MoneySubtitle;
if (string.IsNullOrEmpty(MoneySubtitle))
{
subt = "";
}
new UIResText(subt, new Point((int)res.Width - safe.X - 70, safe.Y - 40), 0.4f, Color.White,
Font.ChaletComprimeCologne, UIResText.Alignment.Right)
{
Shadow = true,
}.Draw();
for (int i = 0; i < Tabs.Count; i++)
{
var activeSize = res.Width - 2 * safe.X;
activeSize -= 4 * 5;
int tabWidth = (int)activeSize / Tabs.Count;
Game.EnableControlThisFrame(0, Control.CursorX);
Game.EnableControlThisFrame(0, Control.CursorY);
var hovering = Screen.IsMouseInBounds(safe.AddPoints(new Point((tabWidth + 5) * i, 0)),
new Size(tabWidth, 40));
var tabColor = Tabs[i].Active
? Color.White
: hovering ? Color.FromArgb(100, 50, 50, 50) : Color.Black;
new UIResRectangle(safe.AddPoints(new Point((tabWidth + 5) * i, 0)), new Size(tabWidth, 40),
Color.FromArgb(Tabs[i].Active ? 255 : 200, tabColor)).Draw();
new UIResText(Tabs[i].Title.ToUpper(), safe.AddPoints(new Point((tabWidth / 2) + (tabWidth + 5) * i, 5)),
0.35f,
Tabs[i].Active ? Color.Black : Color.White, Font.ChaletLondon, UIResText.Alignment.Centered)
.Draw();
if (Tabs[i].Active)
{
new UIResRectangle(safe.SubtractPoints(new Point(-((tabWidth + 5) * i), 10)),
new Size(tabWidth, 10), Color.DodgerBlue).Draw();
}
if (hovering && Game.IsControlJustPressed(0, Control.CursorAccept) && !Tabs[i].Active)
{
Tabs[Index].Active = false;
Tabs[Index].Focused = false;
Tabs[Index].Visible = false;
Index = (1000 - (1000 % Tabs.Count) + i) % Tabs.Count;
Tabs[Index].Active = true;
Tabs[Index].Focused = true;
Tabs[Index].Visible = true;
Tabs[Index].JustOpened = true;
if (Tabs[Index].CanBeFocused)
FocusLevel = 1;
else
FocusLevel = 0;
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
}
}
}
Tabs[Index].Draw();
_sc.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1);
_sc.Render2D();
}
}
}
================================================
FILE: NativeUI/PointExtensions.cs
================================================
using System;
using System.Drawing;
using GTA.Math;
namespace NativeUI
{
public static class MiscExtensions
{
public static Random SharedRandom = new Random();
public static Point AddPoints(this Point left, Point right)
{
return new Point(left.X + right.X, left.Y + right.Y);
}
public static Point SubtractPoints(this Point left, Point right)
{
return new Point(left.X - right.X, left.Y - right.Y);
}
public static float Clamp(this float val, float min, float max)
{
if (val > max)
return max;
if (val < min)
return min;
return val;
}
public static Vector3 LinearVectorLerp(Vector3 start, Vector3 end, int currentTime, int duration)
{
return new Vector3()
{
X = LinearFloatLerp(start.X, end.X, currentTime, duration),
Y = LinearFloatLerp(start.Y, end.Y, currentTime, duration),
Z = LinearFloatLerp(start.Z, end.Z, currentTime, duration),
};
}
public static Vector3 VectorLerp(Vector3 start, Vector3 end, int currentTime, int duration, Func<float, float, int, int, float> easingFunc)
{
return new Vector3()
{
X = easingFunc(start.X, end.X, currentTime, duration),
Y = easingFunc(start.Y, end.Y, currentTime, duration),
Z = easingFunc(start.Z, end.Z, currentTime, duration),
};
}
public static float LinearFloatLerp(float start, float end, int currentTime, int duration)
{
float change = end - start;
return change * currentTime / duration + start;
}
public static float QuadraticEasingLerp(float start, float end, int currentTime, int duration)
{
var time = (float)currentTime;
var dur = (float)duration;
float change = end - start;
time /= dur / 2;
if (time < 1) return change / 2 * time * time + start;
time--;
return -change / 2 * (time * (time - 2) - 1) + start;
}
}
}
================================================
FILE: NativeUI/Properties/AssemblyInfo.cs
================================================
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("NativeUI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NativeUI")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f3e16ed9-dbf7-4e7b-b04b-9b24b11891d3")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.9.0.0")]
[assembly: AssemblyFileVersion("1.9.0.0")]
================================================
FILE: NativeUI/Screen.cs
================================================
using GTA;
using GTA.Native;
using System;
using System.Drawing;
namespace NativeUI
{
/// <summary>
/// Tools to deal with the game screen.
/// </summary>
public static class Screen
{
/// <summary>
/// The 1080pixels-based screen resolution while mantaining current aspect ratio.
/// </summary>
public static SizeF ResolutionMaintainRatio
{
get
{
// Get the game width and height
int screenw = Game.ScreenResolution.Width;
int screenh = Game.ScreenResolution.Height;
// Calculate the ratio
float ratio = (float)screenw / screenh;
// And the width with that ratio
float width = 1080f * ratio;
// Finally, return a SizeF
return new SizeF(width, 1080f);
}
}
/// <summary>
/// Safezone bounds relative to the 1080pixel based resolution.
/// </summary>
public static Point SafezoneBounds
{
get
{
// Get the size of the safezone as a float
float t = Function.Call<float>(Hash.GET_SAFE_ZONE_SIZE);
// Round the value with a max of 2 decimal places and do some calculations
double g = Math.Round(Convert.ToDouble(t), 2);
g = (g * 100) - 90;
g = 10 - g;
// Then, get the screen resolution
int screenw = Game.ScreenResolution.Width;
int screenh = Game.ScreenResolution.Height;
// Calculate the ratio
float ratio = (float)screenw / screenh;
// And this thing (that I don't know what it does)
float wmp = ratio * 5.4f;
// Finally, return a new point with the correct resolution
return new Point((int)Math.Round(g * wmp), (int)Math.Round(g * 5.4f));
}
}
/// <summary>
/// Chech whether the mouse is inside the specified rectangle.
/// </summary>
/// <param name="topLeft">Start point of the rectangle at the top left.</param>
/// <param name="boxSize">size of your rectangle.</param>
/// <returns>true if the mouse is inside of the specified bounds, false otherwise.</returns>
public static bool IsMouseInBounds(Point topLeft, Size boxSize)
{
// Get the resolution while maintaining the ratio.
SizeF res = ResolutionMaintainRatio;
// Then, get the position of mouse on the screen while relative to the current resolution
int mouseX = (int)Math.Round(Function.Call<float>(Hash.GET_CONTROL_NORMAL, 0, (int)Control.CursorX) * res.Width);
int mouseY = (int)Math.Round(Function.Call<float>(Hash.GET_CONTROL_NORMAL, 0, (int)Control.CursorY) * res.Height);
// And check if the mouse is on the rectangle bounds
bool isX = mouseX >= topLeft.X && mouseX <= topLeft.X + boxSize.Width;
bool isY = mouseY > topLeft.Y && mouseY < topLeft.Y + boxSize.Height;
// Finally, return the result of the checks
return isX && isY;
}
/// <summary>
/// Calculates the width of a string.
/// </summary>
/// <param name="text">The text to measure.</param>
/// <param name="font">Game font used for measurements.</param>
/// <param name="scale">The scale of the characters.</param>
/// <returns>The width of the string based on the font and scale.</returns>
public static float GetTextWidth(string text, GTA.Font font, float scale)
{
// Start by requesting the game to start processing a width measurement
Function.Call(Hash._SET_TEXT_ENTRY_FOR_WIDTH, "CELL_EMAIL_BCON"); // _BEGIN_TEXT_COMMAND_WIDTH
// Add the text string
UIResText.AddLongString(text);
// Set the properties for the text
Function.Call(Hash.SET_TEXT_FONT, (int)font);
Function.Call(Hash.SET_TEXT_SCALE, 1f, scale);
// Ask the game for the relative string width
float width = Function.Call<float>(Hash._GET_TEXT_SCREEN_WIDTH, true);
// And return the literal result
return ResolutionMaintainRatio.Width * width;
}
/// <summary>
/// Gets the line count for the text.
/// </summary>
/// <param name="text">The text to measure.</param>
/// <param name="position">The position of the text.</param>
/// <param name="font">The font to use.</param>
/// <returns>The number of lines used.</returns>
public static int GetLineCount(string text, Point position, GTA.Font font, float scale, int wrap)
{
// Tell the game that we are going to request the number of lines
Function.Call(Hash._SET_TEXT_GXT_ENTRY, "CELL_EMAIL_BCON"); // _BEGIN_TEXT_COMMAND_LINE_COUNT
// Add the text that has been sent to us
UIResText.AddLongStringForUtf8(text); // ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME
// Get the resolution with the correct aspect ratio
SizeF res = ResolutionMaintainRatio;
// Calculate the x and y positions
float x = position.X / res.Width;
float y = position.Y / res.Height;
// Set the properties for the text
Function.Call(Hash.SET_TEXT_FONT, (int)font);
Function.Call(Hash.SET_TEXT_SCALE, 1f, scale);
// If there is some text wrap to add
if (wrap > 0)
{
// Calculate the wrap size
float start = position.X / res.Width;
float end = start + (wrap / res.Width);
// And apply it
Function.Call(Hash.SET_TEXT_WRAP, x, end);
}
// Finally, return the number of lines being made by the string
return Function.Call<int>(Hash._0x9040DFB09BE75706, x, y); // _GET_TEXT_SCREEN_LINE_COUNT
}
}
}
================================================
FILE: NativeUI/StringMeasurer.cs
================================================
using System;
using GTA;
namespace NativeUI
{
public static class StringMeasurer
{
/// <summary>
/// Measures width of a 0.35 scale string.
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[Obsolete("Use Screen.GetTextWidth instead.", true)]
public static int MeasureString(string input) => (int)Screen.GetTextWidth(input, Font.ChaletLondon, 1f);
[Obsolete("Use Screen.GetTextWidth instead.", true)]
public static float MeasureString(string input, Font font, float scale) => Screen.GetTextWidth(input, font, scale);
}
}
================================================
FILE: NativeUI/UIMenu.cs
================================================
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using GTA;
using GTA.Native;
using Control = GTA.Control;
using Font = GTA.Font;
namespace NativeUI
{
#region Delegates
public delegate void IndexChangedEvent(UIMenu sender, int newIndex);
public delegate void ListChangedEvent(UIMenu sender, UIMenuListItem listItem, int newIndex);
public delegate void SliderChangedEvent(UIMenu sender, UIMenuSliderItem listItem, int newIndex);
public delegate void CheckboxChangeEvent(UIMenu sender, UIMenuCheckboxItem checkboxItem, bool Checked);
public delegate void ItemSelectEvent(UIMenu sender, UIMenuItem selectedItem, int index);
public delegate void MenuOpenEvent(UIMenu sender);
public delegate void MenuCloseEvent(UIMenu sender);
public delegate void MenuChangeEvent(UIMenu oldMenu, UIMenu newMenu, bool forward);
public delegate void ItemActivatedEvent(UIMenu sender, UIMenuItem selectedItem);
public delegate void ItemCheckboxEvent(UIMenuCheckboxItem sender, bool Checked);
public delegate void ItemListEvent(UIMenuListItem sender, int newIndex);
public delegate void ItemSliderEvent(UIMenuSliderItem sender, int newIndex);
#endregion
/// <summary>
/// Base class for NativeUI. Calls the next events: OnIndexChange, OnListChanged, OnCheckboxChange, OnItemSelect, OnMenuClose, OnMenuchange.
/// </summary>
public class UIMenu
{
#region Private Fields
private readonly UIContainer _mainMenu;
private readonly Sprite _background;
private readonly UIResRectangle _descriptionBar;
private readonly Sprite _descriptionRectangle;
private readonly UIResText _descriptionText;
private readonly UIResText _counterText;
private int _activeItem = 1000;
private bool _visible;
private bool _useCursor = true;
private bool _buttonsEnabled = true;
private bool _justOpened = true;
private bool _itemsDirty = false;
//Pagination
private const int MaxItemsOnScreen = 9;
private int _minItem;
private int _maxItem = MaxItemsOnScreen;
//Keys
private readonly Dictionary<MenuControls, Tuple<List<Keys>, List<Tuple<Control, int>>>> _keyDictionary =
new Dictionary<MenuControls, Tuple<List<Keys>, List<Tuple<Control, int>>>>();
private readonly List<InstructionalButton> _instructionalButtons = new List<InstructionalButton>();
private readonly Sprite _upAndDownSprite;
private readonly UIResRectangle _extraRectangleUp;
private readonly UIResRectangle _extraRectangleDown;
private readonly Scaleform _instructionalButtonsScaleform;
private readonly int _extraYOffset;
private static readonly MenuControls[] _menuControls = Enum.GetValues(typeof(MenuControls)).Cast<MenuControls>().ToArray();
// Draw Variables
private Point Safe { get; set; }
private Size BackgroundSize { get; set; }
private Size DrawWidth { get; set; }
private bool ReDraw = true;
internal readonly static string _selectTextLocalized = Game.GetGXTEntry("HUD_INPUT2");
internal readonly static string _backTextLocalized = Game.GetGXTEntry("HUD_INPUT3");
#endregion
#region Public Fields
public string AUDIO_LIBRARY = "HUD_FRONTEND_DEFAULT_SOUNDSET";
public string AUDIO_UPDOWN = "NAV_UP_DOWN";
public string AUDIO_LEFTRIGHT = "NAV_LEFT_RIGHT";
public string AUDIO_SELECT = "SELECT";
public string AUDIO_BACK = "BACK";
public string AUDIO_ERROR = "ERROR";
public List<UIMenuItem> MenuItems = new List<UIMenuItem>();
public bool MouseEdgeEnabled = true;
public bool ControlDisablingEnabled = true;
public bool ResetCursorOnOpen = true;
[Obsolete("The description is now formated automatically by the game.")]
public bool FormatDescriptions = true;
public bool MouseControlsEnabled = true;
public bool ScaleWithSafezone = true;
public Point Offset { get; }
public Sprite BannerSprite { get; private set; }
public UIResRectangle BannerRectangle { get; private set; }
public string BannerTexture { get; private set; }
#endregion
#region Events
/// <summary>
/// Called when user presses up or down, changing current selection.
/// </summary>
public event IndexChangedEvent OnIndexChange;
/// <summary>
/// Called when user presses left or right, changing a list position.
/// </summary>
public event ListChangedEvent OnListChange;
/// <summary>
/// Called when user presses enter on a checkbox item.
/// </summary>
public event CheckboxChangeEvent OnCheckboxChange;
/// <summary>
/// Called when user selects a simple item.
/// </summary>
public event ItemSelectEvent OnItemSelect;
/// <summary>
/// Called when user presses left or right, changing a slider position.
/// </summary>
public event SliderChangedEvent OnSliderChange;
/// <summary>
/// Called when user opens the menu.
/// </summary>
public event MenuOpenEvent OnMenuOpen;
/// <summary>
/// Called when user closes the menu or goes back in a menu chain.
/// </summary>
public event MenuCloseEvent OnMenuClose;
/// <summary>
/// Called when user either clicks on a binded button or goes back to a parent menu.
/// </summary>
public event MenuChangeEvent OnMenuChange;
#endregion
#region Constructors
/// <summary>
/// Basic Menu constructor.
/// </summary>
/// <param name="title">Title that appears on the big banner.</param>
/// <param name="subtitle">Subtitle that appears in capital letters in a small black bar.</param>
public UIMenu(string title, string subtitle) : this(title, subtitle, new Point(0, 0), "commonmenu", "interaction_bgd")
{
}
/// <summary>
/// Basic Menu constructor with an offset.
/// </summary>
/// <param name="title">Title that appears on the big banner.</param>
/// <param name="subtitle">Subtitle that appears in capital letters in a small black bar. Set to "" if you dont want a subtitle.</param>
/// <param name="offset">Point object with X and Y data for offsets. Applied to all menu elements.</param>
public UIMenu(string title, string subtitle, Point offset) : this(title, subtitle, offset, "commonmenu", "interaction_bgd")
{
}
/// <summary>
/// Initialise a menu with a custom texture banner.
/// </summary>
/// <param name="title">Title that appears on the big banner. Set to "" if you don't want a title.</param>
/// <param name="subtitle">Subtitle that appears in capital letters in a small black bar. Set to "" if you dont want a subtitle.</param>
/// <param name="offset">Point object with X and Y data for offsets. Applied to all menu elements.</param>
/// <param name="customBanner">Path to your custom texture.</param>
public UIMenu(string title, string subtitle, Point offset, string customBanner) : this(title, subtitle, offset, "commonmenu", "interaction_bgd")
{
BannerTexture = customBanner;
}
/// <summary>
/// Advanced Menu constructor that allows custom title banner.
/// </summary>
/// <param name="title">Title that appears on the big banner. Set to "" if you are using a custom banner.</param>
/// <param name="subtitle">Subtitle that appears in capital letters in a small black bar.</param>
/// <param name="offset">Point object with X and Y data for offsets. Applied to all menu elements.</param>
/// <param name="spriteLibrary">Sprite library name for the banner.</param>
/// <param name="spriteName">Sprite name for the banner.</param>
public UIMenu(string title, string subtitle, Point offset, string spriteLibrary, string spriteName)
{
Offset = offset;
Children = new Dictionary<UIMenuItem, UIMenu>();
WidthOffset = 0;
_instructionalButtonsScaleform = new Scaleform("instructional_buttons");
UpdateScaleform();
_mainMenu = new UIContainer(new Point(0, 0), new Size(700, 500), Color.FromArgb(0, 0, 0, 0));
BannerSprite = new Sprite(spriteLibrary, spriteName, new Point(0 + Offset.X, 0 + Offset.Y), new Size(431, 107));
_mainMenu.Items.Add(Title = new UIResText(title, new Point(215 + Offset.X, 20 + Offset.Y), 1.15f, Color.White, Font.HouseScript, UIResText.Alignment.Centered));
if (!String.IsNullOrWhiteSpace(subtitle))
{
_mainMenu.Items.Add(new UIResRectangle(new Point(0 + offset.X, 107 + Offset.Y), new Size(431, 37), Color.Black));
_mainMenu.Items.Add(Subtitle = new UIResText(subtitle, new Point(8 + Offset.X, 110 + Offset.Y), 0.35f, Color.WhiteSmoke, 0, UIResText.Alignment.Left));
if (subtitle.StartsWith("~"))
{
CounterPretext = subtitle.Substring(0, 3);
}
_counterText = new UIResText("", new Point(425 + Offset.X, 110 + Offset.Y), 0.35f, Color.WhiteSmoke, 0, UIResText.Alignment.Right);
_extraYOffset = 37;
}
_upAndDownSprite = new Sprite("commonmenu", "shop_arrows_upanddown", new Point(190 + Offset.X, 147 + 37 * (MaxItemsOnScreen + 1) + Offset.Y - 37 + _extraYOffset), new Size(50, 50));
_extraRectangleUp = new UIResRectangle(new Point(0 + Offset.X, 144 + 38 * (MaxItemsOnScreen + 1) + Offset.Y - 37 + _extraYOffset), new Size(431, 18), Color.FromArgb(200, 0, 0, 0));
_extraRectangleDown = new UIResRectangle(new Point(0 + Offset.X, 144 + 18 + 38 * (MaxItemsOnScreen + 1) + Offset.Y - 37 + _extraYOffset), new Size(431, 18), Color.FromArgb(200, 0, 0, 0));
_descriptionBar = new UIResRectangle(new Point(Offset.X, 123), new Size(431, 4), Color.Black);
_descriptionRectangle = new Sprite("commonmenu", "gradient_bgd", new Point(Offset.X, 127), new Size(431, 30));
_descriptionText = new UIResText("Description", new Point(Offset.X + 5, 125), 0.35f, Color.FromArgb(255, 255, 255, 255), Font.ChaletLondon, UIResText.Alignment.Left);
_background = new Sprite("commonmenu", "gradient_bgd", new Point(Offset.X, 144 + Offset.Y - 37 + _extraYOffset), new Size(290, 25));
SetKey(MenuControls.Up, Control.PhoneUp);
SetKey(MenuControls.Up, Control.CursorScrollUp);
SetKey(MenuControls.Down, Control.PhoneDown);
SetKey(MenuControls.Down, Control.CursorScrollDown);
SetKey(MenuControls.Left, Control.PhoneLeft);
SetKey(MenuControls.Right, Control.PhoneRight);
SetKey(MenuControls.Select, Control.FrontendAccept);
SetKey(MenuControls.Back, Control.PhoneCancel);
SetKey(MenuControls.Back, Control.FrontendPause);
}
#endregion
#region Static Methods
/// <summary>
/// Toggles the availability of the controls.
/// It does not disable the basic movement and frontend controls.
/// </summary>
/// <param name="toggle">If we want to enable or disable the controls.</param>
[Obsolete("Use Controls.Toggle instead.", true)]
public static void DisEnableControls(bool toggle) => Controls.Toggle(toggle);
/// <summary>
/// Returns the 1080pixels-based screen resolution while mantaining current aspect ratio.
/// </summary>
[Obsolete("Use Screen.ResolutionMantainRatio instead.", true)]
public static SizeF GetScreenResolutionMaintainRatio() => Screen.ResolutionMaintainRatio;
/// <summary>
/// Screen.ResolutionMantainRatio for providing backwards compatibility.
/// </summary>
[Obsolete("Use Screen.ResolutionMantainRatio instead.", true)]
public static SizeF GetScreenResolutionMantainRatio() => Screen.ResolutionMaintainRatio;
/// <summary>
/// Chech whether the mouse is inside the specified rectangle.
/// </summary>
/// <param name="topLeft">Start point of the rectangle at the top left.</param>
/// <param name="boxSize">size of your rectangle.</param>
/// <returns>true if the mouse is inside of the specified bounds, false otherwise.</returns>
[Obsolete("Use Screen.IsMouseInBounds instead.", true)]
public static bool IsMouseInBounds(Point topLeft, Size boxSize) => Screen.IsMouseInBounds(topLeft, boxSize);
/// <summary>
/// Returns the safezone bounds in pixel, relative to the 1080pixel based system.
/// </summary>
[Obsolete("Use Screen.SafezoneBounds instead.", true)]
public static Point GetSafezoneBounds() => Screen.SafezoneBounds;
#endregion
#region Public Methods
/// <summary>
/// Change the menu's width. The width is calculated as DefaultWidth + WidthOffset, so a width offset of 10 would enlarge the menu by 10 pixels.
/// </summary>
/// <param name="widthOffset">New width offset.</param>
public void SetMenuWidthOffset(int widthOffset)
{
WidthOffset = widthOffset;
BannerSprite.Size = new Size(431 + WidthOffset, 107);
_mainMenu.Items[0].Position = new Point((WidthOffset + Offset.X + 431) / 2, 20 + Offset.Y); // Title
_counterText.Position = new Point(425 + Offset.X + widthOffset, 110 + Offset.Y);
if (_mainMenu.Items.Count >= 1)
{
var tmp = (UIResRectangle)_mainMenu.Items[1];
tmp.Size = new Size(431 + WidthOffset, 37);
}
if (BannerRectangle != null)
{
BannerRectangle.Size = new Size(431 + WidthOffset, 107);
}
}
/// <summary>
/// Enable or disable the instructional buttons.
/// </summary>
/// <param name="disable"></param>
public void DisableInstructionalButtons(bool disable)
{
_buttonsEnabled = !disable;
}
/// <summary>
/// Set the banner to your own Sprite object.
/// </summary>
/// <param name="spriteBanner">Sprite object. The position and size does not matter.</param>
public void SetBannerType(Sprite spriteBanner)
{
BannerSprite = spriteBanner;
BannerSprite.Size = new Size(431 + WidthOffset, 107);
BannerSprite.Position = new Point(Offset.X, Offset.Y);
}
/// <summary>
/// Set the banner to your own Rectangle.
/// </summary>
/// <param name="rectangle">UIResRectangle object. Position and size does not matter.</param>
public void SetBannerType(UIResRectangle rectangle)
{
BannerSprite = null;
BannerRectangle = rectangle;
BannerRectangle.Position = new Point(Offset.X, Offset.Y);
BannerRectangle.Size = new Size(431 + WidthOffset, 107);
}
/// <summary>
/// Set the banner to your own custom texture. Set it to "" if you want to restore the banner.
/// </summary>
/// <param name="pathToCustomSprite">Path to your sprite image.</param>
public void SetBannerType(string pathToCustomSprite)
{
BannerTexture = pathToCustomSprite;
}
/// <summary>
/// Add an item to the menu.
/// </summary>
/// <param name="item">Item object to be added. Can be normal item, checkbox or list item.</param>
public void AddItem(UIMenuItem item)
{
int selectedItem = CurrentSelection;
item.Offset = Offset;
item.Parent = this;
item.Position((MenuItems.Count * 25) - 37 + _extraYOffset);
MenuItems.Add(item);
RecaulculateDescriptionPosition();
CurrentSelection = selectedItem;
}
/// <summary>
/// Remove an item at index n.
/// </summary>
/// <param name="index">Index to remove the item at.</param>
public void RemoveItemAt(int index)
{
int selectedItem = CurrentSelection;
if (Size > MaxItemsOnScreen && _maxItem == Size - 1)
{
_maxItem--;
_minItem--;
}
MenuItems.RemoveAt(index);
RecaulculateDescriptionPosition();
CurrentSelection = selectedItem;
}
/// <summary>
/// Reset the current selected item to 0. Use this after you add or remove items dynamically.
/// </summary>
public void RefreshIndex()
{
if (MenuItems.Count == 0)
{
_activeItem = 1000;
_maxItem = MaxItemsOnScreen;
_minItem = 0;
return;
}
MenuItems[_activeItem % (MenuItems.Count)].Selected = false;
_activeItem = 1000 - (1000 % MenuItems.Count);
_maxItem = MaxItemsOnScreen;
_minItem = 0;
ReDraw = true;
}
/// <summary>
/// Remove all items from the menu.
/// </summary>
public void Clear()
{
MenuItems.Clear();
RecaulculateDescriptionPosition();
}
/// <summary>
/// Removes the items that matches the predicate.
/// </summary>
/// <param name="predicate">The function to use as the check.</param>
public void Remove(Func<UIMenuItem, bool> predicate)
{
List<UIMenuItem> TempList = new List<UIMenuItem>(MenuItems);
foreach (var item in TempList)
{
if (predicate(item))
{
MenuItems.Remove(item);
}
}
RecaulculateDescriptionPosition();
}
private void DrawCalculations()
{
DrawWidth = new Size(431 + WidthOffset, 107);
Safe = Screen.SafezoneBounds;
BackgroundSize = Size > MaxItemsOnScreen + 1 ? new Size(431 + WidthOffset, 38 * (MaxItemsOnScreen + 1)) : new Size(431 + WidthOffset, 38 * Size);
_extraRectangleUp.Size = new Size(431 + WidthOffset, 18);
_extraRectangleDown.Size = new Size(431 + WidthOffset, 18);
_upAndDownSprite.Position = new Point(190 + Offset.X + (WidthOffset > 0 ? (WidthOffset / 2) : WidthOffset), 147 + 37 * (MaxItemsOnScreen + 1) + Offset.Y - 37 + _extraYOffset);
ReDraw = false;
if (MenuItems.Count != 0 && !String.IsNullOrWhiteSpace(MenuItems[_activeItem % (MenuItems.Count)].Description))
{
RecaulculateDescriptionPosition();
string descCaption = MenuItems[_activeItem % (MenuItems.Count)].Description;
_descriptionText.Caption = descCaption;
_descriptionText.Wrap = 400;
int numLines = Screen.GetLineCount(descCaption, _descriptionText.Position, _descriptionText.Font, _descriptionText.Scale, 400);
_descriptionRectangle.Size = new Size(431 + WidthOffset, (numLines * 25) + 15);
}
}
/// <summary>
/// Go up the menu if the number of items is more than maximum items on screen.
/// </summary>
public void GoUpOverflow()
{
if (Size <= MaxItemsOnScreen + 1) return;
if (_activeItem % MenuItems.Count <= _minItem)
{
if (_activeItem % MenuItems.Count == 0)
{
_minItem = MenuItems.Count - MaxItemsOnScreen - 1;
_maxItem = MenuItems.Count - 1;
MenuItems[_activeItem % (MenuItems.Count)].Selected = false;
_activeItem = 1000 - (1000 % MenuItems.Count);
_activeItem += MenuItems.Count - 1;
MenuItems[_activeItem % (MenuItems.Count)].Selected = true;
}
else
{
_minItem--;
_maxItem--;
MenuItems[_activeItem % (MenuItems.Count)].Selected = false;
_activeItem--;
MenuItems[_activeItem % (MenuItems.Count)].Selected = true;
}
}
else
{
MenuItems[_activeItem % (MenuItems.Count)].Selected = false;
_activeItem--;
MenuItems[_activeItem % (MenuItems.Count)].Selected = true;
}
Game.PlaySound(AUDIO_UPDOWN, AUDIO_LIBRARY);
IndexChange(CurrentSelection);
}
/// <summary>
/// Go up the menu if the number of items is less than or equal to the maximum items on screen.
/// </summary>
public void GoUp()
{
if (Size > MaxItemsOnScreen + 1) return;
MenuItems[_activeItem % (MenuItems.Count)].Selected = false;
_activeItem--;
MenuItems[_activeItem % (MenuItems.Count)].Selected = true;
Game.PlaySound(AUDIO_UPDOWN, AUDIO_LIBRARY);
IndexChange(CurrentSelection);
}
/// <summary>
/// Go down the menu if the number of items is more than maximum items on screen.
/// </summary>
public void GoDownOverflow()
{
if (Size <= MaxItemsOnScreen + 1) return;
if (_activeItem % MenuItems.Count >= _maxItem)
{
if (_activeItem % MenuItems.Count == MenuItems.Count - 1)
{
_minItem = 0;
_maxItem = MaxItemsOnScreen;
MenuItems[_activeItem % (MenuItems.Count)].Selected = false;
_activeItem = 1000 - (1000 % MenuItems.Count);
MenuItems[_activeItem % (MenuItems.Count)].Selected = true;
}
else
{
_minItem++;
_maxItem++;
MenuItems[_activeItem % (MenuItems.Count)].Selected = false;
_activeItem++;
MenuItems[_activeItem % (MenuItems.Count)].Selected = true;
}
}
else
{
MenuItems[_activeItem % (MenuItems.Count)].Selected = false;
_activeItem++;
MenuItems[_activeItem % (MenuItems.Count)].Selected = true;
}
Game.PlaySound(AUDIO_UPDOWN, AUDIO_LIBRARY);
IndexChange(CurrentSelection);
}
/// <summary>
/// Go up the menu if the number of items is less than or equal to the maximum items on screen.
/// </summary>
public void GoDown()
{
if (Size > MaxItemsOnScreen + 1) return;
MenuItems[_activeItem % (MenuItems.Count)].Selected = false;
_activeItem++;
MenuItems[_activeItem % (MenuItems.Count)].Selected = true;
Game.PlaySound(AUDIO_UPDOWN, AUDIO_LIBRARY);
IndexChange(CurrentSelection);
}
/// <summary>
/// Go left on a UIMenuListItem, UIMenuDynamicListItem or UIMenuSliderItem.
/// </summary>
public void GoLeft()
{
if (!MenuItems[CurrentSelection].Enabled)
{
return;
}
if (MenuItems[CurrentSelection] is UIMenuListItem)
{
var it = (UIMenuListItem)MenuItems[CurrentSelection];
it.Index = it.Index - 1;
Game.PlaySound(AUDIO_LEFTRIGHT, AUDIO_LIBRARY);
ListChange(it, it.Index);
it.ListChangedTrigger(it.Index);
}
else if (MenuItems[CurrentSelection] is UIMenuDynamicListItem)
{
UIMenuDynamicListItem it = (UIMenuDynamicListItem)MenuItems[CurrentSelection];
string newItem = it.Callback(it, UIMenuDynamicListItem.ChangeDirection.Left);
it.CurrentListItem = newItem;
Game.PlaySound(AUDIO_LEFTRIGHT, AUDIO_LIBRARY);
}
else if (MenuItems[CurrentSelection] is UIMenuSliderItem)
{
UIMenuSliderItem it = (UIMenuSliderItem)MenuItems[CurrentSelection];
it.Value -= it.Multiplier;
Game.PlaySound(AUDIO_LEFTRIGHT, AUDIO_LIBRARY);
SliderChange(it, it.Value);
}
}
/// <summary>
/// Go right on a UIMenuListItem.
/// </summary>
public void GoRight()
{
if (!MenuItems[CurrentSelection].Enabled)
{
return;
}
if (MenuItems[CurrentSelection] is UIMenuListItem)
{
UIMenuListItem it = (UIMenuListItem)MenuItems[CurrentSelection];
it.Index++;
Game.PlaySound(AUDIO_LEFTRIGHT, AUDIO_LIBRARY);
ListChange(it, it.Index);
it.ListChangedTrigger(it.Index);
}
else if (MenuItems[CurrentSelection] is UIMenuDynamicListItem)
{
UIMenuDynamicListItem it = (UIMenuDynamicListItem)MenuItems[CurrentSelection];
string newItem = it.Callback(it, UIMenuDynamicListItem.ChangeDirection.Right);
it.CurrentListItem = newItem;
Game.PlaySound(AUDIO_LEFTRIGHT, AUDIO_LIBRARY);
}
else if (MenuItems[CurrentSelection] is UIMenuSliderItem)
{
UIMenuSliderItem it = (UIMenuSliderItem)MenuItems[CurrentSelection];
it.Value += it.Multiplier;
Game.PlaySound(AUDIO_LEFTRIGHT, AUDIO_LIBRARY);
SliderChange(it, it.Value);
}
}
/// <summary>
/// Activate the current selected item.
/// </summary>
public void SelectItem()
{
if (!MenuItems[CurrentSelection].Enabled)
{
Game.PlaySound(AUDIO_ERROR, AUDIO_LIBRARY);
return;
}
if (MenuItems[CurrentSelection] is UIMenuCheckboxItem)
{
UIMenuCheckboxItem it = (UIMenuCheckboxItem)MenuItems[CurrentSelection];
it.Checked = !it.Checked;
Game.PlaySound(AUDIO_SELECT, AUDIO_LIBRARY);
CheckboxChange(it, it.Checked);
it.CheckboxEventTrigger();
}
else
{
Game.PlaySound(AUDIO_SELECT, AUDIO_LIBRARY);
ItemSelect(MenuItems[CurrentSelection], CurrentSelection);
MenuItems[CurrentSelection].ItemActivate(this);
if (!Children.ContainsKey(MenuItems[CurrentSelection])) return;
Visible = false;
Children[MenuItems[CurrentSelection]].Visible = true;
MenuChangeEv(Children[MenuItems[CurrentSelection]], true);
}
}
/// <summary>
/// Close or go back in a menu chain.
/// </summary>
public void GoBack()
{
Game.PlaySound(AUDIO_BACK, AUDIO_LIBRARY);
Visible = false;
if (ParentMenu != null)
{
var tmp = Cursor.Position;
ParentMenu.Visible = true;
MenuChangeEv(ParentMenu, false);
if (ResetCursorOnOpen)
Cursor.Position = tmp;
}
}
/// <summary>
/// Makes the specified item open a menu when is activated.
/// </summary>
/// <param name="menuToBind">The menu that is going to be opened when the item is activated.</param>
/// <param name="itemToBindTo">The item that is going to activate the menu.</param>
public void BindMenuToItem(UIMenu menuToBind, UIMenuItem itemToBindTo)
{
if (!MenuItems.Contains(itemToBindTo))
AddItem(itemToBindTo);
menuToBind.ParentMenu = this;
menuToBind.ParentItem = itemToBindTo;
if (Children.ContainsKey(itemToBindTo))
Children[itemToBindTo] = menuToBind;
else
Children.Add(itemToBindTo, menuToBind);
}
/// <summary>
/// Remove menu binding from button.
/// </summary>
/// <param name="releaseFrom">Button to release from.</param>
/// <returns>Returns true if the operation was successful.</returns>
public bool ReleaseMenuFromItem(UIMenuItem releaseFrom)
{
if (!Children.ContainsKey(releaseFrom)) return false;
Children[releaseFrom].ParentItem = null;
Children[releaseFrom].ParentMenu = null;
Children.Remove(releaseFrom);
return true;
}
/// <summary>
/// Set a key to control a menu. Can be multiple keys for each control.
/// </summary>
/// <param name="control"></param>
/// <param name="keyToSet"></param>
public void SetKey(MenuControls control, Keys keyToSet)
{
if (_keyDictionary.ContainsKey(control))
_keyDictionary[control].Item1.Add(keyToSet);
else
{
_keyDictionary.Add(control,
new Tuple<List<Keys>, List<Tuple<Control, int>>>(new List<Keys>(), new List<Tuple<Control, int>>()));
_keyDictionary[control].Item1.Add(keyToSet);
}
}
/// <summary>
/// Set a GTA.Control to control a menu. Can be multiple controls. This applies it to all indexes.
/// </summary>
/// <param name="control"></param>
/// <param name="gtaControl"></param>
public void SetKey(MenuControls control, Control gtaControl)
{
SetKey(control, gtaControl, 0);
SetKey(control, gtaControl, 1);
SetKey(control, gtaControl, 2);
}
/// <summary>
/// Set a GTA.Control to control a menu only on a specific index.
/// </summary>
/// <param name="control"></param>
/// <param name="gtaControl"></param>
/// <param name="controlIndex"></param>
public void SetKey(MenuControls control, Control gtaControl, int controlIndex)
{
if (_keyDictionary.ContainsKey(control))
_keyDictionary[control].Item2.Add(new Tuple<Control, int>(gtaControl, controlIndex));
else
{
_keyDictionary.Add(control,
new Tuple<List<Keys>, List<Tuple<Control, int>>>(new List<Keys>(), new List<Tuple<Control, int>>()));
_keyDictionary[control].Item2.Add(new Tuple<Control, int>(gtaControl, controlIndex));
}
}
/// <summary>
/// Remove all controls on a control.
/// </summary>
/// <param name="control"></param>
public void ResetKey(MenuControls control)
{
_keyDictionary[control].Item1.Clear();
_keyDictionary[control].Item2.Clear();
}
/// <summary>
/// Check whether a menucontrol has been pressed.
/// </summary>
/// <param name="control">Control to check for.</param>
/// <param name="key">Key if you're using keys.</param>
/// <returns></returns>
public bool HasControlJustBeenPressed(MenuControls control, Keys key = Keys.None)
{
List<Keys> tmpKeys = new List<Keys>(_keyDictionary[control].Item1);
List<Tuple<Control, int>> tmpControls = new List<Tuple<Control, int>>(_keyDictionary[control].Item2);
if (key != Keys.None)
{
if (tmpKeys.Any(Game.IsKeyPressed))
return true;
}
if (tmpControls.Any(tuple => Game.IsControlJustPressed(tuple.Item2, tuple.Item1)))
return true;
return false;
}
/// <summary>
/// Check whether a menucontrol has been released.
/// </summary>
/// <param name="control">Control to check for.</param>
/// <param name="key">Key if you're using keys.</param>
/// <returns></returns>
public bool HasControlJustBeenReleaseed(MenuControls control, Keys key = Keys.None)
{
List<Keys> tmpKeys = new List<Keys>(_keyDictionary[control].Item1);
List<Tuple<Control, int>> tmpControls = new List<Tuple<Control, int>>(_keyDictionary[control].Item2);
if (key != Keys.None)
{
if (tmpKeys.Any(Game.IsKeyPressed))
return true;
}
if (tmpControls.Any(tuple => Game.IsControlJustReleased(tuple.Item2, tuple.Item1)))
return true;
return false;
}
private int _controlCounter;
/// <summary>
/// Check whether a menucontrol is being pressed.
/// </summary>
/// <param name="control"></param>
/// <param name="key"></param>
/// <returns></returns>
public bool IsControlBeingPressed(MenuControls control, Keys key = Keys.None)
{
List<Keys> tmpKeys = new List<Keys>(_keyDictionary[control].Item1);
List<Tuple<Control, int>> tmpControls = new List<Tuple<Control, int>>(_keyDictionary[control].Item2);
if (HasControlJustBeenReleaseed(control, key)) _controlCounter = 0;
if (_controlCounter > 0)
{
_controlCounter++;
if (_controlCounter > 30)
_controlCounter = 0;
return false;
}
if (key != Keys.None)
{
if (tmpKeys.Any(Game.IsKeyPressed))
{
_controlCounter = 1;
return true;
}
}
if (tmpControls.Any(tuple => Game.IsControlPressed(tuple.Item2, tuple.Item1)))
{
_controlCounter = 1;
return true;
}
return false;
}
public void AddInstructionalButton(InstructionalButton button)
{
_instructionalButtons.Add(button);
}
public void RemoveInstructionalButton(InstructionalButton button)
{
_instructionalButtons.Remove(button);
}
#endregion
#region Private Methods
private void RecaulculateDescriptionPosition()
{
//_descriptionText.WordWrap = new Size(425 + WidthOffset, 0);
_descriptionBar.Position = new Point(Offset.X, 149 - 37 + _extraYOffset + Offset.Y);
_descriptionRectangle.Position = new Point(Offset.X, 149 - 37 + _extraYOffset + Offset.Y);
_descriptionText.Position = new Point(Offset.X + 8, 155 - 37 + _extraYOffset + Offset.Y);
_descriptionBar.Size = new Size(431 + WidthOffset, 4);
_descriptionRectangle.Size = new Size(431 + WidthOffset, 30);
int count = Size;
if (count > MaxItemsOnScreen + 1)
count = MaxItemsOnScreen + 2;
_descriptionBar.Position = new Point(Offset.X, 38 * count + _descriptionBar.Position.Y);
_descriptionRectangle.Position = new Point(Offset.X, 38 * count + _descriptionRectangle.Position.Y);
_descriptionText.Position = new Point(Offset.X + 8, 38 * count + _descriptionText.Position.Y);
}
/// <summary>
/// Function to get whether the cursor is in an arrow space, or in label of an UIMenuListItem.
/// </summary>
/// <param name="item">What item to check</param>
/// <param name="topLeft">top left point of the item.</param>
/// <param name="safezone">safezone size.</param>
/// <returns>0 - Not in item at all, 1 - In label, 2 - In arrow space.</returns>
private int IsMouseInListItemArrows(UIMenuItem item, Point topLeft, Point safezone) // TODO: Ability to scroll left and right
gitextract_bxv95l5f/ ├── .appveyor.yml ├── .gitattributes ├── .gitignore ├── LICENSE.md ├── MenuExample/ │ ├── MenuExample.cs │ ├── MenuExample.csproj │ └── packages.config ├── NativeUI/ │ ├── BigMessage.cs │ ├── Controls.cs │ ├── Elements/ │ │ ├── Sprite.cs │ │ ├── TimerBars.cs │ │ ├── UIResRectangle.cs │ │ └── UIResText.cs │ ├── InstructionalButton.cs │ ├── Items/ │ │ ├── IListItem.cs │ │ ├── UIMenuCheckboxItem.cs │ │ ├── UIMenuColoredItem.cs │ │ ├── UIMenuDynamicListItem.cs │ │ ├── UIMenuItem.cs │ │ ├── UIMenuListItem.cs │ │ └── UIMenuSliderItem.cs │ ├── MenuPool.cs │ ├── NativeUI.csproj │ ├── NativeUI.nuspec │ ├── PauseMenu/ │ │ ├── TabInteractiveListItem.cs │ │ ├── TabItem.cs │ │ ├── TabItemSimpleList.cs │ │ ├── TabMissionSelectItem.cs │ │ ├── TabSubmenuItem.cs │ │ ├── TabTextItem.cs │ │ └── TabView.cs │ ├── PointExtensions.cs │ ├── Properties/ │ │ └── AssemblyInfo.cs │ ├── Screen.cs │ ├── StringMeasurer.cs │ ├── UIMenu.cs │ └── packages.config ├── NativeUI.sln └── README.md
SYMBOL INDEX (261 symbols across 27 files)
FILE: MenuExample/MenuExample.cs
class MenuExample (line 7) | public class MenuExample : Script
method AddMenuKetchup (line 13) | public void AddMenuKetchup(UIMenu menu)
method AddMenuFoods (line 27) | public void AddMenuFoods(UIMenu menu)
method AddMenuCook (line 50) | public void AddMenuCook(UIMenu menu)
method AddMenuAnotherMenu (line 71) | public void AddMenuAnotherMenu(UIMenu menu)
method MenuExample (line 78) | public MenuExample()
FILE: NativeUI/BigMessage.cs
class BigMessageHandler (line 8) | public class BigMessageHandler
method BigMessageHandler (line 14) | public BigMessageHandler()
method Load (line 19) | public void Load()
method Dispose (line 28) | public void Dispose()
method ShowMissionPassedMessage (line 34) | public void ShowMissionPassedMessage(string msg, int time = 5000)
method ShowColoredShard (line 42) | public void ShowColoredShard(string msg, string desc, HudColor textCol...
method ShowOldMessage (line 50) | public void ShowOldMessage(string msg, int time = 5000)
method ShowSimpleShard (line 58) | public void ShowSimpleShard(string title, string subtitle, int time = ...
method ShowRankupMessage (line 66) | public void ShowRankupMessage(string msg, string subtitle, int rank, i...
method ShowWeaponPurchasedMessage (line 74) | public void ShowWeaponPurchasedMessage(string bigMessage, string weapo...
method ShowMpMessageLarge (line 82) | public void ShowMpMessageLarge(string msg, int time = 5000)
method ShowCustomShard (line 91) | public void ShowCustomShard(string funcName, params object[] paremeters)
method Update (line 97) | internal void Update()
class BigMessageThread (line 111) | public class BigMessageThread : Script
method BigMessageThread (line 115) | public BigMessageThread()
type HudColor (line 126) | public enum HudColor
FILE: NativeUI/Controls.cs
class Controls (line 11) | public static class Controls
method Toggle (line 63) | public static void Toggle(bool toggle)
FILE: NativeUI/Elements/Sprite.cs
class Sprite (line 10) | public class Sprite
method Sprite (line 41) | public Sprite(string textureDict, string textureName, Point position, ...
method Sprite (line 62) | public Sprite(string textureDict, string textureName, Point position, ...
method Draw (line 70) | public void Draw()
method Draw (line 91) | public static void Draw(string dict, string name, int xpos, int ypos, ...
method DrawTexture (line 117) | public static void DrawTexture(string path, Point position, Size size,...
method DrawTexture (line 147) | public static void DrawTexture(string path, Point position, Size size)
method WriteFileFromResources (line 178) | public static string WriteFileFromResources(Assembly yourAssembly, str...
method WriteFileFromResources (line 192) | public static string WriteFileFromResources(Assembly yourAssembly, str...
FILE: NativeUI/Elements/TimerBars.cs
class TimerBarBase (line 8) | public abstract class TimerBarBase
method TimerBarBase (line 12) | public TimerBarBase(string label)
method Draw (line 17) | public virtual void Draw(int interval)
class TextTimerBar (line 32) | public class TextTimerBar : TimerBarBase
method TextTimerBar (line 36) | public TextTimerBar(string label, string text) : base(label)
method Draw (line 41) | public override void Draw(int interval)
class BarTimerBar (line 52) | public class BarTimerBar : TimerBarBase
method BarTimerBar (line 62) | public BarTimerBar(string label) : base(label)
method Draw (line 68) | public override void Draw(int interval)
class TimerBarPool (line 82) | public class TimerBarPool
method TimerBarPool (line 86) | public TimerBarPool()
method ToList (line 91) | public List<TimerBarBase> ToList()
method Add (line 96) | public void Add(TimerBarBase timer)
method Remove (line 101) | public void Remove(TimerBarBase timer)
method Draw (line 106) | public void Draw()
FILE: NativeUI/Elements/UIResRectangle.cs
class UIResRectangle (line 10) | public class UIResRectangle : UIRectangle
method UIResRectangle (line 12) | public UIResRectangle()
method UIResRectangle (line 15) | public UIResRectangle(Point pos, Size size) : base(pos, size)
method UIResRectangle (line 18) | public UIResRectangle(Point pos, Size size, Color color) : base(pos, s...
method Draw (line 21) | public override void Draw(Size offset)
method Draw (line 38) | public static void Draw(int xPos, int yPos, int boxWidth, int boxHeigh...
FILE: NativeUI/Elements/UIResText.cs
class UIResText (line 12) | public class UIResText : UIText
method UIResText (line 14) | public UIResText(string caption, Point position, float scale) : base(c...
method UIResText (line 19) | public UIResText(string caption, Point position, float scale, Color co...
method UIResText (line 24) | public UIResText(string caption, Point position, float scale, Color co...
method AddLongString (line 36) | public static void AddLongString(string str)
method AddLongStringForAscii (line 50) | private static void AddLongStringForAscii(string input)
method AddLongStringForUtf8 (line 61) | internal static void AddLongStringForUtf8(string input)
method MeasureStringWidth (line 100) | [Obsolete("Use Screen.GetTextWidth instead.", true)]
method MeasureStringWidthNoConvert (line 103) | [Obsolete("Use Screen.GetTextWidth instead.", true)]
method Draw (line 120) | public override void Draw(Size offset)
method Draw (line 161) | public static void Draw(string caption, int xPos, int yPos, Font font,...
type Alignment (line 202) | public enum Alignment
FILE: NativeUI/InstructionalButton.cs
class InstructionalButton (line 5) | public class InstructionalButton
method InstructionalButton (line 21) | public InstructionalButton(GTA.Control control, string text)
method InstructionalButton (line 34) | public InstructionalButton(string keystring, string text)
method BindToItem (line 46) | public void BindToItem(UIMenuItem item)
method GetButtonId (line 51) | public string GetButtonId()
FILE: NativeUI/Items/IListItem.cs
type IListItem (line 3) | public interface IListItem
method CurrentItem (line 5) | string CurrentItem();
FILE: NativeUI/Items/UIMenuCheckboxItem.cs
class UIMenuCheckboxItem (line 6) | public class UIMenuCheckboxItem : UIMenuItem
method UIMenuCheckboxItem (line 20) | public UIMenuCheckboxItem(string text, bool check) : this(text, check,...
method UIMenuCheckboxItem (line 30) | public UIMenuCheckboxItem(string text, bool check, string description)...
method Position (line 48) | public override void Position(int y)
method Draw (line 58) | public override void Draw()
method CheckboxEventTrigger (line 73) | public void CheckboxEventTrigger()
method SetRightBadge (line 78) | public override void SetRightBadge(BadgeStyle badge)
method SetRightLabel (line 83) | public override void SetRightLabel(string text)
FILE: NativeUI/Items/UIMenuColoredItem.cs
class UIMenuColoredItem (line 5) | public class UIMenuColoredItem : UIMenuItem
method UIMenuColoredItem (line 13) | public UIMenuColoredItem(string label, Color color, Color highlightCol...
method UIMenuColoredItem (line 24) | public UIMenuColoredItem(string label, string description, Color color...
method Init (line 35) | protected void Init()
method Draw (line 49) | public override void Draw()
FILE: NativeUI/Items/UIMenuDynamicListItem.cs
class UIMenuDynamicListItem (line 7) | public class UIMenuDynamicListItem : UIMenuItem, IListItem
type ChangeDirection (line 9) | public enum ChangeDirection
method UIMenuDynamicListItem (line 28) | public UIMenuDynamicListItem(string text, string startingItem, Dynamic...
method UIMenuDynamicListItem (line 37) | public UIMenuDynamicListItem(string text, string description, string s...
method Position (line 54) | public override void Position(int y)
method Draw (line 65) | public override void Draw()
method SetRightBadge (line 93) | public override void SetRightBadge(BadgeStyle badge)
method SetRightLabel (line 98) | public override void SetRightLabel(string text)
method CurrentItem (line 103) | public string CurrentItem()
FILE: NativeUI/Items/UIMenuItem.cs
class UIMenuItem (line 9) | public class UIMenuItem
method UIMenuItem (line 32) | public UIMenuItem(string text) : this(text, "")
method UIMenuItem (line 41) | public UIMenuItem(string text, string description)
method ItemActivate (line 80) | internal virtual void ItemActivate(UIMenu sender)
method Position (line 90) | public virtual void Position(int y)
method Draw (line 105) | public virtual void Draw()
method SetLeftBadge (line 174) | public virtual void SetLeftBadge(BadgeStyle badge)
method SetRightBadge (line 184) | public virtual void SetRightBadge(BadgeStyle badge)
method SetRightLabel (line 194) | public virtual void SetRightLabel(string text)
type BadgeStyle (line 216) | public enum BadgeStyle
method BadgeToSpriteLib (line 251) | internal static string BadgeToSpriteLib(BadgeStyle badge)
method BadgeToSpriteName (line 268) | internal static string BadgeToSpriteName(BadgeStyle badge, bool selected)
method BadgeToColor (line 339) | internal static Color BadgeToColor(BadgeStyle badge, bool selected)
FILE: NativeUI/Items/UIMenuListItem.cs
class UIMenuListItem (line 9) | public class UIMenuListItem : UIMenuItem, IListItem
method UIMenuListItem (line 54) | public UIMenuListItem(string text, List<object> items, int index) : th...
method UIMenuListItem (line 65) | public UIMenuListItem(string text, List<object> items, int index, stri...
method Position (line 81) | public override void Position(int y)
method ItemToIndex (line 95) | [Obsolete("Use UIMenuListItem.Items.FindIndex(p => ReferenceEquals(p, ...
method IndexToItem (line 107) | [Obsolete("Use UIMenuListItem.Items[Index] instead.")]
method Draw (line 117) | public override void Draw()
method ListChangedTrigger (line 145) | internal virtual void ListChangedTrigger(int newindex)
method SetRightBadge (line 150) | public override void SetRightBadge(BadgeStyle badge)
method SetRightLabel (line 155) | public override void SetRightLabel(string text)
method CurrentItem (line 160) | [Obsolete("Use UIMenuListItem.Items[Index].ToString() instead.")]
FILE: NativeUI/Items/UIMenuSliderItem.cs
class UIMenuSliderItem (line 6) | public class UIMenuSliderItem : UIMenuItem
method UIMenuSliderItem (line 86) | public UIMenuSliderItem(string text) : this(text, "", false)
method UIMenuSliderItem (line 97) | public UIMenuSliderItem(string text, string description) : this(text, ...
method UIMenuSliderItem (line 109) | public UIMenuSliderItem(string text, string description, bool divider)...
method Position (line 130) | public override void Position(int y)
method Draw (line 145) | public override void Draw()
method SliderChanged (line 167) | internal virtual void SliderChanged()
FILE: NativeUI/MenuPool.cs
class MenuPool (line 12) | public class MenuPool
method Add (line 51) | public void Add(UIMenu menu)
method AddSubMenu (line 64) | public UIMenu AddSubMenu(UIMenu menu, string text)
method AddSubMenu (line 81) | public UIMenu AddSubMenu(UIMenu menu, string text, Point offset)
method AddSubMenu (line 95) | public UIMenu AddSubMenu(UIMenu menu, string text, string description)
method AddSubMenu (line 112) | public UIMenu AddSubMenu(UIMenu menu, string text, string description,...
method RefreshIndex (line 132) | public void RefreshIndex()
method ToList (line 141) | public List<UIMenu> ToList()
method ProcessControl (line 149) | public void ProcessControl()
method ProcessKey (line 169) | public void ProcessKey(Keys key)
method ProcessMouse (line 188) | public void ProcessMouse()
method Draw (line 207) | public void Draw()
method IsAnyMenuOpen (line 227) | public bool IsAnyMenuOpen()
method ProcessMenus (line 236) | public void ProcessMenus()
method CloseAllMenus (line 247) | public void CloseAllMenus()
method SetBannerType (line 255) | public void SetBannerType(Sprite bannerType)
method SetBannerType (line 260) | public void SetBannerType(UIResRectangle bannerType)
method SetBannerType (line 265) | public void SetBannerType(string bannerPath)
method SetKey (line 270) | public void SetKey(UIMenu.MenuControls menuControl, Control control)
method SetKey (line 275) | public void SetKey(UIMenu.MenuControls menuControl, Control control, i...
method SetKey (line 280) | public void SetKey(UIMenu.MenuControls menuControl, Keys control)
method ResetKey (line 285) | public void ResetKey(UIMenu.MenuControls menuControl)
FILE: NativeUI/PauseMenu/TabInteractiveListItem.cs
class TabInteractiveListItem (line 10) | public class TabInteractiveListItem : TabItem
method TabInteractiveListItem (line 12) | public TabInteractiveListItem(string name, IEnumerable<UIMenuItem> ite...
method MoveDown (line 29) | public void MoveDown()
method MoveUp (line 48) | public void MoveUp()
method RefreshIndex (line 67) | public void RefreshIndex()
method ProcessControls (line 75) | public override void ProcessControls()
method Draw (line 130) | public override void Draw()
FILE: NativeUI/PauseMenu/TabItem.cs
class TabItem (line 6) | public class TabItem
method TabItem (line 8) | public TabItem(string name)
method OnActivated (line 36) | public void OnActivated()
method ProcessControls (line 42) | public virtual void ProcessControls()
method Draw (line 47) | public virtual void Draw()
FILE: NativeUI/PauseMenu/TabItemSimpleList.cs
class TabItemSimpleList (line 8) | public class TabItemSimpleList : TabItem
method TabItemSimpleList (line 10) | public TabItemSimpleList(string title, Dictionary<string, string> dict...
method Draw (line 18) | public override void Draw()
FILE: NativeUI/PauseMenu/TabMissionSelectItem.cs
class MissionInformation (line 12) | public class MissionInformation
method MissionInformation (line 14) | public MissionInformation(string name, IEnumerable<Tuple<string, strin...
method MissionInformation (line 20) | public MissionInformation(string name, string description, IEnumerable...
class MissionLogo (line 33) | public class MissionLogo
method MissionLogo (line 39) | public MissionLogo(string filepath)
method MissionLogo (line 50) | public MissionLogo(string textureDict, string textureName)
class TabMissionSelectItem (line 62) | public class TabMissionSelectItem : TabItem
method TabMissionSelectItem (line 64) | public TabMissionSelectItem(string name, IEnumerable<MissionInformatio...
method ProcessControls (line 88) | public override void ProcessControls()
method Draw (line 145) | public override void Draw()
FILE: NativeUI/PauseMenu/TabSubmenuItem.cs
class TabSubmenuItem (line 8) | public class TabSubmenuItem : TabItem
method TabSubmenuItem (line 12) | public TabSubmenuItem(string name, IEnumerable<TabItem> items) : base(...
method RefreshIndex (line 20) | public void RefreshIndex()
method ProcessControls (line 45) | public override void ProcessControls()
method Draw (line 94) | public override void Draw()
FILE: NativeUI/PauseMenu/TabTextItem.cs
class TabTextItem (line 5) | public class TabTextItem : TabItem
method TabTextItem (line 11) | public TabTextItem(string name, string title) : base(name)
method TabTextItem (line 16) | public TabTextItem(string name, string title, string text) : base(name)
method Draw (line 22) | public override void Draw()
FILE: NativeUI/PauseMenu/TabView.cs
class TabView (line 10) | public class TabView
method TabView (line 12) | public TabView(string title)
method AddTab (line 56) | public void AddTab(TabItem item)
method ShowInstructionalButtons (line 66) | public void ShowInstructionalButtons()
method DrawInstructionalButton (line 85) | public void DrawInstructionalButton(int slot, Control control, string ...
method ProcessControls (line 90) | public void ProcessControls()
method RefreshIndex (line 192) | public void RefreshIndex()
method Update (line 208) | public void Update()
FILE: NativeUI/PointExtensions.cs
class MiscExtensions (line 7) | public static class MiscExtensions
method AddPoints (line 11) | public static Point AddPoints(this Point left, Point right)
method SubtractPoints (line 16) | public static Point SubtractPoints(this Point left, Point right)
method Clamp (line 21) | public static float Clamp(this float val, float min, float max)
method LinearVectorLerp (line 30) | public static Vector3 LinearVectorLerp(Vector3 start, Vector3 end, int...
method VectorLerp (line 40) | public static Vector3 VectorLerp(Vector3 start, Vector3 end, int curre...
method LinearFloatLerp (line 50) | public static float LinearFloatLerp(float start, float end, int curren...
method QuadraticEasingLerp (line 56) | public static float QuadraticEasingLerp(float start, float end, int cu...
FILE: NativeUI/Screen.cs
class Screen (line 11) | public static class Screen
method IsMouseInBounds (line 65) | public static bool IsMouseInBounds(Point topLeft, Size boxSize)
method GetTextWidth (line 86) | public static float GetTextWidth(string text, GTA.Font font, float scale)
method GetLineCount (line 111) | public static int GetLineCount(string text, Point position, GTA.Font f...
FILE: NativeUI/StringMeasurer.cs
class StringMeasurer (line 6) | public static class StringMeasurer
method MeasureString (line 13) | [Obsolete("Use Screen.GetTextWidth instead.", true)]
method MeasureString (line 16) | [Obsolete("Use Screen.GetTextWidth instead.", true)]
FILE: NativeUI/UIMenu.cs
class UIMenu (line 44) | public class UIMenu
method UIMenu (line 173) | public UIMenu(string title, string subtitle) : this(title, subtitle, n...
method UIMenu (line 184) | public UIMenu(string title, string subtitle, Point offset) : this(titl...
method UIMenu (line 195) | public UIMenu(string title, string subtitle, Point offset, string cust...
method UIMenu (line 209) | public UIMenu(string title, string subtitle, Point offset, string spri...
method DisEnableControls (line 267) | [Obsolete("Use Controls.Toggle instead.", true)]
method GetScreenResolutionMaintainRatio (line 273) | [Obsolete("Use Screen.ResolutionMantainRatio instead.", true)]
method GetScreenResolutionMantainRatio (line 279) | [Obsolete("Use Screen.ResolutionMantainRatio instead.", true)]
method IsMouseInBounds (line 288) | [Obsolete("Use Screen.IsMouseInBounds instead.", true)]
method GetSafezoneBounds (line 294) | [Obsolete("Use Screen.SafezoneBounds instead.", true)]
method SetMenuWidthOffset (line 304) | public void SetMenuWidthOffset(int widthOffset)
method DisableInstructionalButtons (line 325) | public void DisableInstructionalButtons(bool disable)
method SetBannerType (line 334) | public void SetBannerType(Sprite spriteBanner)
method SetBannerType (line 345) | public void SetBannerType(UIResRectangle rectangle)
method SetBannerType (line 357) | public void SetBannerType(string pathToCustomSprite)
method AddItem (line 366) | public void AddItem(UIMenuItem item)
method RemoveItemAt (line 384) | public void RemoveItemAt(int index)
method RefreshIndex (line 400) | public void RefreshIndex()
method Clear (line 420) | public void Clear()
method Remove (line 430) | public void Remove(Func<UIMenuItem, bool> predicate)
method DrawCalculations (line 443) | private void DrawCalculations()
method GoUpOverflow (line 476) | public void GoUpOverflow()
method GoUp (line 513) | public void GoUp()
method GoDownOverflow (line 527) | public void GoDownOverflow()
method GoDown (line 563) | public void GoDown()
method GoLeft (line 577) | public void GoLeft()
method GoRight (line 612) | public void GoRight()
method SelectItem (line 647) | public void SelectItem()
method GoBack (line 678) | public void GoBack()
method BindMenuToItem (line 698) | public void BindMenuToItem(UIMenu menuToBind, UIMenuItem itemToBindTo)
method ReleaseMenuFromItem (line 716) | public bool ReleaseMenuFromItem(UIMenuItem releaseFrom)
method SetKey (line 730) | public void SetKey(MenuControls control, Keys keyToSet)
method SetKey (line 748) | public void SetKey(MenuControls control, Control gtaControl)
method SetKey (line 762) | public void SetKey(MenuControls control, Control gtaControl, int contr...
method ResetKey (line 780) | public void ResetKey(MenuControls control)
method HasControlJustBeenPressed (line 793) | public bool HasControlJustBeenPressed(MenuControls control, Keys key =...
method HasControlJustBeenReleaseed (line 815) | public bool HasControlJustBeenReleaseed(MenuControls control, Keys key...
method IsControlBeingPressed (line 837) | public bool IsControlBeingPressed(MenuControls control, Keys key = Key...
method AddInstructionalButton (line 865) | public void AddInstructionalButton(InstructionalButton button)
method RemoveInstructionalButton (line 870) | public void RemoveInstructionalButton(InstructionalButton button)
method RecaulculateDescriptionPosition (line 878) | private void RecaulculateDescriptionPosition()
method IsMouseInListItemArrows (line 905) | private int IsMouseInListItemArrows(UIMenuItem item, Point topLeft, Po...
method Draw (line 931) | public void Draw()
method ProcessMouse (line 1037) | public void ProcessMouse()
method ProcessControl (line 1167) | public void ProcessControl(Keys key = Keys.None)
method ProcessKey (line 1220) | public void ProcessKey(Keys key)
method UpdateScaleform (line 1233) | public void UpdateScaleform()
method IndexChange (line 1380) | protected virtual void IndexChange(int newindex)
method ListChange (line 1388) | protected virtual void ListChange(UIMenuListItem sender, int newindex)
method ItemSelect (line 1394) | protected virtual void ItemSelect(UIMenuItem selecteditem, int index)
method SliderChange (line 1399) | protected virtual void SliderChange(UIMenuSliderItem sender, int newin...
method CheckboxChange (line 1404) | protected virtual void CheckboxChange(UIMenuCheckboxItem sender, bool ...
method MenuOpenEv (line 1409) | protected virtual void MenuOpenEv()
method MenuCloseEv (line 1414) | protected virtual void MenuCloseEv()
method MenuChangeEv (line 1419) | protected virtual void MenuChangeEv(UIMenu newmenu, bool forward)
type MenuControls (line 1426) | public enum MenuControls
Condensed preview — 39 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (227K chars).
[
{
"path": ".appveyor.yml",
"chars": 1107,
"preview": "version: \"1.9.1.{build}\"\nimage: Visual Studio 2017\n\nassembly_info:\n patch: true\n file: Properties\\AssemblyInfo.cs\n as"
},
{
"path": ".gitattributes",
"chars": 2518,
"preview": "###############################################################################\n# Set default behavior to automatically "
},
{
"path": ".gitignore",
"chars": 5646,
"preview": "## Ignore Visual Studio temporary files, build results, and\n## files generated by popular Visual Studio add-ons.\n##\n## G"
},
{
"path": "LICENSE.md",
"chars": 1061,
"preview": "MIT License\n\nCopyright (c) 2016 Guad\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof th"
},
{
"path": "MenuExample/MenuExample.cs",
"chars": 3066,
"preview": "using System;\nusing System.Collections.Generic;\nusing System.Windows.Forms;\nusing GTA;\nusing NativeUI;\n\npublic class Me"
},
{
"path": "MenuExample/MenuExample.csproj",
"chars": 3101,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"14.0\" DefaultTargets=\"Build\" xmlns=\"http://schemas.micros"
},
{
"path": "MenuExample/packages.config",
"chars": 142,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<packages>\n <package id=\"ScriptHookVDotNet2\" version=\"2.10.12\" targetFramework="
},
{
"path": "NativeUI/BigMessage.cs",
"chars": 10625,
"preview": "using System;\nusing System.Runtime.Remoting.Messaging;\nusing GTA;\nusing GTA.Native;\n\nnamespace NativeUI\n{\n public cl"
},
{
"path": "NativeUI/Controls.cs",
"chars": 3007,
"preview": "using GTA;\nusing GTA.Native;\nusing System.Collections.Generic;\nusing System.Linq;\n\nnamespace NativeUI\n{\n /// <summar"
},
{
"path": "NativeUI/Elements/Sprite.cs",
"chars": 8407,
"preview": "using System;\nusing System.Drawing;\nusing System.IO;\nusing System.Reflection;\nusing GTA;\nusing GTA.Native;\n\nnamespace N"
},
{
"path": "NativeUI/Elements/TimerBars.cs",
"chars": 3329,
"preview": "using System.Collections.Generic;\nusing System.Drawing;\nusing GTA;\nusing Font = GTA.Font;\n\nnamespace NativeUI\n{\n pub"
},
{
"path": "NativeUI/Elements/UIResRectangle.cs",
"chars": 1752,
"preview": "using System.Drawing;\nusing GTA;\nusing GTA.Native;\n\nnamespace NativeUI\n{\n /// <summary>\n /// A rectangle in 1080 "
},
{
"path": "NativeUI/Elements/UIResText.cs",
"chars": 7144,
"preview": "using System;\nusing System.Drawing;\nusing GTA;\nusing GTA.Native;\nusing Font = GTA.Font;\n\nnamespace NativeUI\n{\n /// <"
},
{
"path": "NativeUI/InstructionalButton.cs",
"chars": 1852,
"preview": "using GTA.Native;\n\nnamespace NativeUI\n{\n public class InstructionalButton\n {\n public string Text { get; se"
},
{
"path": "NativeUI/Items/IListItem.cs",
"chars": 96,
"preview": "namespace NativeUI\n{\n public interface IListItem\n {\n string CurrentItem();\n }\n}"
},
{
"path": "NativeUI/Items/UIMenuCheckboxItem.cs",
"chars": 2792,
"preview": "using System;\nusing System.Drawing;\n\nnamespace NativeUI\n{ \n public class UIMenuCheckboxItem : UIMenuItem\n "
},
{
"path": "NativeUI/Items/UIMenuColoredItem.cs",
"chars": 3911,
"preview": "using System.Drawing;\n\nnamespace NativeUI\n{\n public class UIMenuColoredItem : UIMenuItem\n {\n public Color "
},
{
"path": "NativeUI/Items/UIMenuDynamicListItem.cs",
"chars": 3983,
"preview": "using System;\nusing System.Drawing;\nusing Font = GTA.Font;\n\nnamespace NativeUI\n{\n public class UIMenuDynamicListItem"
},
{
"path": "NativeUI/Items/UIMenuItem.cs",
"chars": 12363,
"preview": "using System;\nusing System.Drawing;\n\nnamespace NativeUI\n{ \n /// <summary>\n /// Simple item with a "
},
{
"path": "NativeUI/Items/UIMenuListItem.cs",
"chars": 5699,
"preview": "using System;\nusing System.Collections.Generic;\nusing System.Drawing;\nusing GTA;\nusing Font = GTA.Font;\n\nnamespace Nati"
},
{
"path": "NativeUI/Items/UIMenuSliderItem.cs",
"chars": 5782,
"preview": "using System.Collections.Generic;\nusing System.Drawing;\n\nnamespace NativeUI\n{\n public class UIMenuSliderItem : UIMen"
},
{
"path": "NativeUI/MenuPool.cs",
"chars": 10492,
"preview": "using System.Collections.Generic;\nusing System.Drawing;\nusing System.Linq;\nusing System.Windows.Forms;\nusing Control = "
},
{
"path": "NativeUI/NativeUI.csproj",
"chars": 4469,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"14.0\" DefaultTargets=\"Build\" xmlns=\"http://schemas.micros"
},
{
"path": "NativeUI/NativeUI.nuspec",
"chars": 718,
"preview": "<?xml version=\"1.0\"?>\n<package >\n <metadata>\n <id>NativeUI</id>\n <version>1.9</version>\n <authors>Guad</autho"
},
{
"path": "NativeUI/PauseMenu/TabInteractiveListItem.cs",
"chars": 12164,
"preview": "using System;\nusing System.Collections.Generic;\nusing System.Drawing;\nusing GTA;\nusing GTA.Native;\nusing Font = GTA.Fon"
},
{
"path": "NativeUI/PauseMenu/TabItem.cs",
"chars": 2674,
"preview": "using System;\nusing System.Drawing;\n\nnamespace NativeUI.PauseMenu\n{\n public class TabItem\n {\n public TabIt"
},
{
"path": "NativeUI/PauseMenu/TabItemSimpleList.cs",
"chars": 1527,
"preview": "using System.Collections.Generic;\nusing System.Drawing;\nusing System.Linq;\nusing Font = GTA.Font;\n\nnamespace NativeUI.P"
},
{
"path": "NativeUI/PauseMenu/TabMissionSelectItem.cs",
"chars": 9059,
"preview": "using System;\nusing System.Collections.Generic;\nusing System.Drawing;\nusing GTA;\nusing GTA.Native;\nusing Font = GTA.Fon"
},
{
"path": "NativeUI/PauseMenu/TabSubmenuItem.cs",
"chars": 6193,
"preview": "using System.Collections.Generic;\nusing System.Drawing;\nusing GTA;\nusing GTA.Native;\n\nnamespace NativeUI.PauseMenu\n{\n "
},
{
"path": "NativeUI/PauseMenu/TabTextItem.cs",
"chars": 1274,
"preview": "using System.Drawing;\n\nnamespace NativeUI.PauseMenu\n{\n public class TabTextItem : TabItem\n {\n public strin"
},
{
"path": "NativeUI/PauseMenu/TabView.cs",
"chars": 12085,
"preview": "using System;\nusing System.Collections.Generic;\nusing System.Drawing;\nusing GTA;\nusing GTA.Native;\nusing Font = GTA.Fon"
},
{
"path": "NativeUI/PointExtensions.cs",
"chars": 2238,
"preview": "using System;\nusing System.Drawing;\nusing GTA.Math;\n\nnamespace NativeUI\n{\n public static class MiscExtensions\n {\n"
},
{
"path": "NativeUI/Properties/AssemblyInfo.cs",
"chars": 1389,
"preview": "using System.Reflection;\nusing System.Runtime.CompilerServices;\nusing System.Runtime.InteropServices;\n\n// General Infor"
},
{
"path": "NativeUI/Screen.cs",
"chars": 6170,
"preview": "using GTA;\nusing GTA.Native;\nusing System;\nusing System.Drawing;\n\nnamespace NativeUI\n{\n /// <summary>\n /// Tools "
},
{
"path": "NativeUI/StringMeasurer.cs",
"chars": 630,
"preview": "using System;\nusing GTA;\n\nnamespace NativeUI\n{\n public static class StringMeasurer\n {\n /// <summary>\n "
},
{
"path": "NativeUI/UIMenu.cs",
"chars": 55565,
"preview": "using System;\nusing System.Collections.Generic;\nusing System.Drawing;\nusing System.Linq;\nusing System.Windows.Forms;\nus"
},
{
"path": "NativeUI/packages.config",
"chars": 142,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<packages>\n <package id=\"ScriptHookVDotNet2\" version=\"2.10.12\" targetFramework="
},
{
"path": "NativeUI.sln",
"chars": 1494,
"preview": "\nMicrosoft Visual Studio Solution File, Format Version 12.00\n# Visual Studio 14\nVisualStudioVersion = 14.0.22823.1\nMini"
},
{
"path": "README.md",
"chars": 1799,
"preview": "> # NativeUI is now deprecated!\n> ## Existing projects should migrate to LemonUI. Please check issue [#136](https://gith"
}
]
About this extraction
This page contains the full source code of the Guad/NativeUI GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 39 files (212.4 KB), approximately 50.5k tokens, and a symbol index with 261 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.