Skip to content
Permalink
Browse files

Added 't' option to REDIT so you can toggle the display of color code…

…s on and off. This is for those who want to copy the current desc and edit it without having to re-do all the color codes.
  • Loading branch information...
luciensadi committed Jul 12, 2019
1 parent e4f85cc commit 8d35dab9ef129cd24c69d9acb70138c0c5f420eb
Showing with 69 additions and 30 deletions.
  1. +1 −13 src/helpedit.cpp
  2. +28 −17 src/redit.cpp
  3. +1 −0 src/structs.h
  4. +37 −0 src/utils.cpp
  5. +2 −0 src/utils.h
@@ -117,19 +117,7 @@ ACMD(do_helpexport) {
return;
}

// Change all ^ to ^^. We will use body_edit_buf in the output.
char edited_output[strlen(output_ptr) * 2 + 1];
const char *read_ptr = output_ptr;
char *write_ptr = edited_output;
while (*read_ptr) {
// If the current character is '^', double it in the output.
if (*read_ptr == '^')
*(write_ptr++) = '^';
*(write_ptr++) = *(read_ptr++);
}
*write_ptr = '\0';

send_to_char(ch, "Output:\r\n\r\n^c%s^n\r\n\r\n^RWARNING:^n Make sure your client's line wrap is turned off!", edited_output);
send_to_char(ch, "Output:\r\n\r\n^c%s^n\r\n\r\n^RWARNING:^n Make sure your client's line wrap is turned off!", double_up_color_codes(output_ptr));
}


@@ -113,7 +113,8 @@ void redit_disp_extradesc_menu(struct descriptor_data * d)
"1) Keyword: %s%s%s\r\n"
"2) Description:\r\n%s\r\n", CCCYN(CH, C_CMP),
extra_desc->keyword, CCNRM(CH, C_CMP),
(extra_desc->description ? extra_desc->description : "(none)"));
(extra_desc->description ?
(d->edit_convert_color_codes ? double_up_color_codes(extra_desc->description) : extra_desc->description) : "(none)"));
send_to_char(CH, "3) %s\r\n"
"Enter Choice:\r\n",
(extra_desc->next ? "Another description set. (not viewed)" : "Another description"));
@@ -155,8 +156,9 @@ void redit_disp_exit_menu(struct descriptor_data * d)
send_to_char(CH, "1) Exit to: %s%d%s\r\n"
"2) Description: %s\r\n",
CCCYN(CH, C_CMP), DOOR->to_room_vnum, CCNRM(CH, C_CMP),
(DOOR->general_description ? DOOR->general_description : "(None)"));
send_to_char(CH, "3) Door names: %s%s%s\r\n"
(DOOR->general_description ?
(d->edit_convert_color_codes ? double_up_color_codes(DOOR->general_description) : DOOR->general_description) : "(None)"));
send_to_char(CH, "3) Door keywords (first one is its name too): %s%s%s\r\n"
"4) Key vnum: %s%d%s\r\n"
"5) Door flag: %s%s%s\r\n",
CCCYN(CH, C_CMP), (DOOR->keyword ? DOOR->keyword : "(none)"),
@@ -253,11 +255,12 @@ void redit_disp_menu(struct descriptor_data * d)
d->edit_mode = REDIT_MAIN_MENU;
send_to_char(CH, "Room number: %s%d%s\r\n"
"1) Room name: %s%s%s\r\n",
CCCYN(CH, C_CMP), d->edit_number, CCNRM(CH, C_CMP),
CCCYN(CH, C_CMP),
d->edit_number, CCNRM(CH, C_CMP),
CCCYN(CH, C_CMP), d->edit_room->name, CCNRM(CH, C_CMP));
send_to_char(CH, "2) Room Desc:\r\n%s\r\n", d->edit_room->description);
send_to_char(CH, "3) Night Desc: \r\n%s\r\n", d->edit_room->night_desc);
d->edit_convert_color_codes ? double_up_color_codes(d->edit_room->name) : d->edit_room->name,
CCNRM(CH, C_CMP));
send_to_char(CH, "2) Room Desc:\r\n%s\r\n", d->edit_convert_color_codes ? double_up_color_codes(d->edit_room->description) : d->edit_room->description);
send_to_char(CH, "3) Night Desc: \r\n%s\r\n", d->edit_convert_color_codes ? double_up_color_codes(d->edit_room->night_desc) : d->edit_room->night_desc);
send_to_char(CH, "Room zone: %s%d%s\r\n",
CCCYN(CH, C_CMP),
zone_table[d->edit_room->zone].number,
@@ -331,6 +334,10 @@ void redit_disp_menu(struct descriptor_data * d)
d->edit_room->sector_type == SPIRIT_RIVER || d->edit_room->room_flags.IsSet(ROOM_FALL))
send_to_char(CH, "m) %s test difficulty (TN): %s%d%s\r\n", d->edit_room->room_flags.IsSet(ROOM_FALL) ? "Fall" : "Swim", CCCYN(CH, C_CMP),
ROOM->rating, CCNRM(CH, C_CMP));
if (d->edit_convert_color_codes)
send_to_char("t) Restore color codes\r\n", d->character);
else
send_to_char("t) Toggle color codes\r\n", d->character);
send_to_char("q) Quit and save\r\n", d->character);
send_to_char("x) Exit and abort\r\n", d->character);
send_to_char("Enter your choice:\r\n", d->character);
@@ -581,26 +588,23 @@ void redit_parse(struct descriptor_data * d, const char *arg)
send_to_char("Saved.\r\n", CH);
/* do NOT free strings! just the room structure */
Mem->ClearRoom(d->edit_room);
d->edit_room = NULL;
PLR_FLAGS(d->character).RemoveBit(PLR_EDITING);
STATE(d) = CON_PLAYING;
char_to_room(CH, GET_WAS_IN(CH));
GET_WAS_IN(CH) = NULL;
STATE(d) = CON_PLAYING;
clear_editing_data(d);
send_to_char("Done.\r\n", d->character);
break;
}
case 'n':
case 'N':
send_to_char("Room not saved, aborting.\r\n", d->character);
STATE(d) = CON_PLAYING;
PLR_FLAGS(d->character).RemoveBit(PLR_EDITING);
/* free everything up, including strings etc */
if (d->edit_room)
Mem->DeleteRoom(d->edit_room);
d->edit_room = NULL;
d->edit_number = 0;
char_to_room(CH, GET_WAS_IN(CH));
GET_WAS_IN(CH) = NULL;
Mem->DeleteRoom(d->edit_room); // this is set to NULL in clear_editing_data().
char_to_room(CH, GET_WAS_IN(CH));
GET_WAS_IN(CH) = NULL;
STATE(d) = CON_PLAYING;
clear_editing_data(d);
break;
default:
send_to_char("Invalid choice!\r\n", d->character);
@@ -618,6 +622,13 @@ void redit_parse(struct descriptor_data * d, const char *arg)
d->edit_mode = REDIT_CONFIRM_SAVESTRING;
redit_parse(d, "n");
break;
case 't':
if ((d->edit_convert_color_codes = !d->edit_convert_color_codes))
send_to_char("OK, color codes for title/desc will be displayed as tags for easier copy-paste.\r\n", CH);
else
send_to_char("OK, color codes will be re-enabled.\r\n", CH);
redit_disp_menu(d);
break;
case '1':
send_to_char("Enter room name:", d->character);
d->edit_mode = REDIT_NAME;
@@ -805,6 +805,7 @@ struct descriptor_data

// all this from here down is stuff for on-line creation
int edit_mode; /* editing sub mode */
bool edit_convert_color_codes; /* if this is true, display color codes in descs as ^^ for copy-paste */
long edit_number; /* virtual num of thing being edited */
long edit_number2; /* misc number for editing */
int edit_zone; /* which zone object is part of */
@@ -2329,3 +2329,40 @@ void copy_over_necessary_info(struct char_data *original, struct char_data *clon
REPLICATE(points.reach[1]);
#undef REPLICATE
}

// Uses static, so don't use it more than once per call (to sprintf, etc)
char *double_up_color_codes(const char *string) {
static char doubledbuf[MAX_STRING_LENGTH];

// This will happen for night descs that haven't been set, etc.
if (!string)
return NULL;

if (strlen(string) * 2 + 1 > sizeof(doubledbuf)) {
mudlog("SYSERR: Size of string passed to double_up_color_codes exceeds max size; aborting process.", NULL, LOG_SYSLOG, TRUE);
return NULL;
}


const char *read_ptr = string;
char *write_ptr = doubledbuf;

while (*read_ptr) {
if (*read_ptr == '^')
*(write_ptr++) = '^';
*(write_ptr++) = *(read_ptr++);
}
*(write_ptr++) = '\0';
return doubledbuf;
}

// Wipes out all the various fiddly bits so we don't have to remember to do it every time.
void clear_editing_data(struct descriptor_data *d) {
// This is distinct from free_editing_structs()! That one purges out memory, this just unsets flags.
d->edit_number = 0;
PLR_FLAGS(d->character).RemoveBit(PLR_EDITING);
d->edit_convert_color_codes = FALSE;

// We're setting things to NULL here. If you don't want to leak memory, clean it up beforehand.
d->edit_room = NULL;
}
@@ -81,6 +81,8 @@ struct obj_data *find_matching_obj_in_container(struct obj_data *container, vnu
bool attach_attachment_to_weapon(struct obj_data *attachment, struct obj_data *weapon, struct char_data *ch);
struct obj_data *unattach_attachment_from_weapon(int location, struct obj_data *weapon, struct char_data *ch);
void copy_over_necessary_info(struct char_data *original, struct char_data *clone);
void clear_editing_data(struct descriptor_data *d);
char *double_up_color_codes(const char *string);

// Message history management and manipulation.
void store_message_to_history(struct descriptor_data *d, int channel, const char *mallocd_message);

0 comments on commit 8d35dab

Please sign in to comment.
You can’t perform that action at this time.