/
CombatCountConditionController.m
67 lines (51 loc) · 1.89 KB
/
CombatCountConditionController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// CombatCountConditionController.m
// Pocket Gnome
//
// Created by Jon Drummond on 8/17/08.
// Copyright 2008 Jon Drummond. All rights reserved.
//
#import "CombatCountConditionController.h"
@implementation CombatCountConditionController
- (id) init {
self = [super init];
if (self != nil) {
if(![NSBundle loadNibNamed: @"CombatCount" owner: self]) {
log(LOG_GENERAL, @"Error loading CombatCount.nib.");
[self release];
self = nil;
}
}
return self;
}
- (IBAction)validateState: (id)sender {
if( ([comparatorSegment selectedTag] == CompareLess) && ([valueText intValue] == 0)) {
[comparatorSegment selectSegmentWithTag: CompareEqual];
NSBeep();
}
if([valueText intValue] < 0) {
[valueText setIntValue: 0];
}
}
- (Condition*)condition {
[self validateState: nil];
int value = [valueText intValue];
if(value < 0) value = 0;
Condition *condition = [Condition conditionWithVariety: VarietyCombatCount
unit: UnitPlayer
quality: QualityNone
comparator: [comparatorSegment selectedTag]
state: value
type: TypeNone
value: nil];
[condition setEnabled: self.enabled];
return condition;
}
- (void)setStateFromCondition: (Condition*)condition {
[super setStateFromCondition: condition];
if( [condition variety] != VarietyCombatCount) return;
[comparatorSegment selectSegmentWithTag: [condition comparator]];
[valueText setStringValue: [NSString stringWithFormat: @"%d", [condition state]]];
[self validateState: nil];
}
@end