This commit is contained in:
Bitl 2021-10-21 12:16:55 -07:00
parent 6f207c2a3c
commit ae8bf46a44
3 changed files with 55 additions and 11 deletions

View File

@ -42,7 +42,7 @@ class CharacterCustomizationShared
#endregion
#region Form Event Functions
public void InitForm()
public async void InitForm()
{
if (GlobalFuncs.HasColorsChanged())
{
@ -112,7 +112,10 @@ class CharacterCustomizationShared
}
int imgsize = (FormStyle == Settings.Style.Extended) ? 28 : 18;
PartColorLoader.AddPartColorsToListView(GlobalVars.PartColorList, ColorView, imgsize);
string oldTitle = Parent.Text;
Parent.Text = "Please Wait...";
await PartColorLoader.AddPartColorsToListView(GlobalVars.PartColorList, ColorView, imgsize);
Parent.Text = oldTitle;
//body
SelectedPartLabel.Text = SelectedPart;

View File

@ -75,7 +75,12 @@ public class PartColorLoader
}
}
//make faster
#if !BASICLAUNCHER
public static async Task AddPartColorsToListView(PartColor[] PartColorList, ListView ColorView, int imgsize, bool showIDs = false)
#else
public static void AddPartColorsToListView(PartColor[] PartColorList, ListView ColorView, int imgsize, bool showIDs = false)
#endif
{
try
{
@ -105,15 +110,14 @@ public class PartColorLoader
lvi.Group = group;
Bitmap Bmp = new Bitmap(imgsize, imgsize, PixelFormat.Format32bppArgb);
using (Graphics gfx = Graphics.FromImage(Bmp))
using (SolidBrush brush = new SolidBrush(item.ColorObject))
#if !BASICLAUNCHER
Bitmap Bmp = await GeneratePartColorIconAsync(item, imgsize);
if (Bmp != null)
{
gfx.FillRectangle(brush, 0, 0, imgsize, imgsize);
ColorImageList.Images.Add(item.ColorName, Bmp);
lvi.ImageIndex = ColorImageList.Images.IndexOfKey(item.ColorName);
}
ColorImageList.Images.Add(item.ColorName, Bmp);
lvi.ImageIndex = ColorImageList.Images.IndexOfKey(item.ColorName);
#endif
ColorView.Items.Add(lvi);
}
@ -133,6 +137,40 @@ public class PartColorLoader
}
}
#if !BASICLAUNCHER
public static async Task<Bitmap> GeneratePartColorIconAsync(PartColor color, int imgsize)
{
Task<Bitmap> task = Task<Bitmap>.Factory.StartNew(() => GeneratePartColorIcon(color, imgsize));
await task;
return task.Result;
}
#endif
public static Bitmap GeneratePartColorIcon(PartColor color, int imgsize)
{
try
{
Bitmap Bmp = new Bitmap(imgsize, imgsize, PixelFormat.Format32bppArgb);
using (Graphics gfx = Graphics.FromImage(Bmp))
using (SolidBrush brush = new SolidBrush(color.ColorObject))
{
gfx.FillRectangle(brush, 0, 0, imgsize, imgsize);
}
return Bmp;
}
#if URI || LAUNCHER || CMD
catch (Exception ex)
{
GlobalFuncs.LogExceptions(ex);
#else
catch (Exception)
{
#endif
return null;
}
}
public static PartColor FindPartColorByName(PartColor[] colors, string query)
{
if (File.Exists(GlobalPaths.ConfigDir + "\\" + GlobalPaths.PartColorXMLName))

View File

@ -45,7 +45,7 @@ public partial class ItemCreationSDKColorMenu : Form
Close();
}
private void ItemCreationSDKColorMenu_Load(object sender, EventArgs e)
private async void ItemCreationSDKColorMenu_Load(object sender, EventArgs e)
{
if (GlobalFuncs.HasColorsChanged())
{
@ -60,7 +60,10 @@ public partial class ItemCreationSDKColorMenu : Form
return;
}
PartColorLoader.AddPartColorsToListView(GlobalVars.PartColorList, colorMenu, 32, true);
string oldTitle = Text;
Text = "Please Wait...";
await PartColorLoader.AddPartColorsToListView(GlobalVars.PartColorList, colorMenu, 32, true);
Text = oldTitle;
CenterToScreen();
}
#endregion