Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
condition if don't have a item
Browse files Browse the repository at this point in the history
  • Loading branch information
brunurd committed Dec 23, 2017
1 parent 734e410 commit 02cacf4
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 170 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/AssetStoreTools*
Diplomata/*.meta
Diplomata/*/*.meta
Diplomata/*/*/*.meta
*.meta
*.unitypackage
Binary file modified Diplomata Canvas.prefab
Binary file not shown.
6 changes: 3 additions & 3 deletions Diplomata Canvas.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Diplomata.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 37 additions & 1 deletion Diplomata/Editor/MessagesEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ public static void Main() {
}
text += condition.DisplayHasItem(itemName);
break;
case Condition.Type.DoesNotHaveTheItem:
var itemNameDont = "";
if (Item.Find(diplomataEditor.inventory.items, condition.itemId) != null) {
itemNameDont = DictHandler.ContainsKey(Item.Find(diplomataEditor.inventory.items, condition.itemId).name,
diplomataEditor.preferences.currentLanguage).value;
}
text += condition.DisplayDoesNotHaveItem(itemNameDont);
break;
case Condition.Type.ItemWasDiscarded:
var itemNameDiscarded = "";
if (Item.Find(diplomataEditor.inventory.items, condition.itemId) != null) {
Expand Down Expand Up @@ -966,7 +974,35 @@ public static void Sidebar() {

GUILayout.EndHorizontal();
break;


case Condition.Type.DoesNotHaveTheItem:
GUILayout.BeginHorizontal();
UpdateItemList();

var itemNameDont = "";

if (itemList.Length > 0) {
itemNameDont = DictHandler.ContainsKey(Item.Find(diplomataEditor.inventory.items, condition.itemId).name, diplomataEditor.preferences.currentLanguage).value;
}

EditorGUI.BeginChangeCheck();

itemNameDont = DGUI.Popup("Does not have the item ", itemNameDont, itemList);

if (EditorGUI.EndChangeCheck()) {
foreach (Item item in diplomataEditor.inventory.items) {

if (DictHandler.ContainsKey(item.name, diplomataEditor.preferences.currentLanguage).value == itemNameDont) {
condition.itemId = item.id;
break;
}

}
}

GUILayout.EndHorizontal();
break;

case Condition.Type.ItemIsEquipped:
GUILayout.BeginHorizontal();
UpdateItemList();
Expand Down
7 changes: 6 additions & 1 deletion Diplomata/Lib/Condition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public enum Type {
ItemWasDiscarded,
CustomFlagEqualTo,
ItemIsEquipped,
InteractsWith
InteractsWith,
DoesNotHaveTheItem
}

[System.Serializable]
Expand Down Expand Up @@ -76,6 +77,10 @@ public string DisplayHasItem(string itemName) {
return "Has the item: <i>" + itemName + "</i>";
}

public string DisplayDoesNotHaveItem(string itemName) {
return "Does not have the item: <i>" + itemName + "</i>";
}

public string DisplayItemWasDiscarded(string itemName) {
return "item was discarded: <i>" + itemName + "</i>";
}
Expand Down
56 changes: 38 additions & 18 deletions Diplomata/Lib/DiplomataCharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
using UnityEngine;

namespace DiplomataLib {

[System.Serializable]
[ExecuteInEditMode]
[DisallowMultipleComponent]
public class DiplomataCharacter : MonoBehaviour {

public List<Message> choices = new List<Message>();
public Message currentMessage;
public Character character;
Expand All @@ -18,13 +18,13 @@ public class DiplomataCharacter : MonoBehaviour {
private Context currentContext;
private Column currentColumn;
private string lastUniqueId;

public void Start() {
controlIndexes = new Dictionary<string, int>();
controlIndexes.Add("context", 0);
controlIndexes.Add("column", 0);
controlIndexes.Add("message", 0);

if (character != null && Application.isPlaying) {
character = Character.Find(Diplomata.characters, character.name);
}
Expand All @@ -44,7 +44,7 @@ public void StartTalk() {
currentMessage = null;

choices = new List<Message>();

for (controlIndexes["context"] = 0; controlIndexes["context"] < character.contexts.Length; controlIndexes["context"]++) {
var context = Context.Find(character, controlIndexes["context"]);
var lastContext = character.contexts.Length - 1;
Expand Down Expand Up @@ -78,7 +78,7 @@ public void StartTalk() {
EndTalk();
}
}

private void Next(bool hasFate) {

if (character != null && currentContext != null) {
Expand Down Expand Up @@ -173,6 +173,27 @@ private void Next(bool hasFate) {
condition.proceed = false;
}

break;
case Condition.Type.DoesNotHaveTheItem:
var itemDont = Item.Find(Diplomata.inventory.items, condition.itemId);

if (itemDont != null) {

if (itemDont.have) {
condition.proceed = false;
}

else {
condition.proceed = true;
}

}

else {
Debug.LogWarning("Cannot find the item with id " + condition.itemId + " to check.");
condition.proceed = false;
}

break;
case Condition.Type.ItemIsEquipped:
var equippedItem = Item.Find(Diplomata.inventory.items, condition.itemId);
Expand Down Expand Up @@ -332,7 +353,7 @@ private void Next(bool hasFate) {
public string ShowMessageContentSubtitle() {

if (talking) {
if (currentMessage != null && Diplomata.gameProgress.options.currentSubtitledLanguage != string.Empty) {
if (currentMessage != null) {
var talkLog = TalkLog.Find(Diplomata.gameProgress.talkLog, character.name);

if (talkLog == null) {
Expand All @@ -358,7 +379,7 @@ public string ShowMessageContentSubtitle() {
}

public void PlayMessageAudioContent() {
if (currentMessage != null && Diplomata.gameProgress.options.currentDubbedLanguage != string.Empty) {
if (currentMessage != null) {
var audioClipPath = DictHandler.ContainsKey(currentMessage.audioClipPath, Diplomata.gameProgress.options.currentDubbedLanguage);

if (audioClipPath.value != string.Empty) {
Expand Down Expand Up @@ -386,7 +407,7 @@ public void PlayMessageAudioContent() {
}

public void StopMessageAudioContent() {
if (currentMessage != null && Diplomata.gameProgress.options.currentDubbedLanguage != string.Empty) {
if (currentMessage != null) {
var audioClipPath = DictHandler.ContainsKey(currentMessage.audioClipPath, Diplomata.gameProgress.options.currentDubbedLanguage);

if (audioClipPath.value != string.Empty) {
Expand Down Expand Up @@ -467,7 +488,6 @@ public void ResetAnimators() {
var animators = FindObjectsOfType(typeof(Animator));

foreach (Animator animator in animators) {

if (animator.runtimeAnimatorController != null) {

foreach (AnimatorAttributeSetter animatorAttribute in currentMessage.animatorAttributesSetters) {
Expand Down Expand Up @@ -532,13 +552,13 @@ public void EndTalk() {

public void NextMessage() {
var hasFate = false;

if (currentMessage != null) {

controlIndexes["column"] = currentMessage.columnId;
controlIndexes["message"] = currentMessage.id;
lastUniqueId = currentMessage.GetUniqueId();

foreach (Effect effect in currentMessage.effects) {

switch (effect.type) {
Expand Down Expand Up @@ -682,11 +702,11 @@ public void NextMessage() {
Next(false);
}
}

public List<string> MessageChoices() {
List<string> choicesText = new List<string>();

if (choices.Count > 0 && Diplomata.gameProgress.options.currentSubtitledLanguage != string.Empty) {
if (choices.Count > 0) {
foreach (Message choice in choices) {
if (!choice.alreadySpoked && choice.disposable) {
choicesText.Add(DictHandler.ContainsKey(choice.title, Diplomata.gameProgress.options.currentSubtitledLanguage).value);
Expand Down Expand Up @@ -720,10 +740,10 @@ public void OnStartCallbacks() {
}

public void ChooseMessage(string title) {
if (currentColumn != null && Diplomata.gameProgress.options.currentSubtitledLanguage != string.Empty) {
if (currentColumn != null) {
foreach (Message msg in choices) {
var localTitle = DictHandler.ContainsKey(msg.title, Diplomata.gameProgress.options.currentSubtitledLanguage).value;

if (localTitle == title) {
currentMessage = msg;
OnStartCallbacks();
Expand Down Expand Up @@ -871,11 +891,11 @@ public Message GetLastMessage() {
}

public string GetLastMessageContent() {
if (lastUniqueId == null || lastUniqueId == "" || Diplomata.gameProgress.options.currentSubtitledLanguage == string.Empty) {
if (lastUniqueId == null || lastUniqueId == "") {
return "";
}

return DictHandler.ContainsKey(GetLastMessage().content,
return DictHandler.ContainsKey(GetLastMessage().content,
Diplomata.gameProgress.options.currentSubtitledLanguage).value;
}

Expand Down
10 changes: 0 additions & 10 deletions Diplomata/Lib/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ public Language(Language other) {
subtitle = other.subtitle;
dubbing = other.dubbing;
}

public static Language Find(Language[] languages, string name) {
foreach (Language lang in languages) {
if (lang.name == name) {
return lang;
}
}

return null;
}
}

[System.Serializable]
Expand Down
4 changes: 2 additions & 2 deletions LICENSE.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Textures.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Textures/DIPLOMATA-Logo_CC-BY-ND_by-Bruno-Araujo.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 02cacf4

Please sign in to comment.