Skip to content

Commit

Permalink
Ability to clear Hue from statics
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczy93 committed Nov 8, 2023
1 parent 1bf6745 commit 591f824
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
13 changes: 8 additions & 5 deletions CentrED/HuesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class HuesManager {

private unsafe HuesManager(GraphicsDevice gd) {
var huesLoader = HuesLoader.Instance;
HuesCount = huesLoader.HuesCount;
Texture = new Texture2D(gd, TEXTURE_WIDTH, HuesCount);
HuesCount = huesLoader.HuesCount + 1;
Texture = new Texture2D(gd, TEXTURE_WIDTH, HuesCount - 1);
uint[] buffer = System.Buffers.ArrayPool<uint>.Shared.Rent(TEXTURE_WIDTH * HuesCount);

fixed (uint* ptr = buffer) {
Expand All @@ -27,9 +27,12 @@ private unsafe HuesManager(GraphicsDevice gd) {
}

System.Buffers.ArrayPool<uint>.Shared.Return(buffer);
var i = 0;
Colors = new ushort[HuesCount][];
Names = new string[HuesCount];

Colors = new ushort[HuesCount + 1][];
Names = new string[HuesCount + 1];
Colors[0] = huesLoader.HuesRange[0].Entries[0].ColorTable;
Names[0] = "No Hue";
var i = 1;
foreach (var huesGroup in huesLoader.HuesRange) {
foreach (var hueEntry in huesGroup.Entries) {
Colors[i] = hueEntry.ColorTable;
Expand Down
4 changes: 2 additions & 2 deletions CentrED/Tools/HueTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override void OnActivated(MapObject? o) {

public override void OnMouseEnter(MapObject? o) {
if (o is StaticObject so) {
so.Hue = (ushort)(_uiManager._huesWindow.SelectedId + 1);
so.Hue = (ushort)_uiManager._huesWindow.SelectedId;
}
}

Expand All @@ -37,7 +37,7 @@ public override void OnMousePressed(MapObject? o) {
public override void OnMouseReleased(MapObject? o) {
if (_pressed && o is StaticObject so && so == _focusObject) {
if(_uiManager._huesWindow.SelectedId != -1)
so.StaticTile.Hue = (ushort)(_uiManager._huesWindow.SelectedId + 1);
so.StaticTile.Hue = (ushort)_uiManager._huesWindow.SelectedId;
}
_pressed = false;
}
Expand Down
20 changes: 14 additions & 6 deletions CentrED/UI/Windows/HuesWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,32 @@ private void HuesDrawElement(int index) {

var selectableSize = new Vector2(_tableWidth, _huesRowHeight);
if (ImGui.Selectable($"##hue{index}", SelectedId == index,
ImGuiSelectableFlags.SpanAllColumns, selectableSize))
ImGuiSelectableFlags.SpanAllColumns, selectableSize)) {
SelectedId = index;
}

ImGui.SetCursorPos(startPos with { Y = startPos.Y + (_huesRowHeight - ImGui.GetFontSize()) / 2 });
ImGui.Text($"0x{index:X4}");

}

if (ImGui.TableNextColumn()) {
if (index == 0)
ImGui.TextColored(UIManager.Red , name);
else {
_uiManager.DrawImage(HuesManager.Instance.Texture, new Rectangle(0, index - 1, 32, 1),
new Vector2(ImGui.GetContentRegionAvail().X, _huesRowHeight));
}

if (ImGui.BeginItemTooltip()) {
ImGui.Text(name);
ImGui.EndTooltip();
}
}

if (ImGui.TableNextColumn()) {
_uiManager.DrawImage(HuesManager.Instance.Texture, new Rectangle(0,index, 32, 1), new Vector2(ImGui.GetContentRegionAvail().X, _huesRowHeight));
}
}

public void UpdateSelectedHue(ushort staticTileHue) {
SelectedId = staticTileHue - 1;
SelectedId = staticTileHue;
_updateScroll = true;
}
}

0 comments on commit 591f824

Please sign in to comment.