public CTooltip(CToolkitUI Toolkit, CGameUIStyle Style, GameObject Root) { _ui = Toolkit; _style = Style; _tooltipOverGame = false; _tooltip = _ui.CreateElement(Root, "tooltip"); _ui.AddImage(_tooltip, _style.TooltipBackground); _ui.SetTransform(_tooltip, 0, 0, 256, 256); _ui.AddVerticalLayout(_tooltip, new RectOffset(3, 3, 3, 3), 3); _tooltip.GetComponent <RectTransform>().anchorMax = new Vector2(0, 0); _tooltip.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0); ContentSizeFitter fitter = _tooltip.AddComponent <ContentSizeFitter>(); fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; float width = 150.0f; GameObject title = _ui.CreateTextElement(_tooltip, "Title", "title", CToolkitUI.ETextStyle.TS_HEADING); _ui.AddLayout(title, width, -1, -1, -1); GameObject details = _ui.CreateTextElement(_tooltip, "Sub-title", "subtitle", CToolkitUI.ETextStyle.TS_DEFAULT); _ui.AddLayout(details, width, -1, -1, -1); GameObject desc = _ui.CreateTextElement(_tooltip, "Description text that can be longer.", "description", CToolkitUI.ETextStyle.TS_HEADING); _ui.AddLayout(desc, width, -1, -1, -1); Hide(false); }
public CContextMenu(CToolkitUI Toolkit, CGameUIStyle Style, GameObject Root) { _ui = Toolkit; _style = Style; _root = _ui.CreateElement(Root, "contextMenuRoot"); _ui.AddImage(_root, new Color(0, 0, 0, 0.0f)); _ui.SetRectFillParent(_root); _root.AddComponent <CUIContextMenuOverlay>(); _contextMenu = _ui.CreateElement(_root, "contextMenu"); _ui.AddImage(_contextMenu, _style.TooltipBackground); _ui.SetTransform(_contextMenu, 0, 0, 128, 256); _ui.AddVerticalLayout(_contextMenu, new RectOffset(3, 3, 3, 3), 3); _contextMenu.GetComponent <RectTransform>().anchorMax = new Vector2(0, 0); _contextMenu.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0); ContentSizeFitter fitter = _contextMenu.AddComponent <ContentSizeFitter>(); fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; Hide(); }
/// <summary> /// Game startup. /// </summary> public CGame(CUnityInterface Interface, string CommandLineArgs) { _cmdArgs = CommandLineArgs.Split(' '); string[] parms; #if !UNITY_EDITOR DataDirectory = Application.dataPath + "/Data/"; PersistentDataDirectory = Application.persistentDataPath + "/"; #else DataDirectory = "Data/"; PersistentDataDirectory = "SaveData/"; #endif Config = new CConfig(PersistentDataDirectory + "config.txt"); Config.Load(); #if !UNITY_EDITOR DataDirectory = Application.dataPath + "/Data/"; PersistentDataDirectory = Application.persistentDataPath + "/"; if (_CheckArg("dev", out parms)) { Screen.SetResolution(1280, 720, false); } else { string resType = Config.GetString("ResolutionType"); if (resType == "default") { Resolution r = Screen.resolutions[Screen.resolutions.Length - 1]; Screen.SetResolution(r.width, r.height, true); } else if (resType == "fullscreen" || resType == "windowed") { Resolution r = Screen.resolutions[Screen.resolutions.Length - 1]; int resX = (int)Config.GetFloat("ResolutionWidth"); int resY = (int)Config.GetFloat("ResolutionHeight"); Screen.SetResolution(resX, resY, (resType == "fullscreen")); } } #endif CUtility.MakeDirectory(PersistentDataDirectory + SAVES_DIRECTORY); CUtility.MakeDirectory(PersistentDataDirectory + REPLAYS_DIRECTORY); PrimaryResources = Interface.GetComponent <CPrimaryResources>(); WorldResources = Interface.GetComponent <CWorldResources>(); UIResources = Interface.GetComponent <CUIResources>(); ToolkitUI = Interface.GetComponent <CToolkitUI>(); GameUIStyle = Interface.GetComponent <CGameUIStyle>(); Console = new CConsole(); Debug.Log("Save game directory: " + PersistentDataDirectory); Debug.Log("Data directory: " + DataDirectory); VarShowGrid = Console.CreateVar("show_grid", false); VarShowVisLines = Console.CreateVar("show_los", false); VarShowDDATest = Console.CreateVar("show_ddatest", false); VarShowArcTest = Console.CreateVar("show_arctest", false); VarShowBounds = Console.CreateVar("show_bounds", false); VarShowDebugStats = Console.CreateVar("show_debugstats", false); VarShowMobility = Console.CreateVar("show_mobility", 0, 0, CWorld.MAX_PLAYERS); VarShowSolidity = Console.CreateVar("show_solidity", 0, 0, CWorld.MAX_PLAYERS + 1); VarShowProfiler = Console.CreateVar("show_profiler", false); VarNoFow = Console.CreateVar("no_fow", false); VarPlaceItemDirect = Console.CreateVar("place_item_direct", false); VarShowComfort = Console.CreateVar("show_comfort", false); VarShowEfficiency = Console.CreateVar("show_efficiency", false); VarShowPathing = Console.CreateVar("pathing", false); VarShowFlowField = Console.CreateVar("show_flowfield", false); VarShowNavMesh = Console.CreateVar("show_navmesh", false); VarShowNavRect = Console.CreateVar("show_navrect", 0, 0, CWorld.MAX_PLAYERS); VarShowProxies = Console.CreateVar("show_proxies", 0, 0, CWorld.MAX_PLAYERS); VarFreePurchases = Console.CreateVar("freebuy", true); Console.CreateCommand("gameui", (Params) => { UIManager.ToggleUIActive(); }); Console.CreateCommand("quit", (Params) => { ExitApplication(); }); Console.CreateCommand("exit", (Params) => { ExitApplication(); }); Console.CreateCommand("set_owed", (Params) => { if (_gameSession == null) { return; } _gameSession.SetOwed(1000); }); Console.CreateCommand("set_stamina", (Params) => { if (_gameSession == null) { return; } _gameSession.SetStamina(10.0f); }); Console.CreateCommand("set_hunger", (Params) => { if (_gameSession == null) { return; } _gameSession.SetHunger(80); }); Console.CreateCommand("rebuild_icons", (Params) => { IconBuilder.RebuildItemIcons(true); }); Game = this; Steam = new CSteam(); PrimaryThreadProfiler = new CProfiler(); SimThreadProfiler = new CProfiler(); DebugLevels = new CDebugLevels(); UniversalRandom = new CRandomStream(); AssetManager = new CAssetManager(); Net = new CNet(); Resources = new CResources(); CameraManager = new CCameraManager(); UIManager = new CUIManager(ToolkitUI, GameUIStyle); CDebug.StaticInit(); AssetManager.Init(); ProfilerManager = new CProfilerManager(); ProfilerManager.Init(); IconBuilder = new CIconBuilder(); IconBuilder.Init(); _inputState = new CInputState(); Console.Hide(); Analytics.SetUserId(Steam.mSteamID.ToString()); // TODO: Backquote is not ~, investigate. // TOOD: Allow the same command to have multiple keys associated with it. _inputState.RegisterCommand("console", Config.GetString("KeyConsole"), true); _inputState.RegisterCommand("escape", Config.GetString("KeyEscape")); _inputState.RegisterCommand("focusOnSpawn", Config.GetString("KeyFocusOnSpawn")); _inputState.RegisterCommand("camForward", Config.GetString("KeyCamForward")); _inputState.RegisterCommand("camLeft", Config.GetString("KeyCamLeft")); _inputState.RegisterCommand("camBackward", Config.GetString("KeyCamBackward")); _inputState.RegisterCommand("camRight", Config.GetString("KeyCamRight")); _inputState.RegisterCommand("camRotateLeft", KeyCode.Delete); _inputState.RegisterCommand("camRotateRight", KeyCode.PageDown); _inputState.RegisterCommand("itemPlaceRotate", Config.GetString("KeyPlaceRotate")); _inputState.RegisterCommand("itemPlaceRepeat", Config.GetString("KeyPlaceRepeat")); _inputState.RegisterCommand("action1", Config.GetString("KeyAction1")); _inputState.RegisterCommand("action2", Config.GetString("KeyAction2")); _inputState.RegisterCommand("action3", Config.GetString("KeyAction3")); _inputState.RegisterCommand("action4", Config.GetString("KeyAction4")); _inputState.RegisterCommand("openOptions", Config.GetString("KeyOptionsMenu")); _inputState.RegisterCommand("reload", KeyCode.F5); _inputState.RegisterCommand("space", KeyCode.Space); _inputState.RegisterCommand("editorDelete", Config.GetString("KeyEditorDelete")); _inputState.RegisterCommand("editorDuplicate", Config.GetString("KeyEditorDuplicate")); _inputState.RegisterCommand("editorUndo", Config.GetString("KeyEditorUndo")); _inputState.RegisterCommand("editorRedo", Config.GetString("KeyEditorRedo")); _inputState.RegisterCommand("editorSave", Config.GetString("KeyEditorSave")); // Apply default settings //Application.targetFrameRate = 60; //QualitySettings.antiAliasing // Volume range: 0.0 - -80.0 // TODO: Volume in DB is exponential, making 0 to 1 range for config ineffective. UIResources.MasterMixer.SetFloat("MasterVolume", CMath.MapRangeClamp(Config.GetFloat("MasterVolume"), 0, 1, -80, -12)); UIResources.MasterMixer.SetFloat("MusicVolume", CMath.MapRangeClamp(Config.GetFloat("MusicVolume"), 0, 1, -80, 0)); UIResources.MasterMixer.SetFloat("SoundsVolume", CMath.MapRangeClamp(Config.GetFloat("SoundsVolume"), 0, 1, -80, 0)); UIResources.MasterMixer.SetFloat("UISoundsVolume", CMath.MapRangeClamp(Config.GetFloat("UISoundsVolume"), 0, 1, -80, 0)); // NOTE: BE SUPER CAREFUL WITH THIS // You can corrupt ALL the item assets if not careful. // Saves asset to disk, but asset currently in memory won't reflect new version. //_resaveAllItemAssetsToLastestVersion(); // TODO: This bootstraps all model assets on startup. // If the model asset is first loaded by the sim thread, then it will crash as it tries to generate the meshes. // Should probably only generate meshes when they are pulled in by the main thread. _testItemAssetVersion(); if (_CheckArg("toolkit", out parms)) { StartAssetToolkit(); } else if (_CheckArg("map", out parms)) { if (parms != null && parms.Length > 0) { CGameSession.CStartParams startParams = new CGameSession.CStartParams(); startParams.mPlayType = CGameSession.EPlayType.SINGLE; startParams.mUserPlayerIndex = 0; // Will be set by the level when loaded. startParams.mLevelName = parms[0]; StartGameSession(startParams); } } else { UIManager.AddInterface(new CMainMenuUI()); } }
public CUIManager(CToolkitUI Toolkit, CGameUIStyle Style) { _ui = Toolkit; _style = Style; _uiRes = CGame.UIResources; mPoseRT = new RenderTexture(512, 512, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); mPoseRT.antiAliasing = 8; gameUI = _ui.CreateElement(_ui.Canvas, "gameUI"); _ui.SetRectFillParent(gameUI); gameUI.transform.SetAsFirstSibling(); underlayLayer = _ui.CreateElement(gameUI, "underlayLayer"); _ui.SetRectFillParent(underlayLayer); CanvasGroup cgroup = underlayLayer.AddComponent <CanvasGroup>(); cgroup.blocksRaycasts = false; primaryLayer = _ui.CreateElement(gameUI, "primaryLayer"); mPrimaryLayerGroup = primaryLayer.AddComponent <CanvasGroup>(); mPrimaryLayerGroup.alpha = 1.0f; _ui.SetRectFillParent(primaryLayer); overlayLayer = _ui.CreateElement(gameUI, "overlayLayer"); _ui.SetRectFillParent(overlayLayer); cgroup = overlayLayer.AddComponent <CanvasGroup>(); cgroup.blocksRaycasts = false; cutsceneLayer = _ui.CreateElement(gameUI, "cutsceneLayer"); _ui.SetRectFillParent(cutsceneLayer); GameObject letterBox = _ui.CreateElement(cutsceneLayer); _ui.SetAnchors(letterBox, new Vector2(0, 1), new Vector2(1, 1), new Vector2(0, 1)); _ui.AddImage(letterBox, _style.ThemeColorC); _ui.SetTransform(letterBox, 0, 0, 0, 54); letterBox = _ui.CreateElement(cutsceneLayer); _ui.SetAnchors(letterBox, new Vector2(0, 0), new Vector2(1, 0), new Vector2(0, 0)); _ui.AddImage(letterBox, _style.ThemeColorC); _ui.SetTransform(letterBox, 0, 0, 0, 54); mCutsceneLayerGroup = cutsceneLayer.AddComponent <CanvasGroup>(); mCutsceneLayerGroup.alpha = 0.0f; mCutsceneLayerGroup.blocksRaycasts = false; /* * fadeOverLayer = _ui.CreateElement(gameUI, "fadeOverLayer"); * _ui.SetRectFillParent(fadeOverLayer); * _ui.AddImage(fadeOverLayer, Color.black); */ contextMenuLayer = _ui.CreateElement(gameUI, "contextMenuLayer"); _ui.SetRectFillParent(contextMenuLayer); mMenuLayer = _ui.CreateElement(gameUI, "menuLayer"); _ui.SetRectFillParent(mMenuLayer); GameObject productText = _ui.CreateTextElement(overlayLayer, CGame.PRODUCT_NAME + " (" + CGame.VERSION_MAJOR + "." + CGame.VERSION_MINOR + ") " + CGame.VERSION_NAME, "productText", CToolkitUI.ETextStyle.TS_HEADING); _ui.SetAnchors(productText, new Vector2(0, 1), new Vector2(1, 1), new Vector2(0, 1)); _ui.SetTransform(productText, 5, 0, -10, 20); productText.GetComponent <Text>().alignment = TextAnchor.MiddleRight; mContextMenu = new CContextMenu(Toolkit, Style, contextMenuLayer); mTooltip = new CTooltip(Toolkit, Style, overlayLayer); SetupForGameSession(); }