@@ -3,10 +3,12 @@ package archipelago.substates;
33import backend .MusicBeatSubstate ;
44import backend .ui .* ;
55import flixel .effects .FlxFlicker ;
6+ import flixel .text .FlxText ;
67import flixel .tweens .FlxEase ;
78import flixel .tweens .FlxTween ;
89import flixel .util .FlxGradient ;
910import flixel .util .FlxTimer ;
11+ import lime .system .Clipboard ;
1012
1113/**
1214 * Specialized port number input substate with validation and presets
@@ -33,9 +35,11 @@ class PortInputSubstate extends MusicBeatSubstate {
3335 var preset38281Button : FlxSprite ;
3436 var preset38282Button : FlxSprite ;
3537 var preset80Button : FlxSprite ;
38+ var clipboardButton : FlxSprite ;
3639 var preset38281Text : FlxText ;
3740 var preset38282Text : FlxText ;
3841 var preset80Text : FlxText ;
42+ var clipboardText : FlxText ;
3943
4044 // Animation elements
4145 var glowEffect : FlxSprite ;
@@ -49,6 +53,7 @@ class PortInputSubstate extends MusicBeatSubstate {
4953 // Visual state
5054 var isAnimating : Bool = false ;
5155 var hasError : Bool = false ;
56+ var clipboardPort : String = null ;
5257
5358 public function new (
5459 currentVal : String ,
@@ -157,7 +162,7 @@ class PortInputSubstate extends MusicBeatSubstate {
157162 var presetY = panel .y + 220 ;
158163 var presetWidth = 120 ;
159164 var presetHeight = 35 ;
160- var spacing = (panel .width - (presetWidth * 3 )) / 4 ;
165+ var spacing = (panel .width - (presetWidth * 4 )) / 5 ; // Updated for 4 buttons
161166
162167 // 38281 preset (most common)
163168 preset38281Button = new FlxSprite (panel .x + spacing , presetY );
@@ -179,8 +184,18 @@ class PortInputSubstate extends MusicBeatSubstate {
179184 preset38282Text .borderSize = 1 ;
180185 add (preset38282Text );
181186
187+ // Clipboard button (between 38282 and 80)
188+ clipboardButton = new FlxSprite (panel .x + spacing * 3 + presetWidth * 2 , presetY );
189+ clipboardButton .makeGraphic (presetWidth , presetHeight , FlxColor .GRAY );
190+ add (clipboardButton );
191+
192+ clipboardText = new FlxText (clipboardButton .x , clipboardButton .y + 8 , presetWidth , " Clipboard\n (Empty)" , 12 );
193+ clipboardText .setFormat (Paths .font (" vcr.ttf" ), 12 , FlxColor .WHITE , CENTER , OUTLINE , FlxColor .BLACK );
194+ clipboardText .borderSize = 1 ;
195+ add (clipboardText );
196+
182197 // 80 preset (HTTP)
183- preset80Button = new FlxSprite (panel .x + spacing * 3 + presetWidth * 2 , presetY );
198+ preset80Button = new FlxSprite (panel .x + spacing * 4 + presetWidth * 3 , presetY );
184199 preset80Button .makeGraphic (presetWidth , presetHeight , FlxColor .fromRGB (128 , 64 , 0 ));
185200 add (preset80Button );
186201
@@ -336,6 +351,41 @@ class PortInputSubstate extends MusicBeatSubstate {
336351 FlxG .sound .play (Paths .sound (' confirmMenu' ));
337352 }
338353
354+ function checkClipboard () {
355+ try {
356+ var clipboardText = Clipboard .text ;
357+ if (clipboardText != null ) {
358+ // Remove any whitespace and non-digit characters
359+ var cleanText = clipboardText .trim ();
360+ var portRegex = ~/ ^ \d + $ / ;
361+
362+ if (portRegex .match (cleanText )) {
363+ var port = Std .parseInt (cleanText );
364+ if (port != null && port >= 1 && port <= 65535 ) {
365+ clipboardPort = cleanText ;
366+ clipboardButton .color = FlxColor .GREEN ;
367+ clipboardText = port + " \n (from clipboard)" ;
368+ this .clipboardText .text = clipboardText ;
369+ return ;
370+ }
371+ }
372+ }
373+ } catch (e : haxe. Exception ) {
374+ // Clipboard access might fail, ignore silently
375+ }
376+
377+ // No valid port found
378+ clipboardPort = null ;
379+ clipboardButton .color = FlxColor .GRAY ;
380+ clipboardText .text = " Clipboard\n (Empty)" ;
381+ }
382+
383+ function setClipboardPort () {
384+ if (clipboardPort != null ) {
385+ setPreset (clipboardPort );
386+ }
387+ }
388+
339389 function confirm () {
340390 if (hasError || currentValue .length == 0 ) {
341391 FlxG .sound .play (Paths .sound (' cancelMenu' ));
@@ -358,6 +408,9 @@ class PortInputSubstate extends MusicBeatSubstate {
358408
359409 if (isAnimating ) return ;
360410
411+ // Check clipboard for valid ports
412+ checkClipboard ();
413+
361414 // Handle keyboard input using the same pattern as TextInputSubstate
362415 var keys = FlxG .keys .justPressed ;
363416
@@ -442,6 +495,18 @@ class PortInputSubstate extends MusicBeatSubstate {
442495 preset38282Button .color = FlxColor .PURPLE ;
443496 }
444497
498+ // Clipboard button
499+ if (FlxG .mouse .overlaps (clipboardButton )) {
500+ if (clipboardPort != null ) {
501+ clipboardButton .color = FlxColor .fromRGB (150 , 255 , 150 );
502+ if (FlxG .mouse .justPressed ) setClipboardPort ();
503+ } else {
504+ clipboardButton .color = FlxColor .fromRGB (150 , 150 , 150 );
505+ }
506+ } else {
507+ clipboardButton .color = clipboardPort != null ? FlxColor .GREEN : FlxColor .GRAY ;
508+ }
509+
445510 if (FlxG .mouse .overlaps (preset80Button )) {
446511 preset80Button .color = FlxColor .fromRGB (180 , 120 , 60 );
447512 if (FlxG .mouse .justPressed ) setPreset (" 80" );
0 commit comments