Advertisement
Guest User

Untitled

a guest
Sep 20th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.53 KB | None | 0 0
  1. //
  2. // PlayButton.m
  3. //
  4. // Created by Alexander Behrhof on 5/25/15.
  5. // Copyright (c) 2015 Alexander Behrhof. All rights reserved.
  6. //
  7.  
  8. #import "PlayButton.h"
  9. #import "JSONModelLib.h"
  10. #import "PlayHelper.h"
  11.  
  12. @implementation PlayButton
  13.  
  14. - (void)createTrackingArea
  15. {
  16. NSTrackingAreaOptions focusTrackingAreaOptions = NSTrackingActiveInActiveApp;
  17. focusTrackingAreaOptions |= NSTrackingMouseEnteredAndExited;
  18. focusTrackingAreaOptions |= NSTrackingAssumeInside;
  19. focusTrackingAreaOptions |= NSTrackingInVisibleRect;
  20.  
  21. NSTrackingArea *focusTrackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect
  22. options:focusTrackingAreaOptions owner:self userInfo:nil];
  23. [self addTrackingArea:focusTrackingArea];
  24. }
  25.  
  26. - (void) awakeFromNib {
  27. [self createTrackingArea];
  28. }
  29.  
  30. - (void) mouseEntered: (NSEvent *) theEvent {
  31. if ([self isEnabled]) {
  32. [self setImage:[NSImage imageNamed:@"PLAY_ROLLOVER"]];
  33. }
  34. }
  35.  
  36. - (void) mouseExited: (NSEvent *) theEvent {
  37. if ([self isEnabled]) {
  38. [self setImage:[NSImage imageNamed:@"PLAY_NORMAL"]];
  39. }
  40. }
  41. - (void) mouseUp: (NSEvent*) theEvent {
  42. if ([self isEnabled]) {
  43. [self setImage:[NSImage imageNamed:@"PLAY_NORMAL"]];
  44. }
  45. }
  46.  
  47. - (void) mouseDown: (NSEvent*) theEvent {
  48. if ([self isEnabled]) {
  49. [self setImage:[NSImage imageNamed:@"PLAY_DOWN"]];
  50. AppDelegate *appDelegate = (AppDelegate *) [[NSApplication sharedApplication] delegate];
  51. NSTextField *_TextUser = appDelegate.TextUser;
  52. NSTextField *_TextPassword = appDelegate.TextPassword;
  53.  
  54. #define allTrim( object ) [object stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet] ]
  55.  
  56. [self setEnabled: NO];
  57.  
  58. [appDelegate.LabelInfo setTitle:@"Contacting the Toon Council..."];
  59. [appDelegate.TextUser setEditable: NO];
  60. [appDelegate.TextUser setTextColor:[NSColor disabledControlTextColor]];
  61.  
  62. [appDelegate.TextPassword setEditable: NO];
  63. [appDelegate.TextPassword setTextColor:[NSColor disabledControlTextColor]];
  64. NSString *UsernameCheck = _TextUser.stringValue;
  65. NSString *PasswordCheck = _TextPassword.stringValue;
  66.  
  67. NSAlert *alert = [[NSAlert alloc] init];
  68. [alert addButtonWithTitle:@"Dismiss"];
  69.  
  70. if ( [allTrim( UsernameCheck ) length] == 0 || [allTrim( PasswordCheck ) length] == 0 ) {
  71. [appDelegate.LabelInfo setTitle:@"Please Login!"];
  72.  
  73. [alert setMessageText:@"Yikes!"];
  74. [alert setInformativeText:@"You must enter both your username and password."];
  75. [alert runModal];
  76.  
  77. [self setEnabled: YES];
  78. [_TextUser setEditable: YES];
  79. [_TextUser setTextColor:[NSColor controlTextColor]];
  80. [_TextPassword setEditable: YES];
  81. [_TextPassword setTextColor:[NSColor controlTextColor]];
  82. return;
  83. }
  84.  
  85. if ( [allTrim( UsernameCheck ) length] != 0 && [allTrim( PasswordCheck ) length] != 0 ) {
  86. [[JSONHTTPClient requestHeaders] setValue:@"application/x-www-form-urlencoded" forKey:@"Content-Type"];
  87.  
  88. //make post, get requests
  89. [JSONHTTPClient postJSONFromURLWithString:@"http://lw2.ez-webz.com/api/login?format=json" params:@{@"username":_TextUser.stringValue, @"password":_TextPassword.stringValue} completion:^(NSDictionary *json, JSONModelError *err) {
  90. NSString *success = json[@"success"];
  91.  
  92. if ([success isEqualToString:@"true"]) {
  93. [PlayHelper startGame:json];
  94. } else if ([success isEqualToString:@"false"]) {
  95.  
  96. [self setEnabled: YES];
  97. [appDelegate.TextUser setEditable: YES];
  98. [appDelegate.TextUser setTextColor:[NSColor controlTextColor]];
  99. [appDelegate.TextPassword setEditable: YES];
  100. [appDelegate.TextPassword setTextColor:[NSColor controlTextColor]];
  101. _TextPassword.stringValue=@"";
  102. [appDelegate.LabelInfo setTitle:@"Please Login!"];
  103.  
  104. [alert setMessageText:@"Yikes!"];
  105. [alert setInformativeText:json[@"banner"]];
  106. [alert runModal];
  107.  
  108. } else if ([success isEqualToString:@"partial"]) {
  109.  
  110. [appDelegate.twoAuthWindow makeKeyAndOrderFront:self];
  111. appDelegate.TextAuthToken=json[@"responseToken"];
  112.  
  113. } else if ([success isEqualToString:@"delayed"]) {
  114. NSString *string_eta = [NSString stringWithFormat:@"You'll be in-game in around %@s", json[@"eta"]];
  115. [appDelegate.LabelInfo setTitle:string_eta];
  116. [JSONHTTPClient postJSONFromURLWithString:@"http://lw2.ez-webz.com/api/login?format=json" params:@{@"queueToken":json[@"queueToken"]} completion:^(NSDictionary *json, JSONModelError *err) {
  117. NSString *success = json[@"success"];
  118.  
  119. if ([success isEqualToString:@"true"]) {
  120. [PlayHelper startGame:json];
  121. } else {
  122. [self setEnabled: YES];
  123. [appDelegate.TextUser setEditable: YES];
  124. [appDelegate.TextUser setTextColor:[NSColor controlTextColor]];
  125. [appDelegate.TextPassword setEditable: YES];
  126. [appDelegate.TextPassword setTextColor:[NSColor controlTextColor]];
  127. _TextPassword.stringValue=@"";
  128. [appDelegate.LabelInfo setTitle:@"Please Login!"];
  129.  
  130. [alert setMessageText:@"Yikes!"];
  131. [alert setInformativeText:json[@"banner"]];
  132. [alert runModal];
  133. }
  134. }];
  135. } else {
  136. [alert setMessageText:@"Yikes!"];
  137. [alert setInformativeText:@"An error has occurred"];
  138. [alert runModal];
  139. }
  140. if (err) {
  141. [alert setMessageText:@"Yikes!"];
  142. [alert setInformativeText:@"An error has occurred"];
  143. [alert runModal];
  144. }
  145. }];
  146. }
  147. }
  148. }
  149.  
  150. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement