From b827aa00841254b941665aa767aa19ca7620c2c7 Mon Sep 17 00:00:00 2001
From: brunzelchen <brunzelchen@b956fd51-792f-4845-bead-9b4dfca2ff2c>
Date: Sun, 17 Apr 2011 15:36:40 +0000
Subject: fix for last commit: check if there are any selectable interactions

git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/1.0.1 Challenge MOD@2821 b956fd51-792f-4845-bead-9b4dfca2ff2c
---
 Game/Code/Menu/UMenu.pas | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)

diff --git a/Game/Code/Menu/UMenu.pas b/Game/Code/Menu/UMenu.pas
index 1ed91087..2729546b 100644
--- a/Game/Code/Menu/UMenu.pas
+++ b/Game/Code/Menu/UMenu.pas
@@ -127,7 +127,8 @@ type
       procedure SetAnimationProgress(Progress: real); virtual;
 
       function IsSelectable(Int: Cardinal): Boolean;
-      
+      function NumSelectable(Int: Cardinal): Integer;
+
       procedure InteractNext; virtual;
       procedure InteractCustom(CustomSwitch: integer); virtual;
       procedure InteractPrev; virtual;
@@ -837,6 +838,19 @@ begin
   end;
 end;
 
+function TMenu.NumSelectable(Int: Cardinal): Integer;
+var
+  i:  Integer;
+
+begin
+  Result := 0;
+  for i := 0 to Length(Interactions) - 1 do
+  begin
+    if (i <> Int) and IsSelectable(i) then
+      inc(Result);
+  end;
+end;
+
 procedure TMenu.InteractNext;
 var
   Int: Integer;
@@ -844,10 +858,12 @@ begin
   Int := Interaction;
 
   // change interaction as long as it's needed
-  repeat
-    Int := (Int + 1) Mod Length(Interactions);
-  Until IsSelectable(Int);
-
+  if (NumSelectable(Int)>0) then
+  begin
+    repeat
+      Int := (Int + 1) Mod Length(Interactions);
+    Until IsSelectable(Int);
+  end;
   //Set Interaction
   Interaction := Int;
 end;
@@ -860,12 +876,14 @@ begin
   Int := Interaction;
 
   // change interaction as long as it's needed
-  repeat
-    Int := Int - 1;
-    if Int = -1 then
-      Int := High(Interactions);
-  Until IsSelectable(Int);
-
+  if (NumSelectable(Int)>0) then
+  begin
+    repeat
+      Int := Int - 1;
+      if Int = -1 then
+        Int := High(Interactions);
+    Until IsSelectable(Int);
+  end;
   //Set Interaction
   Interaction := Int
 end;
-- 
cgit v1.2.3