Moved Dialogue to Helpers.ocd to avoid copies

heavy-resources
Maikel de Vries 2014-02-02 13:16:54 +01:00
parent 9f78f85206
commit 6ff632e2f2
14 changed files with 7 additions and 243 deletions

View File

@ -1,220 +0,0 @@
/**
Dialogue
Attach to a non player charachter to provide a message interface.
*/
local dlg_target;
local dlg_name;
local dlg_info;
local dlg_progress;
local dlg_status;
static const DLG_Status_Active = 0;
static const DLG_Status_Stop = 1;
static const DLG_Status_Remove = 2;
/*-- Dialogue creation --*/
// Sets a new dialogue for a npc.
global func SetDialogue(string name)
{
if (!this)
return;
var dialogue = CreateObject(Dialogue);
dialogue->InitDialogue(name, this);
dialogue->SetObjectLayer(nil);
return dialogue;
}
// Removes the existing dialogue of an object.
global func RemoveDialogue()
{
if (!this)
return;
var dialogue = FindObject(Find_ID(Dialogue), Find_ActionTarget(this));
if (dialogue)
dialogue->RemoveObject();
return;
}
/*-- Dialogue properties --*/
protected func Initialize()
{
// Dialogue progress to one.
dlg_progress = 1;
dlg_status = DLG_Status_Active;
return;
}
public func InitDialogue(string name, object target)
{
dlg_target = target;
dlg_name = name;
// Attach dialogue object to target.
SetAction("Dialogue", target);
// Update dialogue to target.
UpdateDialogue();
return;
}
private func UpdateDialogue()
{
// Adapt size to target and its direction.
var wdt = dlg_target->GetID()->GetDefWidth();
var hgt = dlg_target->GetID()->GetDefHeight();
var dir = dlg_target->GetDir();
SetShape(-wdt/2 + 2*(dir-1)*wdt, -hgt/2, 3*wdt, hgt);
// Transfer target name.
//SetName(Format("$MsgSpeak$", dlg_target->GetName()));
return;
}
public func SetDialogueInfo()
{
return;
}
public func SetDialogueProgress(int progress)
{
dlg_progress = Max(1, progress);
return;
}
public func SetDialogueStatus(int status)
{
dlg_status = status;
return;
}
/*-- Interaction --*/
// Players can talk to NPC via the interaction bar.
public func IsInteractable() { return true; }
// Adapt appearance in the interaction bar.
public func GetInteractionMetaInfo(object clonk)
{
if (InDialogue(clonk))
return { Description = Format("$MsgSpeak$", dlg_target->GetName()) , IconName = nil, IconID = Clonk, Selected = true };
return { Description = Format("$MsgSpeak$", dlg_target->GetName()) , IconName = nil, IconID = Clonk, Selected = false };
}
// Called on player interaction.
public func Interact(object clonk)
{
// Currently in a dialogue: abort that dialogue.
if (InDialogue(clonk))
clonk->CloseMenu();
// No conversation context: abort.
if (!dlg_name)
return true;
// Stop dialogue?
if (dlg_status == DLG_Status_Stop)
{
clonk->CloseMenu();
dlg_status = DLG_Status_Active;
return true;
}
// Remove dialogue?
if (dlg_status == DLG_Status_Remove)
{
clonk->CloseMenu();
RemoveObject();
return true;
}
// Start conversation context.
// Update dialogue progress first.
var progress = dlg_progress;
dlg_progress++;
// Then call relevant functions.
Call(Format("Dlg_%s_%d", dlg_name, progress), clonk);
return true;
}
private func InDialogue(object clonk)
{
return clonk->GetMenu() == Dialogue;
}
public func MessageBoxAll(string message, object talker)
{
for(var i = 0; i < GetPlayerCount(); ++i)
MessageBox(message, GetCursor(GetPlayerByIndex(i)), talker);
}
private func MessageBox(string message, object clonk, object talker)
{
// Use current NPC as talker if unspecified.
if (!talker)
talker = dlg_target;
// Use a menu for this dialogue.
clonk->CreateMenu(Dialogue, this, C4MN_Extra_None, nil, nil, C4MN_Style_Dialog, false, Dialogue);
// Add NPC portrait.
//var portrait = Format("%i", talker->GetID()); //, Dialogue, talker->GetColor(), "1");
clonk->AddMenuItem("", "MenuOk", Dialogue, nil, clonk, nil, C4MN_Add_ImgObject, talker); //TextSpec);
// Add NPC message.
var msg = Format("<c %x>%s:</c> %s", talker->GetColor(), talker->GetName(), message);
clonk->AddMenuItem(msg, "", nil, nil, nil, nil, C4MN_Add_ForceNoDesc);
// Add answers.
//for (var i = 0; i < GetLength(message.Answers); i++)
//{
// var ans = message.Answers[i][0];
// var call_back = message.Answers[i][1];
// target->AddMenuItem(ans, call_back, nil, nil, target, nil, C4MN_Add_ForceNoDesc);
//}
// Set menu decoration.
clonk->SetMenuDecoration(GUI_MenuDeco);
// Set text progress to NPC name.
var name = dlg_target->GetName();
var n_length;
while (GetChar(name, n_length))
n_length++;
clonk->SetMenuTextProgress(n_length + 1);
return;
}
public func MenuOk(unused, object clonk)
{
Interact(clonk);
}
local ActMap = {
Dialogue = {
Prototype = Action,
Name = "Dialogue",
Procedure = DFA_ATTACH,
Delay = 0,
NextAction = "Dialogue",
}
};
local Name = "$Name$";

View File

@ -1,10 +1,7 @@
[DefCore]
id=Dialogue
id=DialogueCastle
Version=5,2,0,1
Category=C4D_StaticBack
Picture=0,0,64,64
Width=1
Height=1

View File

@ -47,8 +47,8 @@ func DoInit(int first_player)
enemy->AddEnergyBar();
}
// Intro. Message 250 frames + regular message time
Dialogue->MessageBoxAll("$MsgIntro1$", Object(2648), true);
Schedule(nil, "Dialogue->MessageBoxAll(\"$MsgIntro1$\", Object(2648))", 250, 1);
DialogueCastle->MessageBoxAll("$MsgIntro1$", Object(2648), true);
Schedule(nil, "DialogueCastle->MessageBoxAll(\"$MsgIntro1$\", Object(2648))", 250, 1);
return true;
}
@ -106,20 +106,20 @@ func JoinPlayer(int plr)
func EncounterCave(object enemy, object player)
{
Dialogue->MessageBoxAll("$MsgEncounterCave$", enemy);
DialogueCastle->MessageBoxAll("$MsgEncounterCave$", enemy);
return true;
}
func EncounterOutpost(object enemy, object player)
{
Dialogue->MessageBoxAll("$MsgEncounterOutpost$", enemy);
DialogueCastle->MessageBoxAll("$MsgEncounterOutpost$", enemy);
return true;
}
func EncounterKing(object enemy, object player)
{
if (!player) player = enemy; // Leads to a funny message, but better than a null pointer.
Dialogue->MessageBoxAll(Format("$MsgEncounterKing$", player->GetName()), enemy);
DialogueCastle->MessageBoxAll(Format("$MsgEncounterKing$", player->GetName()), enemy);
return true;
}
@ -130,7 +130,7 @@ func ShroomCaveCheck()
{
var intruder = FindObject(Find_InRect(1252,1342,320,138), Find_OCF(OCF_CrewMember));
if (!intruder) return true;
Dialogue->MessageBoxAll("$MsgEncounterShrooms$", intruder);
DialogueCastle->MessageBoxAll("$MsgEncounterShrooms$", intruder);
ClearScheduleCall(nil, Scenario.ShroomCaveCheck);
return true;
}

View File

@ -1,9 +0,0 @@
[DefCore]
id=Dialogue
Version=5,2,0,1
Category=C4D_StaticBack
Width=8
Height=20
Offset=-4,-10

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

View File

@ -1,2 +0,0 @@
Name=Dialogue
MsgSpeak=%s ansprechen

View File

@ -1,2 +0,0 @@
Name=Dialogue
MsgSpeak=Speak to %s

View File

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

View File

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB