Example #1
0
	public void CopyTo(InputDefinition def)
	{
		def.isUsed = this.isUsed;
		def.showInGUI = this.showInGUI;
		//def.order = this.order; - do not copy order, not something that is changes outside of code
		def.inputName = this.inputName;
		def.groupName = this.groupName;
		def.triggerOnSingle = this.triggerOnSingle;
		def.triggerOnDouble = this.triggerOnDouble;
		def.triggerOnHeld = this.triggerOnHeld;
		def.primaryButton = this.primaryButton;
		def.secondaryButton = this.secondaryButton;
		def.isCustom = this.isCustom;
		def.eventGUID = this.eventGUID;
	}
Example #2
0
	// ================================================================================================================

	public static void Show(InputDefinition def, bool forPrimary)
	{
		InputSelectWiz window = EditorWindow.GetWindow<InputSelectWiz>(true, "Select Button",true);
		window.inited = false;
		window.def = def;
		window.forPrimary = forPrimary;

		window.keys = System.Enum.GetNames(typeof(KeyCode));
		string s = (forPrimary ? def.primaryButton.ToString() : def.secondaryButton.ToString());
		for (int i = 0; i < window.keys.Length; i++)
		{
			if (window.keys[i].Equals(s))
			{
				window.sel = window.prev = i;
				break;
			}
		}
		
		window.ShowUtility();
	}
Example #3
0
	private void OnAddInputDef(object sender, object[] args)
	{
		TextInputWiz wiz = sender as TextInputWiz;
		string groupName = args[0] as string;
		if (!string.IsNullOrEmpty(wiz.text) && !string.IsNullOrEmpty(groupName))
		{
			if (UniRPGEditorGlobal.inputBinds.ContainsKey(groupName))
			{
				if (!UniRPGEditorGlobal.inputBinds[groupName].ContainsKey(wiz.text))
				{
					inputSettingsChanged = true;
					InputDefinition def = new InputDefinition();
					def.isCustom = true;
					def.inputName = wiz.text;
					def.groupName = groupName;
					UniRPGEditorGlobal.inputBinds[groupName].Add(def.inputName, def);
				}
				else Debug.LogWarning("The given name was same as an existing input definition's name");
			}
		}
		wiz.Close();
		ed.Repaint();
	}
Example #4
0
	private void OnNewGroup(object sender)
	{
		TextInputWiz wiz = sender as TextInputWiz;
		if (!string.IsNullOrEmpty(wiz.text))
		{
			if (!UniRPGEditorGlobal.inputBinds.ContainsKey(wiz.text))
			{
				inputSettingsChanged = true;
				InputDefinition def = new InputDefinition();
				def.inputName = wiz.text + "_input";
				def.groupName = wiz.text;
				def.isCustom = true;
				Dictionary<string, InputDefinition> inputDef = new Dictionary<string, InputDefinition>();
				inputDef.Add(def.inputName, def);
				UniRPGEditorGlobal.inputBinds.Add(def.groupName, inputDef);
			}
		}
		wiz.Close();
		ed.Repaint();
	}
Example #5
0
	public InputDefinition GetCopy()
	{
		InputDefinition def = new InputDefinition();
		this.CopyTo(def);
		return def;
	}
Example #6
0
	private void MakeCallback(InputEvent e, InputDefinition def)
	{
		if (def.isCustom)
		{
			if (UniRPGGlobal.Instance.state != UniRPGGlobal.State.InMainMenu)
			{
				def.cachedEvent.Execute(null);
			}
		}
		else
		{
			def.callback(e, def.callbackParams);
		}
	}
Example #7
0
	private void CheckKey(KeyCode k, InputDefinition def)
	{		
		if (k != KeyCode.None)
		{
			// Get it started
			if (Input.GetKeyDown(k))
			{
				KeyStateInfo ks = null;
				keyState.TryGetValue(k, out ks);
				if (ks == null)
				{	// is a new key, add it now
					ks = new KeyStateInfo()
					{
						timer = 0.45f,
						wentUpCount = 0,
						allreadyWentUpThisFrame = false,
						hasSendSingleTriggers = false,
						shouldSetAs_hasSendSingleTriggers = false,
						shouldRemove = false,
					};
					keyState.Add(k, ks);
				}
			}

			// Detect Single/Double click event
			if (Input.GetKeyUp(k))
			{
				KeyStateInfo ks = null;
				keyState.TryGetValue(k, out ks);
				if (ks != null)
				{
					if (!ks.allreadyWentUpThisFrame)
					{
						ks.allreadyWentUpThisFrame = true;
						ks.wentUpCount++;
					}

					if (!ks.hasSendSingleTriggers)
					{
						ks.shouldSetAs_hasSendSingleTriggers = true;
						if (def.triggerOnSingle)
						{
							MakeCallback(new InputEvent() { isSingle = true }, def);
						}
					}

					if (ks.wentUpCount > 1)
					{	// a double click was detected?
						if (ks.timer > 0.0f)
						{	// yes
							if (def.triggerOnDouble)
							{	// send double click event
								ks.hasSendSingleTriggers = true; // don't allow further single triggers to occur
								MakeCallback(new InputEvent() { isDouble = true }, def);
							}
						}
						ks.shouldRemove = true;
					}

					else
					{
						if (ks.timer <= 0.0f)
						{
							ks.shouldRemove = true;
						}
					}
				}
			}

			// Detect 'Held' event
			if (Input.GetKey(k))
			{
				KeyStateInfo ks = null;
				keyState.TryGetValue(k, out ks);
				if (ks != null)
				{
					if (def.triggerOnHeld)
					{
						MakeCallback(new InputEvent() { isHeld = true }, def);
					}
				}
			}
		}
	}
Example #8
0
	/// <summary>add a new input and return its idx and the idx for the group it is in. will return groupIdx=-1 and inputIdx=-1 if the inputdef was not added</summary>
	public InputIdxCache AddInput(InputDefinition definition)
	{
		if (!definition.isUsed) return new InputIdxCache() { groupIdx = -1, inputIdx = -1 }; // not actually used, dont add

		InputIdxCache idx = new InputIdxCache();

		// get the group idx, else add group
		idx.groupIdx = GetInputGroupIdx(definition.groupName);
		if (idx.groupIdx < 0)
		{
			InputGroup group = new InputGroup() { name = definition.groupName };
			inputGroups.Add(group);
			idx.groupIdx = inputGroups.IndexOf(group);
		}

		// check if the input was already raged before and show warning if so (someone forgot to unload an input binder)
		int inputIdx = GetInputIdx(idx.groupIdx, definition.inputName);
		if (inputIdx < 0)
		{
			inputGroups[idx.groupIdx].inputs.Add(definition);
			idx.inputIdx = inputGroups[idx.groupIdx].inputs.IndexOf(definition);

			if (definition.callback != null) callbackList.Add(definition); // add to special list too
			else if (definition.isCustom && !string.IsNullOrEmpty(definition.eventGUID))
			{
				RPGEvent e = UniRPGGlobal.DB.GetEvent(new GUID(definition.eventGUID));
				if (e != null)
				{					
					definition.cachedEvent = e;
					callbackList.Add(definition);
				}
			}
		}
		else
		{
			if (!definition.isCustom) Debug.LogError(string.Format("InputBinder Error. It seems like you are trying to load an InputBinder that is already loaded. Forgot to unload it when you should have? {0} :: {1}", definition.groupName, definition.inputName));
			return new InputIdxCache() { groupIdx = -1, inputIdx = -1 };
		}

		return idx;
	}