CoverView.m
上传用户:qhdwjd2004
上传日期:2020-12-29
资源大小:362k
文件大小:3k
源码类别:

iPhone

开发平台:

Objective-C

  1. #import "CoverView.h"
  2. #import "MainView.h"
  3. @implementation CoverView
  4. - (id)initWithFrame:(CGRect)rect
  5. {
  6.     if ((self == [ super initWithFrame: rect ]) != nil) {
  7.         // Start New Game
  8.         StartImage = [UIImage applicationImageNamed: @"images/btnstart.png"];
  9.         // Continue
  10.         if(canContinue = [Map CheckMessExist])
  11.         {
  12.             ContinueImage = [UIImage applicationImageNamed: @"images/btncontinue1.png"];
  13.         }
  14.         else
  15.         {
  16.             ContinueImage = [UIImage applicationImageNamed: @"images/btncontinue2.png"];
  17.         }
  18.         // Load Stage
  19.     CustomImage = [UIImage applicationImageNamed: @"images/btncustom.png"];
  20.         // About
  21.     AboutGameImage = [UIImage applicationImageNamed: @"images/btnabout.png"];
  22.         int i;
  23.         for(i=0;i<MenuNumber;i++)
  24.         {
  25.             menu[i] = CGRectMake(MenuX, MenuY + i*MenuItemHeight + MenuSplit, MenuWidth, MenuItemHeight);
  26.         }
  27.     }
  28.     return self;
  29. }
  30. - (void)drawRect:(CGRect)rect
  31. {
  32.     [ StartImage draw1PartImageInRect: menu[0] ];
  33.     [ ContinueImage draw1PartImageInRect: menu[1] ];
  34.     [ CustomImage draw1PartImageInRect: menu[2] ];
  35.     [ AboutGameImage draw1PartImageInRect: menu[3] ];
  36. }
  37. - (void)dealloc
  38. {
  39.     [StartImage release];
  40.     [ContinueImage release];
  41.     [CustomImage release];
  42.     [AboutGameImage release];
  43.     [ self dealloc ];
  44.     [ super dealloc];
  45. }
  46. - (void)updateview
  47. {
  48.     if(canContinue = [Map CheckMessExist])
  49.     {
  50.         ContinueImage = [UIImage applicationImageNamed: @"images/btncontinue1.png"];
  51.     }
  52.     else
  53.     {
  54.         ContinueImage = [UIImage applicationImageNamed: @"images/btncontinue2.png"];
  55.     }
  56.     [self setNeedsDisplayInRect:menu[1]];
  57. }
  58. - (void)setParentView:(UIView*)view;
  59. {
  60.     parentView = view;
  61. }
  62. - (void)mouseDown: (struct __GSEvent *)event
  63. {
  64.     MainView *mView = (MainView *)parentView;
  65.     CGPoint p = GSEventGetInnerMostPathPosition(event);
  66.     if([self isPoint:p InRect:menu[0]])
  67.     {
  68.         [mView startGame];
  69.         return;
  70.     }
  71.     if([self isPoint:p InRect:menu[1]])
  72.     {
  73.         if(canContinue)
  74.         {
  75.             [mView continueGame];
  76.         }
  77.         return;
  78.     }
  79.     if([self isPoint:p InRect:menu[2]])
  80.     {
  81.         [(MainView*)mView customGame:NO];
  82.         return;
  83.     }
  84.     if([self isPoint:p InRect:menu[3]])
  85.     {
  86.         [mView showAbout];
  87.         return;
  88.     }
  89. }
  90. - (bool)isPoint:(CGPoint)pt InRect:(CGRect)rect 
  91. {
  92.     if(pt.x>rect.origin.x && pt.x < rect.origin.x + rect.size.width
  93.        && pt.y>rect.origin.y && pt.y < rect.origin.y + rect.size.height)
  94.     {
  95.         return YES;
  96.     }
  97.     else
  98.     {
  99.         return NO;
  100.     }
  101. }
  102. @end