project_files/HedgewarsMobile/Classes/HoldTableViewCell.m
author koda
Wed, 02 Nov 2011 16:31:16 +0100
changeset 6261 7050772ae46a
parent 6115 485cfecadc9a
child 6700 e04da46ee43c
permissions -rw-r--r--
remove the need of saving the calling controller (disabling stats, but they were already broken by a previous commit)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4476
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
     1
/*
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4486
diff changeset
     3
 * Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com>
4476
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
     4
 *
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
     8
 *
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    12
 * GNU General Public License for more details.
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    13
 *
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    17
 *
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    18
 * File created on 03/07/2010.
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    19
 */
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    20
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    21
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    22
#import "HoldTableViewCell.h"
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    23
#import "CGPointUtils.h"
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    24
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    25
@implementation HoldTableViewCell
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    26
@synthesize delegate;
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    27
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    28
#define SWIPE_DRAG_HORIZ_MIN 10
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    29
#define SWIPE_DRAG_VERT_MAX 40
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    30
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    31
-(id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    32
    if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    33
        delegate = nil;
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    34
    }
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    35
    return self;
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    36
}
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    37
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    38
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
4486
2c8e4d859d37 fix crasher (somehow, might be glitchy)
koda
parents: 4476
diff changeset
    39
    UITouch *touch = [[event allTouches] anyObject];
2c8e4d859d37 fix crasher (somehow, might be glitchy)
koda
parents: 4476
diff changeset
    40
    
2c8e4d859d37 fix crasher (somehow, might be glitchy)
koda
parents: 4476
diff changeset
    41
    time = touch.timestamp; 
2c8e4d859d37 fix crasher (somehow, might be glitchy)
koda
parents: 4476
diff changeset
    42
    [self performSelector:@selector(holdAction) withObject:nil afterDelay:0.25];
4476
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    43
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    44
    [super touchesBegan:touches withEvent:event];
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    45
}
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    46
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    47
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
4486
2c8e4d859d37 fix crasher (somehow, might be glitchy)
koda
parents: 4476
diff changeset
    48
    UITouch *touch = [[event allTouches] anyObject];
2c8e4d859d37 fix crasher (somehow, might be glitchy)
koda
parents: 4476
diff changeset
    49
    
2c8e4d859d37 fix crasher (somehow, might be glitchy)
koda
parents: 4476
diff changeset
    50
    if ( touch.timestamp - time < 0.25 ) {
2c8e4d859d37 fix crasher (somehow, might be glitchy)
koda
parents: 4476
diff changeset
    51
        [NSObject cancelPreviousPerformRequestsWithTarget:self
2c8e4d859d37 fix crasher (somehow, might be glitchy)
koda
parents: 4476
diff changeset
    52
                                                 selector:@selector(holdAction)
2c8e4d859d37 fix crasher (somehow, might be glitchy)
koda
parents: 4476
diff changeset
    53
                                                   object:nil];
2c8e4d859d37 fix crasher (somehow, might be glitchy)
koda
parents: 4476
diff changeset
    54
        
2c8e4d859d37 fix crasher (somehow, might be glitchy)
koda
parents: 4476
diff changeset
    55
        [super touchesEnded:touches withEvent:event];
2c8e4d859d37 fix crasher (somehow, might be glitchy)
koda
parents: 4476
diff changeset
    56
    } else
2c8e4d859d37 fix crasher (somehow, might be glitchy)
koda
parents: 4476
diff changeset
    57
        [super touchesCancelled:touches withEvent:event];
4476
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    58
}
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    59
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    60
-(void) holdAction {
6115
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 4976
diff changeset
    61
    if (self.delegate != nil && [self.delegate respondsToSelector:@selector(holdAction:onTable:)])
485cfecadc9a HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents: 4976
diff changeset
    62
        [self.delegate holdAction:self.textLabel.text onTable:(UITableView *)self.superview];
4476
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    63
}
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    64
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    65
-(void) dealloc {
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    66
    self.delegate = nil;
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    67
    [super dealloc];
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    68
}
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    69
4bf74e158f44 team selection completely refactored, now has animation and more performance
koda
parents:
diff changeset
    70
@end