2009-05-08 13:28:41 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2009-06-05 13:41:20 +00:00
|
|
|
* Copyright (c) 1998-2000, 2003 Matthes Bender
|
|
|
|
* Copyright (c) 2001, 2005-2007 Sven Eberhardt
|
|
|
|
* Copyright (c) 2004-2005, 2007 Peter Wortmann
|
|
|
|
* Copyright (c) 2005-2008 Günther Brammer
|
|
|
|
* Copyright (c) 2006 Armin Burgmeier
|
|
|
|
* Copyright (c) 2009 Nicolas Hake
|
2009-05-08 13:28:41 +00:00
|
|
|
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de
|
|
|
|
*
|
|
|
|
* Portions might be copyrighted by other authors who have contributed
|
|
|
|
* to OpenClonk.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
* See isc_license.txt for full license and disclaimer.
|
|
|
|
*
|
|
|
|
* "Clonk" is a registered trademark of Matthes Bender.
|
|
|
|
* See clonk_trademark_license.txt for full license.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Handles viewport editing in console mode */
|
|
|
|
|
|
|
|
#include <C4Include.h>
|
|
|
|
#include <C4EditCursor.h>
|
|
|
|
|
|
|
|
#include <C4Console.h>
|
|
|
|
#include <C4Object.h>
|
|
|
|
#include <C4Application.h>
|
|
|
|
#include <C4Random.h>
|
2009-06-05 18:00:23 +00:00
|
|
|
#include <C4MouseControl.h>
|
2009-06-12 18:52:21 +00:00
|
|
|
#include <C4Landscape.h>
|
|
|
|
#include <C4Texture.h>
|
|
|
|
#include <C4GraphicsResource.h>
|
|
|
|
#include <C4Game.h>
|
2009-06-15 21:47:26 +00:00
|
|
|
#include <C4GameObjects.h>
|
2009-06-15 22:06:37 +00:00
|
|
|
#include <C4GameControl.h>
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-10-23 07:29:58 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "resource.h"
|
2009-05-08 13:28:41 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WITH_DEVELOPER_MODE
|
|
|
|
# include <C4Language.h>
|
|
|
|
|
2010-09-22 15:11:19 +00:00
|
|
|
# include <gtk/gtk.h>
|
2009-05-08 13:28:41 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
C4EditCursor::C4EditCursor()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
Default();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
C4EditCursor::~C4EditCursor()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
Clear();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4EditCursor::Execute()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
// alt check
|
|
|
|
bool fAltIsDown = Application.IsAltDown();
|
|
|
|
if (fAltIsDown != fAltWasDown)
|
2010-01-25 04:00:59 +00:00
|
|
|
{
|
|
|
|
if ((fAltWasDown = fAltIsDown))
|
|
|
|
AltDown();
|
|
|
|
else
|
|
|
|
AltUp();
|
|
|
|
}
|
2010-03-27 16:05:02 +00:00
|
|
|
// drawing
|
2009-05-08 13:28:41 +00:00
|
|
|
switch (Mode)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2010-03-28 18:58:01 +00:00
|
|
|
case C4CNS_ModeEdit:
|
|
|
|
// Hold selection
|
|
|
|
if (Hold)
|
|
|
|
EMMoveObject(EMMO_Move, 0, 0, NULL, &Selection);
|
|
|
|
break;
|
2009-05-08 13:28:41 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2010-03-28 18:58:01 +00:00
|
|
|
case C4CNS_ModeDraw:
|
|
|
|
switch (Console.ToolsDlg.Tool)
|
|
|
|
{
|
|
|
|
case C4TLS_Fill:
|
|
|
|
if (Hold) if (!Game.HaltCount) if (Console.Editing) ApplyToolFill();
|
2009-05-08 13:28:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
break;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
// selection update
|
|
|
|
if (fSelectionChanged)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
fSelectionChanged = false;
|
|
|
|
UpdateStatusBar();
|
|
|
|
Console.PropertyDlg.Update(Selection);
|
|
|
|
Console.ObjectListDlg.Update(Selection);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4EditCursor::Init()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (!(hMenu = LoadMenu(Application.GetInstance(),MAKEINTRESOURCE(IDR_CONTEXTMENUS))))
|
2009-08-15 18:50:32 +00:00
|
|
|
return false;
|
2009-05-08 13:28:41 +00:00
|
|
|
#else // _WIN32
|
|
|
|
#ifdef WITH_DEVELOPER_MODE
|
|
|
|
menuContext = gtk_menu_new();
|
|
|
|
|
2009-06-28 20:53:32 +00:00
|
|
|
itemDelete = gtk_menu_item_new_with_label(LoadResStr("IDS_MNU_DELETE"));
|
|
|
|
itemDuplicate = gtk_menu_item_new_with_label(LoadResStr("IDS_MNU_DUPLICATE"));
|
|
|
|
itemGrabContents = gtk_menu_item_new_with_label(LoadResStr("IDS_MNU_CONTENTS"));
|
2009-05-08 13:28:41 +00:00
|
|
|
itemProperties = gtk_menu_item_new_with_label(""); // Set dynamically in DoContextMenu
|
|
|
|
|
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(menuContext), itemDelete);
|
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(menuContext), itemDuplicate);
|
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(menuContext), itemGrabContents);
|
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(menuContext), GTK_WIDGET(gtk_separator_menu_item_new()));
|
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(menuContext), itemProperties);
|
|
|
|
|
|
|
|
g_signal_connect(G_OBJECT(itemDelete), "activate", G_CALLBACK(OnDelete), this);
|
|
|
|
g_signal_connect(G_OBJECT(itemDuplicate), "activate", G_CALLBACK(OnDuplicate), this);
|
|
|
|
g_signal_connect(G_OBJECT(itemGrabContents), "activate", G_CALLBACK(OnGrabContents), this);
|
|
|
|
g_signal_connect(G_OBJECT(itemProperties), "activate", G_CALLBACK(OnProperties), this);
|
|
|
|
|
|
|
|
gtk_widget_show_all(menuContext);
|
|
|
|
#endif // WITH_DEVELOPER_MODe
|
|
|
|
#endif // _WIN32
|
|
|
|
Console.UpdateModeCtrls(Mode);
|
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4EditCursor::ClearPointers(C4Object *pObj)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
if (Target==pObj) Target=NULL;
|
|
|
|
if (Selection.ClearPointers(pObj))
|
2010-03-28 18:58:01 +00:00
|
|
|
OnSelectionChanged();
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
bool C4EditCursor::Move(float iX, float iY, WORD wKeyFlags)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// Offset movement
|
|
|
|
float xoff = iX-X; float yoff = iY-Y;
|
2010-10-06 23:11:52 +00:00
|
|
|
X=iX; Y=iY;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
switch (Mode)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
case C4CNS_ModeEdit:
|
|
|
|
// Hold
|
|
|
|
if (!DragFrame && Hold)
|
2009-05-08 13:28:41 +00:00
|
|
|
{
|
2010-03-28 18:58:01 +00:00
|
|
|
MoveSelection(int32_t(xoff),int32_t(yoff));
|
|
|
|
UpdateDropTarget(wKeyFlags);
|
|
|
|
}
|
|
|
|
// Update target
|
|
|
|
// Shift always indicates a target outside the current selection
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Target = ((wKeyFlags & MK_SHIFT) && Selection.Last) ? Selection.Last->Obj : NULL;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Target = Game.FindObject(C4ID::None,X,Y,0,0,OCF_NotContained, NULL, NULL, NULL, NULL, ANY_OWNER, Target);
|
|
|
|
}
|
|
|
|
while ((wKeyFlags & MK_SHIFT) && Target && Selection.GetLink(Target));
|
|
|
|
}
|
|
|
|
break;
|
2009-05-08 13:28:41 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2010-03-28 18:58:01 +00:00
|
|
|
case C4CNS_ModeDraw:
|
|
|
|
switch (Console.ToolsDlg.Tool)
|
|
|
|
{
|
|
|
|
case C4TLS_Brush:
|
|
|
|
if (Hold) ApplyToolBrush();
|
2009-05-08 13:28:41 +00:00
|
|
|
break;
|
2010-03-28 18:58:01 +00:00
|
|
|
case C4TLS_Line: case C4TLS_Rect:
|
2009-05-08 13:28:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
break;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// Update
|
|
|
|
UpdateStatusBar();
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4EditCursor::UpdateStatusBar()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-10-06 23:11:52 +00:00
|
|
|
int32_t X=this->X, Y=this->Y;
|
2009-05-11 13:09:53 +00:00
|
|
|
StdStrBuf str;
|
2009-05-08 13:28:41 +00:00
|
|
|
switch (Mode)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2010-03-28 18:58:01 +00:00
|
|
|
case C4CNS_ModePlay:
|
|
|
|
if (::MouseControl.GetCaption()) str.CopyUntil(::MouseControl.GetCaption(),'|');
|
|
|
|
break;
|
2009-05-08 13:28:41 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2010-03-28 18:58:01 +00:00
|
|
|
case C4CNS_ModeEdit:
|
|
|
|
str.Format("%i/%i (%s)",X,Y,Target ? (Target->GetName()) : LoadResStr("IDS_CNS_NOTHING") );
|
|
|
|
break;
|
2009-05-08 13:28:41 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2010-03-28 18:58:01 +00:00
|
|
|
case C4CNS_ModeDraw:
|
|
|
|
str.Format("%i/%i (%s)",X,Y,MatValid(GBackMat(X,Y)) ? ::MaterialMap.Map[GBackMat(X,Y)].Name : LoadResStr("IDS_CNS_NOTHING") );
|
|
|
|
break;
|
2009-05-08 13:28:41 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
return Console.UpdateCursorBar(str.getData());
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4EditCursor::OnSelectionChanged()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
fSelectionChanged = true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4EditCursor::LeftButtonDown(bool fControl)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// Hold
|
2009-08-15 18:50:32 +00:00
|
|
|
Hold=true;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
switch (Mode)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2010-03-28 18:58:01 +00:00
|
|
|
case C4CNS_ModeEdit:
|
|
|
|
if (fControl)
|
|
|
|
{
|
|
|
|
// Toggle target
|
|
|
|
if (Target)
|
|
|
|
if (!Selection.Remove(Target))
|
|
|
|
Selection.Add(Target, C4ObjectList::stNone);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Click on unselected: select single
|
|
|
|
if (Target && !Selection.GetLink(Target))
|
|
|
|
{ Selection.Clear(); Selection.Add(Target, C4ObjectList::stNone); }
|
|
|
|
// Click on nothing: drag frame
|
|
|
|
if (!Target)
|
|
|
|
{ Selection.Clear(); DragFrame=true; X2=X; Y2=Y; }
|
|
|
|
}
|
|
|
|
break;
|
2009-05-08 13:28:41 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2010-03-28 18:58:01 +00:00
|
|
|
case C4CNS_ModeDraw:
|
|
|
|
switch (Console.ToolsDlg.Tool)
|
|
|
|
{
|
|
|
|
case C4TLS_Brush: ApplyToolBrush(); break;
|
|
|
|
case C4TLS_Line: DragLine=true; X2=X; Y2=Y; break;
|
|
|
|
case C4TLS_Rect: DragFrame=true; X2=X; Y2=Y; break;
|
|
|
|
case C4TLS_Fill:
|
|
|
|
if (Game.HaltCount)
|
|
|
|
{ Hold=false; Console.Message(LoadResStr("IDS_CNS_FILLNOHALT")); return false; }
|
2009-05-08 13:28:41 +00:00
|
|
|
break;
|
2010-03-28 18:58:01 +00:00
|
|
|
case C4TLS_Picker: ApplyToolPicker(); break;
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
break;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
DropTarget=NULL;
|
|
|
|
|
|
|
|
OnSelectionChanged();
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4EditCursor::RightButtonDown(bool fControl)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
switch (Mode)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2010-03-28 18:58:01 +00:00
|
|
|
case C4CNS_ModeEdit:
|
|
|
|
if (!fControl)
|
|
|
|
{
|
|
|
|
// Check whether cursor is on anything in the selection
|
|
|
|
bool fCursorIsOnSelection = false;
|
|
|
|
for (C4ObjectLink *pLnk = Selection.First; pLnk; pLnk = pLnk->Next)
|
|
|
|
if (pLnk->Obj->At(X,Y))
|
2009-05-08 13:28:41 +00:00
|
|
|
{
|
2010-03-28 18:58:01 +00:00
|
|
|
fCursorIsOnSelection = true;
|
|
|
|
break;
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
if (!fCursorIsOnSelection)
|
|
|
|
{
|
|
|
|
// Click on unselected
|
|
|
|
if (Target && !Selection.GetLink(Target))
|
|
|
|
{
|
|
|
|
Selection.Clear(); Selection.Add(Target, C4ObjectList::stNone);
|
|
|
|
}
|
|
|
|
// Click on nothing
|
|
|
|
if (!Target) Selection.Clear();
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
break;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
OnSelectionChanged();
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4EditCursor::LeftButtonUp()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// Finish edit/tool
|
|
|
|
switch (Mode)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2010-03-28 18:58:01 +00:00
|
|
|
case C4CNS_ModeEdit:
|
|
|
|
if (DragFrame) FrameSelection();
|
|
|
|
if (DropTarget) PutContents();
|
|
|
|
break;
|
2009-05-08 13:28:41 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2010-03-28 18:58:01 +00:00
|
|
|
case C4CNS_ModeDraw:
|
|
|
|
switch (Console.ToolsDlg.Tool)
|
|
|
|
{
|
|
|
|
case C4TLS_Line:
|
|
|
|
if (DragLine) ApplyToolLine();
|
|
|
|
break;
|
|
|
|
case C4TLS_Rect:
|
|
|
|
if (DragFrame) ApplyToolRect();
|
2009-05-08 13:28:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
break;
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// Release
|
2009-08-15 18:50:32 +00:00
|
|
|
Hold=false;
|
|
|
|
DragFrame=false;
|
|
|
|
DragLine=false;
|
2009-05-08 13:28:41 +00:00
|
|
|
DropTarget=NULL;
|
|
|
|
// Update
|
|
|
|
UpdateStatusBar();
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2009-08-15 18:50:32 +00:00
|
|
|
bool SetMenuItemEnable(HMENU hMenu, WORD id, bool fEnable)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-10-13 18:41:57 +00:00
|
|
|
return !!EnableMenuItem(hMenu,id,MF_BYCOMMAND | MF_ENABLED | ( fEnable ? 0 : MF_GRAYED));
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool SetMenuItemText(HMENU hMenu, WORD id, const char *szText)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
MENUITEMINFO minfo;
|
|
|
|
ZeroMem(&minfo,sizeof(minfo));
|
|
|
|
minfo.cbSize = sizeof(minfo);
|
|
|
|
minfo.fMask = MIIM_ID | MIIM_TYPE | MIIM_DATA;
|
|
|
|
minfo.fType = MFT_STRING;
|
|
|
|
minfo.wID = id;
|
|
|
|
minfo.dwTypeData = (char*) szText;
|
|
|
|
minfo.cch = SLen(szText);
|
2009-10-13 18:41:57 +00:00
|
|
|
return !!SetMenuItemInfo(hMenu,id,false,&minfo);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
#endif
|
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4EditCursor::RightButtonUp()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
Target=NULL;
|
|
|
|
|
|
|
|
DoContextMenu();
|
|
|
|
|
|
|
|
// Update
|
|
|
|
UpdateStatusBar();
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
bool C4EditCursor::Delete()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-08-15 18:50:32 +00:00
|
|
|
if (!EditingOK()) return false;
|
2009-05-08 13:28:41 +00:00
|
|
|
EMMoveObject(EMMO_Remove, 0, 0, NULL, &Selection);
|
2010-03-28 18:58:01 +00:00
|
|
|
if (::Control.isCtrlHost())
|
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
OnSelectionChanged();
|
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4EditCursor::OpenPropTools()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
switch (Mode)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
|
|
|
case C4CNS_ModeEdit: case C4CNS_ModePlay:
|
|
|
|
Console.PropertyDlg.Open();
|
|
|
|
Console.PropertyDlg.Update(Selection);
|
|
|
|
break;
|
|
|
|
case C4CNS_ModeDraw:
|
|
|
|
Console.ToolsDlg.Open();
|
|
|
|
break;
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4EditCursor::Duplicate()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
EMMoveObject(EMMO_Duplicate, 0, 0, NULL, &Selection);
|
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-09-24 17:51:34 +00:00
|
|
|
void C4EditCursor::Draw(C4TargetFacet &cgo)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-09-25 20:54:27 +00:00
|
|
|
ZoomDataStackItem zdsi(cgo.X, cgo.Y, cgo.Zoom);
|
2009-05-08 13:28:41 +00:00
|
|
|
// Draw selection marks
|
|
|
|
C4Object *cobj; C4ObjectLink *clnk;
|
|
|
|
for (clnk=Selection.First; clnk && (cobj=clnk->Obj); clnk=clnk->Next)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// target pos (parallax)
|
2010-09-23 01:51:08 +00:00
|
|
|
float offX, offY, newzoom;
|
2010-09-25 20:54:27 +00:00
|
|
|
cobj->GetDrawPosition(cgo, offX, offY, newzoom);
|
|
|
|
ZoomDataStackItem zdsi(cgo.X, cgo.Y, newzoom);
|
2010-03-28 18:58:01 +00:00
|
|
|
FLOAT_RECT frame =
|
|
|
|
{
|
2010-09-25 20:54:27 +00:00
|
|
|
offX+cobj->Shape.x,
|
|
|
|
offX+cobj->Shape.x + cobj->Shape.Wdt,
|
|
|
|
offY+cobj->Shape.y,
|
|
|
|
offY+cobj->Shape.y + cobj->Shape.Hgt
|
2010-03-28 18:58:01 +00:00
|
|
|
};
|
2009-05-08 13:28:41 +00:00
|
|
|
DrawSelectMark(cgo, frame);
|
|
|
|
// highlight selection if shift is pressed
|
|
|
|
if (Application.IsShiftDown())
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
uint32_t dwOldMod = cobj->ColorMod;
|
|
|
|
uint32_t dwOldBlitMode = cobj->BlitMode;
|
2009-08-23 21:46:56 +00:00
|
|
|
cobj->ColorMod = 0xffffffff;
|
2009-05-08 13:28:41 +00:00
|
|
|
cobj->BlitMode = C4GFXBLIT_CLRSFC_MOD2 | C4GFXBLIT_ADDITIVE;
|
2010-04-05 15:02:41 +00:00
|
|
|
|
2010-04-28 21:43:25 +00:00
|
|
|
StdMeshInstance::FaceOrdering old_fo = StdMeshInstance::FO_Fixed;
|
2010-04-05 15:02:41 +00:00
|
|
|
if(cobj->pMeshInstance)
|
|
|
|
{
|
|
|
|
old_fo = cobj->pMeshInstance->GetFaceOrdering();
|
|
|
|
cobj->pMeshInstance->SetFaceOrdering(StdMeshInstance::FO_NearestToFarthest);
|
|
|
|
}
|
|
|
|
|
2009-05-08 13:28:41 +00:00
|
|
|
cobj->Draw(cgo,-1);
|
|
|
|
cobj->DrawTopFace(cgo, -1);
|
2010-04-05 15:02:41 +00:00
|
|
|
|
|
|
|
if(cobj->pMeshInstance)
|
|
|
|
cobj->pMeshInstance->SetFaceOrdering(old_fo);
|
|
|
|
|
2009-05-08 13:28:41 +00:00
|
|
|
cobj->ColorMod = dwOldMod;
|
|
|
|
cobj->BlitMode = dwOldBlitMode;
|
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
// Draw drag frame
|
|
|
|
if (DragFrame)
|
2010-09-28 18:35:26 +00:00
|
|
|
lpDDraw->DrawFrameDw(cgo.Surface,
|
2010-09-25 20:54:27 +00:00
|
|
|
Min(X, X2) + cgo.X - cgo.TargetX, Min(Y, Y2) + cgo.Y - cgo.TargetY,
|
|
|
|
Max(X, X2) + cgo.X - cgo.TargetX, Max(Y, Y2) + cgo.Y - cgo.TargetY, 0xffffffff);
|
2009-05-08 13:28:41 +00:00
|
|
|
// Draw drag line
|
|
|
|
if (DragLine)
|
2010-09-28 18:35:26 +00:00
|
|
|
lpDDraw->DrawLineDw(cgo.Surface,
|
2010-09-25 20:54:27 +00:00
|
|
|
X + cgo.X - cgo.TargetX, Y + cgo.Y - cgo.TargetY,
|
|
|
|
X2 + cgo.X - cgo.TargetX, Y2 + cgo.Y - cgo.TargetY, 0xffffffff);
|
2009-05-08 13:28:41 +00:00
|
|
|
// Draw drop target
|
|
|
|
if (DropTarget)
|
2009-06-05 15:19:15 +00:00
|
|
|
::GraphicsResource.fctDropTarget.Draw(cgo.Surface,
|
2010-09-25 20:54:27 +00:00
|
|
|
DropTarget->GetX() + cgo.X - cgo.TargetX - ::GraphicsResource.fctDropTarget.Wdt / 2,
|
|
|
|
DropTarget->GetY() + DropTarget->Shape.y + cgo.Y - cgo.TargetY - ::GraphicsResource.fctDropTarget.Hgt);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
void C4EditCursor::DrawSelectMark(C4Facet &cgo, FLOAT_RECT frame)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
if ((cgo.Wdt<1) || (cgo.Hgt<1)) return;
|
|
|
|
|
|
|
|
if (!cgo.Surface) return;
|
|
|
|
|
2010-09-28 18:35:26 +00:00
|
|
|
lpDDraw->DrawPix(cgo.Surface,frame.left,frame.top,0xFFFFFFFF);
|
|
|
|
lpDDraw->DrawPix(cgo.Surface,frame.left+1,frame.top,0xFFFFFFFF);
|
|
|
|
lpDDraw->DrawPix(cgo.Surface,frame.left,frame.top+1,0xFFFFFFFF);
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-09-28 18:35:26 +00:00
|
|
|
lpDDraw->DrawPix(cgo.Surface,frame.left,frame.bottom-1,0xFFFFFFFF);
|
|
|
|
lpDDraw->DrawPix(cgo.Surface,frame.left+1,frame.bottom-1,0xFFFFFFFF);
|
|
|
|
lpDDraw->DrawPix(cgo.Surface,frame.left,frame.bottom-2,0xFFFFFFFF);
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-09-28 18:35:26 +00:00
|
|
|
lpDDraw->DrawPix(cgo.Surface,frame.right-1,frame.top,0xFFFFFFFF);
|
|
|
|
lpDDraw->DrawPix(cgo.Surface,frame.right-2,frame.top,0xFFFFFFFF);
|
|
|
|
lpDDraw->DrawPix(cgo.Surface,frame.right-1,frame.top+1,0xFFFFFFFF);
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-09-28 18:35:26 +00:00
|
|
|
lpDDraw->DrawPix(cgo.Surface,frame.right-1,frame.bottom-1,0xFFFFFFFF);
|
|
|
|
lpDDraw->DrawPix(cgo.Surface,frame.right-2,frame.bottom-1,0xFFFFFFFF);
|
|
|
|
lpDDraw->DrawPix(cgo.Surface,frame.right-1,frame.bottom-2,0xFFFFFFFF);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
void C4EditCursor::MoveSelection(int32_t iXOff, int32_t iYOff)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
EMMoveObject(EMMO_Move, iXOff, iYOff, NULL, &Selection);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4EditCursor::FrameSelection()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
Selection.Clear();
|
2010-03-27 16:05:02 +00:00
|
|
|
C4Object *cobj; C4ObjectLink *clnk;
|
2009-06-15 21:47:26 +00:00
|
|
|
for (clnk=::Objects.First; clnk && (cobj=clnk->Obj); clnk=clnk->Next)
|
2009-05-08 13:28:41 +00:00
|
|
|
if (cobj->Status) if (cobj->OCF & OCF_NotContained)
|
|
|
|
{
|
2010-03-28 18:58:01 +00:00
|
|
|
if (Inside(cobj->GetX(),Min(X,X2),Max(X,X2)) && Inside(cobj->GetY(),Min(Y,Y2),Max(Y,Y2)))
|
|
|
|
Selection.Add(cobj, C4ObjectList::stNone);
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
|
|
|
Console.PropertyDlg.Update(Selection);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4EditCursor::In(const char *szText)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
EMMoveObject(EMMO_Script, 0, 0, NULL, &Selection, szText);
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4EditCursor::Default()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
fAltWasDown=false;
|
2009-05-08 13:28:41 +00:00
|
|
|
Mode=C4CNS_ModePlay;
|
|
|
|
X=Y=X2=Y2=0;
|
|
|
|
Target=DropTarget=NULL;
|
|
|
|
#ifdef _WIN32
|
|
|
|
hMenu=NULL;
|
|
|
|
#endif
|
2009-08-15 18:50:32 +00:00
|
|
|
Hold=DragFrame=DragLine=false;
|
2009-05-08 13:28:41 +00:00
|
|
|
Selection.Default();
|
|
|
|
fSelectionChanged = false;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4EditCursor::Clear()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (hMenu) DestroyMenu(hMenu); hMenu=NULL;
|
|
|
|
#endif
|
|
|
|
Selection.Clear();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4EditCursor::SetMode(int32_t iMode)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// Store focus
|
|
|
|
#ifdef _WIN32
|
|
|
|
HWND hFocus=GetFocus();
|
|
|
|
#endif
|
|
|
|
// Update console buttons (always)
|
|
|
|
Console.UpdateModeCtrls(iMode);
|
|
|
|
// No change
|
2009-08-15 18:50:32 +00:00
|
|
|
if (iMode==Mode) return true;
|
2009-05-08 13:28:41 +00:00
|
|
|
// Set mode
|
|
|
|
Mode = iMode;
|
|
|
|
// Update prop tools by mode
|
2009-08-15 18:50:32 +00:00
|
|
|
bool fOpenPropTools = false;
|
2009-05-08 13:28:41 +00:00
|
|
|
switch (Mode)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2010-03-28 18:58:01 +00:00
|
|
|
case C4CNS_ModeEdit: case C4CNS_ModePlay:
|
|
|
|
if (Console.ToolsDlg.Active || Console.PropertyDlg.Active) fOpenPropTools=true;
|
|
|
|
Console.ToolsDlg.Clear();
|
|
|
|
if (fOpenPropTools) OpenPropTools();
|
|
|
|
break;
|
2009-05-08 13:28:41 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2010-03-28 18:58:01 +00:00
|
|
|
case C4CNS_ModeDraw:
|
|
|
|
if (Console.ToolsDlg.Active || Console.PropertyDlg.Active) fOpenPropTools=true;
|
|
|
|
Console.PropertyDlg.Clear();
|
|
|
|
if (fOpenPropTools) OpenPropTools();
|
|
|
|
break;
|
2009-05-08 13:28:41 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
// Update cursor
|
2009-06-05 15:20:07 +00:00
|
|
|
if (Mode==C4CNS_ModePlay) ::MouseControl.ShowCursor();
|
|
|
|
else ::MouseControl.HideCursor();
|
2009-05-08 13:28:41 +00:00
|
|
|
// Restore focus
|
|
|
|
#ifdef _WIN32
|
|
|
|
SetFocus(hFocus);
|
|
|
|
#endif
|
|
|
|
// Done
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
bool C4EditCursor::ToggleMode()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-03-28 18:58:01 +00:00
|
|
|
if (!EditingOK()) return false;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// Step through modes
|
|
|
|
int32_t iNewMode;
|
|
|
|
switch (Mode)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
|
|
|
case C4CNS_ModePlay: iNewMode=C4CNS_ModeEdit; break;
|
|
|
|
case C4CNS_ModeEdit: iNewMode=C4CNS_ModeDraw; break;
|
|
|
|
case C4CNS_ModeDraw: iNewMode=C4CNS_ModePlay; break;
|
|
|
|
default: iNewMode=C4CNS_ModePlay; break;
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// Set new mode
|
|
|
|
SetMode(iNewMode);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4EditCursor::ApplyToolBrush()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
if (!EditingOK()) return;
|
|
|
|
C4ToolsDlg *pTools=&Console.ToolsDlg;
|
2010-03-27 16:05:02 +00:00
|
|
|
// execute/send control
|
2009-06-05 15:20:41 +00:00
|
|
|
EMControl(CID_EMDrawTool, new C4ControlEMDrawTool(EMDT_Brush, ::Landscape.Mode, X,Y,0,0, pTools->Grade, !!pTools->ModeIFT, pTools->Material,pTools->Texture));
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4EditCursor::ApplyToolLine()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
if (!EditingOK()) return;
|
|
|
|
C4ToolsDlg *pTools=&Console.ToolsDlg;
|
2010-03-27 16:05:02 +00:00
|
|
|
// execute/send control
|
2009-06-05 15:20:41 +00:00
|
|
|
EMControl(CID_EMDrawTool, new C4ControlEMDrawTool(EMDT_Line, ::Landscape.Mode, X,Y,X2,Y2, pTools->Grade, !!pTools->ModeIFT, pTools->Material,pTools->Texture));
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4EditCursor::ApplyToolRect()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
if (!EditingOK()) return;
|
|
|
|
C4ToolsDlg *pTools=&Console.ToolsDlg;
|
2010-03-27 16:05:02 +00:00
|
|
|
// execute/send control
|
2009-06-05 15:20:41 +00:00
|
|
|
EMControl(CID_EMDrawTool, new C4ControlEMDrawTool(EMDT_Rect, ::Landscape.Mode, X,Y,X2,Y2, pTools->Grade, !!pTools->ModeIFT, pTools->Material,pTools->Texture));
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4EditCursor::ApplyToolFill()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
if (!EditingOK()) return;
|
|
|
|
C4ToolsDlg *pTools=&Console.ToolsDlg;
|
2010-03-27 16:05:02 +00:00
|
|
|
// execute/send control
|
2009-06-05 15:20:41 +00:00
|
|
|
EMControl(CID_EMDrawTool, new C4ControlEMDrawTool(EMDT_Fill, ::Landscape.Mode, X,Y,0,Y2, pTools->Grade, false, pTools->Material));
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4EditCursor::DoContextMenu()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-03-25 19:57:08 +00:00
|
|
|
bool fObjectSelected = !!Selection.ObjectCount();
|
2009-05-08 13:28:41 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
POINT point; GetCursorPos(&point);
|
|
|
|
HMENU hContext = GetSubMenu(hMenu,0);
|
|
|
|
SetMenuItemEnable( hContext, IDM_VIEWPORT_DELETE, fObjectSelected && Console.Editing);
|
|
|
|
SetMenuItemEnable( hContext, IDM_VIEWPORT_DUPLICATE, fObjectSelected && Console.Editing);
|
|
|
|
SetMenuItemEnable( hContext, IDM_VIEWPORT_CONTENTS, fObjectSelected && Selection.GetObject()->Contents.ObjectCount() && Console.Editing);
|
|
|
|
SetMenuItemEnable( hContext, IDM_VIEWPORT_PROPERTIES, Mode!=C4CNS_ModePlay);
|
|
|
|
SetMenuItemText(hContext,IDM_VIEWPORT_DELETE,LoadResStr("IDS_MNU_DELETE"));
|
|
|
|
SetMenuItemText(hContext,IDM_VIEWPORT_DUPLICATE,LoadResStr("IDS_MNU_DUPLICATE"));
|
|
|
|
SetMenuItemText(hContext,IDM_VIEWPORT_CONTENTS,LoadResStr("IDS_MNU_CONTENTS"));
|
|
|
|
SetMenuItemText(hContext,IDM_VIEWPORT_PROPERTIES,LoadResStr((Mode==C4CNS_ModeEdit) ? "IDS_CNS_PROPERTIES" : "IDS_CNS_TOOLS"));
|
|
|
|
int32_t iItem = TrackPopupMenu(
|
2010-03-28 18:58:01 +00:00
|
|
|
hContext,
|
|
|
|
TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_NONOTIFY,
|
|
|
|
point.x,point.y, 0,
|
|
|
|
Console.hWindow,
|
|
|
|
NULL);
|
2009-05-08 13:28:41 +00:00
|
|
|
switch (iItem)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
|
|
|
case IDM_VIEWPORT_DELETE: Delete(); break;
|
|
|
|
case IDM_VIEWPORT_DUPLICATE: Duplicate(); break;
|
|
|
|
case IDM_VIEWPORT_CONTENTS: GrabContents(); break;
|
|
|
|
case IDM_VIEWPORT_PROPERTIES: OpenPropTools(); break;
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
#else
|
|
|
|
#ifdef WITH_DEVELOPER_MODE
|
|
|
|
gtk_widget_set_sensitive(itemDelete, fObjectSelected && Console.Editing);
|
|
|
|
gtk_widget_set_sensitive(itemDuplicate, fObjectSelected && Console.Editing);
|
|
|
|
gtk_widget_set_sensitive(itemGrabContents, fObjectSelected && Selection.GetObject()->Contents.ObjectCount() && Console.Editing);
|
|
|
|
gtk_widget_set_sensitive(itemProperties, Mode!=C4CNS_ModePlay);
|
|
|
|
|
|
|
|
GtkLabel* label = GTK_LABEL(gtk_bin_get_child(GTK_BIN(itemProperties)));
|
2009-06-28 20:53:32 +00:00
|
|
|
gtk_label_set_text(label, LoadResStr((Mode==C4CNS_ModeEdit) ? "IDS_CNS_PROPERTIES" : "IDS_CNS_TOOLS"));
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
gtk_menu_popup(GTK_MENU(menuContext), NULL, NULL, NULL, NULL, 3, 0);
|
|
|
|
#endif
|
|
|
|
#endif
|
2009-08-15 18:50:32 +00:00
|
|
|
return true;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4EditCursor::GrabContents()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// Set selection
|
|
|
|
C4Object *pFrom;
|
|
|
|
if (!( pFrom = Selection.GetObject() )) return;
|
|
|
|
Selection.Copy(pFrom->Contents);
|
|
|
|
Console.PropertyDlg.Update(Selection);
|
2009-08-15 18:50:32 +00:00
|
|
|
Hold=true;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// Exit all objects
|
2010-03-27 16:05:02 +00:00
|
|
|
EMMoveObject(EMMO_Exit, 0, 0, NULL, &Selection);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4EditCursor::UpdateDropTarget(WORD wKeyFlags)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
C4Object *cobj; C4ObjectLink *clnk;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
DropTarget=NULL;
|
|
|
|
|
|
|
|
if (wKeyFlags & MK_CONTROL)
|
|
|
|
if (Selection.GetObject())
|
2009-06-15 21:47:26 +00:00
|
|
|
for (clnk=::Objects.First; clnk && (cobj=clnk->Obj); clnk=clnk->Next)
|
2009-05-08 13:28:41 +00:00
|
|
|
if (cobj->Status)
|
|
|
|
if (!cobj->Contained)
|
|
|
|
if (Inside<int32_t>(X-(cobj->GetX()+cobj->Shape.x),0,cobj->Shape.Wdt-1))
|
|
|
|
if (Inside<int32_t>(Y-(cobj->GetY()+cobj->Shape.y),0,cobj->Shape.Hgt-1))
|
|
|
|
if (!Selection.GetLink(cobj))
|
|
|
|
{ DropTarget=cobj; break; }
|
|
|
|
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4EditCursor::PutContents()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
if (!DropTarget) return;
|
2010-03-27 16:05:02 +00:00
|
|
|
EMMoveObject(EMMO_Enter, 0, 0, DropTarget, &Selection);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
C4Object *C4EditCursor::GetTarget()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
return Target;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-08-15 18:50:32 +00:00
|
|
|
bool C4EditCursor::EditingOK()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
if (!Console.Editing)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-08-15 18:50:32 +00:00
|
|
|
Hold=false;
|
2009-05-08 13:28:41 +00:00
|
|
|
Console.Message(LoadResStr("IDS_CNS_NONETEDIT"));
|
2009-08-15 18:50:32 +00:00
|
|
|
return false;
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
int32_t C4EditCursor::GetMode()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
return Mode;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4EditCursor::ToolFailure()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
C4ToolsDlg *pTools=&Console.ToolsDlg;
|
2009-08-15 18:50:32 +00:00
|
|
|
Hold=false;
|
2009-05-11 13:09:53 +00:00
|
|
|
Console.Message(FormatString(LoadResStr("IDS_CNS_NOMATDEF"),pTools->Material,pTools->Texture).getData());
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4EditCursor::ApplyToolPicker()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
int32_t iMaterial;
|
|
|
|
BYTE byIndex;
|
2009-06-05 15:20:41 +00:00
|
|
|
switch (::Landscape.Mode)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
|
|
|
case C4LSC_Static:
|
|
|
|
// Material-texture from map
|
|
|
|
if ((byIndex=::Landscape.GetMapIndex(X/::Landscape.MapZoom,Y/::Landscape.MapZoom)))
|
2009-05-08 13:28:41 +00:00
|
|
|
{
|
2010-03-28 18:58:01 +00:00
|
|
|
const C4TexMapEntry *pTex = ::TextureMap.GetEntry(byIndex & (IFT-1));
|
|
|
|
if (pTex)
|
|
|
|
{
|
|
|
|
Console.ToolsDlg.SelectMaterial(pTex->GetMaterialName());
|
|
|
|
Console.ToolsDlg.SelectTexture(pTex->GetTextureName());
|
2010-04-07 01:12:28 +00:00
|
|
|
Console.ToolsDlg.SetIFT(!!(byIndex & ~(IFT-1)));
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
else
|
|
|
|
Console.ToolsDlg.SelectMaterial(C4TLS_MatSky);
|
|
|
|
break;
|
|
|
|
case C4LSC_Exact:
|
|
|
|
// Material only from landscape
|
|
|
|
if (MatValid(iMaterial=GBackMat(X,Y)))
|
|
|
|
{
|
|
|
|
Console.ToolsDlg.SelectMaterial(::MaterialMap.Map[iMaterial].Name);
|
|
|
|
Console.ToolsDlg.SetIFT(!!GBackIFT(X,Y));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Console.ToolsDlg.SelectMaterial(C4TLS_MatSky);
|
|
|
|
break;
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
Hold=false;
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4EditCursor::EMMoveObject(C4ControlEMObjectAction eAction, int32_t tx, int32_t ty, C4Object *pTargetObj, const C4ObjectList *pObjs, const char *szScript)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
// construct object list
|
|
|
|
int32_t iObjCnt = 0; int32_t *pObjIDs = NULL;
|
2010-03-28 18:58:01 +00:00
|
|
|
if (pObjs && (iObjCnt = pObjs->ObjectCount()))
|
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
pObjIDs = new int32_t [iObjCnt];
|
|
|
|
// fill
|
|
|
|
int32_t i = 0;
|
2010-03-28 18:58:01 +00:00
|
|
|
for (C4ObjectLink *pLnk = pObjs->First; pLnk; pLnk = pLnk->Next, i++)
|
|
|
|
if (pLnk->Obj && pLnk->Obj->Status)
|
2010-03-27 16:05:02 +00:00
|
|
|
pObjIDs[i] = pLnk->Obj->Number;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2010-03-27 16:05:02 +00:00
|
|
|
|
|
|
|
// execute control
|
|
|
|
EMControl(CID_EMMoveObj, new C4ControlEMMoveObject(eAction, tx, ty, pTargetObj, iObjCnt, pObjIDs, szScript));
|
|
|
|
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4EditCursor::EMControl(C4PacketType eCtrlType, C4ControlPacket *pCtrl)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
::Control.DoInput(eCtrlType, pCtrl, CDT_Decide);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
#ifdef WITH_DEVELOPER_MODE
|
|
|
|
// GTK+ callbacks
|
|
|
|
void C4EditCursor::OnDelete(GtkWidget* widget, gpointer data)
|
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
static_cast<C4EditCursor*>(data)->Delete();
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void C4EditCursor::OnDuplicate(GtkWidget* widget, gpointer data)
|
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
static_cast<C4EditCursor*>(data)->Duplicate();
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void C4EditCursor::OnGrabContents(GtkWidget* widget, gpointer data)
|
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
static_cast<C4EditCursor*>(data)->GrabContents();
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void C4EditCursor::OnProperties(GtkWidget* widget, gpointer data)
|
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
static_cast<C4EditCursor*>(data)->OpenPropTools();
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool C4EditCursor::AltDown()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
// alt only has an effect in draw mode (picker)
|
|
|
|
if (Mode == C4CNS_ModeDraw)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
Console.ToolsDlg.SetAlternateTool();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2010-03-27 16:05:02 +00:00
|
|
|
// key not processed - allow further usages of Alt
|
|
|
|
return false;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
bool C4EditCursor::AltUp()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
if (Mode == C4CNS_ModeDraw)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
Console.ToolsDlg.ResetAlternateTool();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2010-03-27 16:05:02 +00:00
|
|
|
// key not processed - allow further usages of Alt
|
|
|
|
return false;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|