How can I auto-hide/open panels in Unity with multiple buttons? - unity3d

I have tried to find solutions but somehow I can't find the right solution for my problem. I have 5 buttons and each button opens or closes its panel. However, I want that if I click on Button 2 that the panel closes for Button 1 and so. There should be only one panel active for each button.
It is just having a tab menu you are clicking through, only the panel of the last pressed button is active. I have seen a tutorial with images and Eventsystems but does not fit my current project.
I would be grateful for any help.

You can create a list for panels and in the same order add buttons to the another list. Respective button and panel in same places. Then when you press a button get index it in script. Activate matching panel index and disable others. In my script, I don't want to disable panels because I need to those script to run everytime. In your case you can just disable them.
for (int i = 0; i < panels.Count; i++)
{
if (i == index)
{
panels[i].GetComponent<CanvasGroup>().interactable = true;
panels[i].GetComponent<CanvasGroup>().alpha = 1;
panels[i].GetComponent<CanvasGroup>().blocksRaycasts = true;
// Place to front for interaction
panels[i].transform.SetAsLastSibling();
}
else
{
panels[i].GetComponent<CanvasGroup>().interactable = false;
panels[i].GetComponent<CanvasGroup>().alpha = 0;
panels[i].GetComponent<CanvasGroup>().blocksRaycasts = false;
}
}

Related

Press, hide button in ChartContainerContent in UI5 fiori

Hi all SAP UI5 and FIORI positive,
I have ChartContainer with button for graph and button for table. It is defined in xml file as:
<suite:ChartContainerContent id="idButtonChart"
icon = "sap-icon://bar-chart"
title = "Chart"
>
<suite:ChartContainerContent id="idButtonTable"
icon = "sap-icon://table-view"
title = "{i18n>table}">
<suite:content>
Let's say I want to hide some of these buttons which are placed inside ChartContainer. I have tried (in controller.js part):
this.getView().byId("idButtonChart").setVisible(false);
or
this.getView().byId("idButtonChart").setVisible(false);
But this code, hided graph but not button. Please, do you have any idea how to hide button? Or to trigger click event on button idButtonTable?
Thanks for any advices.
Have you found any good solution for this issue? I've been checking the SDK and I can't find a way to get those buttons in an straight way.
Anyway, you could do it using the following code -
var chartContainerContent = this.getView().byId('your chart id');
var chartContainer = chartContainerContent.getParent();
var aToolbarButtons = chartContainer._oToolBar.getContent();
var segmentedButton;
for(var i=0; i<aToolbarButtons.length; i++){
var button = aToolbarButtons[i];
if(button.getMetadata()._sClassName === "sap.m.SegmentedButton"){
segmentedButton = button;
break;
}
}
//segmentedButton.getButtons()
Once you get the buttons you can setVisible(false) to the one you want.
Of course this is not the best, but the chartContainer doesn't provide any public function to get the buttons of the chart.
I try to understand the issue. You define 2 charts in your example.
The buttons are usually used to switch the display to the corresponding chart.
How are you going to switch between the 2 charts if you hide the corresponding button?
A little late but I guess an .updateChartContainer() after the .setVisible should do the trick:
this.getView().byId("idButtonChart").setVisible(false);
this.getView().byId("<NAME OF THE CONTENT CONTAINER>").updateChartContainer();

Gui.Window ContextClick

Is there a way to add an Event.ContextClick to a Gui.Window in a Unity Editor script?
The following is my context menu method that I've tried calling from both OnGUI() and my window's WindowFunction (call sites denoted below as "site: no luck"). I have not been able to get the "Success" message to show up unless I'm right clicking directly in the main editor window. If I right click in any of the Gui.Windows I have created, the ContextClick event doesn't show up.
void OnStateContextMenu(){
Event evt = Event.current;
// Ignore anything but contextclicks
if(evt.type != EventType.ContextClick)return;
Debug.Log("Success");
// Add generic menu at context point
GenericMenu menu = new GenericMenu();
menu.AddItem (new GUIContent ("AddState"),false,AddState,evt.mousePosition);
menu.ShowAsContext ();
evt.Use();
}
And the call site(s):
void doWindow(int id){
// OnStateContextMenu(); //site1: no luck
GUI.DragWindow();
}
void OnGUI(){
OnStateContextMenu(); //site2: no luck here either
BeginWindows();
wndRect = GUI.Window(0,wndRect,doWindow,"StateWnd");
EndWindows();
}
Update
For reference, green area responds to right-click, red area does not. But I want it to. The right-click menu I've created has specific actions I only want visible if the mouse cursor right clicks inside one of my windows, the 'Hello' in the image. Note: Ignore the button, right click doesn't work anywhere inside that window.
This might not directly answer your question but should be able to help
You are trying to achieve a rightclick function inside your red box( as shown in picute )
I had a sort alike question a while back but it was not for a rightclick but for a mouseover
so i figured this might be able to help you
string mouseover; // first of i created a new string
if (GUI.Button (new Rect (100,100,200,200),new GUIContent("Load game", "MouseOverOnButton0") ,menutexture ))
{
//added a mousoveronbutton command to my GUIcontent
executestuff();
}
buttoncheck();
}
void buttoncheck()
{
mouseover = GUI.tooltip;
if(mouseover == "MouseOverOnButton0")
{
GUI.Box(new Rect(380,45,235,25),"Not a implemented function as of yet ");
}
}
this code made a new gui box the moment the mouse hitted the box.
If you created the hello in a seperate box you could use this
if(mouseover == hello)
{
if(rightclick == true)
{
execute the stuff you want
}
}
or something like that. Hope this helps a bit atleast
UPDATE
To obtain the rightclick event you will have to use the
if(Event.current.button == 1 && Event.current.isMouse)
You have to place this in the OnGUI to work properly
this way you first trigger the in box part, then check for a right click and execute the stuff you want.

Remove "File, edit,...etc" menus from Eclipse RCP application

I want to remove the File, edit, Source, Refactor, etc. menus from my RCP application
Can I use hideActionSet() ? or what should I do ?
That's right; in your ApplicationWorkbenchWindowAdvisor, override postWindowOpen().
The tricky bit is usually figuring out the names of the actionsets that you want to remove, but you can use the old standby ALT-SHIFT-F2 (the default keybinding for 'Plugin-in Menu Spy') and click on one of the menu items that you want to remove.
Note that if the menu item is disabled, the spy won't give you any info on it.
public void postWindowOpen() {
runApplicationWorkbenchDelegate();
// remove unwanted UI contributions that eclipse makes by default
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
for (int i = 0; i < windows.length; ++i) {
IWorkbenchPage page = windows[i].getActivePage();
if (page != null) {
// hide generic 'File' commands
page.hideActionSet("org.eclipse.ui.actionSet.openFiles");
// hide 'Convert Line Delimiters To...'
page.hideActionSet("org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo");
// hide 'Search' commands
page.hideActionSet("org.eclipse.search.searchActionSet");
// hide 'Annotation' commands
page.hideActionSet("org.eclipse.ui.edit.text.actionSet.annotationNavigation");
// hide 'Forward/Back' type navigation commands
page.hideActionSet("org.eclipse.ui.edit.text.actionSet.navigation");
}
}
}
Although the question is old:
Lars Vogel's tutorial about Eclipse Activities shows how to hide entire menus in an RCP application rather than removing single menu-entries.
EDIT:
Alternatively you can use the MenuManager attached to the workbench window to show or hide Menus/Contributions.
Try the following code to hide all menus:
WorkbenchWindow workbenchWin = (WorkbenchWindow)PlatformUI.getWorkbench().getActiveWorkbenchWindow();
MenuManager menuManager = workbenchWin.getMenuManager();
IContributionItem[] items = menuManager.getItems();
for(IContributionItem item : items) {
item.setVisible(false);
}

detecting right mouse double click with Bing maps

I don't see an event in the Bing map API v7 that will surface a double click event. Is there a way to do this? Assuming there isn't native support that I missed, I think I will have to write my own double click handler with a timer.
I had also a problem with the click-events. In facts, the normal click-event also fires during a double-click event. That is why I had to implement my own double-click handler. My approach can be translated to the rigth click, because I am only using the single-click event, which is also available for the right mouse button.
//Set up my Handler (of course every object can be the target)
Microsoft.Maps.Events.addHandler(map, 'click', Click);
//count variable, that counts the amount of clicks that belong together
myClick=0;
//A click fires this function
function click (e)
{
//If it is the first click of a "series", than start the timeout after which the clicks are handled
if (myClick == 0)
{
//Target have to be buffered
target= e;
//accumulate the clicks for 200ms and react afterwards
setTimeout("reaction(target)", 200);
}
//count the clicks
myClick = myClick+1;
}
//At the end of timeout check how often a click has been performed and react
function reaction(e)
{
if (myClick==1)
{
alert("Single Click!");
}
else (myClick==2)
{
alert("Double click!");
}
else (myClick==3)
{
alert("Tripple click");
}
//reset ClickCount to zero for the next clicks
myClick = 0;
}
Moreover it might be interesting to remove the standart double-click behaviour of Bing-Maps, to zoom in. This can be realized by the following code:
Microsoft.Maps.Events.addHandler(map, 'dblclick', function(e){
e.handled = true;
});
If you only use double click event
Microsoft.Maps.Events.addHandler(this.map, 'dblclick', functionHandler)
should solve the problem

How do I update a progress bar OnSelectedIndexChanged?

I am developing a Windows application using .NET (C#) and I have a DropDownList with some list items. On the event OnSelectedIndexChanged I need to display a progess bar, which should disappear after retrieving some data.
I'm trying this way:
for (int i = progressBar1.Minimum; i <= progressBar1.Maximum; i++)
{
progressBar1.PerformStep();
}
panel1.Visible = false;
where my progress bar is placed in panel1, but I get the progress bar when I initially load my application. After that whenever the item is changed the progress bar is not visible.
I need the solution asap...
Thanks in advance!
Try panel1.Visible = true; at the start of your on selected index changed event of the combo box.
I don't see the code that would make the Panel visible again and you would also need to reset the ProgressBar before updating it again by changing the Value property to zero.
private void comboBox1_SelectedIndexChanged(...)
{
progressBar1.Value=progressBar1.Minimum;
panel1.Visible = true;
for (int i = progressBar1.Minimum; i <= progressBar1.Maximum; i++)
{
progressBar1.PerformStep();
}
panel1.Visible = false
}
This should make the panel1 visible, however, I'm not sure what you mean by:
"and should disappear after retrieving
some data"
and if the solution of filling the progress bar solves it.