351 [dimTimer setFireDate:HIDING_TIME_DEFAULT]; |
351 [dimTimer setFireDate:HIDING_TIME_DEFAULT]; |
352 } |
352 } |
353 */ |
353 */ |
354 |
354 |
355 switch ([allTouches count]) { |
355 switch ([allTouches count]) { |
356 case 1: |
356 case 1: |
357 touch = [[allTouches allObjects] objectAtIndex:0]; |
|
358 CGPoint currentPosition = [touch locationInView:self.view]; |
|
359 |
|
360 //DLog(@"X:%d Y:%d", HWX(currentPosition.x), HWY(currentPosition.y)); |
|
361 // this is a single touch/tap |
|
362 isSingleClick = YES; |
|
363 // save were the click event will take place |
|
364 pointWhereToClick = currentPosition; |
|
365 |
|
366 removeConfirmationInput(); |
357 removeConfirmationInput(); |
367 if (2 == [touch tapCount]) |
358 if (2 == [[[allTouches allObjects] objectAtIndex:0] tapCount]) |
368 HW_zoomReset(); |
359 HW_zoomReset(); |
369 break; |
360 break; |
370 case 2: |
361 case 2: |
371 // pinching |
362 // pinching |
372 first = [[allTouches allObjects] objectAtIndex:0]; |
363 first = [[allTouches allObjects] objectAtIndex:0]; |
381 //if (currentPosition.y < screen.size.width - 130 || (currentPosition.x > 130 && currentPosition.x < screen.size.height - 130)) { |
372 //if (currentPosition.y < screen.size.width - 130 || (currentPosition.x > 130 && currentPosition.x < screen.size.height - 130)) { |
382 |
373 |
383 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
374 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
384 CGRect screen = [[UIScreen mainScreen] bounds]; |
375 CGRect screen = [[UIScreen mainScreen] bounds]; |
385 NSSet *allTouches = [event allTouches]; |
376 NSSet *allTouches = [event allTouches]; |
386 UITouch *touch; |
377 CGPoint currentPosition = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view]; |
387 |
378 |
388 switch ([allTouches count]) { |
379 switch ([allTouches count]) { |
389 case 1: |
380 case 1: |
|
381 // if we're in the menu we just click in the point |
390 if (HW_isAmmoOpen()) { |
382 if (HW_isAmmoOpen()) { |
391 // if we're in the menu we just click in the point |
383 HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
392 HW_setCursor(HWX(pointWhereToClick.x), HWY(pointWhereToClick.y)); |
384 // this click doesn't need any wrapping because the ammoMenu already limits the cursor |
393 HW_click(); |
385 HW_click(); |
394 } else |
386 } else |
395 if (isSingleClick) { |
387 // if weapon requires a further click, ask for tapping again |
396 // if they tapped in the screen we trick the system so that camera doesn't move |
388 if (HW_isWeaponRequiringClick()) { |
397 HW_saveCursor(FALSE); |
389 // here don't have to wrap thanks to isCursorVisible magic |
398 HW_setCursor(HWX(pointWhereToClick.x), HWY(pointWhereToClick.y)); |
390 HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
399 HW_click(); |
|
400 HW_saveCursor(TRUE); |
|
401 |
391 |
402 // and remove the label (if any) |
392 // draw the button at the last touched point (which is the current position) |
403 removeConfirmationInput(); |
393 UIButton *tapAgain = [UIButton buttonWithType:UIButtonTypeRoundedRect]; |
404 } else { |
394 tapAgain.frame = CGRectMake(currentPosition.x - 90, currentPosition.y + 15, 180, 30); |
405 // if weapon requires a further click, ask for tapping again |
395 tapAgain.tag = CONFIRMATION_TAG; |
406 if (HW_isWeaponRequiringClick()) { |
396 tapAgain.alpha = 0; |
407 touch = [[allTouches allObjects] objectAtIndex:0]; |
397 [tapAgain addTarget:self action:@selector(sendHWClick) forControlEvents:UIControlEventTouchUpInside]; |
408 CGPoint currentPosition = [touch locationInView:self.view]; |
398 [tapAgain setTitle:NSLocalizedString(@"Tap again to confirm",@"from the overlay") forState:UIControlStateNormal]; |
409 UILabel *tapAgain = [[UILabel alloc] initWithFrame:CGRectMake(currentPosition.x-100, currentPosition.y + 10, 200, 25)]; |
399 [self.view addSubview:tapAgain]; |
410 tapAgain.text = NSLocalizedString(@"Tap again to confirm",@"from the overlay"); |
400 |
411 tapAgain.backgroundColor = [UIColor clearColor]; |
401 // animation ftw! |
412 tapAgain.tag = CONFIRMATION_TAG; |
402 [UIView beginAnimations:@"inserting button" context:NULL]; |
413 tapAgain.textColor = [UIColor blueColor]; |
403 [UIView setAnimationDuration:ANIMATION_DURATION]; |
414 tapAgain.textAlignment = UITextAlignmentCenter; |
404 [self.view viewWithTag:CONFIRMATION_TAG].alpha = 1; |
415 tapAgain.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
405 [UIView commitAnimations]; |
416 [self.view addSubview:tapAgain]; |
|
417 [tapAgain release]; |
|
418 } |
|
419 } |
406 } |
420 break; |
407 break; |
421 case 2: |
408 case 2: |
422 HW_allKeysUp(); |
409 HW_allKeysUp(); |
423 break; |
410 break; |
424 } |
411 default: |
425 |
412 DLog(@"too many touches"); |
426 pointWhereToClick = CGPointZero; |
413 break; |
|
414 } |
|
415 |
427 initialDistanceForPinching = 0; |
416 initialDistanceForPinching = 0; |
428 isSingleClick = NO; |
417 } |
|
418 |
|
419 -(void) sendHWClick { |
|
420 HW_click(); |
|
421 removeConfirmationInput(); |
429 } |
422 } |
430 |
423 |
431 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
424 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
432 [self touchesEnded:touches withEvent:event]; |
425 [self touchesEnded:touches withEvent:event]; |
433 } |
426 } |
440 |
433 |
441 switch ([allTouches count]) { |
434 switch ([allTouches count]) { |
442 case 1: |
435 case 1: |
443 touch = [[allTouches allObjects] objectAtIndex:0]; |
436 touch = [[allTouches allObjects] objectAtIndex:0]; |
444 CGPoint currentPosition = [touch locationInView:self.view]; |
437 CGPoint currentPosition = [touch locationInView:self.view]; |
445 isSingleClick = NO; |
438 |
446 if (HW_isAmmoOpen()) { |
439 if (HW_isAmmoOpen()) { |
447 // saves the point on which to select the ammo |
440 // moves the cursor around |
448 pointWhereToClick = currentPosition; |
|
449 // moves the cursor over |
|
450 HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
441 HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
451 } else { |
442 } else { |
452 DLog(@"x: %f y: %f -> X:%d Y:%d", currentPosition.x, currentPosition.y, HWX(currentPosition.x), HWY(currentPosition.y)); |
443 DLog(@"x: %f y: %f -> X:%d Y:%d", currentPosition.x, currentPosition.y, HWX(currentPosition.x), HWY(currentPosition.y)); |
453 HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
444 HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
454 } |
445 } |