package FlashChat { import components.CustomList; import flash.display.Loader; import flash.events.Event; import flash.events.EventDispatcher; import flash.events.IOErrorEvent; import flash.events.ProgressEvent; import flash.media.SoundTransform; import flash.net.SharedObject; import flash.net.URLLoader; import flash.net.URLRequest; import flash.net.navigateToURL; import flash.system.ApplicationDomain; import flash.system.LoaderContext; import flash.text.Font; import flash.utils.Timer; import flash.xml.XMLDocument; import flash.xml.XMLNode; import mx.collections.ArrayCollection; import mx.collections.Sort; import mx.collections.SortField; import mx.containers.Canvas; import mx.controls.Alert; import mx.events.StyleEvent; import mx.skins.halo.ButtonSkin; import mx.skins.halo.PanelSkin; import mx.skins.halo.ScrollTrackSkin; import mx.styles.CSSStyleDeclaration; import mx.styles.StyleManager; import mx.utils.ObjectUtil; public class Settings extends EventDispatcher { public static var IS_DEBUG: Boolean = false; public static const LOOKS_DIR: String = 'looks/'; public static const FONTS_DIR: String = 'fonts/'; public static var path: String = ''; // =================For tests=============== // //public static var path: String = 'http://radioscatrachas.info/chat6/'; // public static var path: String = 'http://drupal/chat/'; // public static const LOOKS_DIR: String = ''; // public static const FONTS_DIR: String = path+'fonts/'; // public static var IS_DEBUG: Boolean = true; // ============================================= // public static var ulAnchor: Object = {x: 0, y: 0, w: 100, h: 100}; public static var userListSpace: Canvas = new Canvas; private static var instance:EventDispatcher = new EventDispatcher(); // [Embed(source='user.swf')] // public static var defaultAvt: Class; // public static var currentAvt: Class = defaultAvt; public static var pageTitle: String = 'FlashChat'; public static var isLoggedOut: Boolean = false; public static var enableSocket: Boolean = false; public static var tmrGag: Timer; public static var isShiftPressed: Boolean = false; public static var curEntry: uint = 0; public static var CurrentTheme:FlashChatTheme; public static var bSaveSettings: Boolean = false; public static var lang: String = 'en'; public static var defaultLang: String = 'en'; public static var allowLanguage: Boolean = true; public static var userSelectedForAction: uint; public static var layout: Array = new Array(); public static var modules: Array = new Array(); public static var socketServer: Object = new Object(); public static var logout: Object = new Object(); public static var login: Object = new Object(); public static var themes: Array = new Array(); public static var privateChatIcon: Class = null; public static var skins: Array = new Array(); public static var avatars: Array = new Array(); public static var fontFamilies: Array = new Array(); public static var fontSize: Array = new Array(); public static var defs: Object = new Object(); public static var themeFieldsToChange: Array = [ ['DialogTitle','dialogTitle'], //Dialog title ['DialogBackground','dialogBackgroundColor'], //Dialog background ['RoomsText','roomText'], //Rooms text ['RoomsBackground','roomBackground'], //Rooms background ['UserlistBackground','userListBackground'], //User list background ['EnterRoomNotification','enterRoomNotify'], //Enter room notification ['ButtonsText','buttonText'], //Buttons text ['ButtonsBackground','button'], //Buttons background ['ButtonsBorderColor','buttonBorder'], //Buttons border color ['InputBoxBackground','inputBoxBackground'], //Input box backgorund ['PrivateLogBackground','privateLogBackground'], //Private log background ['PublicLogBackground','publicLogBackground'], //Public log background ['BorderColor','borderColor'], //Border color ['BodyText','bodyText'], //Body text ['TitleText','titleText'], //Title tet ['MainBackground','background'] //Main background ]; public static var anchors: Array = new Array; public static function setAnchor(a: uint, l: *, r: *, t: *, b: *): void { if (anchors.hasOwnProperty(a)) { if (anchors[a].stretch) { l = t = 0; r = Settings.anchors[a].parent.width; b = Settings.anchors[a].parent.height; } if (null != l) { Settings.anchors[a].left = l; } if (null != r) { Settings.anchors[a].right = r; } if (null != t) { Settings.anchors[a].top = t; } if (null != b) { Settings.anchors[a].bottom = b; } dispatchEvent(new Event('updateAnchors')); } } public static var themeFields: Array = [ 'id', 'name', 'dialogBackgroundImage', 'backgroundImage', 'showBackgroundImages', 'uiAlpha', 'dialogTitle', //Dialog title 'dialogBackgroundColor', //Dialog background 'roomText', //Rooms text 'roomBackground', //Rooms background 'userListBackground', //User list background 'enterRoomNotify', //Enter room notification 'buttonText', //Buttons text 'button', //Buttons background 'buttonBorder', //Buttons border color 'inputBoxBackground', //Input box backgorund 'privateLogBackground', //Private log background 'publicLogBackground', //Public log background 'borderColor', //Border color 'bodyText', //Body text 'titleText', //Title tet 'background', //Main background 'recommendedUserColor', 'closeButton', 'closeButtonPress', 'closeButtonBorder', 'closeButtonArrow', 'minimizeButton', 'minimizeButtonPress', 'minimizeButtonBorder', 'check', 'buttonPress', 'controlsBackground', 'headline', 'scrollBG', 'scrollBGPress', 'scrollBorder', 'scrollerBG', 'userListItem', 'cacheType', 'cachePath', 'cacheFilePrefix' ]; public static var avtDisabledFor: Array = []; //admin & moderator public static var allowedSmiles: Array = new Array(); public static var modOnly: Array = new Array(); public static var patternList:Array = [ //['::', 'smi_'], [':?', 'smi_ask', 87.5, 87.5, 14, 14], [':awe:', 'smi_awe', 84.8484848484849, 84.8484848484849, 18.6242424242424, 14], [':baby:', 'smi_baby', 100, 100, 14, 14], [':8)', 'smi_cool', 87.5, 87.5, 14.875, 14], [':evil:', 'smi_evil', 83.3333333333333, 83.3333333333333, 14.083333333333, 14], [':finger:', 'smi_finger', 87.5, 87.5, 13.60625, 14], [':grin:', 'smi_grin', 87.5, 87.5, 14, 14], [':heart:', 'smi_heart', 98.5915492957746, 98.5915492957746, 15.7746478873239, 14], [':kiss:', 'smi_kiss', 87.5, 87.5, 32.375, 14], [':d', 'smi_laugh', 87.5, 87.5, 14, 14], [':break:', 'smi_newline', 87.5, 87.5, 14, 14], [':ninja:', 'smi_ninja', 74.8663101604278, 74.8663101604278, 18.192513368984, 14], [':red:', 'smi_red', 87.5, 87.5, 14, 14], [':roll:', 'smi_roll', 87.5, 87.5, 35, 14], [':rolleyes:', 'smi_roll_eyes', 87.5, 87.5, 14, 14], [':(', 'smi_sad', 87.5, 87.5, 14, 14], [':!', 'smi_slash', 92.1052631578947, 92.1052631578947, 14.7368421052632, 14], [':zzz:', 'smi_sleep', 81.8713450292398, 81.8713450292398, 17.9298245614035, 14], [':)', 'smi_smile', 87.5, 87.5, 14, 14], [':p', 'smi_tongue', 87.5, 87.5, 14, 14], [':weird:', 'smi_weird', 87.5, 87.5, 13.9125, 14], [':whistle:', 'smi_whistle', 87.5, 87.5, 28.13125, 14], [':;)', 'smi_wink', 87.5, 87.5, 14, 14], [':8s', 'smi_wonder', 87.5, 87.5, 14, 14], //addon 1 [':call:', 'smi_call', 80.4597701149425, 80.4597701149425, 12.7528735632184, 14], [':cash:', 'smi_cash', 87.5, 87.5, 14, 14], [':check:', 'smi_check', 56, 56, 10.64, 14], [':shock:', 'smi_shock', 87.5, 87.5, 14, 14], //addon 2 [':ball:', 'smi_ball', 18.2291666666667, 18.2291666666667, 26.015625, 14], [':clap:', 'smi_clap', 17.5, 17.5, 22.75, 14], [':cry:', 'smi_cry', 15.625, 15.625, 18.6875, 14], [':luck:', 'smi_luck', 12.6582278481013, 12.6582278481013, 14.5886075949367, 14], [':nono:', 'smi_nono', 16.4705882352941, 16.4705882352941, 18.48, 14], [':Punch:', 'smi_punch', 88.0503144654088, 88.0503144654088, 22.0125786163522, 14], [':skull:', 'smi_skull', 100, 100, 14, 14], [':yeah:', 'smi_yeah', 15.625, 15.625, 21.875, 14], [':69:', 'smi_yinyang', 48.2758620689655, 48.2758620689655, 13.6620689655172, 14], //addon 3 [':earth:', 'smi_earth', 47.4576271186441, 47.4576271186441, 13.7152542372881, 14], [':huh:', 'smi_huh', 87.5, 87.5, 21.875, 14], [':hypno:', 'smi_hypno', 36.8421052631579, 36.8421052631579, 14, 14], [':java:', 'smi_java', 56, 56, 14, 14], [':no:', 'smi_no', 11.3821138211382, 11.3821138211382, 14.1138211382114, 14], [':rain:', 'smi_rain', 86.4197530864197, 86.4197530864198, 13.7407407407407, 14], [':rose:', 'smi_rose', 35.9897172236504, 35.9897172236504, 13.0282776349614, 14], [':usa:', 'smi_usa', 84.8484848484848, 84.8484848484848, 20.1939393939394, 14], //addon 4 [':biggrin:', 'smi_big_grin', 87.5, 87.5, 14, 14], [':faint:', 'smi_faint', 76.5027322404371, 76.5027322404372, 16.3715846994535, 14], [':mean:', 'smi_ill_content', 87.5, 87.5, 14, 14], [':cat:', 'smi_meow', 87.5, 87.5, 16.1875, 14], [':down:', 'smi_thumbs_down', 72.7272727272727, 72.7272727272727, 18.8727272727273, 14], [':up:', 'smi_thumbs_up', 74.2705570291777, 74.2705570291777, 18.1220159151194, 14], [':dog:', 'smi_woof', 87.5, 87.5, 21.875, 14], [':au:', 'smi_AustraliaFlag', 68.1265206812652, 68.1265206812652, 20.8126520681265, 14], [':br:', 'smi_Brazil', 70, 70, 21, 14], [':ca:', 'smi_CanadaFlag', 70, 70, 21, 14], [':cn:', 'smi_China', 70, 70, 21, 14], [':eu:', 'smi_European_Union', 70, 70, 21, 14], [':fr:', 'smi_France', 70, 70, 21, 14], [':de:', 'smi_Germany', 70, 70, 21, 14], [':gr:', 'smi_Greece', 70, 70, 21, 14], [':in:', 'smi_IndianFlag', 70, 70, 21, 14], [':it:', 'smi_Italy', 70, 70, 21, 14], [':jp:', 'smi_Japan', 70, 70, 21, 14], [':mx:', 'smi_MexicoFlag', 70, 70, 21, 14], [':pl:', 'smi_PolandFlag', 70, 70, 21, 14], [':pt:', 'smi_PortugalFlag', 70, 70, 21, 14], [':ru:', 'smi_Russia', 70, 70, 21, 14], [':se:', 'smi_Sweeden', 70, 70, 21, 14], [':es:', 'smi_Spain', 70, 70, 21, 14], [':uk:', 'smi_UK', 66.6666666666667, 66.6666666666667, 20.6666666666667, 14], [':ua:', 'smi_UkraineFlag', 70, 70, 21, 14], [':us:', 'smi_US_Map', 70, 70, 21, 14], [':beer:', 'smi_beer', 82.3529411764706, 82.3529411764706, 15.2352941176471, 14], [':music:', 'smi_music', 87.5, 87.5, 23.625, 14], [':read:', 'smi_reading', 87.5, 87.5, 23.625, 14], [':admin:', 'smi_admin', 84.3373493975903, 84.3373493975904, 13.9578313253012, 14], [':female:', 'smi_female', 74.8663101604278, 74.8663101604278, 8.68449197860963, 14], [':ms:', 'smi_female2', 91.5032679738562, 91.5032679738562, 6.86274509803922, 14], [':male:', 'smi_male', 100.358422939068, 100.358422939068, 15.505376344086, 14], [':mr:', 'smi_male2', 91.5032679738562, 91.5032679738562, 6.86274509803922, 14], [':mod:', 'smi_moderator', 86.687306501548, 86.687306501548, 14, 14], [':speak:', 'smi_word_bubble', 89.171974522293, 89.171974522293, 15.9171974522293, 14], [':bball:', 'smi_basketball', 82.3529411764706, 82.3529411764706, 14, 14], [':bowl:', 'smi_bowling', 82.3529411764706, 82.3529411764706, 14, 14], [':cricket:', 'smi_cricket', 86.9565217391304, 86.9565217391304, 15.0869565217391, 14], [':fball:', 'smi_football', 77.7777777777778, 77.7777777777778, 14.5055555555556, 14], [':golf:', 'smi_golf', 78.4313725490196, 78.4313725490196, 21.7647058823529, 14], [':hockey:', 'smi_hockey', 84.0840840840841, 84.0840840840841, 17.1111111111, 14], [':sail:', 'smi_sailing', 80.2292263610315, 80.2292263610315, 13.6790830945559, 14], [':soccer:', 'smi_soccer', 82.3529411764706, 82.3529411764706, 14, 14], [':tennis:', 'smi_tennis', 84.0840840840841, 84.0840840840841, 21.8618618618619, 14] ]; [Bindable] public static var statuses: Array = new Array(); [Bindable] public static var textLanguage:ArrayCollection = new ArrayCollection(); /* "Rosans", "" "Roserif", "" */ public static var fontsHistory: Array = new Array(); public static var sysFonts: Array = [ 'Arial', 'Georgia', 'Verdana', 'Times', 'Courier', 'Tahoma' ]; public static var complFonts: Array = [ ["Bluestone", "BlueStone"], ["Bubblegum", "BubbleGum"], ["Chubbycheeks", "ChubbyCheeks"], ["Conventionalwisdom", "ConventionalWisdom"], ["Digitalstrip", "DigitalStrip"], ["Eastmarket", "EastMarket"], ["Grusskartengotisch", "GrusskartenGotisch"], ["Hemihead", "HemiHead"], ["Holyempire", "HolyEmpire"], ["Hotpizza", "HotPizza"], ["Ironman", "IronMan"], ["Jellybelly", "JellyBelly"], ["Kidkosmic", "KidKosmic"], ["Lucidablackletter", "LucidaBlackletter"], ["Lucidabright", "LucidaBright"], ["Magicmedieval", "MagicMedieval"], ["Mangatemple", "MangaTemple"], ["Mattoscript", "MattoScript"], ["Nativealien", "NativeAlien"], ["Oldenglish", "OldEnglish"], ["Omegasentry", "OmegaSentry"], ["Scoobydoo", "ScoobyDoo"], ["Seadog", "SeaDog"], ["Southpark", "SouthPark"], ["Terryscript", "TerryScript"], ["Underattack", "UnderAttack"], ]; public static var myid:uint = 0; public static var myname:String = ""; public static var myroom:uint = 0; public static var myrole:uint = 1; public static var lastSmile:String = ''; [Bindable] public static var rooms:ArrayCollection = new ArrayCollection(); public static var users:ArrayCollection = new ArrayCollection(); public static var status:Array = new Array(); public static var soPrefix : String = 'flex_chat_'; public static var custBgs: Array = new Array(); [Bindable] public static var options:Object = { theme: 'macintosh', defaultTheme: 'macintosh', skin: 'aqua_skin', defColor: '16777215', //effects mAvtEnabled : false, mAvt : '', rAvtEnabled : false, rAvt : '', bgEnabled : true, photo: '', focus: true, //text textAreaFontSize : 10, textAreaFontName: 'Arial', textAreaFontFile: 'Arial', textAreaPresence: 1, interfaceFontSize : 10, interfaceFontName: 'Arial', interfaceFontFile: 'Arial', interfacePresence: 1, titleFontSize: 10, titleFontName: 'Arial', titleFontFile: 'Arial', titleFontPresence: 1, useMyColor : false }; [Bindable] public static var common: Array = new Array(); public static var updateAllRooms : Boolean = false;; public static function initSounds(node: XMLNode, settings: XMLNode):void { return; } public function Settings() { super(); } public static function getRoomById(id : int) : Object { for each (var r: Object in Settings.rooms) { if (id == r.id) { return r; } } return false; } public static function getUserById(id : int) : Object { /*for each (var u: Object in Settings.users) { if (id == u.id) { return u; } }*/ for (var uId: uint = 0; uId < Settings.users.length; uId++) { var u: Object = Settings.users.getItemAt(uId); if (id == u.id) { return u; } } return null; } public static function getPatternByName(name: String): String { for (var i: String in patternList) { if (name == patternList[i][1]) { var res: Array = (patternList[i][0] as String).split(' '); return res[0]; } } return null; } public static function getCurrentBg():String { if (Settings.options.bgEnabled) { if (Settings.custBgs.hasOwnProperty(Settings.options.theme)) { return Settings.custBgs[Settings.options.theme]; } else { for (var themeInd : String in Settings.themes) { if (Settings.themes[themeInd].id == Settings.options.theme) { return Settings.themes[themeInd].backgroundImage; break; } } } } return ''; } public static function setSkin(id: String, callback: Function = null):void { options.skin = id; Settings.dispatchEvent(new Event('skinChanged')); id = id.split('_')[0]; id = id.charAt(0).toUpperCase() + id.substr(1); var skinName: String = id; var myEvent:IEventDispatcher = StyleManager.loadStyleDeclarations(LOOKS_DIR + skinName + "Style.swf"); if (null !== callback) { myEvent.addEventListener(ProgressEvent.PROGRESS, callback); } myEvent.addEventListener(StyleEvent.COMPLETE, function():void { var loader: Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function():void{ var wrapperClass:Class = loader.contentLoaderInfo.applicationDomain.getDefinition(skinName) as Class; var wrapper:Object = new wrapperClass(); var skin: Class; //if special list items: if (wrapper.hasOwnProperty('drawListItem')) { CustomList.skinClass = wrapper; } else { CustomList.skinClass = null; } Settings.setSmallTheme(Settings.options.theme); StyleManager.getStyleDeclaration("Button").setStyle("upSkin", wrapper.buttonSkin); StyleManager.getStyleDeclaration("Button").setStyle("downSkin", wrapper.buttonSkin); StyleManager.getStyleDeclaration("Button").setStyle("overSkin", wrapper.buttonSkin); StyleManager.getStyleDeclaration("Button").setStyle("disabledSkin", wrapper.buttonSkin); if (wrapper.hasOwnProperty('avtSkin')) { skin = wrapper.avtSkin; } else { skin = wrapper.avtSkin; } StyleManager.getStyleDeclaration(".btnUserAvtDefault").setStyle("upSkin", skin); StyleManager.getStyleDeclaration(".btnUserAvtDefault").setStyle("downSkin", skin); StyleManager.getStyleDeclaration(".btnUserAvtDefault").setStyle("overSkin", skin); StyleManager.getStyleDeclaration(".btnUserAvtDefault").setStyle("disabledSkin", skin); skin = ButtonSkin; if (wrapper.hasOwnProperty('privateChatRestoreButtonSkin')) { skin = wrapper.privateChatRestoreButtonSkin; } StyleManager.getStyleDeclaration(".privateChatRestore").setStyle("upSkin", skin); StyleManager.getStyleDeclaration(".privateChatRestore").setStyle("downSkin", skin); StyleManager.getStyleDeclaration(".privateChatRestore").setStyle("overSkin", skin); StyleManager.getStyleDeclaration(".privateChatRestore").setStyle("disabledSkin", skin); StyleManager.getStyleDeclaration(".accordionHeader").setStyle("skin", wrapper.accordionButtonSkin); StyleManager.getStyleDeclaration(".accordionHeader").setStyle("upSkin", wrapper.accordionButtonSkin); StyleManager.getStyleDeclaration(".accordionHeader").setStyle("downSkin", wrapper.accordionButtonSkin); StyleManager.getStyleDeclaration(".accordionHeader").setStyle("overSkin", wrapper.accordionButtonSkin); StyleManager.getStyleDeclaration(".accordionHeader").setStyle("disabledSkin", wrapper.accordionButtonSkin); StyleManager.getStyleDeclaration(".scrollBar").setStyle("thumbSkin", wrapper.verticalScrollSkin); StyleManager.getStyleDeclaration(".scrollBar").setStyle("thumbDownSkin", wrapper.verticalScrollSkin); StyleManager.getStyleDeclaration(".scrollBar").setStyle("downArrowSkin", wrapper.verticalScrollArrowSkin); StyleManager.getStyleDeclaration(".scrollBar").setStyle("upArrowSkin", wrapper.verticalScrollArrowSkin); skin = ScrollTrackSkin; if (wrapper.hasOwnProperty('verticalScrollTrackSkin')) { skin = wrapper.verticalScrollTrackSkin; } StyleManager.getStyleDeclaration(".scrollBar").setStyle("trackSkin", skin); skin = wrapper.comboBoxSkin; StyleManager.getStyleDeclaration("ComboBox").setStyle("upSkin", skin); StyleManager.getStyleDeclaration("ComboBox").setStyle("downSkin", skin); StyleManager.getStyleDeclaration("ComboBox").setStyle("overSkin", skin); StyleManager.getStyleDeclaration("ComboBox").setStyle("disabledSkin", skin); StyleManager.getStyleDeclaration(".btnAvt").setStyle("upSkin", skin); StyleManager.getStyleDeclaration(".btnAvt").setStyle("downSkin", skin); StyleManager.getStyleDeclaration(".btnAvt").setStyle("overSkin", skin); StyleManager.getStyleDeclaration(".btnAvt").setStyle("disabledSkin", skin); StyleManager.getStyleDeclaration("TitleWindow").setStyle("closeButtonSkin", wrapper.titleWindowCloseSkin); StyleManager.getStyleDeclaration("TitleWindow").setStyle("closeButtonUpSkin", wrapper.titleWindowCloseSkin); StyleManager.getStyleDeclaration("TitleWindow").setStyle("closeButtonDownSkin", wrapper.titleWindowCloseSkin); StyleManager.getStyleDeclaration("TitleWindow").setStyle("closeButtonOverSkin", wrapper.titleWindowCloseSkin); skin = wrapper.titleWindowCloseSkin; StyleManager.getStyleDeclaration("ResizableTitleWindow").setStyle("minimizeButtonDisabledSkin", skin); StyleManager.getStyleDeclaration("ResizableTitleWindow").setStyle("minimizeButtonOverSkin", skin); StyleManager.getStyleDeclaration("ResizableTitleWindow").setStyle("minimizeButtonDownSkin", skin); StyleManager.getStyleDeclaration("ResizableTitleWindow").setStyle("minimizeButtonUpSkin", skin); skin = PanelSkin; if (wrapper.hasOwnProperty('titleBorderSkin')) { skin = wrapper.titleBorderSkin; StyleManager.getStyleDeclaration(".dialog").setStyle("paddingTop", StyleManager.getStyleDeclaration("TitleWindow").getStyle('headerHeight')); } StyleManager.getStyleDeclaration(".dialog").setStyle("borderSkin", skin); skin = PanelSkin; if (wrapper.hasOwnProperty('changePopUp')) { skin = wrapper.titleBorderSkin; } StyleManager.getStyleDeclaration(".userPopUp").setStyle("borderSkin", skin); StyleManager.getStyleDeclaration(".tab").setStyle("skin", wrapper.tabSkin); StyleManager.getStyleDeclaration(".tabFirst").setStyle("skin", wrapper.tabSkin); StyleManager.getStyleDeclaration(".tabLast").setStyle("skin", wrapper.tabSkin); dispatchEvent(new Event("skinLoaded")); /*if (wrapper.hasOwnProperty('defaultTheme') && Settings.options.theme != wrapper.defaultTheme) { Settings.setSmallTheme(wrapper.defaultTheme); }*/ }); var request: URLRequest = new URLRequest(LOOKS_DIR + skinName + '.swf'); var context: LoaderContext = new LoaderContext(); context.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain); loader.load(request, context); }); } public static function setSmallTheme(id: String):void { var themeId: String = id; Settings.options.theme = themeId; var themeIndex: int = -1; for (var i:* in Settings.themes) { if (Settings.themes[i].id == themeId) { themeIndex = i; break; } } if (themeIndex != -1) { for (i in Settings.themeFieldsToChange) { var v: int = Settings.themes[themeIndex][Settings.themeFieldsToChange[i][1]]; CurrentTheme[Settings.themeFieldsToChange[i][0]] = v; } CurrentTheme.invalidateStyles(); } } public static function saveSettings():void { var so: SharedObject = SharedObject.getLocal(soPrefix + myid.toString()); var currentTheme: Array = new Array(); var name: String; for (var field:String in themeFieldsToChange) { name = themeFieldsToChange[field][0]; currentTheme[name] = CurrentTheme[name]; } currentTheme['MainAlpha'] = CurrentTheme['MainAlpha']; so.data.custBgs = Settings.custBgs; so.data.options = options; so.data.currentTheme = currentTheme; so.data.sounds = Sounds.sounds; so.data.commonMute = Sounds.commonMute; so.data.commonTrans = Sounds.commonTrans; so.data.lang = lang; so.data.color = Settings.getUserById(myid).color; so.flush(); } public static function loadFont(newFontName: String, targetClass: *, callback: Function = null):Boolean { var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoaded); for each (var f: Array in Settings.complFonts) { if (f[0] == newFontName) { newFontName = f[1]; break; } } switch (targetClass) { case 1: Settings.options.textAreaFontFile = newFontName; break; case 2: Settings.options.interfaceFontFile = newFontName; break; case 3: Settings.options.titleFontFile = newFontName; break; default: break; } if (fontsHistory.hasOwnProperty(newFontName)) { switch (targetClass) { case 1: Settings.changeFontName(fontsHistory[newFontName]); break; case 2: Settings.changeInterfaceFontName(fontsHistory[newFontName]); break; case 3: Settings.changeTitleFontName(fontsHistory[newFontName]); break; default: break; } return false; } else { if (null != callback) { loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, callback); } loader.load(new URLRequest(FONTS_DIR+newFontName.toLowerCase()+".swf"));//, new LoaderContext( false, app.ApplicationDomain.currentDomain )); return true; } function onLoaded(event:Event):void{ var prevFontsState: Array = Font.enumerateFonts().sortOn("fontName", Array.CASEINSENSITIVE); var fontClassName: String = newFontName.replace('-', ''); if (parseInt(fontClassName.charAt(0))) { fontClassName = '_'+fontClassName; } Font.registerFont(loader.contentLoaderInfo.applicationDomain.getDefinition(fontClassName) as Class); Font.registerFont(loader.contentLoaderInfo.applicationDomain.getDefinition(fontClassName+'i') as Class); Font.registerFont(loader.contentLoaderInfo.applicationDomain.getDefinition(fontClassName+'b') as Class); Font.registerFont(loader.contentLoaderInfo.applicationDomain.getDefinition(fontClassName+'bi') as Class); var fonts:Array = Font.enumerateFonts().sortOn("fontName", Array.CASEINSENSITIVE); for (var i:String in fonts) { if (parseInt(i)+1 > prevFontsState.length || fonts[i].fontName != prevFontsState[i].fontName) { fontsHistory[newFontName] = fonts[i].fontName; switch (targetClass) { case 1: Settings.changeFontName(fonts[i].fontName); break; case 2: Settings.changeInterfaceFontName(fonts[i].fontName, fonts[i] as Font); break; case 3: Settings.changeTitleFontName(fonts[i].fontName); break; default: break; } break; } } } } public static function preloadLanguage(name: String): void { //if null - get def lang var request:URLRequest = new URLRequest(Settings.path+"settings.php"); var loader:URLLoader = new URLLoader(request); loader.addEventListener(Event.COMPLETE,function(e:Event):void { var xml:XMLDocument = new XMLDocument(); xml.ignoreWhite = true; xml.parseXML(new XML(e.target.data)); for (var i:int = 0; i < xml.firstChild.childNodes.length; i++) { var node:XMLNode = xml.firstChild.childNodes[i]; if ('language' == node.nodeName) { if (name == node.attributes['id']) { Language.xml = node.toString(); } } } dispatchEvent(new Event('getDefaultLanguage')); }); } public static function restoreSettings():void { var so: SharedObject = SharedObject.getLocal(soPrefix + myid.toString()); if (so.size) { for each (var field:* in themeFieldsToChange) { CurrentTheme[field[0]] = so.data.currentTheme[field[0]]; } CurrentTheme['MainAlpha'] = so.data.currentTheme['MainAlpha']; custBgs = so.data.custBgs; var prevOptions: Object = ObjectUtil.copy(options); if (options.skin != so.data.options.skin) { setSkin(so.data.options.skin); } if (so.data.color != options.defColor) { ChatManager.colorChange(so.data.color); } options = so.data.options; for (var soundName: String in so.data.sounds) { Sounds.sounds[soundName].trans = new SoundTransform(so.data.sounds[soundName].trans.volume, so.data.sounds[soundName].trans.pan); Sounds.sounds[soundName].mute = so.data.sounds[soundName].mute; } Sounds.commonMute = so.data.commonMute; Sounds.commonTrans = so.data.commonTrans; if (Settings.avtDisabledFor.indexOf(Settings.myrole) == -1) { var curMAvt: String = (options.mAvtEnabled) ? options.mAvt : ''; if (prevOptions.mAvt != curMAvt) { ChatManager.changeAvt(curMAvt, 'mavt'); } var curRAvt: String = (options.rAvtEnabled) ? options.rAvt : ''; if (prevOptions.rAvt != curRAvt) { ChatManager.changeAvt(curRAvt, 'ravt'); } } if (options.photo != prevOptions.photo) { var curPhoto: String = (options.photo) ? path+options.photo : ''; ChatManager.setPhoto(curPhoto); } if (lang != so.data.lang) { lang = so.data.lang; ChatManager.setLanguage(lang); } if (getUserById(Settings.myid) && getUserById(Settings.myid).color != so.data.color) { ChatManager.colorChange(so.data.color); } Settings.dispatchEvent(new Event("updateUsers")); } changeFontSize(options.textAreaFontSize); changeInterfaceFont(options.interfaceFontSize); changeTitleFontSize(options.titleFontSize); changeFontName(options.textAreaFontName); changeInterfaceFontName(options.interfaceFontName); changeTitleFontName(options.titleFontName); if (options.textAreaFontFile) { loadFont(options.textAreaFontFile, 1); } if (options.interfaceFontFile) { loadFont(options.interfaceFontFile, 2); } if (options.titleFontFile) { loadFont(options.titleFontFile, 3); } } public static function changeInterfaceFont(fontSize: *):void { Settings.options.interfaceFontSize = fontSize; var selectors:Array = ['Button', 'ComboBox', 'Label', 'List', 'TitleWindow', '.ChannelHeader']; var style:CSSStyleDeclaration; for (var selector:* in selectors) { style = StyleManager.getStyleDeclaration(selectors[selector]); if (!style) style = new CSSStyleDeclaration(); style.setStyle( "fontSize", fontSize); StyleManager.setStyleDeclaration(selectors[selector] , style, true ); } Settings.dispatchEvent(new Event("updateUsers")); } public static function changeTitleFontSize(fontSize: *):void { Settings.options.titleFontSize = fontSize; var selectors:Array = [".mainTitle"]; var style:CSSStyleDeclaration; for (var selector:* in selectors) { style = StyleManager.getStyleDeclaration(selectors[selector]); if (!style) style = new CSSStyleDeclaration(); style.setStyle( "fontSize", fontSize); StyleManager.setStyleDeclaration(selectors[selector] , style, true ); } } public static function changeTitleFontName(fontName: *):void { Settings.options.interfaceFontName = fontName; var selectors:Array = ['.mainTitle']; var style:CSSStyleDeclaration; for (var selector:* in selectors) { style = StyleManager.getStyleDeclaration(selectors[selector]); if (!style) style = new CSSStyleDeclaration(); style.setStyle( "fontFamily", fontName); StyleManager.setStyleDeclaration(selectors[selector] , style, true ); } } public static function changeInterfaceFontName(fontName: String, font: Font = null):void { if (null == font) { var fonts: Array = Font.enumerateFonts(false); for each (var curFont: Font in fonts) { if (curFont.fontName == fontName) { font = curFont; break; } } } for (var ind:* in Settings.textLanguage) { if (null == font || font.hasGlyphs(Settings.textLanguage[ind].originalLabel)) { Settings.textLanguage[ind].label = Settings.textLanguage[ind].originalLabel; } else { Settings.textLanguage[ind].label = 'Language not available for this font (' + Settings.textLanguage[ind].data + ')'; } } Settings.options.interfaceFontName = fontName; var selectors:Array = ['Button', 'ComboBox', 'Label', 'List', 'TitleWindow', '.ChannelHeader']; var style:CSSStyleDeclaration; for (var selector:* in selectors) { style = StyleManager.getStyleDeclaration(selectors[selector]); if (!style) style = new CSSStyleDeclaration(); style.setStyle( "fontFamily", fontName); StyleManager.setStyleDeclaration(selectors[selector] , style, true ); } Settings.dispatchEvent(new Event("updateUsers")); } public static function changeFontSize(fontSize: *):void { Settings.options.textAreaFontSize = fontSize; var style:CSSStyleDeclaration; style = StyleManager.getStyleDeclaration("TextArea"); if (!style) style = new CSSStyleDeclaration(); style.setStyle( "fontSize", fontSize); StyleManager.setStyleDeclaration( "TextArea", style, true ); StyleManager.setStyleDeclaration( ".publicLog", style, true ); Settings.dispatchEvent(new Event('FontChange')); } public static function changeFontName(fontName: String):void { Settings.options.textAreaFontName = fontName; var style:CSSStyleDeclaration; style = StyleManager.getStyleDeclaration("TextArea"); if (!style) style = new CSSStyleDeclaration(); style.setStyle( "fontFamily", fontName); StyleManager.setStyleDeclaration( "TextArea", style, true ); Settings.dispatchEvent(new Event('FontChange')); } public static function loadSettings():void { var reqPath: String = Settings.path+"settings.php"; var request:URLRequest = new URLRequest(reqPath); var loader:URLLoader = new URLLoader(request); loader.addEventListener(IOErrorEvent.IO_ERROR, function(): void { Alert.show("Can't open "+reqPath, 'IOError',4, null, function(): void { navigateToURL(new URLRequest(Settings.path), '_self'); }); }); loader.addEventListener(Event.COMPLETE,function(e:Event):void { var xml:XMLDocument = new XMLDocument(); xml.ignoreWhite = true; xml.parseXML(new XML(e.target.data)); for (var attrIndex: String in xml.firstChild.attributes) { common[attrIndex] = xml.firstChild.attributes[attrIndex]; } var sound: XMLNode; var soundOptions: XMLNode; var settingsSmiles: Object; var settingsSmilesIndices: Object; allowLanguage = ('1' == xml.firstChild.attributes['allowLanguage']); defaultLang = xml.firstChild.attributes['defaultLanguage']; for (var i:int = 0; i < xml.firstChild.childNodes.length; i++) { var node:XMLNode = xml.firstChild.childNodes[i]; switch (node.nodeName) { case 'theme': var theme: Array = new Array; for (var index:String in themeFields) { //hack to prevent bug with dialogBackgound names if ('dialogBackgroundColor' == themeFields[index] && node.attributes.hasOwnProperty('dialog')) { theme[themeFields[index]] = node.attributes['dialog']; } else { theme[themeFields[index]] = node.attributes[themeFields[index]]; } } themes.push(theme); break; case 'skin': skins[node.attributes['id']] = node.attributes; break; case 'sound_options': soundOptions = node; break; case 'sound': sound = node; break; case 'avatars': modOnly = (node.childNodes[0].attributes.list as String).split(','); avatars['user'] = { male: { main: node.childNodes[1].childNodes[0].childNodes[0].attributes, room: node.childNodes[1].childNodes[0].childNodes[1].attributes }, female: { main: node.childNodes[1].childNodes[1].childNodes[0].attributes, room: node.childNodes[1].childNodes[1].childNodes[1].attributes } } avatars['admin'] = { male: { main: node.childNodes[2].childNodes[0].childNodes[0].attributes, room: node.childNodes[2].childNodes[0].childNodes[1].attributes }, female: { main: node.childNodes[2].childNodes[1].childNodes[0].attributes, room: node.childNodes[2].childNodes[1].childNodes[1].attributes } } avatars['moderator'] = { male: { main: node.childNodes[3].childNodes[0].childNodes[0].attributes, room: node.childNodes[3].childNodes[0].childNodes[1].attributes }, female: { main: node.childNodes[3].childNodes[1].childNodes[0].attributes, room: node.childNodes[3].childNodes[1].childNodes[1].attributes } } break; case 'layout': var role: String = node.attributes.role; layout[role] = node.attributes; for (var id: int = 0; id < node.childNodes.length; id ++) { switch (node.childNodes[id].nodeName) { case 'toolbar': layout[role].toolbar = node.childNodes[id].attributes; break; case 'optionPanel': layout[role].optionPanel = node.childNodes[id].attributes; break; case 'constraint': layout[role][node.childNodes[id].attributes['id']] = node.childNodes[id].attributes; break; default: break; } } break; case 'module': var modAttr: Array = new Array('anchor', 'path', 'stretch', 'float_x', 'float_y', 'float_w', 'float_h', 'enabled'); for each (var mod: String in modAttr) { if (node.attributes.hasOwnProperty(mod)) { modules[mod] = node.attributes[mod].split(','); } } break; case 'text': options.textAreaFontSize = node.firstChild.childNodes[0].attributes['fontSize']; options.textAreaFontFile = options.textAreaFontName = node.firstChild.childNodes[0].attributes['fontFamily']; options.textAreaPresence= node.firstChild.childNodes[0].attributes['presence']; options.interfaceFontSize = node.firstChild.childNodes[1].attributes['fontSize']; options.interfaceFontFile = options.interfaceFontName = node.firstChild.childNodes[1].attributes['fontFamily']; options.interfacePresence = node.firstChild.childNodes[1].attributes['presence']; options.titleFontSize = node.firstChild.childNodes[2].attributes['fontSize']; options.titleFontFile = options.titleFontName = node.firstChild.childNodes[2].attributes['fontFamily']; options.titleFontPresence = node.firstChild.childNodes[2].attributes['presence']; for (var ti:int = 0; ti < node.childNodes.length; ti++) { if (node.childNodes[ti].nodeName == 'fontSize') { for each (var size: String in node.childNodes[ti].attributes) { if (-1 == fontFamilies.indexOf(size)) { fontSize.push({label: size}); } } fontSize.sortOn('label', Array.NUMERIC); } if (node.childNodes[ti].nodeName == 'fontFamily') { for each (var itm: String in node.childNodes[ti].attributes) { if (-1 == fontFamilies.indexOf(itm)) { fontFamilies.push({name: itm, label: itm}); } } } } break; case 'logout': logout = node.attributes; break; case 'socketServer': socketServer = node.attributes; break; case 'smiles': settingsSmiles = node.attributes; for (var sml:Object in Settings.patternList) { if (node.attributes.hasOwnProperty(Settings.patternList[sml][1])) { Settings.patternList[sml][0] = (node.attributes[Settings.patternList[sml][1]] as String).toLowerCase(); } } break; case 'smilesIndices': settingsSmilesIndices = node.attributes; break; case 'language': textLanguage.addItem({data: node.attributes['id'], label: node.attributes['name'], originalLabel: node.attributes['name']}); if (defaultLang == node.attributes['id']) { Language.xml = node.toString(); } break; case 'login': login.common = node.attributes; login.username = node.childNodes[0].attributes; login.password = node.childNodes[1].attributes; login.lang = node.childNodes[2].attributes; login.title_label = node.childNodes[3].attributes; break; default: break; } } for (var smlId: String in settingsSmiles) { if (modOnly.indexOf(smlId) == -1) { allowedSmiles[settingsSmilesIndices[smlId]] = smlId; } } for (var patId: String in patternList) { if (allowedSmiles.indexOf(patternList[patId][1]) == -1 && modOnly.indexOf(patternList[patId][1]) == -1) { delete patternList[patId]; } } enableSocket = common['enableSocketServer']; options.defaultTheme = options.theme = common['defaultTheme']; options.skin = common['defaultSkin']; IS_DEBUG = '1' == common['debug']; defs.CurrentTheme = CurrentTheme; defs.options = options; //limit msg length if (!Settings.common['maxMessageSize']) { Settings.common['maxMessageSize'] = 500; } ChatManager.tmrFlood = new Timer(common['floodInterval']*1000, 1); Sounds.initSounds(soundOptions, sound) }); for each (var sysFont: String in sysFonts) { fontsHistory[sysFont] = sysFont; } } public static function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void { instance.addEventListener(type,listener,useCapture,priority,useWeakReference); } public static function removeEventListener(type:String, listener:Function, useCapture:Boolean = false): void { instance.removeEventListener(type,listener,useCapture); } public static function dispatchEvent(event:Event):Boolean { return instance.dispatchEvent(event); } public static function addRoom(title:String,id:uint):void { Settings.rooms.addItem({name:title,id:id,locked:false, data: id, label: title}); instance.dispatchEvent(new Event("updateRooms")); } public static function lockRoom(id:uint, value: Boolean):void { for (var room:String in rooms) { if (rooms[room].id == id) { rooms[room].locked = value; updateAllRooms = true; break; } } } public static function addStatus(id:uint,s:String):void { status[id] = s; } public static function addUser(title:String,id:int,room:uint, role: String):void { Settings.users.addItem({ name:title, id:id, room:room, status:1, ravt:'', mavt:'', color:0xFFFFFF, photo:null, privateExists: false, ignored: false, role: parseInt(role), entryOrder: curEntry++ }); function compareFunc(a: Object, b: Object): int { /** * 0 - A-Z * 1 - by entry * 2 - mods&admin, A-Z * 3 - mods&admins, entry * 4 - status * 5 - mods&admins, status */ var res: int = -1; var sortType: uint = parseInt(Settings.common['listOrder']); switch (sortType) { case 0: res = ObjectUtil.stringCompare(a.name, b.name); break; case 1: res = (a.entryOrder > b.entryOrder) ? 1: -1; break; case 2: if (a.role == b.role) { res = ObjectUtil.stringCompare(a.name, b.name); } else { res = (a.role < b.role) ? 1 : -1; } break; case 3: if (a.role == b.role) { res = (a.entryOrder > b.entryOrder) ? 1: -1; } else { res = (a.role < b.role) ? 1 : -1; } break; case 4: res = (a.status > b.status) ? 1: -1; break; case 5: if (a.role == b.role) { res = (a.status > b.status) ? 1: -1; } else { res = (a.role < b.role) ? 1 : -1; } break; default: break; } return res; } var sortField:SortField = new SortField(); sortField.compareFunction = compareFunc; sortField.descending = false; var sort: Sort = new Sort(); sort.fields = [sortField]; Settings.users.sort = sort; Settings.users.refresh(); instance.dispatchEvent(new Event("updateUsers")); } public static function dec2hex(num:uint):String { var hex:String = ""; for (var i:int = 20; i >= 0; i -= 4) { var v:uint = num >> i; num -= v << i; hex += String.fromCharCode((v > 9 ? v+7 : v) + 48); } return hex; } public static function getStatus(id:uint):String { if ('here' == Settings.statuses[id-1].key) { return ''; } else { return Settings.statuses[id-1].label; } /*status[1] = ""; status[2] = Language.status.busy; status[3] = Language.status.away; status[4] = Language.status.brb; if (status[id]) return status[id]; else return null;*/ } public static function moveUser(id:int,room:uint):void { if (id == Settings.myid) { Settings.myroom = room; Settings.dispatchEvent(new Event('updateRooms')); } for (var i:uint = 0; i < Settings.users.length; i++) { if (Settings.users.getItemAt(i).id == id) { Settings.users.getItemAt(i).room = room; instance.dispatchEvent(new Event("updateUsers")); return; } } } public static function removeRoom(id:uint):void { if (!id) return; for (var i:uint = 0; i < Settings.rooms.length; i++) { if (Settings.rooms.getItemAt(i).id == id) { Settings.rooms.removeItemAt(i); Settings.updateAllRooms = true; instance.dispatchEvent(new Event("updateRooms")); return; } } } public static function removeUser(id:int):void { if (!id) return; for (var i:uint = 0; i < Settings.users.length; i++) { if (Settings.users.getItemAt(i).id == id) { Settings.users.removeItemAt(i); Settings.users.refresh(); instance.dispatchEvent(new Event("updateUsers")); return; } } } public static function removeAllUsers():void { users.removeAll(); instance.dispatchEvent(new Event("updateUsers")); } public static function userStatus(id:int,s:String):void { for (var i:uint = 0; i < users.length; i++) { if (users.getItemAt(i).id == id) { users.getItemAt(i).status = parseInt(s); instance.dispatchEvent(new Event("updateUsers")); return; } } } public static function userColor(id:int,s:String):void { for (var i:uint = 0; i < Settings.users.length; i++) { if (Settings.users.getItemAt(i).id == id) { Settings.users.getItemAt(i).color = parseInt(s); instance.dispatchEvent(new Event("updateUsers")); return; } } } public static function userRavt(id:int,s:String):void { for (var i:uint = 0; i < Settings.users.length; i++) { if (Settings.users.getItemAt(i).id == id) { Settings.users.getItemAt(i).ravt = s; instance.dispatchEvent(new Event("updateUsers")); return; } } } public static function setUserPhoto(id:int,s:String):void { for (var i:uint = 0; i < Settings.users.length; i++) { if (Settings.users.getItemAt(i).id == id) { Settings.users.getItemAt(i).photo = s; return; } } } public static function getUserPhoto(id:int):String { for (var i:uint = 0; i < Settings.users.length; i++) { if (Settings.users.getItemAt(i).id == id) { return Settings.users.getItemAt(i).photo; } } return null; } } }