[character_select] { interface = true; ////////////////////////////////////////////////////////////////////////////// // // Author(s): Witness (Lisa Hui) // Purpose : Alters the character selection system to hide the usage of // multiple templates used for determining the head selection. // // Versions : v2.1 [October 9, 2004] // - added a performance check in SyncTextureSelections$ to exit // immediately if there are no non-zero deltas (texture changes) // - moved constants to an #include file for easier editing/overriding // // v2.0 [August 15, 2004] // - fixed the skin desync problem caused occasional offsetting // caused by the formula for negative modulos // - optimized texture shifting count in the texture shifting function // // v1.0 [July 25, 2004] // - first version // //---------------------------------------------------------------------------- // Version: 2.1 Date: October 9, 2004 //---------------------------------------------------------------------------- ////////////////////////////////////////////////////////////////////////////// skrit = [[ owner = UIWindow; //input property int shift$ = 0; //constants #include "k_inc_character" //bool toggle_sound$; void Init$ { report.screen("character_select interface loaded"); //reset counters GameAuditor.Db.SetInt( "ui_delta_heroclth", 0 ); GameAuditor.Db.SetInt( "ui_delta_herohair", 0 ); GameAuditor.Db.SetInt( "ui_delta_heroskin", 0 ); //disable audio if it is not off already... /*if ( UIShell.FindUIWindow( "slider_mastervolume", "options_audio" ).IsEnabled() ) { //Messenger.Notify( "toggle_option_audio_sound", wnd$ ); UIShell.SendUIMessage( MSG_ONBUTTONPRESS, "button_sound", "options_audio" ); report.screen("...sound was enabled, so toggled it off..."); toggle_sound$ = true; } else { report.screen("...sound was NOT enabled, so no toggling required..."); toggle_sound$ = false; }*/ } void SyncTextureSelections$( string shift_direction$, string next_direction$, UIWindow wnd$, bool end_at_start$ ) { report.screenf("character_select sync message: %s", shift_direction$); //get the accumulated deltas int delta_clth$ = GameAuditor.Db.GetInt( "ui_delta_heroclth" ); int delta_hair$ = GameAuditor.Db.GetInt( "ui_delta_herohair" ); int delta_skin$ = GameAuditor.Db.GetInt( "ui_delta_heroskin" ); int delta_zero$; //since the limits are preset, optimize deltas to result in the shortest number of shifts if ( delta_clth$ != 0 ) { int limit_mid$ = clothes$ / 2; if ( delta_clth$ > 0 ) { if ( delta_clth$ > limit_mid$ ) { //would be faster to shift in the opposite direction delta_clth$ = delta_clth$ - clothes$; } } else if ( delta_clth$ > ( 0 - limit_mid$ ) ) { //would be faster to shift in the opposite direction delta_clth$ = clothes$ + delta_clth$; } delta_zero$ = false; } else { delta_zero$ = true; } if ( delta_hair$ != 0 ) { int limit_mid$ = hairs$ / 2; if ( delta_hair$ > 0 ) { if ( delta_hair$ > limit_mid$ ) { //would be faster to shift in the opposite direction delta_hair$ = delta_hair$ - hairs$; } } else if ( delta_hair$ > ( 0 - limit_mid$ ) ) { //would be faster to shift in the opposite direction delta_hair$ = hairs$ + delta_hair$; } } else if ( delta_zero$ && ( delta_skin$ == 0 ) ) { //no synchronization necessary b/c all deltas are zero (no skin changes) //move to the next head if ( !end_at_start$ ) { int d_race$ = races$ * genders$; report.screenf("race shift: %d", d_race$); while ( d_race$ > 0 ) { Messenger.Notify( next_direction$, wnd$ ); d_race$ -= 1; } } return; } /* //small number of skins, don't need to optimize in this case if ( delta_skin$ != 0 ) { int limit_mid$ = skins$ / 2; if ( delta_skin$ > 0 ) { if ( delta_skin$ > limit_mid$ ) { //would be faster to shift in the opposite direction delta_skin$ = delta_skin$ - skins$; } } else if ( delta_clth$ > ( 0 - limit_mid$ ) ) { //would be faster to shift in the opposite direction delta_skin$ = skins$ + delta_skin$; } }*/ int jump$ = races$ * genders$; int d_clth$, d_hair$, d_skin$, d_race$; int count$ = 1; while ( count$ < heads$ ) { d_race$ = jump$; report.screenf("race shift: %d", d_race$); while ( d_race$ > 0 ) { Messenger.Notify( shift_direction$, wnd$ ); d_race$ -= 1; } d_clth$ = delta_clth$; d_hair$ = delta_hair$; d_skin$ = delta_skin$; //sync clothing change if ( d_clth$ > 0 ) { while ( d_clth$ > 0 ) { Messenger.Notify( "char_next_shirt", wnd$ ); d_clth$ -= 1; } } else if ( d_clth$ < 0 ) { while ( d_clth$ < 0 ) { Messenger.Notify( "char_prev_shirt", wnd$ ); d_clth$ += 1; } } //sync hair color change if ( d_hair$ > 0 ) { while ( d_hair$ > 0 ) { Messenger.Notify( "char_next_hair", wnd$ ); d_hair$ -= 1; } } else if ( d_hair$ < 0 ) { while ( d_hair$ < 0 ) { Messenger.Notify( "char_prev_hair", wnd$ ); d_hair$ += 1; } } //sync skin color/face change if ( d_skin$ > 0 ) { while ( d_skin$ > 0 ) { Messenger.Notify( "char_next_face", wnd$ ); Messenger.Notify( "char_next_pants", wnd$ ); d_skin$ -= 1; } } else if ( d_skin$ < 0 ) { while ( d_skin$ < 0 ) { Messenger.Notify( "char_prev_face", wnd$ ); Messenger.Notify( "char_prev_pants", wnd$ ); d_skin$ += 1; } } count$ += 1; } if ( end_at_start$ ) { //next race d_race$ = 0; while ( d_race$ < races$ ) { Messenger.Notify( shift_direction$, wnd$ ); d_race$ += 1; } } //reset deltas GameAuditor.Db.SetInt( "ui_delta_heroclth", 0 ); GameAuditor.Db.SetInt( "ui_delta_herohair", 0 ); GameAuditor.Db.SetInt( "ui_delta_heroskin", 0 ); } void SyncNext$ { //flip the shift direction for shorter update path //string msg$ = ( shift$ < 0 ? "next_character" : "previous_character" ); UIWindow wnd$ = UIShell.FindUIWindow( "button_next", "character_select" ); //sync selected race if ( shift$ < 0 ) { SyncTextureSelections$( "next_character", "previous_character", wnd$, true ); } else { SyncTextureSelections$( "previous_character", "next_character", wnd$, true ); } //continue to the next step Messenger.Notify( "on_change_map", wnd$ ); } void LoadRace$ { //flip the shift direction for shorter update path //string msg$ = ( shift$ < 0 ? "next_character" : "previous_character" ); UIWindow wnd$ = UIShell.FindUIWindow( "button_gender_right", "character_select" ); //synchronize textures with the rest of the characters in the same race if ( shift$ < 0 ) { SyncTextureSelections$( "next_character", "previous_character", wnd$, false ); Messenger.Notify( "next_character", wnd$ ); //next race } else { SyncTextureSelections$( "previous_character", "next_character", wnd$, false ); Messenger.Notify( "previous_character", wnd$ ); //next race } } void LoadHead$ { report.screenf("character_select - shift head: %d", shift$); //synchronize textures with the rest of the characters in the same race //...just flip the shift direction! //- SyncTextureSelections$ ends up on the prev head when seeking forward //- SyncTextureSelections$ ends up on the next head when seeking backwards //SyncTextureSelections$( ( shift$ < 0 ? "next_character" : "previous_character" ), // UIShell.FindUIWindow( "button_face_right", "character_select" ), // false ); UIWindow wnd$ = UIShell.FindUIWindow( "button_face_right", "character_select" ); if ( shift$ < 0 ) { SyncTextureSelections$( "next_character", "previous_character", wnd$, false ); } else { SyncTextureSelections$( "previous_character", "next_character", wnd$, false ); } } void ChangeSkin$ { int delta_old$ = GameAuditor.Db.GetInt( "ui_delta_heroskin" ); int delta_new$ = delta_old$ + shift$; if ( delta_new$ > 0 ) { if ( delta_new$ >= skins$ ) { delta_new$ %= skins$; } } else if ( delta_new$ < 0 ) { int skin_limit$ = 0 - skins$; while ( delta_new$ <= skin_limit$ ) { delta_new$ += skins$; } /*//buggy computation, only "works" sometimes if ( ( 0 - delta_new$ ) >= skins$ ) { delta_new$ = skins$ - ( ( 0 - delta_new$ ) % skins$ ) - 1; }*/ } GameAuditor.Db.SetInt( "ui_delta_heroskin", delta_new$ ); report.screenf("ChangeSkin$ - delta: %d", delta_new$); } void ChangeHair$ { int delta_old$ = GameAuditor.Db.GetInt( "ui_delta_herohair" ); int delta_new$ = delta_old$ + shift$; if ( delta_new$ > 0 ) { if ( delta_new$ >= hairs$ ) { delta_new$ %= hairs$; } } else if ( delta_new$ < 0 ) { int hairs_limit$ = 0 - hairs$; while ( delta_new$ <= hairs_limit$ ) { delta_new$ += hairs$; } /*//buggy computation, only "works" sometimes if ( ( 0 - delta_new$ ) >= hairs$ ) { delta_new$ = hairs$ - ( ( 0 - delta_new$ ) % hairs$ ) - 1; }*/ } GameAuditor.Db.SetInt( "ui_delta_herohair", delta_new$ ); report.screenf("ChangeHair$ - delta: %d", delta_new$); } void ChangeClothes$ { int delta_old$ = GameAuditor.Db.GetInt( "ui_delta_heroclth" ); int delta_new$ = delta_old$ + shift$; if ( delta_new$ > 0 ) { if ( delta_new$ >= clothes$ ) { delta_new$ %= clothes$; } } else if ( delta_new$ < 0 ) { int clothes_limit$ = 0 - clothes$; while ( delta_new$ <= clothes_limit$ ) { delta_new$ += clothes$; } /*//buggy computation, only "works" sometimes if ( ( 0 - delta_new$ ) >= clothes$ ) { delta_new$ = clothes$ - ( ( 0 - delta_new$ ) % clothes$ ) - 1; }*/ } GameAuditor.Db.SetInt( "ui_delta_heroclth", delta_new$ ); report.screenf("ChangeClothes$ - delta: %d", delta_new$); } ]]; //RACE [t:button,n:button_gender_left] { alpha = 1.000000; common_control = false; common_template = ; draw_order = 9; rect = 176,204,213,224; uvcoords = 0.000000,0.000000,1.000000,1.000000; wrap_mode = clamp; [messages] { onbuttonpress = call(LoadRace$?shift=-1); //notify(previous_character); onlbuttondown = notify(button_down); onlbuttonup = notify(button_up); onrolloff = notify(button_up); onrollover = notify(button_rollover); } index = 3; } [t:button,n:button_gender_right] { alpha = 1.000000; common_control = false; common_template = ; draw_order = 8; rect = 340,204,377,224; uvcoords = 0.000000,0.000000,1.000000,1.000000; wrap_mode = clamp; [messages] { onbuttonpress = call(LoadRace$?shift=1); onlbuttondown = notify(button_down); onlbuttonup = notify(button_up); onrolloff = notify(button_up); onrollover = notify(button_rollover); } index = 3; } //GENDER /*[t:button,n:button_head_left] { alpha = 1.000000; common_control = false; common_template = ; draw_order = 3; rect = 176,255,213,275; uvcoords = 0.000000,0.000000,1.000000,1.000000; wrap_mode = clamp; [messages] { onbuttonpress=notify(char_prev_head); onlbuttondown = notify(button_down); onlbuttonup = notify(button_up); onrolloff = notify(button_up); onrollover = notify(button_rollover); } index = 3; } [t:button,n:button_head_right] { alpha = 1.000000; common_control = false; common_template = ; draw_order = 4; rect = 340,255,377,275; uvcoords = 0.000000,0.000000,1.000000,1.000000; wrap_mode = clamp; [messages] { onbuttonpress=notify(char_next_head); onlbuttondown = notify(button_down); onlbuttonup = notify(button_up); onrolloff = notify(button_up); onrollover = notify(button_rollover); } index = 3; }*/ //HEAD [t:button,n:button_face_left] { alpha = 1.000000; common_control = false; common_template = ; draw_order = 11; rect = 176,306,213,326; uvcoords = 0.000000,0.000000,1.000000,1.000000; wrap_mode = clamp; [messages] { onbuttonpress = call(LoadHead$?shift=-1); ///*notify(char_prev_head) &*/ onlbuttondown = notify(button_down); onlbuttonup = notify(button_up); onrolloff = notify(button_up); onrollover = notify(button_rollover); } index = 3; } [t:button,n:button_face_right] { alpha = 1.000000; common_control = false; common_template = ; draw_order = 6; rect = 340,305,377,325; uvcoords = 0.000000,0.000000,1.000000,1.000000; wrap_mode = clamp; [messages] { onbuttonpress = call(LoadHead$?shift=1); ///*notify(char_next_head) &*/ onlbuttondown = notify(button_down); onlbuttonup = notify(button_up); onrolloff = notify(button_up); onrollover = notify(button_rollover); } index = 3; } //HAIR [t:button,n:button_hair_left] { alpha = 1.000000; common_control = false; common_template = ; draw_order = 10; rect = 176,355,213,375; uvcoords = 0.000000,0.000000,1.000000,1.000000; wrap_mode = clamp; [messages] { onbuttonpress = notify(char_prev_hair) & call(ChangeHair$?shift=-1); //call(LoadHead$); onlbuttondown = notify(button_down); onlbuttonup = notify(button_up); onrolloff = notify(button_up); onrollover = notify(button_rollover); } index = 3; } [t:button,n:button_hair_right] { alpha = 1.000000; common_control = false; common_template = ; draw_order = 7; rect = 340,355,377,375; uvcoords = 0.000000,0.000000,1.000000,1.000000; wrap_mode = clamp; [messages] { onbuttonpress=notify(char_next_hair) & call(ChangeHair$?shift=1); //call(LoadHead$); onlbuttondown = notify(button_down); onlbuttonup = notify(button_up); onrolloff = notify(button_up); onrollover = notify(button_rollover); } index = 3; } //SKIN //notify(char_prev_face) notify(char_next_face) [t:button,n:button_shirt_left] { alpha = 1.000000; common_control = false; common_template = ; draw_order = 3; rect = 176,403,213,423; uvcoords = 0.000000,0.000000,1.000000,1.000000; wrap_mode = clamp; [messages] { onbuttonpress = notify(char_prev_face) & notify(char_prev_pants) & call(ChangeSkin$?shift=-1); //call(LoadHead$); onlbuttondown = notify(button_down); onlbuttonup = notify(button_up); onrolloff = notify(button_up); onrollover = notify(button_rollover); } index = 3; } [t:button,n:button_shirt_right] { alpha = 1.000000; common_control = false; common_template = ; draw_order = 4; rect = 340,403,377,423; uvcoords = 0.000000,0.000000,1.000000,1.000000; wrap_mode = clamp; [messages] { onbuttonpress = notify(char_next_face) & notify(char_next_pants) & call(ChangeSkin$?shift=1); //call(LoadHead$); onlbuttondown = notify(button_down); onlbuttonup = notify(button_up); onrolloff = notify(button_up); onrollover = notify(button_rollover); } index = 3; } //CLOTHES [t:button,n:button_pants_left] { alpha = 1.000000; common_control = false; common_template = ; draw_order = 1; rect = 176,453,213,473; uvcoords = 0.000000,0.000000,1.000000,1.000000; wrap_mode = clamp; [messages] { onbuttonpress = notify(char_prev_shirt) & call(ChangeClothes$?shift=-1); //call(LoadHead$); onlbuttondown = notify(button_down); onlbuttonup = notify(button_up); onrolloff = notify(button_up); onrollover = notify(button_rollover); } index = 3; } [t:button,n:button_pants_right] { alpha = 1.000000; common_control = false; common_template = ; draw_order = 5; rect = 340,453,377,473; uvcoords = 0.000000,0.000000,1.000000,1.000000; wrap_mode = clamp; [messages] { onbuttonpress = notify(char_next_shirt) & call(ChangeClothes$?shift=1); //call(LoadHead$); onlbuttondown = notify(button_down); onlbuttonup = notify(button_up); onrolloff = notify(button_up); onrollover = notify(button_rollover); } index = 3; } [t:button,n:button_previous] { alpha = 1.000000; common_control = false; common_template = ; draw_order = 12; rect = 237,575,338,595; uvcoords = 0.000000,0.000000,1.000000,1.000000; wrap_mode = clamp; [messages] { onbuttonpress = notify(back_to_single_player); onlbuttondown = notify(button_down); onlbuttonup = notify(button_up); onrolloff = notify(button_up); onrollover = notify(button_rollover); } index = 1; } [t:button,n:button_next] { alpha = 1.000000; common_control = false; common_template = ; draw_order = 25; rect = 461,575,562,595; uvcoords = 0.000000,0.000000,1.000000,1.000000; wrap_mode = clamp; [messages] { onbuttonpress = call(SyncNext$); onlbuttondown = notify(button_down); onlbuttonup = notify(button_up); onrolloff = notify(button_up); onrollover = notify(button_rollover); } index = 1; } [t:edit_box,n:name_edit_box] { alpha = 1.000000; clear_select = false; common_control = false; common_template = ; draw_order = 11; font_color = -1; font_size = 15; font_type = b_gui_fnt_12p_copperplate-light; max_string_size = 14; excluded_chars = [["<>:/\|?*.%;]]; max_pixels = 155; has_pixel_limit = true; permanent_focus = true; rect = 297,518,530,542; text = ""; uvcoords = 0.000000,0.000000,1.000000,1.000000; wrap_mode = clamp; prompt_flash = 0.5; [prompt] { texture=b_gui_fe_m_single_prompt; width=1; } [messages] { onlbuttondown = notify(button_down); onlbuttonup = notify(button_up); onrolloff = notify(button_up); onrollover = notify(button_rollover); } index = 1; } [t:listener,n:listener] { alpha = 1.000000; common_control = false; common_template = ; draw_order = 15; rect = 408,73,649,494; uvcoords = 0.000000,0.000000,1.000000,1.000000; wrap_mode = clamp; [messages] { onshow = call(Init$); } } }