mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-31 00:15:54 -04:00
127 lines
2.8 KiB
Plaintext
127 lines
2.8 KiB
Plaintext
include library.player_structure;
|
|
include library.static_item;
|
|
include library.sui;
|
|
include library.utils;
|
|
|
|
|
|
const int MAX_NAME_LENGTH = 32;
|
|
|
|
const string_id SID_SET_NAME_TITLE = new string_id("sui","set_name_title");
|
|
const string_id SID_SET_NAME_PROMPT = new string_id("sui","set_name_prompt");
|
|
|
|
const string HANDLER_NAME_OBJECT = "handleNameObject";
|
|
|
|
//------------------------------------------------
|
|
|
|
trigger OnObjectMenuRequest(obj_id player, menu_info mi)
|
|
{
|
|
if(static_item.isStaticItem(self))
|
|
return SCRIPT_CONTINUE;
|
|
|
|
if ( utils.isNestedWithin(self, player) || isInPlayersHouse(self, player) )
|
|
{
|
|
menu_info_data data = mi.getMenuItemByType (menu_info_types.SET_NAME);
|
|
if (data != null)
|
|
data.setServerNotify (true);
|
|
else
|
|
mi.addRootMenu(menu_info_types.SET_NAME, null);
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
//------------------------------------------------
|
|
|
|
trigger OnObjectMenuSelect(obj_id player, int item)
|
|
{
|
|
if ( item == menu_info_types.SET_NAME )
|
|
{
|
|
if ( utils.isNestedWithin(self, player) || isInPlayersHouse(self, player) )
|
|
{
|
|
showNameInputUI(player, self);
|
|
}
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
void showNameInputUI(obj_id player, obj_id self)
|
|
{
|
|
string title = utils.packStringId (SID_SET_NAME_TITLE);
|
|
string prompt = utils.packStringId (SID_SET_NAME_PROMPT);
|
|
|
|
sui.inputbox(self, player, prompt, title, HANDLER_NAME_OBJECT, MAX_NAME_LENGTH, true, getEncodedName(self));
|
|
}
|
|
|
|
//------------------------------------------------
|
|
|
|
messageHandler handleNameObject()
|
|
{
|
|
if ( (params == null) || (params.isEmpty()) )
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
int btn = sui.getIntButtonPressed(params);
|
|
switch ( btn )
|
|
{
|
|
case sui.BP_CANCEL:
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
obj_id player = sui.getPlayerId(params);
|
|
if ( !isIdValid(player) )
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
if ( utils.isNestedWithin(self, player) || isInPlayersHouse(self, player) )
|
|
{
|
|
string text = sui.getInputBoxText(params);
|
|
|
|
// remove leading @'s to prevent name from being interpreted as code string
|
|
int i = 0;
|
|
int textlen = text.length();
|
|
while(textlen > i && '@' == text.charAt(i))
|
|
{
|
|
++i;
|
|
}
|
|
|
|
text = text.substring(i, textlen);
|
|
|
|
if ( !text.equals("") )
|
|
{
|
|
/*
|
|
if ( text.length() > MAX_NAME_LENGTH + 1 )
|
|
{
|
|
text = text.substring(0,MAX_NAME_LENGTH - 1);
|
|
}
|
|
*/
|
|
|
|
setName(self, text);
|
|
/*if ( !utils.setNonReservedName(self, text) )
|
|
{
|
|
sendSystemMessageTestingOnly(player, "You have input an invalid name. Please try again.");
|
|
showNameInputUI(player, self);
|
|
}*/
|
|
}
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
//------------------------------------------------
|
|
|
|
boolean isInPlayersHouse(obj_id self, obj_id player)
|
|
{
|
|
if ( utils.isInHouseCellSpace(self) )
|
|
{
|
|
//make sure player is on the admin list of the house
|
|
obj_id structure = getTopMostContainer(self);
|
|
if ( player_structure.isAdmin(structure, player))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|