Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 111 additions & 2 deletions scenes/main_menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
[ext_resource type="Shader" uid="uid://rngh60dyh10b" path="res://scripts/shaders/outline.gdshader" id="30_q13xq"]
[ext_resource type="Texture2D" uid="uid://bfy3x7rqnts4i" path="res://user/skins/default/ui/buttons/filter.png" id="31_5053t"]
[ext_resource type="Texture2D" uid="uid://bl6ten82nkjmd" path="res://user/skins/default/ui/buttons/sort.png" id="32_2wgix"]
[ext_resource type="Script" uid="uid://b6mbjcjxklb81" path="res://scripts/ui/menu/play/SortMenuButton.cs" id="33_71lbq"]
[ext_resource type="Texture2D" uid="uid://c6k1k4817che2" path="res://user/skins/default/ui/buttons/author.png" id="33_b56yx"]
[ext_resource type="Script" uid="uid://b47jydbbjdh3i" path="res://scripts/ui/menu/SoundSpaceButton.cs" id="33_yxnar"]
[ext_resource type="Script" uid="uid://dtnrcumiy038m" path="res://scripts/ui/menu/play/SearchPanel.cs" id="34_71lbq"]
Expand Down Expand Up @@ -200,6 +201,15 @@ shader = SubResource("Shader_1a85y")

[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_18lcc"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_hjv1c"]
bg_color = Color(0, 0, 0, 0.8784314)
corner_radius_top_left = 4
corner_radius_top_right = 4
corner_radius_bottom_right = 4
corner_radius_bottom_left = 4

[sub_resource type="Theme" id="Theme_akqfu"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_68b7m"]
bg_color = Color(0, 0, 0, 1)
corner_radius_top_left = 4
Expand Down Expand Up @@ -807,15 +817,114 @@ theme_override_colors/font_color = Color(1, 1, 1, 1)
disabled = true
icon = ExtResource("31_5053t")

[node name="Sort" type="Button" parent="Menus/Play/SubTopBar/HBoxContainer" unique_id=1032136468]
[node name="Sort" type="Button" parent="Menus/Play/SubTopBar/HBoxContainer" unique_id=1032136468 node_paths=PackedStringArray("panel", "order", "orderLabel", "buttons")]
custom_minimum_size = Vector2(0, 36)
layout_mode = 2
focus_mode = 0
mouse_default_cursor_shape = 2
theme = ExtResource("6_engjn")
theme_override_colors/font_color = Color(1, 1, 1, 1)
disabled = true
toggle_mode = true
icon = ExtResource("32_2wgix")
script = ExtResource("33_71lbq")
panel = NodePath("Panel")
order = NodePath("Panel/MarginContainer/VBoxContainer/HBoxContainer/Sort")
orderLabel = NodePath("Panel/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/SortOrder")
buttons = NodePath("Panel/MarginContainer/VBoxContainer/SortTypeButtons")

[node name="Panel" type="PanelContainer" parent="Menus/Play/SubTopBar/HBoxContainer/Sort" unique_id=1319633459]
visible = false
z_index = 1
custom_minimum_size = Vector2(140, 0)
layout_mode = 1
anchors_preset = -1
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_top = 4.0
grow_horizontal = 2
theme = ExtResource("6_engjn")

[node name="Background" type="Panel" parent="Menus/Play/SubTopBar/HBoxContainer/Sort/Panel" unique_id=1479500309]
layout_mode = 2
mouse_filter = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_hjv1c")

[node name="MarginContainer" type="MarginContainer" parent="Menus/Play/SubTopBar/HBoxContainer/Sort/Panel" unique_id=1414498950]
layout_mode = 2
theme = ExtResource("6_engjn")
theme_override_constants/margin_left = 6
theme_override_constants/margin_top = 6
theme_override_constants/margin_right = 6
theme_override_constants/margin_bottom = 6

[node name="VBoxContainer" type="VBoxContainer" parent="Menus/Play/SubTopBar/HBoxContainer/Sort/Panel/MarginContainer" unique_id=2071863039]
layout_mode = 2
theme_override_constants/separation = 3

[node name="HBoxContainer" type="HBoxContainer" parent="Menus/Play/SubTopBar/HBoxContainer/Sort/Panel/MarginContainer/VBoxContainer" unique_id=991582469]
layout_mode = 2

[node name="Sort" type="Button" parent="Menus/Play/SubTopBar/HBoxContainer/Sort/Panel/MarginContainer/VBoxContainer/HBoxContainer" unique_id=1504277605]
layout_mode = 2
focus_mode = 0
mouse_default_cursor_shape = 2
theme = ExtResource("6_engjn")
theme_override_colors/font_color = Color(1, 1, 1, 1)
theme_override_constants/icon_max_width = 24
icon = ExtResource("32_2wgix")
icon_alignment = 1

[node name="VBoxContainer" type="VBoxContainer" parent="Menus/Play/SubTopBar/HBoxContainer/Sort/Panel/MarginContainer/VBoxContainer/HBoxContainer" unique_id=578559987]
layout_mode = 2
size_flags_horizontal = 6
size_flags_vertical = 4
theme = ExtResource("6_engjn")
theme_override_constants/separation = 2

[node name="SortOrder" type="Label" parent="Menus/Play/SubTopBar/HBoxContainer/Sort/Panel/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer" unique_id=643031713]
layout_mode = 2
size_flags_horizontal = 0
text = "Ascending"

[node name="SortTypeButtons" type="VBoxContainer" parent="Menus/Play/SubTopBar/HBoxContainer/Sort/Panel/MarginContainer/VBoxContainer" unique_id=712676656]
layout_mode = 2
theme = SubResource("Theme_akqfu")
theme_override_constants/separation = 4

[node name="Alphabetical" type="Button" parent="Menus/Play/SubTopBar/HBoxContainer/Sort/Panel/MarginContainer/VBoxContainer/SortTypeButtons" unique_id=1928126648]
layout_mode = 2
focus_mode = 0
mouse_default_cursor_shape = 2
theme = ExtResource("6_engjn")
theme_override_colors/font_color = Color(1, 1, 1, 1)
theme_override_constants/icon_max_width = 24
disabled = true
text = "Alphabetical
"
icon_alignment = 1

[node name="Difficulty" type="Button" parent="Menus/Play/SubTopBar/HBoxContainer/Sort/Panel/MarginContainer/VBoxContainer/SortTypeButtons" unique_id=2003836240]
layout_mode = 2
focus_mode = 0
mouse_default_cursor_shape = 2
theme = ExtResource("6_engjn")
theme_override_colors/font_color = Color(1, 1, 1, 1)
theme_override_constants/icon_max_width = 24
text = "Difficulty
"
icon_alignment = 1

[node name="Mappers" type="Button" parent="Menus/Play/SubTopBar/HBoxContainer/Sort/Panel/MarginContainer/VBoxContainer/SortTypeButtons" unique_id=234550645]
layout_mode = 2
focus_mode = 0
mouse_default_cursor_shape = 2
theme = ExtResource("6_engjn")
theme_override_colors/font_color = Color(1, 1, 1, 1)
theme_override_constants/icon_max_width = 24
text = "Mappers"
icon_alignment = 1

[node name="SearchAuthor" type="Panel" parent="Menus/Play/SubTopBar/HBoxContainer" unique_id=1189820153]
custom_minimum_size = Vector2(150, 36)
Expand Down
1 change: 1 addition & 0 deletions scripts/skinning/SkinManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public static void Load()
skin.RandomButtonImage = loadTexture("ui/buttons/random.png");
skin.FilterButtonImage = loadTexture("ui/buttons/filter.png");
skin.SortButtonImage = loadTexture("ui/buttons/sort.png");
skin.SortAscendButtonImage = loadTexture("ui/buttons/sort_ascend.png");
skin.AuthorButtonImage = loadTexture("ui/buttons/author.png");
skin.SearchButtonImage = loadTexture("ui/buttons/search.png");
skin.LayoutListButtonImage = loadTexture("ui/buttons/layout_list.png");
Expand Down
2 changes: 2 additions & 0 deletions scripts/skinning/SkinProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public partial class SkinProfile : GodotObject

public ImageTexture SortButtonImage { get; set; } = new();

public ImageTexture SortAscendButtonImage { get; set; } = new();

public ImageTexture AuthorButtonImage { get; set; } = new();

public ImageTexture SearchButtonImage { get; set; } = new();
Expand Down
48 changes: 46 additions & 2 deletions scripts/ui/menu/play/MapList.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Godot;
Expand All @@ -12,6 +10,13 @@ public partial class MapList : Panel, ISkinnable

public enum ListLayout { List, Grid }

public enum SortType
{
Alphabetical,
Difficulty,
Mappers
}

[ExportGroup("Layout")]

[Export]
Expand Down Expand Up @@ -60,6 +65,8 @@ public enum ListLayout { List, Grid }
public bool DisplaySelectionCursor = false;
public string SearchQuery = "";
public string AuthorQuery = "";
public Bindable<bool> Ascending = new(true);
public Bindable<SortType> Sorting = new(SortType.Alphabetical);

/// <summary>
/// Queried and ordered maps to display in the list
Expand Down Expand Up @@ -111,6 +118,9 @@ public override void _Ready()
scrollBarBackgroundMiddle = scrollBarBackground.GetNode<TextureRect>("Middle");
scrollBarBackgroundBottom = scrollBarBackground.GetNode<TextureRect>("Bottom");

Sorting.ValueChanged += (_, _) => Sort();
Ascending.ValueChanged += (_, _) => Sort();

MouseExited += () => { toggleSelectionCursor(false); };
Resized += clear;
SkinManager.Instance.Loaded += UpdateSkin;
Expand Down Expand Up @@ -407,6 +417,40 @@ public void Focus(Map map)
}
}

public void Sort()
{
List<Map> orderedMaps;

switch (Sorting.Value)
{
case SortType.Difficulty:
orderedMaps = Maps.OrderBy(map => map.Difficulty).ToList();
break;

case SortType.Mappers:
orderedMaps = Maps.OrderBy(map =>
{
string[] mappers = map.Mappers?.Length == 0 ? map.PrettyMappers.Split(", ") : map.Mappers;
return mappers.Order().First();
}).ToList();
break;

default:
orderedMaps = Maps.OrderBy(map => map.PrettyTitle).ToList();
break;
}

if (!Ascending.Value)
{
orderedMaps.Reverse();
}

Maps = orderedMaps.Where(map => map.Favorite).ToList();
Maps.AddRange(orderedMaps.Where(map => !map.Favorite));

clear();
}

public void Search(string query = "", string author = "")
{
SearchQuery = query ?? SearchQuery;
Expand Down
83 changes: 83 additions & 0 deletions scripts/ui/menu/play/SortMenuButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using Godot;

public partial class SortMenuButton : Button, ISkinnable
{
[Export]
private Control panel;

[Export]
private Button order;

[Export]
private Label orderLabel;

[Export]
private VBoxContainer buttons;

private Button previousButton;

public override void _Ready()
{
Toggled += toggle;
order.Pressed += toggleOrder;
SkinManager.Instance.Loaded += UpdateSkin;

previousButton = buttons.GetNode<Button>("Alphabetical");

foreach (Button button in buttons.GetChildren())
{
button.Pressed += () => selectSort(button);
}

UpdateSkin(SkinManager.Instance.Skin);
}

public override void _Input(InputEvent @event)
{
if (@event is InputEventMouseButton mouseButton && mouseButton.Pressed)
{
Rect2 rect = new(panel.GlobalPosition, panel.Size);
Rect2 rect2 = new(GlobalPosition, Size);

if (!rect.HasPoint(mouseButton.Position) && !rect2.HasPoint(mouseButton.Position))
{
ButtonPressed = false;
}
}
}

public void UpdateSkin(SkinProfile skin)
{
order.Icon = MapList.Instance.Ascending.Value ? skin.SortAscendButtonImage : skin.SortButtonImage;
Icon = order.Icon;
}

private void toggle(bool toggled)
{
panel.Visible = toggled;
}

private void selectSort(Button button)
{
if (Enum.TryParse<MapList.SortType>(button.Name, true, out var result) && MapList.Instance.Sorting.Value != result)
{
previousButton?.Disabled = false;
button.Disabled = true;
previousButton = button;

MapList.Instance.Sorting.Value = result;
}
}

private void toggleOrder()
{
var skin = SkinManager.Instance.Skin;

MapList.Instance.Ascending.Value = !MapList.Instance.Ascending.Value;
orderLabel.Text = MapList.Instance.Ascending.Value ? "Ascending" : "Descending";
order.Icon = MapList.Instance.Ascending.Value ? skin.SortAscendButtonImage : skin.SortButtonImage;

Icon = order.Icon;
}
}
1 change: 1 addition & 0 deletions scripts/ui/menu/play/SortMenuButton.cs.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://b6mbjcjxklb81
Binary file added user/skins/default/ui/buttons/sort_ascend.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions user/skins/default/ui/buttons/sort_ascend.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://5hmrvxdsxcql"
path="res://.godot/imported/sort_ascend.png-598eb8e58c57701015f44a062aac4b71.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://user/skins/default/ui/buttons/sort_ascend.png"
dest_files=["res://.godot/imported/sort_ascend.png-598eb8e58c57701015f44a062aac4b71.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Loading