Skip to content

Commit b4570c6

Browse files
feat: Implement Style-Based Skin Generation
- Add a 'Style' property to the OsuSkin class. - Create a database of skin styles in styles.json. - Implement a StyleSelector UI component. - Integrate the StyleSelector with the AI generator to allow you to generate skins based on a selected style.
1 parent ee03d2b commit b4570c6

File tree

6 files changed

+118
-2
lines changed

6 files changed

+118
-2
lines changed

assets/styles.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"Name": "Yugen",
4+
"Description": "A popular skin known for its clean and minimalist design."
5+
},
6+
{
7+
"Name": "Cookiezi",
8+
"Description": "A skin used by the legendary player Cookiezi."
9+
},
10+
{
11+
"Name": "FlyingTuna",
12+
"Description": "A skin used by the popular streamer FlyingTuna."
13+
}
14+
]

src/Components/StyleSelector.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Godot;
2+
using OsuSkinMixer.Models;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Text.Json;
6+
7+
namespace OsuSkinMixer.Components;
8+
9+
public partial class StyleSelector : Popup
10+
{
11+
[Signal]
12+
public delegate void StyleSelectedEventHandler(string style);
13+
14+
private VBoxContainer StyleList;
15+
16+
public override void _Ready()
17+
{
18+
StyleList = GetNode<VBoxContainer>("%StyleList");
19+
var styles = LoadStyles();
20+
21+
foreach (var style in styles)
22+
{
23+
var button = new Button();
24+
button.Text = style.Name;
25+
button.Pressed += () => OnStyleButtonPressed(style.Name);
26+
StyleList.AddChild(button);
27+
}
28+
}
29+
30+
private void OnStyleButtonPressed(string style)
31+
{
32+
EmitSignal(SignalName.StyleSelected, style);
33+
Out();
34+
}
35+
36+
private IEnumerable<SkinStyle> LoadStyles()
37+
{
38+
string stylesJson = File.ReadAllText("assets/styles.json");
39+
return JsonSerializer.Deserialize<IEnumerable<SkinStyle>>(stylesJson);
40+
}
41+
}
42+
43+
public class SkinStyle
44+
{
45+
public string Name { get; set; }
46+
public string Description { get; set; }
47+
}

src/Components/StyleSelector.tscn

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://bcy8j8f8j8f8"]
2+
3+
[ext_resource type="Script" path="res://src/Components/StyleSelector.cs" id="1_f8j8f"]
4+
5+
[node name="StyleSelector" type="Popup"]
6+
script = ExtResource("1_f8j8f")
7+
8+
[node name="VBoxContainer" type="VBoxContainer" parent="."]
9+
anchors_preset = 8
10+
anchor_left = 0.5
11+
anchor_top = 0.5
12+
anchor_right = 0.5
13+
anchor_bottom = 0.5
14+
offset_left = -150.0
15+
offset_top = -100.0
16+
offset_right = 150.0
17+
offset_bottom = 100.0
18+
grow_horizontal = 2
19+
grow_vertical = 2
20+
theme_override_constants/separation = 15
21+
22+
[node name="Label" type="Label" parent="VBoxContainer"]
23+
layout_mode = 2
24+
text = "Select a style"
25+
horizontal_alignment = 1
26+
27+
[node name="HSeparator" type="HSeparator" parent="VBoxContainer"]
28+
layout_mode = 2
29+
30+
[node name="StyleList" type="VBoxContainer" parent="VBoxContainer"]
31+
unique_name_in_owner = true
32+
layout_mode = 2

src/Models/Osu/OsuSkin.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public OsuSkin(DirectoryInfo dir, bool hidden = false)
4747

4848
public bool Hidden { get; set; }
4949

50+
public string Style { get; set; }
51+
5052
public Color[] ComboColors
5153
{
5254
get

src/StackScenes/AiGenerator/AiGenerator.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public partial class AiGenerator : StackScene
3030
private FileDialog FileDialog;
3131

3232
private string SelectedImagePath;
33+
private string SelectedStyle;
34+
35+
private StyleSelector StyleSelector;
36+
private Button SelectStyleButton;
3337

3438
public override void _Ready()
3539
{
@@ -38,16 +42,25 @@ public override void _Ready()
3842
PromptEdit = GetNode<LineEdit>("%Prompt");
3943
SelectImageButton = GetNode<Button>("%SelectImageButton");
4044
GenerateButton = GetNode<Button>("%GenerateButton");
45+
SelectStyleButton = GetNode<Button>("%SelectStyleButton");
4146
TextureRect = GetNode<TextureRect>("%TextureRect");
4247
HttpRequest = GetNode<HttpRequest>("HttpRequest");
4348
FileDialog = GetNode<FileDialog>("FileDialog");
49+
StyleSelector = GetNode<StyleSelector>("StyleSelector");
4450

4551
SelectImageButton.Pressed += () => FileDialog.PopupCentered();
4652
FileDialog.FileSelected += OnFileSelected;
4753
GenerateButton.Pressed += OnGenerateButtonPressed;
54+
SelectStyleButton.Pressed += () => StyleSelector.In();
55+
StyleSelector.StyleSelected += OnStyleSelected;
4856
HttpRequest.RequestCompleted += OnRequestCompleted;
4957
}
5058

59+
private void OnStyleSelected(string style)
60+
{
61+
SelectedStyle = style;
62+
}
63+
5164
private void OnFileSelected(string path)
5265
{
5366
SelectedImagePath = path;
@@ -69,7 +82,7 @@ private void OnGenerateButtonPressed()
6982
{
7083
parts = new object[]
7184
{
72-
new { text = PromptEdit.Text },
85+
new { text = $"{PromptEdit.Text} in the style of {SelectedStyle}" },
7386
new
7487
{
7588
inline_data = new

src/StackScenes/AiGenerator/AiGenerator.tscn

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
[gd_scene load_steps=2 format=3 uid="uid://cgt7d5l7g2a3e"]
1+
[gd_scene load_steps=3 format=3 uid="uid://cgt7d5l7g2a3e"]
22

33
[ext_resource type="Script" path="res://src/StackScenes/AiGenerator/AiGenerator.cs" id="1_vj5qg"]
4+
[ext_resource type="PackedScene" uid="uid://bcy8j8f8j8f8" path="res://src/Components/StyleSelector.tscn" id="2_abcde"]
45

56
[node name="AiGenerator" type="Control"]
67
layout_mode = 3
@@ -48,6 +49,10 @@ text = "Select Image"
4849
layout_mode = 2
4950
text = "Generate"
5051

52+
[node name="SelectStyleButton" type="Button" parent="VBoxContainer/HBoxContainer"]
53+
layout_mode = 2
54+
text = "Select Style"
55+
5156
[node name="TextureRect" type="TextureRect" parent="VBoxContainer"]
5257
custom_minimum_size = Vector2(256, 256)
5358
layout_mode = 2
@@ -63,3 +68,6 @@ ok_button_text = "Open"
6368
file_mode = 0
6469
access = 2
6570
filters = PackedStringArray("*.png", "*.jpg")
71+
72+
[node name="StyleSelector" parent="." instance=ExtResource("2_abcde")]
73+
visible = false

0 commit comments

Comments
 (0)