BOOL C4PropertyDlg::Update() { if (!Active) return FALSE; StdStrBuf Output; idSelectedDef = C4ID_None; // Compose info text by selected object(s) switch (Selection.ObjectCount()) { // No selection case 0: Output = LoadResStr("IDS_CNS_NOOBJECT"); break; // One selected object case 1: { C4Object *cobj = Selection.GetObject(); // Type Output.AppendFormat(LoadResStr("IDS_CNS_TYPE"), cobj->GetName(), C4IdText(cobj->Def->id)); // Owner if (ValidPlr(cobj->Owner)) { Output.Append(LineFeed); Output.AppendFormat(LoadResStr("IDS_CNS_OWNER"), Game.Players.Get(cobj->Owner)->GetName()); } // Contents if (cobj->Contents.ObjectCount()) { Output.Append(LineFeed); Output.Append(LoadResStr("IDS_CNS_CONTENTS")); Output.Append(static_cast<const StdStrBuf &>( cobj->Contents.GetNameList(Game.Defs))); } // Action if (cobj->Action.Act != ActIdle) { Output.Append(LineFeed); Output.Append(LoadResStr("IDS_CNS_ACTION")); Output.Append(cobj->Def->ActMap[cobj->Action.Act].Name); } // Locals int cnt; bool fFirstLocal = true; for (cnt = 0; cnt < cobj->Local.GetSize(); cnt++) if (!!cobj->Local[cnt]) { // Header if (fFirstLocal) { Output.Append(LineFeed); Output.Append(LoadResStr("IDS_CNS_LOCALS")); fFirstLocal = false; } Output.Append(LineFeed); // Append id Output.AppendFormat(" Local(%d) = ", cnt); // write value Output.Append( static_cast<const StdStrBuf &>(cobj->Local[cnt].GetDataString())); } // Locals (named) for (cnt = 0; cnt < cobj->LocalNamed.GetAnzItems(); cnt++) { // Header if (fFirstLocal) { Output.Append(LineFeed); Output.Append(LoadResStr("IDS_CNS_LOCALS")); fFirstLocal = false; } Output.Append(LineFeed); // Append name Output.AppendFormat(" %s = ", cobj->LocalNamed.pNames->pNames[cnt]); // write value Output.Append(static_cast<const StdStrBuf &>( cobj->LocalNamed.pData[cnt].GetDataString())); } // Effects for (C4Effect *pEffect = cobj->pEffects; pEffect; pEffect = pEffect->pNext) { // Header if (pEffect == cobj->pEffects) { Output.Append(LineFeed); Output.Append(LoadResStr("IDS_CNS_EFFECTS")); } Output.Append(LineFeed); // Effect name Output.AppendFormat(" %s: Interval %d", pEffect->Name, pEffect->iIntervall); } // Store selected def idSelectedDef = cobj->id; break; } // Multiple selected objects default: Output.Format(LoadResStr("IDS_CNS_MULTIPLEOBJECTS"), Selection.ObjectCount()); break; } // Update info edit control #ifdef WITH_DEVELOPER_MODE GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); gtk_text_buffer_set_text( buffer, C4Language::IconvUtf8(Output.getData()).getData(), -1); #endif return TRUE; }
bool C4ObjectMenu::DoRefillInternal(bool &rfRefilled) { // Variables C4FacetSurface fctSymbol; C4Object *pObj; char szCaption[256+1],szCommand[256+1],szCommand2[256+1]; int32_t iCount; C4Def *pDef; C4IDList ListItems; C4Object *pTarget; C4Facet fctTarget; // Refill switch (Identification) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - case C4MN_Activate: // Clear items ClearItems(); // Refill target if (!(pTarget=RefillObject)) return false; { // Add target contents items C4ObjectListIterator iter(pTarget->Contents); while ((pObj = iter.GetNext(&iCount))) { pDef = pObj->Def; if (pDef->NoGet) continue; // Prefer fully constructed objects if (~pObj->OCF & OCF_FullCon) { // easy way: only if first concat check matches // this doesn't catch all possibilities, but that will rarely matter C4Object *pObj2=pTarget->Contents.Find(pDef, ANY_OWNER, OCF_FullCon); if (pObj2) if (pObj2->CanConcatPictureWith(pObj)) pObj = pObj2; } // Caption sprintf(szCaption,LoadResStr("IDS_MENU_ACTIVATE"),(const char *) pObj->GetName()); // Picture fctSymbol.Set(fctSymbol.Surface, 0,0,C4SymbolSize,C4SymbolSize); pObj->Picture2Facet(fctSymbol); // Commands sprintf(szCommand,"SetCommand(\"Activate\",Object(%d))&&ExecuteCommand()",pObj->Number); sprintf(szCommand2,"SetCommand(\"Activate\",nil,%d,0,Object(%d),%s)&&ExecuteCommand()",pTarget->Contents.ObjectCount(pDef->id),pTarget->Number,pDef->id.ToString()); // Add menu item Add(szCaption,fctSymbol,szCommand,iCount,pObj,"",pDef->id,szCommand2,true,pObj->GetValue(pTarget, NO_OWNER)); // facet taken over (arrg!) fctSymbol.Default(); } } break; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - case C4MN_Get: case C4MN_Contents: // Clear items ClearItems(); // Refill target if (!(pTarget = RefillObject)) return false; { // Add target contents items C4ObjectListIterator iter(pTarget->Contents); while ((pObj = iter.GetNext(&iCount))) { pDef = pObj->Def; if (pDef->NoGet) continue; // Prefer fully constructed objects if (~pObj->OCF & OCF_FullCon) { // easy way: only if first concat check matches // this doesn't catch all possibilities, but that will rarely matter C4Object *pObj2 = pTarget->Contents.Find(pDef, ANY_OWNER, OCF_FullCon); if (pObj2) if (pObj2->CanConcatPictureWith(pObj)) pObj = pObj2; } // Determine whether to get or activate bool fGet = true; if (!(pObj->OCF & OCF_Carryable)) fGet = false; // not a carryable item if (Identification == C4MN_Contents) { if (Object && !!Object->Call(PSF_RejectCollection, &C4AulParSet(pObj->Def, pObj))) fGet = false; // collection rejected } if (!(pTarget->OCF & OCF_Entrance)) fGet = true; // target object has no entrance: cannot activate - force get // Caption sprintf(szCaption, LoadResStr(fGet ? "IDS_MENU_GET" : "IDS_MENU_ACTIVATE"), (const char *)pObj->GetName()); // Picture fctSymbol.Set(fctSymbol.Surface, 0, 0, C4SymbolSize, C4SymbolSize); pObj->Picture2Facet(fctSymbol); // Primary command: get/activate single object sprintf(szCommand, "SetCommand(\"%s\", Object(%d)) && ExecuteCommand()", fGet ? "Get" : "Activate", pObj->Number); // Secondary command: get/activate all objects of the chosen type szCommand2[0] = 0; int32_t iAllCount; if ((iAllCount = pTarget->Contents.ObjectCount(pDef->id)) > 1) sprintf(szCommand2, "SetCommand(\"%s\", nil, %d,0, Object(%d), %s) && ExecuteCommand()", fGet ? "Get" : "Activate", iAllCount, pTarget->Number, pDef->id.ToString()); // Add menu item (with object) Add(szCaption, fctSymbol, szCommand, iCount, pObj, "", pDef->id, szCommand2); fctSymbol.Default(); } } break; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - default: // Not an internal menu return true; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - } // Successfull internal refill rfRefilled = true; return true; }
bool C4EditCursor::DoContextMenu(DWORD dwKeyState) { bool fObjectSelected = !!Selection.ObjectCount(); #ifdef USE_WIN32_WINDOWS 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); 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")); ObjselectDelItems(); C4FindObjectAtPoint pFO(X,Y); C4ValueArray * atcursor; atcursor = pFO.FindMany(::Objects, ::Objects.Sectors); // needs freeing (single object ptr) int itemcount = atcursor->GetSize(); if(itemcount > 0) { const int maxitems = 25; // Maximum displayed objects. if you raise it, also change note with IDM_VPORTDYN_FIRST in resource.h if(itemcount > maxitems) itemcount = maxitems+1; itemsObjselect.resize(itemcount+1); // +1 for a separator itemsObjselect[0].ItemId = IDM_VPORTDYN_FIRST; itemsObjselect[0].Object = NULL; AppendMenu(hContext, MF_SEPARATOR, IDM_VPORTDYN_FIRST, NULL); int i = 1; for(std::vector<ObjselItemDt>::iterator it = itemsObjselect.begin() + 1; it != itemsObjselect.end(); ++it, ++i) { C4Object * obj = (*atcursor)[i-1].getObj(); assert(obj); it->ItemId = IDM_VPORTDYN_FIRST+i; it->Object = obj; AppendMenu(hContext, MF_STRING, it->ItemId, FormatString("%s #%i (%i/%i)", obj->GetName(), obj->Number, obj->GetX(), obj->GetY()).GetWideChar()); } if(atcursor->GetSize() > maxitems) { AppendMenu(hContext, MF_GRAYED, IDM_VPORTDYN_FIRST+maxitems+1, L"..."); itemsObjselect[maxitems+1].ItemId = IDM_VPORTDYN_FIRST+maxitems+1; itemsObjselect[maxitems+1].Object = NULL; } } delete atcursor; int32_t iItem = TrackPopupMenu( hContext, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_NONOTIFY, point.x,point.y, 0, Console.hWindow, NULL); switch (iItem) { case IDM_VIEWPORT_DELETE: Delete(); break; case IDM_VIEWPORT_DUPLICATE: Duplicate(); break; case IDM_VIEWPORT_CONTENTS: GrabContents(); break; case 0: break; default: for(std::vector<ObjselItemDt>::iterator it = itemsObjselect.begin() + 1; it != itemsObjselect.end(); ++it) if(it->ItemId == iItem) { DoContextObjsel(it->Object, (dwKeyState & MK_SHIFT) == 0); break; } break; } ObjselectDelItems(); #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); ObjselectDelItems(); C4FindObjectAtPoint pFO(X,Y); C4ValueArray * atcursor; atcursor = pFO.FindMany(::Objects, ::Objects.Sectors); // needs freeing int itemcount = atcursor->GetSize(); if(itemcount > 0) { itemsObjselect.resize(itemcount+1); // +1 for a separator itemsObjselect[0].MenuItem = gtk_separator_menu_item_new(); itemsObjselect[0].EditCursor = this; gtk_menu_shell_append(GTK_MENU_SHELL(menuContext), itemsObjselect[0].MenuItem); int i = 0; for(std::vector<ObjselItemDt>::iterator it = itemsObjselect.begin() + 1; it != itemsObjselect.end(); ++it, ++i) { it->EditCursor = this; C4Object * obj = (*atcursor)[i].getObj(); assert(obj); it->Object = obj; GtkWidget * wdg = gtk_menu_item_new_with_label(FormatString("%s #%i (%i/%i)", obj->GetName(), obj->Number, obj->GetX(), obj->GetY()).getData()); it->MenuItem = wdg; gtk_menu_shell_append(GTK_MENU_SHELL(menuContext), wdg); g_signal_connect(G_OBJECT(wdg), "activate", G_CALLBACK(OnObjselect), &*it); } } delete atcursor; gtk_widget_show_all(menuContext); gtk_menu_popup(GTK_MENU(menuContext), NULL, NULL, NULL, NULL, 3, 0); #endif #endif return true; }