LCOV - code coverage report
Current view: top level - Core/Entities - PlayerEntityStickProfile.m (source / functions) Hit Total Coverage
Test: coverxygen.info Lines: 0 25 0.0 %
Date: 2025-05-28 07:50:54 Functions: 0 0 -

          Line data    Source code
       1           0 : /*
       2             : 
       3             : PlayerEntityStickProfile.m
       4             : 
       5             : Oolite
       6             : Copyright (C) 2004-2013 Giles C Williams and contributors
       7             : 
       8             : This program is free software; you can redistribute it and/or
       9             : modify it under the terms of the GNU General Public License
      10             : as published by the Free Software Foundation; either version 2
      11             : of the License, or (at your option) any later version.
      12             : 
      13             : This program is distributed in the hope that it will be useful,
      14             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             : GNU General Public License for more details.
      17             : 
      18             : You should have received a copy of the GNU General Public License
      19             : along with this program; if not, write to the Free Software
      20             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
      21             : MA 02110-1301, USA.
      22             : 
      23             : */
      24             : 
      25             : #import "PlayerEntity.h"
      26             : #import "PlayerEntityStickProfile.h"
      27             : #import "PlayerEntityStickMapper.h"
      28             : #import "OOJoystickManager.h"
      29             : #import "OOJoystickProfile.h"
      30             : #import "PlayerEntityControls.h"
      31             : #import "PlayerEntitySound.h"
      32             : #import "OOOpenGL.h"
      33             : #import "OOMacroOpenGL.h"
      34             : #import "HeadUpDisplay.h"
      35             : 
      36           0 : #define GUI_ROW_STICKPROFILE_BACK               20
      37           0 : #define GUI_ROW_STICKPROFILE_AXIS               1
      38           0 : #define GUI_ROW_STICKPROFILE_DEADZONE           2
      39           0 : #define GUI_ROW_STICKPROFILE_PROFILE_TYPE       3
      40           0 : #define GUI_ROW_STICKPROFILE_POWER      4
      41           0 : #define GUI_ROW_STICKPROFILE_PARAM      5
      42             : 
      43           0 : static BOOL stickProfileArrow_pressed;
      44             : 
      45             : @interface StickProfileScreen (StickProfileInternal)
      46             : 
      47           0 : - (void) showScreen;
      48           0 : - (void) nextAxis;
      49           0 : - (NSString *) currentAxis;
      50           0 : - (void) previousAxis;
      51           0 : - (void) increaseDeadzone;
      52           0 : - (void) decreaseDeadzone;
      53           0 : - (void) nextProfileType;
      54           0 : - (void) previousProfileType;
      55           0 : - (void) IncreasePower;
      56           0 : - (BOOL) currentProfileIsSpline;
      57           0 : - (void) DecreasePower;
      58           0 : - (void) IncreaseParam;
      59           0 : - (void) DecreaseParam;
      60           0 : - (void) saveSettings;
      61           0 : - (void) graphProfile: (GLfloat) alpha at: (Vector) at size: (NSSize) size;
      62           0 : - (void) startEdit;
      63           0 : - (NSString *) profileType;
      64             : 
      65             : @end
      66             : 
      67             : @implementation PlayerEntity (StickProfile)
      68             : 
      69             : - (void) setGuiToStickProfileScreen: (GuiDisplayGen *) gui
      70             : {
      71             :         gui_screen = GUI_SCREEN_STICKPROFILE;
      72             :         [stickProfileScreen startGui: gui];
      73             :         return;
      74             : }
      75             : 
      76             : - (void) stickProfileInputHandler: (GuiDisplayGen *) gui
      77             :         view: (MyOpenGLView *) gameView
      78             : {
      79             :         if ([gameView isDown: gvMouseLeftButton])
      80             :         {
      81             :                 NSPoint mouse_position = NSMakePoint(
      82             :                         [gameView virtualJoystickPosition].x * [gui size].width,
      83             :                         [gameView virtualJoystickPosition].y * [gui size].height );
      84             :                 [stickProfileScreen mouseDown: mouse_position];
      85             :         }
      86             :         else
      87             :         {
      88             :                 [stickProfileScreen mouseUp];
      89             :         }
      90             :         if ([gameView isDown: gvDeleteKey])
      91             :         {
      92             :                 [stickProfileScreen deleteSelected];
      93             :         }
      94             :         [self handleGUIUpDownArrowKeys];
      95             :         
      96             :         if ([self checkKeyPress:n_key_gui_select] && [gui selectedRow] == GUI_ROW_STICKPROFILE_BACK)
      97             :         {
      98             :                 [stickProfileScreen saveSettings];
      99             :                 [self setGuiToStickMapperScreen: 0 resetCurrentRow: YES];
     100             :         }
     101             :         switch ([gui selectedRow])
     102             :         {
     103             :         case GUI_ROW_STICKPROFILE_AXIS:
     104             :                 if ([self checkKeyPress:n_key_gui_arrow_left])
     105             :                 {
     106             :                         if (!stickProfileArrow_pressed && ![self checkKeyPress:n_key_gui_arrow_right])
     107             :                         {
     108             :                                 [stickProfileScreen previousAxis];
     109             :                                 stickProfileArrow_pressed = YES;
     110             :                         }
     111             :                 }
     112             :                 else if ([self checkKeyPress: n_key_gui_arrow_right])
     113             :                 {
     114             :                         if (!stickProfileArrow_pressed && ![self checkKeyPress: n_key_gui_arrow_left])
     115             :                         {
     116             :                                 [stickProfileScreen nextAxis];
     117             :                                 stickProfileArrow_pressed = YES;
     118             :                         }
     119             :                 }
     120             :                 else
     121             :                 {
     122             :                         stickProfileArrow_pressed = NO;
     123             :                 }
     124             :                 break;
     125             : 
     126             :         case GUI_ROW_STICKPROFILE_DEADZONE:
     127             :                 if ([self checkKeyPress:n_key_gui_arrow_left])
     128             :                 {
     129             :                         if (!stickProfileArrow_pressed && ![self checkKeyPress: n_key_gui_arrow_right])
     130             :                         {
     131             :                                 [stickProfileScreen decreaseDeadzone];
     132             :                                 stickProfileArrow_pressed = YES;
     133             :                         }
     134             :                 }
     135             :                 else if ([self checkKeyPress: n_key_gui_arrow_right])
     136             :                 {
     137             :                         if (!stickProfileArrow_pressed && ![self checkKeyPress: n_key_gui_arrow_left])
     138             :                         {
     139             :                                 [stickProfileScreen increaseDeadzone];
     140             :                                 stickProfileArrow_pressed = YES;
     141             :                         }
     142             :                 }
     143             :                 else
     144             :                 {
     145             :                         stickProfileArrow_pressed = NO;
     146             :                 }
     147             :                 break;
     148             : 
     149             :         case GUI_ROW_STICKPROFILE_PROFILE_TYPE:
     150             :                 if ([self checkKeyPress:n_key_gui_arrow_left])
     151             :                 {
     152             :                         if (!stickProfileArrow_pressed && ![self checkKeyPress: n_key_gui_arrow_right])
     153             :                         {
     154             :                                 [stickProfileScreen previousProfileType];
     155             :                                 stickProfileArrow_pressed = YES;
     156             :                         }
     157             :                 }
     158             :                 else if ([self checkKeyPress: n_key_gui_arrow_right])
     159             :                 {
     160             :                         if (!stickProfileArrow_pressed && ![self checkKeyPress: n_key_gui_arrow_left])
     161             :                         {
     162             :                                 [stickProfileScreen nextProfileType];
     163             :                                 stickProfileArrow_pressed = YES;
     164             :                         }
     165             :                 }
     166             :                 else
     167             :                 {
     168             :                         stickProfileArrow_pressed = NO;
     169             :                 }
     170             :                 break;
     171             :         }
     172             :                 
     173             :         if (![stickProfileScreen currentProfileIsSpline])
     174             :         {
     175             :                 if ([gui selectedRow] == GUI_ROW_STICKPROFILE_POWER)
     176             :                 {
     177             :                         if ([self checkKeyPress:n_key_gui_arrow_left])
     178             :                         {
     179             :                                 if (!stickProfileArrow_pressed && ![self checkKeyPress: n_key_gui_arrow_right])
     180             :                                 {
     181             :                                         [stickProfileScreen DecreasePower];
     182             :                                         stickProfileArrow_pressed = YES;
     183             :                                 }
     184             :                         }
     185             :                         else if ([self checkKeyPress: n_key_gui_arrow_right])
     186             :                         {
     187             :                                 if (!stickProfileArrow_pressed && ![self checkKeyPress: n_key_gui_arrow_left])
     188             :                                 {
     189             :                                         [stickProfileScreen IncreasePower];
     190             :                                         stickProfileArrow_pressed = YES;
     191             :                                 }
     192             :                         }
     193             :                         else
     194             :                         {
     195             :                                 stickProfileArrow_pressed = NO;
     196             :                         }
     197             :                 }
     198             :                 else if ([gui selectedRow] == GUI_ROW_STICKPROFILE_PARAM)
     199             :                 {
     200             :                         if ([self checkKeyPress:n_key_gui_arrow_left])
     201             :                         {
     202             :                                 if (!stickProfileArrow_pressed && ![self checkKeyPress: n_key_gui_arrow_right])
     203             :                                 {
     204             :                                         [stickProfileScreen DecreaseParam];
     205             :                                         stickProfileArrow_pressed = YES;
     206             :                                 }
     207             :                         }
     208             :                         else if ([self checkKeyPress: n_key_gui_arrow_right])
     209             :                         {
     210             :                                 if (!stickProfileArrow_pressed && ![self checkKeyPress: n_key_gui_arrow_left])
     211             :                                 {
     212             :                                         [stickProfileScreen IncreaseParam];
     213             :                                         stickProfileArrow_pressed = YES;
     214             :                                 }
     215             :                         }
     216             :                         else
     217             :                         {
     218             :                                 stickProfileArrow_pressed = NO;
     219             :                         }
     220             :                 }
     221             :         }
     222             :         return;
     223             : }
     224             : 
     225             : - (void) stickProfileGraphAxisProfile: (GLfloat) alpha screenAt: (Vector) screenAt screenSize: (NSSize) screenSize
     226             : {
     227             : 
     228             :         [stickProfileScreen graphProfile: alpha at: make_vector(screenAt.x - 110.0, screenAt.y - 100, screenAt.z) size: NSMakeSize(220,220)];
     229             :         return;
     230             : }
     231             : 
     232             : @end
     233             : 
     234             : @implementation StickProfileScreen
     235             : 
     236             : - (id) init
     237             : {
     238             :         int i, j;
     239             :         
     240             :         if ((self = [super init]))
     241             :         {
     242             :                 stickHandler = [OOJoystickManager sharedStickHandler];
     243             :                 current_axis = AXIS_ROLL;
     244             :                 for (i = 0; i < 3; i++)
     245             :                 {
     246             :                         for (j = 0; j < 2; j++)
     247             :                         {
     248             :                                 profiles[i][j] = nil;
     249             :                         }
     250             :                 }
     251             :         }
     252             :         return self;
     253             : }
     254             : 
     255             : - (void) dealloc
     256             : {
     257             :         int i, j;
     258             :         for (i = 0; i < 3; i++)
     259             :         {
     260             :                 for (j = 0; j < 2; j++)
     261             :                 {
     262             :                         [profiles[i][j] release];
     263             :                 }
     264             :         }
     265             :         [super dealloc];
     266             : }
     267             : - (void) startGui: (GuiDisplayGen *) gui_display_gen
     268             : {
     269             :         gui = gui_display_gen;
     270             :         [self startEdit];
     271             :         [gui clear];
     272             :         [gui setTitle:DESC(@"oolite-stickprofile-title")];
     273             :         [self showScreen];
     274             :         [gui setSelectedRow: GUI_ROW_STICKPROFILE_AXIS];
     275             :         return;
     276             : }
     277             : 
     278             : - (void) mouseDown: (NSPoint) position
     279             : {
     280             :         OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
     281             :         OOJoystickSplineAxisProfile *spline_profile;
     282             :         NSPoint spline_position;
     283             :         
     284             :         if (![profile isKindOfClass: [OOJoystickSplineAxisProfile class]])
     285             :         {
     286             :                 return;
     287             :         }
     288             :         spline_profile = (OOJoystickSplineAxisProfile *)profile;
     289             :         spline_position.x = (position.x - graphRect.origin.x - 10) / (graphRect.size.width - 20);
     290             :         spline_position.y = (-position.y - graphRect.origin.y - 10) / (graphRect.size.height - 20);
     291             :         if (spline_position.x >= 0.0 && spline_position.x <= 1.0 && spline_position.y >= 0.0 && spline_position.y <= 1.0)
     292             :         {
     293             :                 if (dragged_control_point < 0)
     294             :                 {
     295             :                         selected_control_point = [spline_profile addControl: spline_position];
     296             :                         dragged_control_point = selected_control_point;
     297             :                         double_click_control_point = -1;
     298             :                 }
     299             :                 else
     300             :                 {
     301             :                         [spline_profile moveControl: dragged_control_point point: spline_position];
     302             :                 }
     303             :                 [stickHandler saveStickSettings];
     304             :         }
     305             :         return;
     306             : }
     307             : 
     308             : - (void) mouseUp
     309             : {
     310             :         if (selected_control_point >= 0)
     311             :         {
     312             :                 double_click_control_point = selected_control_point;
     313             :         }
     314             :         dragged_control_point = -1;
     315             :         return;
     316             : }
     317             : 
     318             : - (void) deleteSelected
     319             : {
     320             :         OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
     321             :         OOJoystickSplineAxisProfile *spline_profile;
     322             :         if ([profile isKindOfClass: [OOJoystickSplineAxisProfile class]] && selected_control_point >= 0)
     323             :         {
     324             :                 spline_profile = (OOJoystickSplineAxisProfile *)profile;
     325             :                 [spline_profile removeControl: selected_control_point];
     326             :                 selected_control_point = -1;
     327             :                 dragged_control_point = -1;
     328             :                 [stickHandler saveStickSettings];
     329             :         }
     330             :         return;
     331             : }
     332             :                         
     333             : 
     334             : @end
     335             : 
     336             : @implementation StickProfileScreen (StickProfileInternal)
     337             : 
     338             : 
     339             : - (void) nextAxis
     340             : {
     341             :         if (current_axis == AXIS_ROLL)
     342             :                 current_axis = AXIS_PITCH;
     343             :         else if (current_axis == AXIS_PITCH)
     344             :                 current_axis = AXIS_YAW;
     345             :         [self showScreen];
     346             :         return;
     347             : }
     348             : 
     349             : - (void) previousAxis
     350             : {
     351             :         if (current_axis == AXIS_PITCH)
     352             :                 current_axis = AXIS_ROLL;
     353             :         else if (current_axis == AXIS_YAW)
     354             :                 current_axis = AXIS_PITCH;
     355             :         [self showScreen];
     356             :         return;
     357             : }
     358             : 
     359             : - (NSString *) currentAxis
     360             : {
     361             :         switch (current_axis)
     362             :         {
     363             :         case AXIS_ROLL:
     364             :                 return DESC(@"stickmapper-roll");
     365             :         
     366             :         case AXIS_PITCH:
     367             :                 return DESC(@"stickmapper-pitch");
     368             :                 
     369             :         case AXIS_YAW:
     370             :                 return DESC(@"stickmapper-yaw");
     371             :         }
     372             :         return @"";
     373             : }
     374             : 
     375             : - (void) increaseDeadzone
     376             : {
     377             :         OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
     378             :         if (profile)
     379             :         {
     380             :                 [profile setDeadzone: [profile deadzone] + STICK_MAX_DEADZONE / 20];
     381             :         }
     382             :         [self showScreen];
     383             :         return;
     384             : }
     385             : 
     386             : - (void) decreaseDeadzone
     387             : {
     388             :         OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
     389             :         if (profile)
     390             :         {
     391             :                 [profile setDeadzone: [profile deadzone] - STICK_MAX_DEADZONE / 20];
     392             :         }
     393             :         [self showScreen];
     394             :         return;
     395             : }
     396             : 
     397             : - (void) nextProfileType
     398             : {
     399             :         OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
     400             :         double deadzone;
     401             :         
     402             :         if ([profile isKindOfClass: [OOJoystickStandardAxisProfile class]])
     403             :         {
     404             :                 deadzone = [profile deadzone];
     405             :                 [profiles[current_axis][0] release];
     406             :                 profiles[current_axis][0] = [profile retain];
     407             :                 if (!profiles[current_axis][1])
     408             :                 {
     409             :                         profiles[current_axis][1] = [[OOJoystickSplineAxisProfile alloc] init];
     410             :                 }
     411             :                 [profiles[current_axis][1] setDeadzone: deadzone];
     412             :                 [stickHandler setProfile: profiles[current_axis][1] forAxis: current_axis];
     413             :                 [stickHandler saveStickSettings];
     414             :         }
     415             :         [self showScreen];
     416             :         return;
     417             : }
     418             : 
     419             : - (void) previousProfileType
     420             : {
     421             :         OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
     422             :         double deadzone;
     423             :         
     424             :         if ([profile isKindOfClass: [OOJoystickSplineAxisProfile class]])
     425             :         {
     426             :                 deadzone = [profile deadzone];
     427             :                 [profiles[current_axis][1] release];
     428             :                 profiles[current_axis][1] = [profile retain];
     429             :                 if (!profiles[current_axis][0])
     430             :                 {
     431             :                         profiles[current_axis][0] = [[OOJoystickStandardAxisProfile alloc] init];
     432             :                 }
     433             :                 [profiles[current_axis][0] setDeadzone: deadzone];
     434             :                 [stickHandler setProfile: profiles[current_axis][0] forAxis: current_axis];
     435             :                 [stickHandler saveStickSettings];
     436             :         }
     437             :         [self showScreen];
     438             :         return;
     439             : }
     440             : 
     441             : - (BOOL) currentProfileIsSpline
     442             : {
     443             :         if ([[stickHandler getProfileForAxis: current_axis] isKindOfClass: [OOJoystickSplineAxisProfile class]])
     444             :         {
     445             :                 return YES;
     446             :         }
     447             :         return NO;
     448             : }
     449             : 
     450             : - (void) IncreasePower
     451             : {
     452             :         OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
     453             :         OOJoystickStandardAxisProfile *standard_profile;
     454             : 
     455             :         if (profile && [profile isKindOfClass: [OOJoystickStandardAxisProfile class]])
     456             :         {
     457             :                 standard_profile = (OOJoystickStandardAxisProfile *) profile;
     458             :                 [standard_profile setPower: [standard_profile power] + STICKPROFILE_MAX_POWER / 20];
     459             :                 [stickHandler saveStickSettings];
     460             :         }
     461             :         [self showScreen];
     462             :         return;
     463             : }
     464             : 
     465             : - (void) DecreasePower
     466             : {
     467             :         OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
     468             :         OOJoystickStandardAxisProfile *standard_profile;
     469             : 
     470             :         if (profile && [profile isKindOfClass: [OOJoystickStandardAxisProfile class]])
     471             :         {
     472             :                 standard_profile = (OOJoystickStandardAxisProfile *) profile;
     473             :                 [standard_profile setPower: [standard_profile power] - STICKPROFILE_MAX_POWER / 20];
     474             :                 [stickHandler saveStickSettings];
     475             :         }
     476             :         [self showScreen];
     477             :         return;
     478             : }
     479             : 
     480             : - (void) IncreaseParam
     481             : {
     482             :         OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
     483             :         OOJoystickStandardAxisProfile *standard_profile;
     484             : 
     485             :         if (profile && [profile isKindOfClass: [OOJoystickStandardAxisProfile class]])
     486             :         {
     487             :                 standard_profile = (OOJoystickStandardAxisProfile *) profile;
     488             :                 [standard_profile setParameter: [standard_profile parameter] + 0.05];
     489             :                 [stickHandler saveStickSettings];
     490             :         }
     491             :         [self showScreen];
     492             :         return;
     493             : }
     494             : 
     495             : - (void) DecreaseParam
     496             : {
     497             :         OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
     498             :         OOJoystickStandardAxisProfile *standard_profile;
     499             : 
     500             :         if (profile && [profile isKindOfClass: [OOJoystickStandardAxisProfile class]])
     501             :         {
     502             :                 standard_profile = (OOJoystickStandardAxisProfile *) profile;
     503             :                 [standard_profile setParameter: [standard_profile parameter] - 0.05];
     504             :                 [stickHandler saveStickSettings];
     505             :         }
     506             :         [self showScreen];
     507             :         return;
     508             : }
     509             : 
     510             : - (void) graphProfile: (GLfloat) alpha at: (Vector) at size: (NSSize) size
     511             : {
     512             :         OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
     513             :         OOJoystickSplineAxisProfile *spline_profile;
     514             :         NSInteger i;
     515             :         NSPoint point;
     516             :         NSArray *control_points;
     517             : 
     518             :         if (!profile) return;
     519             :         graphRect = NSMakeRect(at.x, at.y, size.width, size.height);
     520             :         OO_ENTER_OPENGL();
     521             :         OOGL(glColor4f(0.2,0.2,0.5,alpha));
     522             :         OOGLBEGIN(GL_QUADS);
     523             :                 glVertex3f(at.x,at.y,at.z);
     524             :                 glVertex3f(at.x + size.width,at.y,at.z);
     525             :                 glVertex3f(at.x + size.width,at.y + size.height,at.z);
     526             :                 glVertex3f(at.x,at.y + size.height,at.z);
     527             :         OOGLEND();
     528             :         OOGL(glColor4f(0.9,0.9,0.9,alpha));
     529             :         OOGL(GLScaledLineWidth(2.0f));
     530             :         OOGLBEGIN(GL_LINE_STRIP);
     531             :                 for (i = 0; i <= size.width - 20; i++)
     532             :                 {
     533             :                         glVertex3f(at.x+i+10,at.y+10+(size.height-20)*[profile rawValue:((float)i)/(size.width-20)],at.z);
     534             :                 }
     535             :         OOGLEND();
     536             :         OOGL(glColor4f(0.5,0.0,0.5,alpha));
     537             :         GLDrawFilledOval(at.x+10,at.y+10,at.z,NSMakeSize(4,4),20);
     538             :         GLDrawFilledOval(at.x+size.width-10,at.y+size.height-10,at.z,NSMakeSize(4,4),20);
     539             :         if ([profile isKindOfClass: [OOJoystickSplineAxisProfile class]])
     540             :         {
     541             :                 spline_profile = (OOJoystickSplineAxisProfile *)profile;
     542             :                 control_points = [spline_profile controlPoints];
     543             :                 for (i = 0; i < (NSInteger)[control_points count]; i++)
     544             :                 {
     545             :                         if (i == selected_control_point)
     546             :                         {
     547             :                                 OOGL(glColor4f(1.0,0.0,0.0,alpha));
     548             :                         }
     549             :                         else
     550             :                         {
     551             :                                 OOGL(glColor4f(0.0,1.0,0.0,alpha));
     552             :                         }
     553             :                         point = [[control_points objectAtIndex: i] pointValue];
     554             :                         GLDrawFilledOval(at.x+10+point.x*(size.width - 20),at.y+10+point.y*(size.height-20),at.z,NSMakeSize(4,4),20);
     555             :                 }
     556             :         }
     557             :         OOGL(glColor4f(0.9,0.9,0.0,alpha));
     558             :         OODrawStringAligned(DESC(@"oolite-stickprofile-movement"), at.x + size.width - 5, at.y, at.z, NSMakeSize(8,10), YES);
     559             :         OODrawString(DESC(@"oolite-stickprofile-response"), at.x, at.y + size.height - 10, at.z, NSMakeSize(8,10));
     560             :         return;
     561             : }
     562             : 
     563             : - (void) startEdit
     564             : {
     565             :         int i, j;
     566             :         
     567             :         for (i = 0; i < 3; i++)
     568             :         {
     569             :                 for (j = 0; j < 2; j++)
     570             :                 {
     571             :                         [profiles[i][j] release];
     572             :                         profiles[i][j] = nil;
     573             :                 }
     574             :         }
     575             :         current_axis = AXIS_ROLL;
     576             :         selected_control_point = -1;
     577             :         dragged_control_point = -1;
     578             :         double_click_control_point = -1;
     579             :         return;
     580             : }
     581             : 
     582             : - (void) saveSettings
     583             : {
     584             :         [stickHandler saveStickSettings];
     585             :         return;
     586             : }
     587             : 
     588             : - (void) showScreen
     589             : {
     590             :         OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
     591             :         OOJoystickStandardAxisProfile *standard_profile;
     592             :         NSString *v1 = @"||||||||||||||||||||";
     593             :         NSString *v2 = @"....................";
     594             :         int bars;
     595             :         double value;
     596             :         double power;
     597             : 
     598             :         OOGUITabStop tabStop[GUI_MAX_COLUMNS];
     599             :         tabStop[0] = 50;
     600             :         tabStop[1] = 140;
     601             :         [gui setTabStops:tabStop];
     602             :         [gui setArray: [NSArray arrayWithObjects: DESC(@"oolite-stickprofile-axis"), [self currentAxis], nil ] forRow: GUI_ROW_STICKPROFILE_AXIS];
     603             :         [gui setKey: GUI_KEY_OK forRow: GUI_ROW_STICKPROFILE_AXIS];
     604             :         value = [profile deadzone];
     605             :         bars = (int)(20 * value / STICK_MAX_DEADZONE + 0.5);
     606             :         if (bars < 0) bars = 0;
     607             :         if (bars > 20) bars = 20;
     608             :         [gui setArray: [NSArray arrayWithObjects: DESC(@"oolite-stickprofile-deadzone"),
     609             :                 [NSString stringWithFormat:
     610             :                         @"%@%@ (%0.4f)",
     611             :                         [v1 substringToIndex: bars],
     612             :                         [v2 substringToIndex: 20 - bars],
     613             :                         value],
     614             :                 nil] forRow: GUI_ROW_STICKPROFILE_DEADZONE];
     615             :         [gui setKey: GUI_KEY_OK forRow: GUI_ROW_STICKPROFILE_DEADZONE];
     616             :         [gui setArray: [NSArray arrayWithObjects: DESC(@"oolite-stickprofile-profile-type"), [self profileType], nil ] forRow: GUI_ROW_STICKPROFILE_PROFILE_TYPE];
     617             :         [gui setKey: GUI_KEY_OK forRow: GUI_ROW_STICKPROFILE_PROFILE_TYPE];
     618             :         if ([profile isKindOfClass:[OOJoystickStandardAxisProfile class]])
     619             :         {
     620             :                 standard_profile = (OOJoystickStandardAxisProfile*) profile;
     621             :                 power = [standard_profile power];
     622             :                 bars = (int)(20*power / STICKPROFILE_MAX_POWER + 0.5);
     623             :                 if (bars < 0) bars = 0;
     624             :                 if (bars > 20) bars = 20;
     625             :                 [gui setArray: [NSArray arrayWithObjects: DESC(@"oolite-stickprofile-range"),
     626             :                         [NSString stringWithFormat: @"%@%@ (%.1f) ", [v1 substringToIndex: bars], [v2 substringToIndex: 20 - bars], power],
     627             :                         nil] forRow: GUI_ROW_STICKPROFILE_POWER];
     628             :                 [gui setKey: GUI_KEY_OK forRow: GUI_ROW_STICKPROFILE_POWER];
     629             :                 value = [standard_profile parameter];
     630             :                 bars = 20*value;
     631             :                 if (bars < 0) bars = 0;
     632             :                 if (bars > 20) bars = 20;
     633             :                 [gui setArray: [NSArray arrayWithObjects: DESC(@"oolite-stickprofile-sensitivity"),
     634             :                         [NSString stringWithFormat: @"%@%@ (%0.2f) ", [v1 substringToIndex: bars], [v2 substringToIndex: 20 - bars], value],
     635             :                         nil] forRow: GUI_ROW_STICKPROFILE_PARAM];
     636             :                 [gui setKey: GUI_KEY_OK forRow: GUI_ROW_STICKPROFILE_PARAM];
     637             :                 [gui setColor:[OOColor yellowColor] forRow: GUI_ROW_STICKPROFILE_PARAM];
     638             :         }
     639             :         else
     640             :         {
     641             :                 [gui setText: @"" forRow: GUI_ROW_STICKPROFILE_POWER];
     642             :                 [gui setKey: GUI_KEY_SKIP forRow: GUI_ROW_STICKPROFILE_POWER];
     643             :                 [gui setText: DESC(@"oolite-stickprofile-spline-instructions") forRow: GUI_ROW_STICKPROFILE_PARAM];
     644             :                 [gui setKey: GUI_KEY_SKIP forRow: GUI_ROW_STICKPROFILE_PARAM];
     645             :                 [gui setColor:[OOColor magentaColor] forRow: GUI_ROW_STICKPROFILE_PARAM];
     646             :         }
     647             :         [gui setText: DESC(@"gui-back") forRow: GUI_ROW_STICKPROFILE_BACK];
     648             :         [gui setKey: GUI_KEY_OK forRow: GUI_ROW_STICKPROFILE_BACK];
     649             :         [gui setSelectableRange: NSMakeRange(1, GUI_ROW_STICKPROFILE_BACK)];
     650             :         [[UNIVERSE gameView] suppressKeysUntilKeyUp];
     651             :         [gui setForegroundTextureKey:[PLAYER status] == STATUS_DOCKED ? @"docked_overlay" : @"paused_overlay"];
     652             :         [gui setBackgroundTextureKey: @"settings"];
     653             :         return;
     654             : }
     655             : 
     656             : - (NSString *) profileType
     657             : {
     658             :         OOJoystickAxisProfile *profile = [stickHandler getProfileForAxis: current_axis];
     659             :         
     660             :         if ([profile isKindOfClass: [OOJoystickStandardAxisProfile class]])
     661             :         {
     662             :                 return DESC(@"oolite-stickprofile-type-standard");
     663             :         }
     664             :         if ([profile isKindOfClass: [OOJoystickSplineAxisProfile class]])
     665             :         {
     666             :                 return DESC(@"oolite-stickprofile-type-spline");
     667             :         }
     668             :         return DESC(@"oolite-stickprofile-type-standard");
     669             : }
     670             : 
     671             : @end
     672             : 

Generated by: LCOV version 1.14