In my game there is a menu, in this menu, there are 4 tabs and each tab have its own stage with tables scrollpanes and buttons (is it a good idea ?)
My problem is that every stage seems "frozen", buttons are not responding and scrollpanes don't scroll
My menu structure :
Menu class
-> render a tab (render selectedTab, selectedTab is a Tab object (custom class) that is asigned with a specific tab (Ex: sele shopTab (extend tab class))
// menu class
private Tab selectedTab;
private Tab RecipeTab, SellTab, UpgradeTab, ShopTab;
// menu constructor
RecipeTab = new RecipeTab(viewport, sb, itemsdata);
SellTab = new SellTab(viewport, sb, hud);
UpgradeTab = new UpgradeTab(viewport, sb, itemsdata);
ShopTab = new ShopTab(viewport, sb);
selectedTab = RecipeTab;
// render
selectedTab.render(sr, delta);
// on tab change
public void setSelectedTab(Tab newTab) {selectedTab = newTab;}
setSelectedTab(ShopTab);
-> menu contain a navbar to switch tabs (the selected tab is asigned with another tab object)
I don't know if the issue comes from the stages or the actors. even a simple textbutton doesn't work
// how my stages are made
// constructor
this.stage = new Stage(viewport, sb); // ExtendViewport (same everywhere), Spritebatch
Gdx.input.setInputProcessor(this.stage);
// render
this.stage.draw();
this.stage.act(delta);
I figured it out.
The answer was simple, there was a conflict with the inputProcessor
i was seting the inputProcessoron each tabs
so i added a setInputProcessor() method to the tabs a called it on tab change
Related
I'm working on an swing application with a main window (which extends JFrame) from which several child windows can be opened (more than 1 contemporarily).
These windows are all non-modal and resizable.
So far, I implemented these 'child' windows as a JFrame. However, I get a new icon on my Windows taskbar for each opened Window.
I therefore tried to implement these windows as a JDialog with type ModalityType.MODELESS.
Looks OK except that a JDialog has no minimize button.
Is there a way to resolve this?
I.e., I need to create non-modal and resizable child windows that can be minimized.
JInternalFrame is not an option since the main frame is not just a container with a JDesktopPane and child windows should be able to cross the borders of the main window.
For those interested:
Child windows register and unregister themselves on the main window when being opened/closed.
The main window has a menu with a 'Windows' item and child windows are added/removed from that menu upon registration/unregistration.
The user can switch between the various windows by selecting an item within this menu.
I am offering two suggestions.
A. Don't use the close button to get rid of the contents.
B. Set the type of child jframes to be utility.
I think having the JDialog close button destroy data is setting your users up for data loss. I would instead use the close to just hide the window, and then have controls inside of the dialog to cancel/finish/restart.
import java.awt.*;
public class DiFrame{
static JDialog log;
static JFrame ame;
public static void main(String[] args){
JFrame frame = new JFrame("Father of two");
JButton one = new JButton("dialog");
one.addActionListener( evt->{
if(log==null){
log = new JDialog(frame, "dialog child", false);
log.add(new JTextArea("fresh start"));
log.pack();
log.setVisible(true);
} else{
log.setVisible(true);
}
});
JButton two = new JButton("frame");
two.addActionListener( evt->{
if(ame==null){
ame = new JFrame("frame child");
ame.add( new JTextArea("fresh start") );
ame.setType(Window.Type.UTILITY);
ame.pack();
ame.setVisible(true);
} else{
ame.setVisible(true);
}
});
frame.add(one, BorderLayout.NORTH);
frame.add(two, BorderLayout.SOUTH);
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Click the dialog button and it shows the dialog. Then the text area can be modified. When the dialog is closed it can be re-opened.
Click the frame button and a jframe is shown. ( I actually cannot check if this shows up as a new application because it doesn't on my computer anyways. )
I'm quite new to the Xamarin.iOS platform.
I created an empty Xamarin.iOS project then create my main UIViewController, which is UIViewController1 and then set it up in the AppDelegate.cs:
// If you have defined a root view controller, set it here:
var view1 = new UIViewController1();
Window.RootViewController = view1;
// make the window visible
Window.MakeKeyAndVisible();
In the UIViewController1 I hard-code all the labels and buttons and stuff. Like this:
var frame = new CGRect(10, 10, 300, 30);
var Label = new UILabel(frame);
View.AddSubView(Label);
But now when everything is confirmed to be working correctly, I want to create a storyboard for my UIViewController1 and move all of the elements onto it for future maintenance, so after creating an Empty Storyboard how can I link it to my current UIViewController1?
The other solutions that I found just don't work. All I got is a blank white screen.
Open your empty Storyboard, on the left window you will see the Toolbox(if you didn't see it, Ctrl + Alt + X to open it). Select a ViewController then put it on the Storyboard.
Here you will see a Storyboard with only one ViewController in it like:
Click the yellow button at left bottom of the ViewController. In the Property window we can choose its Class, click the down arrow to select:
In this way, we have bound the ViewController to the UIViewController1. But we also need to create a initial method in this class:
public UIViewController1 (IntPtr handle) : base(handle)
{
}
If you want to use the Storyboard as your initial Window, open your info.plist, select the Main Interface to your Storyboard. Then in the FinishedLaunching() remove all your code about initializing the Window:
//var view1 = new UIViewController1();
//Window.RootViewController = view1;
// make the window visible
//Window.MakeKeyAndVisible();
Moreover instead of constructing the ViewController with var view1 = new UIViewController1();, we should use UIStoryboard.FromName("StoryboardName", null).InstantiateViewController("ViewControllerID");. This ViewControllerID can be set in the property window I post above called Storyboard ID;
I have a share function on the app that allows users to share app to others, but I want to track number of shares. The share item is on the action bar, not on the app dropdown menu.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
//some other code here for items search item
//share menu item
MenuItem shareItem = menu.findItem(R.id.menu_item_share);
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
String playStoreLink = Constants.PLAYSTORE_LINK + getPackageName();
String shareText = "Install app" + playStoreLink;
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
.setType("text/plain").setText(shareText).getIntent();
// Set the share Intent
mShareActionProvider.setShareIntent(shareIntent);
return true;
}
I have managed to implement tracking on other events by simply adding code in onClick() events but share event doesnt have onClick.
Code for tracking events example
Bundle param = new Bundle();
param.putString("call_data", "1");
mFirebaseAnalytics.logEvent("calls_made", param);
I've been strugling with the exact challenge, the quick answer is NO.
BUT, you can create your own share dialog in which you can detect on which app the user chose to share and then use analytics as desired:
Find the solution here
Another solution with ShareActionProvider
I’ve tried a few different methods to get a selected item from a list (see code below), but everything I’ve tried only returns the first item in the list no matter which item was actually selected. Visually it appears to work because the correct item gets highlighted when it is clicked on.
As a general overview of what I’m trying to do, I have a folder that contains all of the saved preset files (json files), then I read the names of all the files into a list of strings, from this list a specific preset can be selected, and then I have a separate “load” textbutton that loads the item that was selected from the list. But as mentioned above, the correct item is not loaded from the list when the load button is clicked.
Here is my code:
public class PresetLoadMenu extends Menu {
private GUI gui;
private SaveManager saveManager;
private Table scrollPaneContainerTable;
private ScrollPane scrollPane;
private Table scrollTable;
private List<String> presetList;
private TextButton loadButton;
private FileHandle rootFolderHandle = Gdx.files.external(“presets/”);
public PresetLoadMenu(GUI gui){
this.gui = gui;
refreshList();
scrollTable = new Table();
scrollTable.add(presetList);
scrollPane = new ScrollPane(scrollTable);
scrollPaneContainerTable = new Table();
scrollPaneContainerTable.add(scrollPane).size(this.getWidth(), this.getHeight()*.2f);
add(scrollPaneContainerTable);
row();
loadButton = new TextButton("LOAD", gui.menuStyles.getMenuOkCancelButtonStyle());
loadButton.addCaptureListener(new ChangeListener(){
#Override
public void changed(ChangeEvent event, Actor actor){
// METHOD 1:
// System.out.println("SELECTED PRESET: " + presetList.getSelected());
// METHOD 2:
// System.out.println("SELECTED PRESET: " + presetList.getSelection().getLastSelected());
// METHOD 3:
// for (int i=0; i<presetList.getSelection().size(); i++){
// System.out.println("INDEX: " + i + " SELECTED PRESET: " + presetList.getSelection().toArray().get(i));
// }
}
});
add(loadButton).size(loadButton.getWidth(), loadButton.getHeight());
}
public void refreshList(){
FileHandle[] files = rootFolderHandle.list();
Array<String> namesArray = new Array<String>();
for(FileHandle file: files) {
namesArray.add(file.name());
}
presetList = new List<String>(gui.menuStyles.getListStyle());
presetList.setItems(namesArray);
}
}
The last method I tried using a for loop just to see if it would print out the other items that I clicked on, but it still printed the first item just one time and didn't detect that I had clicked on any of the other items.
On request I'm copying my last comment as an answer in order to close my question.
The problem was actually something else outside of the class that I posted, so presetList.getSelected() may work just fine now that I figured out what the problem was. But before I figured it out, I had swapped out the List for a ButtonGroup, which is actually better for me than using the List anyways so it worked out. The List has a built in listener that selects the item on touch down, so items would get selected when trying to scroll up or down. With a button I can have a listener just for the checked state, which is what I want.
Based on your answer, I solved it by creating a table of TextButton (buttonTable) , every of them initialize with an string:
final TextButton button = new TextButton("my string",skin);
and a listener:
button.addListener(new ClickListener() {
public void clicked (InputEvent event, float x, float y) {
button.getText()));
}
});
This buttonTable initialize a ScrollPane to allow vertical scrolling:
scrollPane = new ScrollPane(buttonsTable);
This scrollPane was added to table used to format my form:
mainTable.add(scrollPane);
This table was the actor added to the stage:
stage.addActor(mainTable);
This is probably a dumb question, but I just can't see it! I have Swing app that uses a popup menu. It works fine, but I want to make the menu persistent (i.e. until I close it). I have basically changed the JPopupMenu to JDialog, and I am getting the JDialog panel, but the menu items are invisible! It's probably something very obvious, so I'll probably be embarrassed! Here is part of the code:
JDialog buildNewItemMenu(DrawFBP base) {
JDialog jd = new JDialog();
jd.setSize(200, 300);
JMenuItem menuItem = null;
JLabel label2 = new JLabel();
label2.setForeground(Color.BLUE);
JMenu menu = new JMenu();
jd.add(menu);
jd.setVisible(true);
menu.setVisible(true);
menu.add(label2);
menu.addSeparator();
menuItem = new JMenuItem("Component");
menuItem.addActionListener(base);
menu.add(menuItem);
....
menu.addSeparator();
menuItem = new JMenuItem("Enclosure");
menuItem.addActionListener(base);
menu.add(menuItem);
return jd;
I think I will close this - as I said in the comment, changing the JMenu to a JPanel and adding
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
fixed the problem, but I plan to tackle the problem a different way. Thanks anyway!