liquid tank: show to which object the pipe is connected in interaction menu

install-platforms
Maikel de Vries 2018-01-25 13:44:57 +01:00
parent 0b42dc8e20
commit 41cecc6a6f
5 changed files with 61 additions and 21 deletions

View File

@ -340,6 +340,13 @@ protected func ControlUse(object clonk, int x, int y)
return true;
}
// Returns to which object the given object is connected through this pipe.
public func GetConnectedObject(object obj)
{
if (!pipe_line)
return;
return pipe_line->GetConnectedObject(obj);
}
/**
Displays a message at top-level container of this object.

View File

@ -99,29 +99,29 @@ public func GetPipeControlMenuEntries(object clonk)
if (GetSourcePipe())
{
if (!GetSourcePipe()->QueryCutLineConnection(this))
PushBack(menu_entries, GetTankMenuEntry(Icon_Cancel, "$MsgCutSource$", 1, LIBRARY_TANK_Menu_Action_Cut_Source, RGB(102, 136, 34)));
PushBack(menu_entries, GetTankMenuEntry(Icon_Cancel, GetConnectedPipeMessage("$MsgCutSource$", GetSourcePipe()), 1, LIBRARY_TANK_Menu_Action_Cut_Source, RGB(102, 136, 34)));
}
else if (source_pipe)
PushBack(menu_entries, GetTankMenuEntry(source_pipe, "$MsgConnectSource$", 1, LIBRARY_TANK_Menu_Action_Add_Source, RGB(102, 136, 34)));
PushBack(menu_entries, GetTankMenuEntry(source_pipe, GetConnectedPipeMessage("$MsgConnectSource$", source_pipe), 1, LIBRARY_TANK_Menu_Action_Add_Source, RGB(102, 136, 34)));
if (GetDrainPipe())
{
if (!GetDrainPipe()->QueryCutLineConnection(this))
PushBack(menu_entries, GetTankMenuEntry(Icon_Cancel, "$MsgCutDrain$", 2, LIBRARY_TANK_Menu_Action_Cut_Drain, RGB(238, 102, 0)));
PushBack(menu_entries, GetTankMenuEntry(Icon_Cancel, GetConnectedPipeMessage("$MsgCutDrain$", GetDrainPipe()), 2, LIBRARY_TANK_Menu_Action_Cut_Drain, RGB(238, 102, 0)));
}
else if (drain_pipe)
PushBack(menu_entries, GetTankMenuEntry(drain_pipe, "$MsgConnectDrain$", 2, LIBRARY_TANK_Menu_Action_Add_Drain, RGB(238, 102, 0)));
PushBack(menu_entries, GetTankMenuEntry(drain_pipe, GetConnectedPipeMessage("$MsgConnectDrain$", drain_pipe), 2, LIBRARY_TANK_Menu_Action_Add_Drain, RGB(238, 102, 0)));
if (GetNeutralPipe())
{
if (!GetNeutralPipe()->QueryCutLineConnection(this))
PushBack(menu_entries, GetTankMenuEntry(Icon_Cancel, "$MsgCutNeutral$", 3, LIBRARY_TANK_Menu_Action_Cut_Neutral, RGB(80, 80, 120)));
PushBack(menu_entries, GetTankMenuEntry(Icon_Cancel, GetConnectedPipeMessage("$MsgCutNeutral$", GetNeutralPipe()), 3, LIBRARY_TANK_Menu_Action_Cut_Neutral, RGB(80, 80, 120)));
}
else if (neutral_pipe)
PushBack(menu_entries, GetTankMenuEntry(neutral_pipe, "$MsgConnectNeutral$", 3, LIBRARY_TANK_Menu_Action_Add_Neutral, RGB(80, 80, 120)));
PushBack(menu_entries, GetTankMenuEntry(neutral_pipe, GetConnectedPipeMessage("$MsgConnectNeutral$", neutral_pipe), 3, LIBRARY_TANK_Menu_Action_Add_Neutral, RGB(80, 80, 120)));
if (IsAllowedSwapSourceDrain())
PushBack(menu_entries, GetTankMenuEntry(Icon_Swap, "$MsgSwapSourceDrain$", 10, LIBRARY_TANK_Menu_Action_Swap_SourceDrain, nil));
PushBack(menu_entries, GetTankMenuEntry(Icon_Swap, GetConnectedPipeMessage("$MsgSwapSourceDrain$", GetSourcePipe(), GetDrainPipe()), 10, LIBRARY_TANK_Menu_Action_Swap_SourceDrain, nil));
return menu_entries;
}
@ -138,16 +138,16 @@ public func GetTankMenuEntry(symbol, string text, int priority, extra_data, int
}};
}
public func OnPipeControlHover(id symbol, string action, desc_menu_target, menu_id)
public func OnPipeControlHover(symbol_or_object, string action, desc_menu_target, menu_id)
{
var text = "";
if (action == LIBRARY_TANK_Menu_Action_Add_Drain) text = "$DescConnectDrain$";
else if (action == LIBRARY_TANK_Menu_Action_Cut_Drain) text = "$DescCutDrain$";
else if (action == LIBRARY_TANK_Menu_Action_Add_Source) text = "$DescConnectSource$";
else if (action == LIBRARY_TANK_Menu_Action_Cut_Source) text = "$DescCutSource$";
else if (action == LIBRARY_TANK_Menu_Action_Add_Neutral) text = "$DescConnectNeutral$";
else if (action == LIBRARY_TANK_Menu_Action_Cut_Neutral) text = "$DescCutNeutral$";
else if (action == LIBRARY_TANK_Menu_Action_Swap_SourceDrain) text = "$DescSwapSourceDrain$";
if (action == LIBRARY_TANK_Menu_Action_Add_Drain) text = GetConnectedPipeDescription("$DescConnectDrain$", symbol_or_object);
else if (action == LIBRARY_TANK_Menu_Action_Cut_Drain) text = GetConnectedPipeDescription("$DescCutDrain$", GetDrainPipe());
else if (action == LIBRARY_TANK_Menu_Action_Add_Source) text = GetConnectedPipeDescription("$DescConnectSource$", symbol_or_object);
else if (action == LIBRARY_TANK_Menu_Action_Cut_Source) text = GetConnectedPipeDescription("$DescCutSource$", GetSourcePipe());
else if (action == LIBRARY_TANK_Menu_Action_Add_Neutral) text = GetConnectedPipeDescription("$DescConnectNeutral$", symbol_or_object);
else if (action == LIBRARY_TANK_Menu_Action_Cut_Neutral) text = GetConnectedPipeDescription("$DescCutNeutral$", GetNeutralPipe());
else if (action == LIBRARY_TANK_Menu_Action_Swap_SourceDrain) text = GetConnectedPipeDescription("$DescSwapSourceDrain$", GetSourcePipe(), GetDrainPipe());
else if (action == LIBRARY_TANK_Menu_Action_Description) text = this.Description;
GuiUpdateText(text, menu_id, 1, desc_menu_target);
}
@ -172,6 +172,29 @@ public func OnPipeControl(symbol_or_object, string action, bool alt)
UpdateInteractionMenus(this.GetPipeControlMenuEntries);
}
public func GetConnectedPipeMessage(string base_msg, object pipe1, object pipe2)
{
var connected1 = (pipe1->GetConnectedObject(this) ?? pipe1->GetConnectedObject(pipe1)) ?? pipe1;
var msg = Format("%s $MsgConnectedTo$", base_msg, connected1->GetID());
if (pipe2)
{
var connected2 = (pipe2->GetConnectedObject(this) ?? pipe2->GetConnectedObject(pipe1)) ?? pipe2;
msg = Format("%s $MsgConnectedToMultiple$", base_msg, connected1->GetID(), connected2->GetID());
}
return msg;
}
public func GetConnectedPipeDescription(string base_desc, object pipe1, object pipe2)
{
var connected1 = (pipe1->GetConnectedObject(this) ?? pipe1->GetConnectedObject(pipe1)) ?? pipe1;
var desc = Format("%s $DescConnectedTo$", base_desc, connected1->GetID());
if (pipe2)
{
var connected2 = (pipe2->GetConnectedObject(this) ?? pipe2->GetConnectedObject(pipe1)) ?? pipe2;
desc = Format("%s $DescConnectedToMultiple$", base_desc, connected1->GetID(), connected2->GetID());
}
return desc;
}
/*-- Handle Connections --*/

View File

@ -14,5 +14,10 @@ DescCutSource=Entfernt das Zuflussrohr.
DescCutDrain=Entfernt das Abflussrohr.
DescCutNeutral=Entfernt das angeschlossene Rohr.
MsgConnectedTo=(verbunden mit {{%i}})
MsgConnectedToMultiple=(verbunden mit {{%i}} und {{%i}})
DescConnectedTo=Dieses Rohr ist momentan verbunden mit {{%i}}.
DescConnectedToMultiple=Dieses Rohr ist momentan verbunden mit {{%i}} und {{%i}}.
MsgSwapSourceDrain=Wechsele Zufluss und Abfluss
DescSwapSourceDrain=Wechselt das Zuflussrohr mit dem Abflussrohr.

View File

@ -14,5 +14,10 @@ DescCutSource=Removes the source pipe.
DescCutDrain=Removes the drain pipe.
DescCutNeutral=Removes the connected pipe.
MsgConnectedTo=(connected to {{%i}})
MsgConnectedToMultiple=(connected to {{%i}} and {{%i}})
DescConnectedTo=This pipe is currently connected to {{%i}}.
DescConnectedToMultiple=This pipe is currently connected to {{%i}} and {{%i}}.
MsgSwapSourceDrain=Swap source and drain
DescSwapSourceDrain=Swaps the source and drain pipes.

View File

@ -199,7 +199,7 @@ public func GetPipeControlMenuEntries(object clonk)
entry.extra_data = LIBRARY_TANK_Menu_Action_Cut_AirPipe;
entry.Priority = 4;
entry.custom.image.BackgroundColor = RGB(0, 153, 255);
entry.custom.text.Text = "$MsgCutAirPipe$";
entry.custom.text.Text = GetConnectedPipeMessage("$MsgCutAirPipe$", GetDrainPipe());
break;
}
}
@ -208,23 +208,23 @@ public func GetPipeControlMenuEntries(object clonk)
// Add attach air pipe menu entry.
var air_pipe = FindAvailablePipe(clonk, Find_Func("IsAirPipe"));
if (!drain_pipe && air_pipe)
PushBack(menu_entries, GetTankMenuEntry(air_pipe, "$MsgConnectAirPipe$", 4, LIBRARY_TANK_Menu_Action_Add_AirPipe, RGB(0, 153, 255)));
PushBack(menu_entries, GetTankMenuEntry(air_pipe, GetConnectedPipeMessage("$MsgConnectAirPipe$", air_pipe), 4, LIBRARY_TANK_Menu_Action_Add_AirPipe, RGB(0, 153, 255)));
return menu_entries;
}
public func OnPipeControlHover(id symbol, string action, desc_menu_target, menu_id)
public func OnPipeControlHover(symbol_or_object, string action, desc_menu_target, menu_id)
{
if (action == LIBRARY_TANK_Menu_Action_Cut_AirPipe)
{
GuiUpdateText("$DescCutAirPipe$", menu_id, 1, desc_menu_target);
GuiUpdateText(GetConnectedPipeDescription("$DescCutAirPipe$", GetDrainPipe()), menu_id, 1, desc_menu_target);
return;
}
if (action == LIBRARY_TANK_Menu_Action_Add_AirPipe)
{
GuiUpdateText("$DescConnectAirPipe$", menu_id, 1, desc_menu_target);
GuiUpdateText(GetConnectedPipeDescription("$DescConnectAirPipe$", symbol_or_object), menu_id, 1, desc_menu_target);
return;
}
return inherited(symbol, action, desc_menu_target, menu_id, ...);
return inherited(symbol_or_object, action, desc_menu_target, menu_id, ...);
}
public func OnPipeControl(symbol_or_object, string action, bool alt)