Skip to content

Commit

Permalink
Fix some typos and clarify variable names (shpaass#73)
Browse files Browse the repository at this point in the history
Besides typos, also fixed some/most camelCase variable names.
  • Loading branch information
shpaass authored Mar 8, 2024
2 parents be81ecb + 38d459d commit 6abde67
Show file tree
Hide file tree
Showing 39 changed files with 187 additions and 186 deletions.
24 changes: 12 additions & 12 deletions YAFC/Utils/WindowsClipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ private static unsafe void CopyToClipboard<T>(uint format, in T header, Span<byt
return;
}

int headersize = Unsafe.SizeOf<T>();
var ptr = Marshal.AllocHGlobal(headersize + data.Length);
int headerSize = Unsafe.SizeOf<T>();
var ptr = Marshal.AllocHGlobal(headerSize + data.Length);
_ = OpenClipboard(IntPtr.Zero);
try {
Marshal.StructureToPtr(header, ptr, false);
Span<byte> targetSpan = new Span<byte>((void*)(ptr + headersize), data.Length);
Span<byte> targetSpan = new Span<byte>((void*)(ptr + headerSize), data.Length);
data.CopyTo(targetSpan);
_ = EmptyClipboard();
_ = SetClipboardData(format, ptr);
Expand All @@ -41,23 +41,23 @@ private struct BitmapInfoHeader {
public short biBitCount;
public uint biCompression;
public uint biSizeImage;
public int biXPlesPerMeter;
public int biYPelsPerMeter;
public int biXPixelPerMeter;
public int biYPixelPerMeter;
public uint biClrUsed;
public uint biClrImportant;
}

public static unsafe void CopySurfaceToClipboard(MemoryDrawingSurface surface) {
ref var surfaceinfo = ref RenderingUtils.AsSdlSurface(surface.surface);
int width = surfaceinfo.w;
int height = surfaceinfo.h;
int pitch = surfaceinfo.pitch;
int size = pitch * surfaceinfo.h;
ref var surfaceInfo = ref RenderingUtils.AsSdlSurface(surface.surface);
int width = surfaceInfo.w;
int height = surfaceInfo.h;
int pitch = surfaceInfo.pitch;
int size = pitch * surfaceInfo.h;

// Windows expect images starting at bottom
Span<byte> flippedPixels = new Span<byte>(new byte[size]);
Span<byte> originalPixels = new Span<byte>((void*)surfaceinfo.pixels, size);
for (int i = 0; i < surfaceinfo.h; i++) {
Span<byte> originalPixels = new Span<byte>((void*)surfaceInfo.pixels, size);
for (int i = 0; i < surfaceInfo.h; i++) {
originalPixels.Slice(i * pitch, pitch).CopyTo(flippedPixels.Slice((height - i - 1) * pitch, pitch));
}

Expand Down
12 changes: 6 additions & 6 deletions YAFC/Widgets/ImmediateWidgets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static bool BuildFactorioObjectButtonWithText(this ImGui gui, FactorioObj
}

public static bool BuildInlineObjectList<T>(this ImGui gui, IEnumerable<T> list, IComparer<T> ordering, string header, out T selected, int maxCount = 10,
Predicate<T> checkmark = null, Func<T, string> extra = null) where T : FactorioObject {
Predicate<T> checkMark = null, Func<T, string> extra = null) where T : FactorioObject {
gui.BuildText(header, Font.subheader);
List<T> sortedList = new List<T>(list);
sortedList.Sort(ordering ?? DataUtils.DefaultOrdering);
Expand All @@ -129,17 +129,17 @@ public static bool BuildInlineObjectList<T>(this ImGui gui, IEnumerable<T> list,
selected = elem;
}

if (checkmark != null && gui.isBuilding && checkmark(elem)) {
if (checkMark != null && gui.isBuilding && checkMark(elem)) {
gui.DrawIcon(Rect.Square(new Vector2(gui.lastRect.Right - 1f, gui.lastRect.Center.Y), 1.5f), Icon.Check, SchemeColor.Green);
}
}

return selected != null;
}

public static void BuildInlineObjectListAndButton<T>(this ImGui gui, ICollection<T> list, IComparer<T> ordering, Action<T> select, string header, int count = 6, bool multiple = false, Predicate<T> checkmark = null, bool allowNone = false, Func<T, string> extra = null) where T : FactorioObject {
public static void BuildInlineObjectListAndButton<T>(this ImGui gui, ICollection<T> list, IComparer<T> ordering, Action<T> select, string header, int count = 6, bool multiple = false, Predicate<T> checkMark = null, bool allowNone = false, Func<T, string> extra = null) where T : FactorioObject {
using (gui.EnterGroup(default, RectAllocator.Stretch)) {
if (gui.BuildInlineObjectList(list, ordering, header, out var selected, count, checkmark, extra)) {
if (gui.BuildInlineObjectList(list, ordering, header, out var selected, count, checkMark, extra)) {
select(selected);
if (!multiple || !InputSystem.Instance.control) {
_ = gui.CloseDropdown();
Expand Down Expand Up @@ -202,8 +202,8 @@ public static void ShowPrecisionValueTooltip(ImGui gui, float amount, UnitOfMeas
/// <summary>Shows a dropdown containing the (partial) <paramref name="list"/> of elements, with an action for when an element is selected.</summary>
/// <param name="count">Maximum number of elements in the list. If there are more another popup can be opened by the user to show the full list.</param>
/// <param name="width">Width of the popup. Make sure the header text fits!</param>
public static void BuildObjectSelectDropDown<T>(this ImGui gui, ICollection<T> list, IComparer<T> ordering, Action<T> select, string header, float width = 20f, int count = 6, bool multiple = false, Predicate<T> checkmark = null, bool allowNone = false, Func<T, string> extra = null) where T : FactorioObject {
gui.ShowDropDown(imGui => imGui.BuildInlineObjectListAndButton(list, ordering, select, header, count, multiple, checkmark, allowNone, extra), width);
public static void BuildObjectSelectDropDown<T>(this ImGui gui, ICollection<T> list, IComparer<T> ordering, Action<T> select, string header, float width = 20f, int count = 6, bool multiple = false, Predicate<T> checkMark = null, bool allowNone = false, Func<T, string> extra = null) where T : FactorioObject {
gui.ShowDropDown(imGui => imGui.BuildInlineObjectListAndButton(list, ordering, select, header, count, multiple, checkMark, allowNone, extra), width);
}

public static GoodsWithAmountEvent BuildFactorioObjectWithEditableAmount(this ImGui gui, FactorioObject obj, float amount, UnitOfMeasure unit, out float newAmount, SchemeColor color = SchemeColor.None) {
Expand Down
10 changes: 5 additions & 5 deletions YAFC/Windows/ImageSharePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ImageSharePanel : PseudoScreen {
private string header;
private string name;
private static readonly string TempImageFile = Path.Combine(Path.GetTempPath(), "yafc_temp.png");
private FilesystemScreen fsscreen;
private FilesystemScreen fsScreen;
private bool copied;

public static void Show(MemoryDrawingSurface surface, string name) {
Expand Down Expand Up @@ -54,8 +54,8 @@ public override bool KeyDown(SDL.SDL_Keysym key) {
}

private async void SaveAsPng() {
fsscreen ??= new FilesystemScreen(header, "Save as PNG", "Save", null, FilesystemScreen.Mode.SelectOrCreateFile, name + ".png", MainScreen.Instance, null, "png");
string path = await fsscreen;
fsScreen ??= new FilesystemScreen(header, "Save as PNG", "Save", null, FilesystemScreen.Mode.SelectOrCreateFile, name + ".png", MainScreen.Instance, null, "png");
string path = await fsScreen;
if (path != null) {
surface?.SavePng(path);
}
Expand All @@ -68,8 +68,8 @@ protected override void Close(bool save = true) {
surface = null;
}

fsscreen?.Close();
fsscreen = null;
fsScreen?.Close();
fsScreen = null;
}
}
}
10 changes: 5 additions & 5 deletions YAFC/Windows/MainScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ private void BuildPage(ImGui gui) {
pageVisibleSize.Y -= usedHeaderSpace; // remaining size minus header
if (_activePageView != null) {
if (secondaryPageView != null) {
var vsize = pageVisibleSize;
vsize.Y /= 2f;
_activePageView.Build(gui, vsize);
secondaryPageView.Build(gui, vsize);
var visibleSize = pageVisibleSize;
visibleSize.Y /= 2f;
_activePageView.Build(gui, visibleSize);
secondaryPageView.Build(gui, visibleSize);
}
else {
_activePageView.Build(gui, pageVisibleSize);
Expand Down Expand Up @@ -492,7 +492,7 @@ private async void DoCheckForUpdates() {
var release = JsonSerializer.Deserialize<GithubReleaseInfo>(result);
string version = release.tag_name.StartsWith("v", StringComparison.Ordinal) ? release.tag_name[1..] : release.tag_name;
if (new Version(version) > YafcLib.version) {
var (_, answer) = await MessageBox.Show("New version availible!", "There is a new version availible: " + release.tag_name, "Visit release page", "Close");
var (_, answer) = await MessageBox.Show("New version available!", "There is a new version available: " + release.tag_name, "Visit release page", "Close");
if (answer) {
Ui.VisitLink(release.html_url);
}
Expand Down
14 changes: 7 additions & 7 deletions YAFC/Windows/NeverEnoughItemsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,22 @@ private void CheckChanging() {
}

private void DrawRecipeEntry(ImGui gui, RecipeEntry entry, bool production) {
var textcolor = SchemeColor.BackgroundText;
var textColor = SchemeColor.BackgroundText;
var bgColor = SchemeColor.Background;
bool isBuilding = gui.isBuilding;
var recipe = entry.recipe;
float waste = recipe.RecipeWaste(atCurrentMilestones);
if (isBuilding) {
if (entry.entryStatus == EntryStatus.NotAccessible) {
bgColor = SchemeColor.None;
textcolor = SchemeColor.BackgroundTextFaint;
textColor = SchemeColor.BackgroundTextFaint;
}
else if (entry.flow > 0f) {
bgColor = SchemeColor.Secondary;
textcolor = SchemeColor.SecondaryText;
textColor = SchemeColor.SecondaryText;
}
}
using (gui.EnterGroup(new Padding(0.5f), production ? RectAllocator.LeftRow : RectAllocator.RightRow, textcolor)) {
using (gui.EnterGroup(new Padding(0.5f), production ? RectAllocator.LeftRow : RectAllocator.RightRow, textColor)) {
using (gui.EnterFixedPositioning(4f, 0f, default)) {
gui.allocator = RectAllocator.Stretch;
_ = gui.BuildFactorioObjectButton(entry.recipe, 4f, MilestoneDisplay.Contained);
Expand All @@ -176,8 +176,8 @@ private void DrawRecipeEntry(ImGui gui, RecipeEntry entry, bool production) {
}
}
gui.AllocateSpacing();
var textalloc = production ? RectAllocator.LeftAlign : RectAllocator.RightAlign;
gui.allocator = textalloc;
var textAlloc = production ? RectAllocator.LeftAlign : RectAllocator.RightAlign;
gui.allocator = textAlloc;
using (gui.EnterRow(0f, production ? RectAllocator.RightRow : RectAllocator.LeftRow)) {
bool favourite = Project.current.preferences.favourites.Contains(entry.recipe);
var iconRect = gui.AllocateRect(1f, 1f).Expand(0.25f);
Expand All @@ -186,7 +186,7 @@ private void DrawRecipeEntry(ImGui gui, RecipeEntry entry, bool production) {
Project.current.preferences.ToggleFavourite(entry.recipe);
}

gui.allocator = textalloc;
gui.allocator = textAlloc;
gui.BuildText(recipe.locName, wrap: true);
}
if (recipe.ingredients.Length + recipe.products.Length <= 8) {
Expand Down
2 changes: 1 addition & 1 deletion YAFC/Windows/ProjectPageSettingsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public static void LoadProjectPageFromClipboard() {
}

_ = DataUtils.ReadLine(bytes, ref index); // reserved 1
if (DataUtils.ReadLine(bytes, ref index) != "") // reserved 2 but this time it is requried to be empty
if (DataUtils.ReadLine(bytes, ref index) != "") // reserved 2 but this time it is required to be empty
{
throw new NotSupportedException("Share string was created with future version of YAFC (" + version + ") and is incompatible");
}
Expand Down
4 changes: 2 additions & 2 deletions YAFC/Windows/ShoppingListScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ private void ExportBlueprintDropdown(ImGui gui) {
}
}

private Recipe FindSingleProduction(Recipe[] prodiuction) {
private Recipe FindSingleProduction(Recipe[] production) {
Recipe current = null;
foreach (var recipe in prodiuction) {
foreach (var recipe in production) {
if (recipe.IsAccessible()) {
if (current != null) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion YAFC/Windows/WelcomeScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class WelcomeScreen : WindowUtility, IProgress<(string, string)> {
{"no", "Norwegian"},
{"pl", "Polish"},
{"pt-PT", "Portuguese"},
{"pt-BR", "Portuguese (Brasilian)"},
{"pt-BR", "Portuguese (Brazilian)"},
{"ro", "Romanian"},
{"ru", "Russian"},
{"es-ES", "Spanish"},
Expand Down
4 changes: 2 additions & 2 deletions YAFC/Workspace/AutoPlannerView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private Action CreateAutoPlannerWizard(List<WizardPanel.PageBuilder> pages) {
string pageName = "Auto planner";

void Page1(ImGui gui, ref bool valid) {
gui.BuildText("This is an experemintal feature and may lack functionality. Unfortunately, after some prototyping it wasn't very useful to work with. More research required.", wrap: true, color: SchemeColor.Error);
gui.BuildText("This is an experimental feature and may lack functionality. Unfortunately, after some prototyping it wasn't very useful to work with. More research required.", wrap: true, color: SchemeColor.Error);
gui.BuildText("Enter page name:");
_ = gui.BuildTextInput(pageName, out pageName, null);
gui.AllocateSpacing(2f);
Expand All @@ -44,7 +44,7 @@ void Page1(ImGui gui, ref bool valid) {
}
}
grid.Next();
if (gui.BuildButton(Icon.Plus, SchemeColor.Primary, SchemeColor.PrimalyAlt, size: 2.5f)) {
if (gui.BuildButton(Icon.Plus, SchemeColor.Primary, SchemeColor.PrimaryAlt, size: 2.5f)) {
SelectObjectPanel.Select(Database.goods.all, "New production goal", x => {
goal.Add(new AutoPlannerGoal { amount = 1f, item = x });
gui.Rebuild();
Expand Down
22 changes: 11 additions & 11 deletions YAFC/Workspace/ProductionSummary/ProductionSummaryView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ public override void BuildHeader(ImGui gui) {

private void BuildButtons(ImGui gui, float size, ProductionSummaryGroup group) {
using (gui.EnterRow()) {
if (gui.BuildButton(Icon.Plus, SchemeColor.Primary, SchemeColor.PrimalyAlt, SchemeColor.PrimalyAlt, size)) {
if (gui.BuildButton(Icon.Plus, SchemeColor.Primary, SchemeColor.PrimaryAlt, SchemeColor.PrimaryAlt, size)) {
pagesDropdown.data = Project.current.pages.Where(x => x.content is ProductionTable).ToArray();
pagesDropdown.filter = productionTableSearchQuery = new SearchQuery();
selectedGroup = group;
gui.ShowDropDown(AddProductionTableDropdown);
}

if (gui.BuildButton(Icon.Folder, SchemeColor.Primary, SchemeColor.PrimalyAlt, SchemeColor.PrimalyAlt, size)) {
if (gui.BuildButton(Icon.Folder, SchemeColor.Primary, SchemeColor.PrimaryAlt, SchemeColor.PrimaryAlt, size)) {
ProductionSummaryEntry entry = new ProductionSummaryEntry(view.model.group);
entry.subgroup = new ProductionSummaryGroup(entry);
view.model.group.RecordUndo().elements.Add(entry);
Expand Down Expand Up @@ -112,12 +112,12 @@ public override void BuildElement(ImGui gui, ProductionSummaryEntry entry) {
MainScreen.Instance.ShowTooltip(gui, entry.page.page, false, gui.lastRect);
}
else if (buttonEvent == ButtonEvent.Click) {
gui.ShowDropDown(tgui => {
if (tgui.BuildButton("Go to page") && tgui.CloseDropdown()) {
gui.ShowDropDown(dropdownGui => {
if (dropdownGui.BuildButton("Go to page") && dropdownGui.CloseDropdown()) {
MainScreen.Instance.SetActivePage(entry.page.page);
}

if (tgui.BuildRedButton("Remove") && tgui.CloseDropdown()) {
if (dropdownGui.BuildRedButton("Remove") && dropdownGui.CloseDropdown()) {
_ = view.model.group.RecordUndo().elements.Remove(entry);
}
});
Expand All @@ -133,8 +133,8 @@ public override void BuildElement(ImGui gui, ProductionSummaryEntry entry) {
}
}

private bool PagesDropdownFilter(ProjectPage data, SearchQuery searchtokens) {
return searchtokens.Match(data.name);
private bool PagesDropdownFilter(ProjectPage data, SearchQuery searchTokens) {
return searchTokens.Match(data.name);
}

private void PagesDropdownDrawer(ImGui gui, ProjectPage element, int index) {
Expand Down Expand Up @@ -305,9 +305,9 @@ protected override void BuildContent(ImGui gui) {
gui.BuildText("List of goods produced/consumed by added blocks. Click on any of these to add it to (or remove it from) the table.");
}

using var igrid = gui.EnterInlineGrid(3f, 1f);
using var inlineGrid = gui.EnterInlineGrid(3f, 1f);
foreach (var (goods, amount) in model.sortedFlow) {
igrid.Next();
inlineGrid.Next();
if (gui.BuildFactorioObjectWithAmount(goods, amount, goods.flowUnitOfMeasure, model.columnsExist.Contains(goods) ? SchemeColor.Primary : SchemeColor.None)) {
AddOrRemoveColumn(goods);
}
Expand All @@ -318,9 +318,9 @@ protected override void BuildContent(ImGui gui) {
}
}

public override void Rebuild(bool visuaOnly = false) {
public override void Rebuild(bool visualOnly = false) {
flatHierarchy.SetData(model.group);
base.Rebuild(visuaOnly);
base.Rebuild(visualOnly);
}

public override void CreateModelDropdown(ImGui gui, Type type, Project project) {
Expand Down
Loading

0 comments on commit 6abde67

Please sign in to comment.