Skip to content

Commit

Permalink
chore: cleanup formatting (#2369)
Browse files Browse the repository at this point in the history
  • Loading branch information
lodicolo authored Aug 3, 2024
1 parent 1ddc2dd commit 1f1a3c0
Show file tree
Hide file tree
Showing 9 changed files with 332 additions and 165 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,13 @@ csharp_preserve_single_line_blocks = true
csharp_style_namespace_declarations = file_scoped:silent

# ReSharper properties
resharper_csharp_wrap_after_invocation_lpar = true
resharper_csharp_wrap_arguments_style = chop_if_long
resharper_csharp_wrap_before_invocation_rpar = true
resharper_keep_existing_invocation_parens_arrangement = false
resharper_max_invocation_arguments_on_line = 3
resharper_place_expr_property_on_single_line = true
resharper_place_simple_initializer_on_single_line = false
resharper_trailing_comma_in_multiline_lists = true
resharper_wrap_array_initializer_style = chop_if_long
###############################
Expand Down
184 changes: 133 additions & 51 deletions Intersect.Client/Interface/Game/Admin/AdminWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,43 @@ public partial class AdminWindow : WindowControl
private readonly CheckBox _checkboxChronological;
private TreeControl? _mapList;

public AdminWindow(Base gameCanvas) : base(gameCanvas, Strings.Admin.Title, false, nameof(AdminWindow))
public AdminWindow(Base gameCanvas) : base(
gameCanvas,
Strings.Admin.Title,
false,
nameof(AdminWindow)
)
{
DisableResizing();
Margin = Margin.Zero;
Padding = Padding.Zero;

// Name label and textbox
_ = new Label(this, "LabelName") { Text = Strings.Admin.Name };
_ = new Label(this, "LabelName")
{
Text = Strings.Admin.Name,
};
_textboxName = new TextBox(this, "TextboxName");
Interface.FocusElements.Add(_textboxName);

// Access label, dropdown and set power button
_ = new Label(this, "LabelAccess") { Text = Strings.Admin.Access };
_ = new Label(this, "LabelAccess")
{
Text = Strings.Admin.Access,
};
_dropdownAccess = new ComboBox(this, "DropdownAccess");
_ = _dropdownAccess.AddItem(label: Strings.Admin.Access0, userData: "None");
_ = _dropdownAccess.AddItem(label: Strings.Admin.Access1, userData: "Moderator");
_ = _dropdownAccess.AddItem(label: Strings.Admin.Access2, userData: "Admin");
var buttonSetPower = new Button(this, "ButtonSetPower") { Text = Strings.Admin.SetPower };
_ = _dropdownAccess.AddItem(Strings.Admin.Access0, userData: "None");
_ = _dropdownAccess.AddItem(Strings.Admin.Access1, userData: "Moderator");
_ = _dropdownAccess.AddItem(Strings.Admin.Access2, userData: "Admin");
var buttonSetPower = new Button(this, "ButtonSetPower")
{
Text = Strings.Admin.SetPower,
};
buttonSetPower.Clicked += (s, e) =>
{
if (_textboxName.Text.Trim().Length > 0)
{
string? power = _dropdownAccess.SelectedItem.UserData.ToString();
var power = _dropdownAccess.SelectedItem.UserData.ToString();
if (!string.IsNullOrEmpty(power) && power.Trim().Length > 0)
{
PacketSender.SendAdminAction(new SetAccessAction(_textboxName.Text, power));
Expand All @@ -56,8 +70,12 @@ public AdminWindow(Base gameCanvas) : base(gameCanvas, Strings.Admin.Title, fals
};

#region Quick Admin Actions

// Warp to me admin action
var buttonWarpToMe = new Button(this, "ButtonWarpToMe") { Text = Strings.Admin.Warp2Me };
var buttonWarpToMe = new Button(this, "ButtonWarpToMe")
{
Text = Strings.Admin.Warp2Me,
};
buttonWarpToMe.Clicked += (s, e) =>
{
if (_textboxName.Text.Trim().Length > 0)
Expand All @@ -67,7 +85,10 @@ public AdminWindow(Base gameCanvas) : base(gameCanvas, Strings.Admin.Title, fals
};

// Warp to player admin action
var buttonWarpMeTo = new Button(this, "ButtonWarpMeTo") { Text = Strings.Admin.WarpMe2 };
var buttonWarpMeTo = new Button(this, "ButtonWarpMeTo")
{
Text = Strings.Admin.WarpMe2,
};
buttonWarpMeTo.Clicked += (s, e) =>
{
if (_textboxName.Text.Trim().Length > 0)
Expand All @@ -77,7 +98,10 @@ public AdminWindow(Base gameCanvas) : base(gameCanvas, Strings.Admin.Title, fals
};

// Warp to overworld admin action
var buttonOverworldReturn = new Button(this, "ButtonOverworldReturn") { Text = Strings.Admin.OverworldReturn };
var buttonOverworldReturn = new Button(this, "ButtonOverworldReturn")
{
Text = Strings.Admin.OverworldReturn,
};
buttonOverworldReturn.Clicked += (s, e) =>
{
if (!string.IsNullOrEmpty(_textboxName.Text))
Expand All @@ -87,7 +111,10 @@ public AdminWindow(Base gameCanvas) : base(gameCanvas, Strings.Admin.Title, fals
};

// Kick player admin action
var buttonKick = new Button(this, "ButtonKick") { Text = Strings.Admin.Kick };
var buttonKick = new Button(this, "ButtonKick")
{
Text = Strings.Admin.Kick,
};
buttonKick.Clicked += (s, e) =>
{
if (_textboxName.Text.Trim().Length > 0)
Expand All @@ -97,7 +124,10 @@ public AdminWindow(Base gameCanvas) : base(gameCanvas, Strings.Admin.Title, fals
};

// Kill player admin action
var buttonKill = new Button(this, "ButtonKill") { Text = Strings.Admin.Kill };
var buttonKill = new Button(this, "ButtonKill")
{
Text = Strings.Admin.Kill,
};
buttonKill.Clicked += (s, e) =>
{
if (_textboxName.Text.Trim().Length > 0)
Expand All @@ -107,45 +137,62 @@ public AdminWindow(Base gameCanvas) : base(gameCanvas, Strings.Admin.Title, fals
};

// Ban and Unban player admin actions
var buttonBan = new Button(this, "ButtonBan") { Text = Strings.Admin.Ban };
var buttonBan = new Button(this, "ButtonBan")
{
Text = Strings.Admin.Ban,
};
buttonBan.Clicked += banButton_Clicked;

var buttonUnban = new Button(this, "ButtonUnban") { Text = Strings.Admin.Unban };
var buttonUnban = new Button(this, "ButtonUnban")
{
Text = Strings.Admin.Unban,
};
buttonUnban.Clicked += (s, e) =>
{
if (_textboxName.Text.Trim().Length > 0)
{
_ = new InputBox(
title: Strings.Admin.UnbanCaption.ToString(_textboxName.Text),
prompt: Strings.Admin.UnbanPrompt.ToString(_textboxName.Text),
inputType: InputBox.InputType.YesNo,
onSuccess: (s, e) => PacketSender.SendAdminAction(new UnbanAction(_textboxName.Text))
Strings.Admin.UnbanCaption.ToString(_textboxName.Text),
Strings.Admin.UnbanPrompt.ToString(_textboxName.Text),
InputBox.InputType.YesNo,
(s, e) => PacketSender.SendAdminAction(new UnbanAction(_textboxName.Text))
);
}
};

// Mute and Unmute player admin actions
var buttonMute = new Button(this, "ButtonMute") { Text = Strings.Admin.Mute };
var buttonMute = new Button(this, "ButtonMute")
{
Text = Strings.Admin.Mute,
};
buttonMute.Clicked += muteButton_Clicked;

var buttonUnmute = new Button(this, "ButtonUnmute") { Text = Strings.Admin.Unmute };
var buttonUnmute = new Button(this, "ButtonUnmute")
{
Text = Strings.Admin.Unmute,
};
buttonUnmute.Clicked += (s, e) =>
{
if (_textboxName.Text.Trim().Length > 0)
{
_ = new InputBox(
title: Strings.Admin.UnmuteCaption.ToString(_textboxName.Text),
prompt: Strings.Admin.UnmutePrompt.ToString(_textboxName.Text),
inputType: InputBox.InputType.YesNo,
onSuccess: (s, e) => PacketSender.SendAdminAction(new UnmuteAction(_textboxName.Text))
Strings.Admin.UnmuteCaption.ToString(_textboxName.Text),
Strings.Admin.UnmutePrompt.ToString(_textboxName.Text),
InputBox.InputType.YesNo,
(s, e) => PacketSender.SendAdminAction(new UnmuteAction(_textboxName.Text))
);
}
};

#endregion Quick Admin Actions

#region Change Player Sprite and Face

// Change player sprite admin action
_ = new Label(this, "LabelSprite") { Text = Strings.Admin.Sprite };
_ = new Label(this, "LabelSprite")
{
Text = Strings.Admin.Sprite,
};
_dropdownSprite = new ComboBox(this, "DropdownSprite");
_ = _dropdownSprite.AddItem(Strings.Admin.None);
_dropdownSprite.ItemSelected += _dropdownSprite_ItemSelected;
Expand All @@ -157,7 +204,10 @@ public AdminWindow(Base gameCanvas) : base(gameCanvas, Strings.Admin.Title, fals
_ = _dropdownSprite.AddItem(sprite);
}

var buttonSetSprite = new Button(this, "ButtonSetSprite") { Text = Strings.Admin.SetSprite };
var buttonSetSprite = new Button(this, "ButtonSetSprite")
{
Text = Strings.Admin.SetSprite,
};
buttonSetSprite.Clicked += (s, e) =>
{
if (_textboxName.Text.Trim().Length > 0)
Expand All @@ -170,7 +220,10 @@ public AdminWindow(Base gameCanvas) : base(gameCanvas, Strings.Admin.Title, fals
_spritePanel = new ImagePanel(panelSprite);

// Change player face admin action
_ = new Label(this, "LabelFace") { Text = Strings.Admin.Face };
_ = new Label(this, "LabelFace")
{
Text = Strings.Admin.Face,
};
_dropdownFace = new ComboBox(this, "DropdownFace");
_ = _dropdownFace.AddItem(Strings.Admin.None);
_dropdownFace.ItemSelected += _dropdownFace_ItemSelected;
Expand All @@ -182,7 +235,10 @@ public AdminWindow(Base gameCanvas) : base(gameCanvas, Strings.Admin.Title, fals
_ = _dropdownFace.AddItem(face);
}

var buttonSetFace = new Button(this, "ButtonSetFace") { Text = Strings.Admin.SetFace };
var buttonSetFace = new Button(this, "ButtonSetFace")
{
Text = Strings.Admin.SetFace,
};
buttonSetFace.Clicked += (s, e) =>
{
if (_textboxName.Text.Trim().Length > 0)
Expand All @@ -197,17 +253,26 @@ public AdminWindow(Base gameCanvas) : base(gameCanvas, Strings.Admin.Title, fals
#endregion Change Player Sprite and Face

// Map list
_ = new Label(this, "LabelMapList") { Text = Strings.Admin.MapList };
_ = new Label(this, "LabelMapList")
{
Text = Strings.Admin.MapList,
};
_checkboxChronological = new CheckBox(this, "CheckboxChronological");
_checkboxChronological.SetToolTipText(Strings.Admin.ChronologicalTip);
_checkboxChronological.CheckChanged += (s, e) => UpdateMapList();
_ = new Label(this, "LabelChronological") { Text = Strings.Admin.Chronological };
_ = new Label(this, "LabelChronological")
{
Text = Strings.Admin.Chronological,
};

LoadJsonUi(UI.InGame, Graphics.Renderer?.GetResolutionString(), true);
UpdateMapList();
}

public void SetName(string name) => _textboxName.Text = name;
public void SetName(string name)
{
_textboxName.Text = name;
}

private void UpdateMapList()
{
Expand All @@ -218,8 +283,13 @@ private void UpdateMapList()
Y = 330,
Width = Width - 8,
Height = 80,
RenderColor = Color.FromArgb(255, 255, 255, 255),
MaximumSize = new Point(4096, 999999)
RenderColor = Color.FromArgb(
255,
255,
255,
255
),
MaximumSize = new Point(4096, 999999),
};

AddMapListToTree(MapList.List, null);
Expand Down Expand Up @@ -266,6 +336,7 @@ private void AddMapListToTree(MapList mapList, TreeNode? parent)
}

#region Action Handlers

private void banButton_Clicked(Base sender, ClickedEventArgs arguments)
{
if (string.IsNullOrWhiteSpace(_textboxName.Text))
Expand All @@ -280,16 +351,16 @@ private void banButton_Clicked(Base sender, ClickedEventArgs arguments)
}

_banOrMuteWindow = new BanMuteBox(
title: Strings.Admin.BanCaption.ToString(name),
prompt: Strings.Admin.BanPrompt.ToString(_textboxName.Text),
okayHandler: (s, e) =>
Strings.Admin.BanCaption.ToString(name),
Strings.Admin.BanPrompt.ToString(_textboxName.Text),
(s, e) =>
{
PacketSender.SendAdminAction(
new BanAction(
name: _textboxName.Text,
durationDays: _banOrMuteWindow?.GetDuration() ?? 0,
reason: _banOrMuteWindow?.GetReason() ?? string.Empty,
banIp: _banOrMuteWindow?.BanIp() ?? false
_textboxName.Text,
_banOrMuteWindow?.GetDuration() ?? 0,
_banOrMuteWindow?.GetReason() ?? string.Empty,
_banOrMuteWindow?.BanIp() ?? false
)
);

Expand All @@ -312,16 +383,16 @@ private void muteButton_Clicked(Base sender, ClickedEventArgs arguments)
}

_banOrMuteWindow = new BanMuteBox(
title: Strings.Admin.MuteCaption.ToString(name),
prompt: Strings.Admin.MutePrompt.ToString(_textboxName.Text),
okayHandler: (s, e) =>
Strings.Admin.MuteCaption.ToString(name),
Strings.Admin.MutePrompt.ToString(_textboxName.Text),
(s, e) =>
{
PacketSender.SendAdminAction(
new MuteAction(
name: _textboxName.Text,
durationDays: _banOrMuteWindow?.GetDuration() ?? 0,
reason: _banOrMuteWindow?.GetReason() ?? string.Empty,
banIp: _banOrMuteWindow?.BanIp() ?? false
_textboxName.Text,
_banOrMuteWindow?.GetDuration() ?? 0,
_banOrMuteWindow?.GetReason() ?? string.Empty,
_banOrMuteWindow?.BanIp() ?? false
)
);

Expand All @@ -341,7 +412,12 @@ private void _dropdownSprite_ItemSelected(Base sender, ItemSelectedEventArgs arg

var textFrameWidth = _spritePanel.Texture.Width / Options.Instance.Sprites.NormalFrames;
var textFrameHeight = _spritePanel.Texture.Height / Options.Instance.Sprites.Directions;
_spritePanel.SetTextureRect(0, 0, textFrameWidth, textFrameHeight);
_spritePanel.SetTextureRect(
0,
0,
textFrameWidth,
textFrameHeight
);
_ = _spritePanel.SetSize(Math.Min(textFrameWidth, 46), Math.Min(textFrameHeight, 46));
Align.Center(_spritePanel);
}
Expand All @@ -357,7 +433,12 @@ private void _dropdownFace_ItemSelected(Base sender, ItemSelectedEventArgs argum

var textFrameWidth = _facePanel.Texture.Width;
var textFrameHeight = _facePanel.Texture.Height;
_facePanel.SetTextureRect(0, 0, textFrameWidth, textFrameHeight);
_facePanel.SetTextureRect(
0,
0,
textFrameWidth,
textFrameHeight
);
_ = _facePanel.SetSize(Math.Min(textFrameWidth, 46), Math.Min(textFrameHeight, 46));
Align.Center(_facePanel);
}
Expand All @@ -369,5 +450,6 @@ private void tmpNode_Clicked(Base sender, ClickedEventArgs arguments)
PacketSender.SendAdminAction(new WarpToMapAction(mapId));
}
}

#endregion
}
}
Loading

0 comments on commit 1f1a3c0

Please sign in to comment.