project_files/HedgewarsMobile/Classes/SquareButtonView.m
changeset 6078 8c0cc07731e5
parent 5208 878e551f0b4a
child 6700 e04da46ee43c
equal deleted inserted replaced
6077:d8fa5a85d24f 6078:8c0cc07731e5
    19  */
    19  */
    20 
    20 
    21 
    21 
    22 #import "SquareButtonView.h"
    22 #import "SquareButtonView.h"
    23 #import <QuartzCore/QuartzCore.h>
    23 #import <QuartzCore/QuartzCore.h>
    24 #import "CommodityFunctions.h"
    24 
    25 #import "UIImageExtra.h"
       
    26 
    25 
    27 @implementation SquareButtonView
    26 @implementation SquareButtonView
    28 @synthesize colorArray, selectedColor, ownerDictionary;
    27 @synthesize colorArray, selectedColor, ownerDictionary;
    29 
    28 
    30 -(id) initWithFrame:(CGRect)frame {
    29 -(id) initWithFrame:(CGRect)frame {
    31     if ((self = [super initWithFrame:frame])) {
    30     if ((self = [super initWithFrame:frame])) {
    32         colorIndex = -1;
    31         colorIndex = -1;
    33         selectedColor = 0;
    32         selectedColor = 0;
    34 
    33 
    35         self.colorArray = getAvailableColors();
    34         self.colorArray = [HWUtils teamColors];
    36 
    35 
    37         // set the color to the first available one
    36         // set the color to the first available one
    38         [self nextColor];
    37         [self nextColor];
    39 
    38 
    40         // this makes the button round and nice with a border
    39         // this makes the button round and nice with a border
    41         [self.layer setCornerRadius:7.0f];
    40         [self.layer setCornerRadius:7.0f];
    42         [self.layer setMasksToBounds:YES];
    41         [self.layer setMasksToBounds:YES];
    43         [self.layer setBorderWidth:2];
    42         [self.layer setBorderWidth:2];
    44         [self.layer setBorderColor:[UICOLOR_HW_YELLOW_BODER CGColor]];
    43         [self.layer setBorderColor:[[UIColor darkYellowColor] CGColor]];
    45 
    44 
    46         // this changes the color at button press
    45         // this changes the color at button press
    47         [self addTarget:self action:@selector(nextColor) forControlEvents:UIControlEventTouchUpInside];
    46         [self addTarget:self action:@selector(nextColor) forControlEvents:UIControlEventTouchUpInside];
    48     }
    47     }
    49     return self;
    48     return self;
    65 }
    64 }
    66 
    65 
    67 -(void) selectColor:(NSUInteger) color {
    66 -(void) selectColor:(NSUInteger) color {
    68     if (color != selectedColor) {
    67     if (color != selectedColor) {
    69         selectedColor = color;
    68         selectedColor = color;
    70         colorIndex = [colorArray indexOfObject:[NSNumber numberWithUnsignedInt:color]];
    69         colorIndex = [self.colorArray indexOfObject:[NSNumber numberWithUnsignedInt:color]];
    71 
    70 
    72         self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f
    71         self.backgroundColor = [UIColor colorWithRed:((color & 0x00FF0000) >> 16)/255.0f
    73                                                green:((color & 0x0000FF00) >> 8)/255.0f
    72                                                green:((color & 0x0000FF00) >> 8)/255.0f
    74                                                 blue: (color & 0x000000FF)/255.0f
    73                                                 blue: (color & 0x000000FF)/255.0f
    75                                                alpha:1.0f];
    74                                                alpha:1.0f];