project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m
changeset 4032 4aeab704d006
parent 3996 eb549fd864a5
child 4034 634a8c8682de
equal deleted inserted replaced
4030:adbb37b8c487 4032:4aeab704d006
    24 #import "CommodityFunctions.h"
    24 #import "CommodityFunctions.h"
    25 #import "UIImageExtra.h"
    25 #import "UIImageExtra.h"
    26 #import "PascalImports.h"
    26 #import "PascalImports.h"
    27 
    27 
    28 #define BTNS_PER_ROW         9
    28 #define BTNS_PER_ROW         9
    29 #define DEFAULT_DESCRIPTION  NSLocalizedString(@"Hold your finger on a weapon to see what it does",@"")
    29 #define DEFAULT_DESCRIPTION  IS_IPAD() ? \
       
    30                              NSLocalizedString(@"Hold your finger on a weapon to see what it does...",@"") : \
       
    31                              NSLocalizedString(@"Hold your finger on a weapon to see what it does.\nTap anywhere to dismiss.",@"")
    30 
    32 
    31 @implementation AmmoMenuViewController
    33 @implementation AmmoMenuViewController
    32 @synthesize imagesArray, buttonsArray, nameLabel, extraLabel, captionLabel, isVisible;
    34 @synthesize imagesArray, buttonsArray, nameLabel, extraLabel, captionLabel, isVisible;
    33 
    35 
    34 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    36 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    48     self.view.layer.borderColor = [[UIColor whiteColor] CGColor];
    50     self.view.layer.borderColor = [[UIColor whiteColor] CGColor];
    49     self.view.layer.borderWidth = 1.3f;
    51     self.view.layer.borderWidth = 1.3f;
    50     [self.view.layer setCornerRadius:10];
    52     [self.view.layer setCornerRadius:10];
    51     [self.view.layer setMasksToBounds:YES];
    53     [self.view.layer setMasksToBounds:YES];
    52     self.view.autoresizingMask = UIViewAutoresizingNone;
    54     self.view.autoresizingMask = UIViewAutoresizingNone;
    53     
    55     placingPoint = CGPointMake(-1, -1);
       
    56 
    54     self.isVisible = NO;
    57     self.isVisible = NO;
    55     delay = (uint8_t *)calloc(HW_getNumberOfWeapons(), sizeof(uint8_t));
    58     delay = (uint8_t *)calloc(HW_getNumberOfWeapons(), sizeof(uint8_t));
    56     HW_getAmmoDelays(delay);
    59     HW_getAmmoDelays(delay);
    57 
    60 
    58     shouldUpdateImage = (BOOL *)calloc(HW_getNumberOfWeapons(), sizeof(BOOL));
    61     shouldUpdateImage = (BOOL *)calloc(HW_getNumberOfWeapons(), sizeof(BOOL));
    66 }
    69 }
    67 
    70 
    68 -(void) appearInView:(UIView *)container {
    71 -(void) appearInView:(UIView *)container {
    69     [self viewWillAppear:YES];
    72     [self viewWillAppear:YES];
    70     [container addSubview:self.view];
    73     [container addSubview:self.view];
       
    74 
       
    75     if (placingPoint.x == -1 && placingPoint.y == -1)
       
    76         placingPoint = container.center;
    71     if (IS_DUALHEAD() == NO)
    77     if (IS_DUALHEAD() == NO)
    72         self.view.center = CGPointMake(container.center.y, container.center.x);
    78         self.view.center = CGPointMake(placingPoint.y, placingPoint.x);
    73     else {
    79     else {
    74         UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    80         UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    75         if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)
    81         if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)
    76             self.view.center = CGPointMake(container.center.y, container.center.x);
    82             self.view.center = CGPointMake(placingPoint.y, placingPoint.x);
    77         else
    83         else
    78             self.view.center = CGPointMake(container.center.x, container.center.y);
    84             self.view.center = CGPointMake(placingPoint.x, placingPoint.y);
    79     }
    85     }
    80     self.isVisible = YES;
    86     self.isVisible = YES;
    81 }
    87 }
    82 
    88 
    83 -(void) disappear {
    89 -(void) disappear {
    84     if (self.isVisible)
    90     if (self.isVisible)
    85         [self.view removeFromSuperview];
    91         [self.view removeFromSuperview];
    86     self.isVisible = NO;
    92     self.isVisible = NO;
       
    93     placingPoint.x = self.view.center.y;
       
    94     placingPoint.y = self.view.center.x;
    87 }
    95 }
    88 
    96 
    89 #pragma mark -
    97 #pragma mark -
    90 #pragma mark drawing
    98 #pragma mark drawing
    91 -(void) loadLabels {
    99 -(void) loadLabels {
   266         self.captionLabel.text = [NSString stringWithUTF8String:HW_getWeaponCaptionByIndex(theButton.tag)];
   274         self.captionLabel.text = [NSString stringWithUTF8String:HW_getWeaponCaptionByIndex(theButton.tag)];
   267 }
   275 }
   268 
   276 
   269 -(void) buttonCancelled:(id) sender {
   277 -(void) buttonCancelled:(id) sender {
   270     self.nameLabel.text = nil;
   278     self.nameLabel.text = nil;
   271     self.extraLabel.text = DEFAULT_DESCRIPTION;
   279     self.extraLabel.text = nil;
   272     self.captionLabel.text = nil;
   280     self.captionLabel.text = nil;
   273 }
   281 }
   274 
   282 
   275 -(void) buttonReleased:(id) sender {
   283 -(void) buttonReleased:(id) sender {
   276     UIButton *theButton = (UIButton *)sender;
   284     UIButton *theButton = (UIButton *)sender;
   277     if (self.nameLabel == nil || self.extraLabel == nil)
   285     if (self.nameLabel == nil || self.extraLabel == nil)
   278         [self loadLabels];
   286         [self loadLabels];
   279 
   287 
   280     self.nameLabel.text = nil;
   288     self.nameLabel.text = nil;
   281     self.extraLabel.text = DEFAULT_DESCRIPTION;
   289     self.extraLabel.text = nil;
   282     self.captionLabel.text = nil;
   290     self.captionLabel.text = nil;
   283     if (theButton.currentTitle == nil) {
   291     if (theButton.currentTitle == nil) {
   284         HW_setWeapon(theButton.tag);
   292         HW_setWeapon(theButton.tag);
   285         playSound(@"clickSound");
   293         playSound(@"clickSound");
   286         if (IS_DUALHEAD() == NO)
   294         if (IS_DUALHEAD() == NO)
   287             [self disappear];
   295             [self disappear];
   288     }
   296     }
   289 }
   297 }
   290 
   298 
   291 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   299 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   292     /*
       
   293     NSSet *allTouches = [event allTouches];
   300     NSSet *allTouches = [event allTouches];
   294 
   301 
   295     if ([touches count] == 1) {
   302     if (IS_IPAD() && [touches count] == 1) {
   296         self.view.layer.borderWidth = 3.5;
   303         self.view.layer.borderWidth = 3.5;
   297         startingPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
   304         startingPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
   298     }
   305     }
   299     */
   306 
   300     if (IS_IPAD() == NO)
   307     if (IS_IPAD() == NO)
   301         [self disappear];
   308         [self disappear];
   302 }
   309 }
   303 
   310 
   304 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   311 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   305     //self.view.layer.borderWidth = 1.3;
   312     self.view.layer.borderWidth = 1.3;
   306 }
   313 }
   307 
   314 
   308 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
   315 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
   309     /*
       
   310     NSSet *allTouches = [event allTouches];
   316     NSSet *allTouches = [event allTouches];
   311 
   317 
   312     if ([touches count] == 1) {
   318     if (IS_IPAD() && [touches count] == 1) {
   313         CGPoint touchedPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
   319         CGPoint touchedPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
   314         CGFloat deltaX = touchedPoint.x - startingPoint.x;
   320         CGFloat deltaX = touchedPoint.x - startingPoint.x;
   315         CGFloat deltaY = touchedPoint.y - startingPoint.y;
   321         CGFloat deltaY = touchedPoint.y - startingPoint.y;
   316 
   322 
   317         //startingPoint = touchedPoint;
   323         //startingPoint = touchedPoint;
   318         self.view.frame = CGRectMake(self.view.frame.origin.x + deltaX, self.view.frame.origin.y + deltaY,
   324         self.view.frame = CGRectMake(self.view.frame.origin.x + deltaX, self.view.frame.origin.y + deltaY,
   319                                      self.view.frame.size.width, self.view.frame.size.height);
   325                                      self.view.frame.size.width, self.view.frame.size.height);
   320     }
   326     }
   321     */
       
   322 }
   327 }
   323 
   328 
   324 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
   329 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
   325     //[self touchesEnded:touches withEvent:event];
   330     [self touchesEnded:touches withEvent:event];
   326 }
   331 }
   327 
   332 
   328 #pragma mark -
   333 #pragma mark -
   329 #pragma mark memory
   334 #pragma mark memory
   330 -(void) didReceiveMemoryWarning {
   335 -(void) didReceiveMemoryWarning {