Adds Hit Dice and Custom HP to monster edit form.

This commit is contained in:
2020-09-25 04:47:23 -07:00
parent 6341081fde
commit f23fe12e7b

View File

@@ -9,6 +9,7 @@
#import "EditMonsterViewController.h" #import "EditMonsterViewController.h"
#import "MCShortStringFieldTableViewCell.h" #import "MCShortStringFieldTableViewCell.h"
#import "MCIntegerFieldTableViewCell.h" #import "MCIntegerFieldTableViewCell.h"
#import "MCBooleanFieldTableViewCell.h"
#import "AppDelegate.h" #import "AppDelegate.h"
@interface EditMonsterViewController () @interface EditMonsterViewController ()
@@ -18,7 +19,8 @@
@end @end
const int kSectionIndexBasicInfo = 0; const int kSectionIndexBasicInfo = 0;
const int kSectionIndexAbilityScores = 1; const int kSectionIndexArmor = 1;
const int kSectionIndexAbilityScores = 2;
const int kBasicInfoSectionRowIndexName = 0; const int kBasicInfoSectionRowIndexName = 0;
const int kBasicInfoSectionRowIndexSize = 1; const int kBasicInfoSectionRowIndexSize = 1;
@@ -26,6 +28,10 @@ const int kBasicInfoSectionRowIndexType = 2;
const int kBasicInfoSectionRowIndexSubtype = 3; const int kBasicInfoSectionRowIndexSubtype = 3;
const int kBasicInfoSectionRowIndexAlignment = 4; const int kBasicInfoSectionRowIndexAlignment = 4;
const int kArmorSectionRowIndexHitDice = 0;
const int kArmorSectionRowIndexCustomHP = 1;
const int kArmorSectionRowIndexCustomHPText = 2;
const int kAbilityScoreSectionRowIndexStrength = 0; const int kAbilityScoreSectionRowIndexStrength = 0;
const int kAbilityScoreSectionRowIndexDexterity = 1; const int kAbilityScoreSectionRowIndexDexterity = 1;
const int kAbilityScoreSectionRowIndexConstitution = 2; const int kAbilityScoreSectionRowIndexConstitution = 2;
@@ -95,6 +101,22 @@ const int kAbilityScoreSectionRowIndexCharisma = 5;
return cell; return cell;
} }
- (MCBooleanFieldTableViewCell*) makeBooleanCellFromTableView:(UITableView*)tableView
withIdentifier:(NSString*)identifier
label:(NSString*)label
andInitialValue:(BOOL)initialValue {
MCBooleanFieldTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MCBooleanField"];
if (!cell || ![cell isKindOfClass:[MCBooleanFieldTableViewCell class]]) {
return nil;
}
cell.delegate = self;
cell.identifier = identifier;
cell.label = label;
cell.value = initialValue;
return cell;
}
#pragma mark - Navigation #pragma mark - Navigation
@@ -123,6 +145,8 @@ const int kAbilityScoreSectionRowIndexCharisma = 5;
// * Subtype // * Subtype
// * Alignment // * Alignment
return 5; return 5;
case kSectionIndexArmor:
return 3;
case kSectionIndexAbilityScores: case kSectionIndexAbilityScores:
return 6; return 6;
default: default:
@@ -132,7 +156,7 @@ const int kAbilityScoreSectionRowIndexCharisma = 5;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{ {
return 2; return 3;
} }
- (NSString *)tableView:(UITableView *)tableView - (NSString *)tableView:(UITableView *)tableView
@@ -140,6 +164,8 @@ titleForHeaderInSection:(NSInteger)section {
switch(section) { switch(section) {
case kSectionIndexBasicInfo: case kSectionIndexBasicInfo:
return NSLocalizedString(@"Basic Info", @"Section title"); return NSLocalizedString(@"Basic Info", @"Section title");
case kSectionIndexArmor:
return NSLocalizedString(@"Armor, HP, and Speed", @"Section title");
case kSectionIndexAbilityScores: case kSectionIndexAbilityScores:
return NSLocalizedString(@"Ability Scores", @"Section title"); return NSLocalizedString(@"Ability Scores", @"Section title");
default: default:
@@ -186,6 +212,18 @@ titleForHeaderInSection:(NSInteger)section {
break; break;
} }
break; break;
case kSectionIndexArmor:
switch (indexPath.row) {
case kArmorSectionRowIndexHitDice:
return [self makeIntegerCellFromTableView:self.monsterTableView withIdentifier:@"monster.hitDice" label:NSLocalizedString(@"Hit Dice", @"") andInitialValue:self.editingMonster.hitDice];
case kArmorSectionRowIndexCustomHP:
return [self makeBooleanCellFromTableView:self.monsterTableView
withIdentifier:@"monster.customHP" label:NSLocalizedString(@"Custom HP", @"") andInitialValue:self.editingMonster.customHP];
return nil;
case kArmorSectionRowIndexCustomHPText:
return [self makeShortStringCellFromTableView:self.monsterTableView withIdentifier:@"monster.customHPText" label:NSLocalizedString(@"Custom HP Text", @"") andInitialValue:self.editingMonster.hpText];
}
break;
case kSectionIndexAbilityScores: case kSectionIndexAbilityScores:
switch (indexPath.row) { switch (indexPath.row) {
case kAbilityScoreSectionRowIndexStrength: case kAbilityScoreSectionRowIndexStrength:
@@ -245,6 +283,8 @@ titleForHeaderInSection:(NSInteger)section {
self.editingMonster.subtype = (NSString*)value; self.editingMonster.subtype = (NSString*)value;
} else if ([@"monster.alignment" isEqualToString:identifier]) { } else if ([@"monster.alignment" isEqualToString:identifier]) {
self.editingMonster.alignment = (NSString*)value; self.editingMonster.alignment = (NSString*)value;
} else if ([@"monster.customHPText" isEqualToString:identifier]){
self.editingMonster.hpText = (NSString*)value;
} }
} }
if ([kMCFieldValueTypeInteger isEqualToString:type]) { if ([kMCFieldValueTypeInteger isEqualToString:type]) {
@@ -260,6 +300,13 @@ titleForHeaderInSection:(NSInteger)section {
self.editingMonster.wisdomScore = [(NSNumber*)value intValue]; self.editingMonster.wisdomScore = [(NSNumber*)value intValue];
} else if ([@"monster.charismaScore" isEqualToString:identifier]) { } else if ([@"monster.charismaScore" isEqualToString:identifier]) {
self.editingMonster.charismaScore = [(NSNumber*)value intValue]; self.editingMonster.charismaScore = [(NSNumber*)value intValue];
} else if ([@"monster.hitDice" isEqualToString:identifier]){
self.editingMonster.hitDice = [(NSNumber*)value intValue];
}
}
if ([kMCFieldValueTypeBoolean isEqualToString:type]) {
if ([@"monster.customHP" isEqualToString:identifier]) {
self.editingMonster.customHP = [(NSNumber*)value boolValue];
} }
} }
} }