335 |
337 |
336 |
338 |
337 #pragma mark - |
339 #pragma mark - |
338 #pragma mark Custom touch event handling |
340 #pragma mark Custom touch event handling |
339 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
341 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
340 NSArray *twoTouches; |
342 NSSet *allTouches = [event allTouches]; |
341 UITouch *touch = [touches anyObject]; |
343 UITouch *touch, *first, *second; |
342 CGRect screen = [[UIScreen mainScreen] bounds]; |
|
343 CGPoint currentPosition = [touch locationInView:self.view]; |
|
344 |
344 |
345 if (isPopoverVisible) { |
345 if (isPopoverVisible) { |
346 [self dismissPopover]; |
346 [self dismissPopover]; |
347 } |
347 } |
348 /* |
348 /* |
349 if (writeChatTextField) { |
349 if (writeChatTextField) { |
350 [self.writeChatTextField resignFirstResponder]; |
350 [self.writeChatTextField resignFirstResponder]; |
351 [dimTimer setFireDate:HIDING_TIME_DEFAULT]; |
351 [dimTimer setFireDate:HIDING_TIME_DEFAULT]; |
352 } |
352 } |
353 */ |
353 */ |
354 |
354 |
355 if (currentPosition.y < screen.size.width - 130 || (currentPosition.x > 130 && currentPosition.x < screen.size.height - 130)) { |
355 switch ([allTouches count]) { |
356 switch ([touches count]) { |
356 case 1: |
357 case 1: |
357 touch = [[allTouches allObjects] objectAtIndex:0]; |
358 //DLog(@"X:%d Y:%d", HWX(currentPosition.x), HWY(currentPosition.y)); |
358 CGPoint currentPosition = [touch locationInView:self.view]; |
359 // this is a single touch/tap |
359 |
360 isSingleClick = YES; |
360 //DLog(@"X:%d Y:%d", HWX(currentPosition.x), HWY(currentPosition.y)); |
361 // save were the click event will take place |
361 // this is a single touch/tap |
362 pointWhereToClick = currentPosition; |
362 isSingleClick = YES; |
363 |
363 // save were the click event will take place |
364 [[self.view viewWithTag:5599] removeFromSuperview]; |
364 pointWhereToClick = currentPosition; |
365 if (2 == [touch tapCount]) |
365 |
366 HW_zoomReset(); |
366 removeConfirmationInput(); |
367 break; |
367 if (2 == [touch tapCount]) |
368 case 2: |
368 HW_zoomReset(); |
369 // pinching |
369 break; |
370 twoTouches = [touches allObjects]; |
370 case 2: |
371 UITouch *first = [twoTouches objectAtIndex:0]; |
371 // pinching |
372 UITouch *second = [twoTouches objectAtIndex:1]; |
372 first = [[allTouches allObjects] objectAtIndex:0]; |
373 initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
373 second = [[allTouches allObjects] objectAtIndex:1]; |
374 break; |
374 initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
375 default: |
375 break; |
376 break; |
376 default: |
377 } |
377 break; |
378 } |
378 } |
379 } |
379 } |
|
380 |
|
381 //if (currentPosition.y < screen.size.width - 130 || (currentPosition.x > 130 && currentPosition.x < screen.size.height - 130)) { |
380 |
382 |
381 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
383 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
382 CGRect screen = [[UIScreen mainScreen] bounds]; |
384 CGRect screen = [[UIScreen mainScreen] bounds]; |
383 //HW_allKeysUp(); |
385 NSSet *allTouches = [event allTouches]; |
384 if (HW_isAmmoOpen()) { |
386 UITouch *touch; |
385 // if we're in the menu we just click in the point |
387 |
386 HW_setCursor(HWX(pointWhereToClick.x), HWY(pointWhereToClick.y)); |
388 switch ([allTouches count]) { |
387 HW_click(); |
389 case 1: |
388 } else |
390 if (HW_isAmmoOpen()) { |
389 if (isSingleClick) { |
391 // if we're in the menu we just click in the point |
390 // if they tapped in the screen we trick the system so that camera doesn't move |
392 HW_setCursor(HWX(pointWhereToClick.x), HWY(pointWhereToClick.y)); |
391 HW_saveCursor(FALSE); |
393 HW_click(); |
392 HW_setCursor(HWX(pointWhereToClick.x), HWY(pointWhereToClick.y)); |
394 } else |
393 HW_click(); |
395 if (isSingleClick) { |
394 HW_saveCursor(TRUE); |
396 // if they tapped in the screen we trick the system so that camera doesn't move |
395 |
397 HW_saveCursor(FALSE); |
396 // and remove the label (if any) |
398 HW_setCursor(HWX(pointWhereToClick.x), HWY(pointWhereToClick.y)); |
397 [[self.view viewWithTag:5599] removeFromSuperview]; |
399 HW_click(); |
398 } else { |
400 HW_saveCursor(TRUE); |
399 // if weapon requires a further click, ask for tapping again |
401 |
400 if (HW_isWeaponRequiringClick()) { |
402 // and remove the label (if any) |
401 CGPoint currentPosition = [[touches anyObject] locationInView:self.view]; |
403 removeConfirmationInput(); |
402 UILabel *tapAgain = [[UILabel alloc] initWithFrame:CGRectMake(currentPosition.x-100, currentPosition.y + 10, 200, 25)]; |
404 } else { |
403 tapAgain.text = NSLocalizedString(@"Tap again to confirm",@"from the overlay"); |
405 // if weapon requires a further click, ask for tapping again |
404 tapAgain.backgroundColor = [UIColor clearColor]; |
406 if (HW_isWeaponRequiringClick()) { |
405 tapAgain.tag = 5599; |
407 touch = [[allTouches allObjects] objectAtIndex:0]; |
406 tapAgain.textColor = [UIColor blueColor]; |
408 CGPoint currentPosition = [touch locationInView:self.view]; |
407 tapAgain.textAlignment = UITextAlignmentCenter; |
409 UILabel *tapAgain = [[UILabel alloc] initWithFrame:CGRectMake(currentPosition.x-100, currentPosition.y + 10, 200, 25)]; |
408 tapAgain.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
410 tapAgain.text = NSLocalizedString(@"Tap again to confirm",@"from the overlay"); |
409 [self.view addSubview:tapAgain]; |
411 tapAgain.backgroundColor = [UIColor clearColor]; |
410 [tapAgain release]; |
412 tapAgain.tag = CONFIRMATION_TAG; |
411 } |
413 tapAgain.textColor = [UIColor blueColor]; |
412 } |
414 tapAgain.textAlignment = UITextAlignmentCenter; |
413 |
415 tapAgain.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
|
416 [self.view addSubview:tapAgain]; |
|
417 [tapAgain release]; |
|
418 } |
|
419 } |
|
420 break; |
|
421 case 2: |
|
422 HW_allKeysUp(); |
|
423 break; |
|
424 } |
|
425 |
414 pointWhereToClick = CGPointZero; |
426 pointWhereToClick = CGPointZero; |
415 initialDistanceForPinching = 0; |
427 initialDistanceForPinching = 0; |
416 isSingleClick = NO; |
428 isSingleClick = NO; |
417 } |
429 } |
418 |
430 |
419 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
431 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
420 // this can happen if the user puts more than 5 touches on the screen at once, or perhaps in other circumstances |
|
421 [self touchesEnded:touches withEvent:event]; |
432 [self touchesEnded:touches withEvent:event]; |
422 } |
433 } |
423 |
434 |
424 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
435 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
425 CGRect screen = [[UIScreen mainScreen] bounds]; |
436 CGRect screen = [[UIScreen mainScreen] bounds]; |
426 |
437 NSSet *allTouches = [event allTouches]; |
427 NSArray *twoTouches; |
438 |
428 CGPoint currentPosition; |
439 UITouch *touch, *first, *second; |
429 UITouch *touch = [touches anyObject]; |
440 |
430 |
441 switch ([allTouches count]) { |
431 switch ([touches count]) { |
|
432 case 1: |
442 case 1: |
|
443 touch = [[allTouches allObjects] objectAtIndex:0]; |
|
444 CGPoint currentPosition = [touch locationInView:self.view]; |
433 isSingleClick = NO; |
445 isSingleClick = NO; |
434 currentPosition = [touch locationInView:self.view]; |
|
435 if (HW_isAmmoOpen()) { |
446 if (HW_isAmmoOpen()) { |
436 // saves the point on which to select the ammo |
447 // saves the point on which to select the ammo |
437 pointWhereToClick = currentPosition; |
448 pointWhereToClick = currentPosition; |
438 // moves the cursor over |
449 // moves the cursor over |
439 HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
450 HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |