private void initialize() { setModal(true); defaults().space(6); add(contentTable = new Table(skin)).expand().fill(); row(); add(buttonTable = new Table(skin)); contentTable.defaults().space(6); buttonTable.defaults().space(6); buttonTable.addListener( new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { if (!values.containsKey(actor)) return; while (actor.getParent() != buttonTable) actor = actor.getParent(); result(values.get(actor)); if (!cancelHide) hide(); cancelHide = false; } }); focusListener = new FocusListener() { public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) { if (!focused) focusChanged(event); } public void scrollFocusChanged(FocusEvent event, Actor actor, boolean focused) { if (!focused) focusChanged(event); } private void focusChanged(FocusEvent event) { Stage stage = getStage(); if (isModal && stage != null && stage.getRoot().getChildren().size > 0 && stage.getRoot().getChildren().peek() == Dialog.this) { // Dialog is top most actor. Actor newFocusedActor = event.getRelatedActor(); if (newFocusedActor != null && !newFocusedActor.isDescendantOf(Dialog.this) && !(newFocusedActor.equals(previousKeyboardFocus) || newFocusedActor.equals(previousScrollFocus))) event.cancel(); } } }; }
private void initMilitaryTopPane() { Table contentTable = new Table(); int itemPerRow = (int) (militaryTablePos.width / (militaryTablePortraitSize.x + militaryTableCaptionSize.x)); int index = 0; for (Military m : parent.getCurrentArchitecture().getMilitariesWithLeader()) { Table item = new Table(); Person leader = m.getLeader(); ImageWidget<Military> portrait; if (leader != null) { portrait = new ImageWidget<>( parent.getScreen().getSmallPortrait(leader.getPortraitId()), militaryTablePortraitColor); } else { portrait = new ImageWidget<>(null, militaryTablePortraitColor); } portrait.setExtra(m); item.add(portrait).width(militaryTablePortraitSize.x).height(militaryTablePortraitSize.y); Table detail = new Table(); TextWidget<Military> caption = new TextWidget<>(militaryTableCaptionTemplate); caption.setExtra(m); caption.setText(m.getName()); detail .add(caption) .width(militaryTableCaptionSize.x) .height(militaryTableCaptionSize.y) .row(); TextWidget<Military> quantity = new TextWidget<>(militaryTableDetailTemplate); quantity.setExtra(m); quantity.setText( GlobalStrings.getString(GlobalStrings.Keys.MILITARY_QUANTITY_SHORT) + m.getQuantity()); detail.add(quantity).width(militaryTableDetailSize.x).height(militaryTableDetailSize.y).row(); TextWidget<Military> morale = new TextWidget<>(militaryTableDetailTemplate); morale.setExtra(m); morale.setText( GlobalStrings.getString(GlobalStrings.Keys.MILITARY_MORALE_SHORT) + m.getMorale()); detail.add(morale).width(militaryTableDetailSize.x).height(militaryTableDetailSize.y).row(); TextWidget<Military> combativity = new TextWidget<>(militaryTableDetailTemplate); combativity.setExtra(m); combativity.setText( GlobalStrings.getString(GlobalStrings.Keys.MILITARY_COMBATIVITY_SHORT) + m.getCombativity()); detail .add(combativity) .width(militaryTableDetailSize.x) .height(militaryTableDetailSize.y) .row(); detail.top(); item.add(detail); item.addListener( new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { currentMilitary = m; currentMilitaryPos = new Rectangle( item.getX() + militaryTablePos.getX(), item.getY() + militaryTablePos.getY(), item.getWidth(), item.getHeight()); if (m.isCampaignable()) { parent .getScreen() .getMapLayer() .startSelectingLocation( parent.getCurrentArchitecture().getCampaignablePositions(), p -> { m.startCampaign(p); invalidateListPanes(); }); } return true; } }); contentTable.add(item); index++; if (index % itemPerRow == 0) { contentTable.row(); } } contentTable.top().left(); ScrollPane data = new ScrollPane(contentTable); militaryTopPane = WidgetUtility.setupScrollpane( militaryTablePos.getX(), militaryTablePos.getY(), militaryTablePos.getWidth(), militaryTablePos.getHeight(), data, parent.getScrollbar()); parent.addActor(militaryTopPane); }
public HotbarInventoryView( Stage stage, Skin skin, Inventory hotbarInventory, Inventory inventory, DragAndDrop dragAndDrop, OreClient client) { m_skin = skin; m_inventory = inventory; m_client = client; m_stage = stage; m_hotbarInventory = hotbarInventory; // attach to the inventory model m_hotbarInventory.addListener(this); container = new Table(m_skin); container.setFillParent(true); container.top().left().setSize(800, 100); container.padLeft(10).padTop(10); container.defaults().space(4); stage.addActor(container); Image dragImage = new Image(); dragImage.setSize(32, 32); for (byte i = 0; i < Inventory.maxHotbarSlots; ++i) { Image slotImage = new Image(); SlotElement element = new SlotElement(); m_slots[i] = element; element.itemImage = slotImage; Table slotTable = new Table(m_skin); element.table = slotTable; slotTable.setTouchable(Touchable.enabled); slotTable.addListener(new SlotClickListener(this, i)); slotTable.addListener(new SlotInputListener(this, i)); slotTable.add(slotImage); slotTable.background("default-pane"); slotTable.row(); Label itemCount = new Label(null, m_skin); slotTable.add(itemCount).bottom().fill(); element.itemCountLabel = itemCount; // container.add(slotTable).size(50, 50); container.add(slotTable).fill().size(50, 50); setHotbarSlotVisible(i, false); dragAndDrop.addSource(new HotbarDragSource(slotTable, i, dragImage, this)); dragAndDrop.addTarget(new HotbarDragTarget(slotTable, i, this)); } m_tooltip = new Label(null, m_skin); stage.addActor(m_tooltip); }
@Override public void show() { super.show(); backgroundStage.addActor(new Image(atlas.findRegion("background"))); Image alien = new Image(atlas.findRegion("alien")); alien.setPosition(mainStage.getWidth() + mainStage.getPadLeft(), -365f); mainStage.addActor(alien); Image energy = new Image(atlas.findRegion("energy")); // 195, 313 energy.setPosition(83f, 201f); energy.setScale(0f); energy.setOrigin(energy.getPrefWidth() / 2, energy.getPrefHeight() / 2); mainStage.addActor(energy); final Table certificateTable = new Table(); certificateTable.padTop(314f).padBottom(101f).defaults().padBottom(100f); certificateTable.setBackground(new TextureRegionDrawable(atlas.findRegion("certificate"))); certificateTable.setSize(mainStage.getWidth(), mainStage.getHeight()); certificateTable.setOrigin(195f, 313f); certificateTable.setTransform(true); certificateTable.setTouchable(Touchable.disabled); certificateTable.addListener( new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { Assets.fanfareFX.stop(); game.loadNextScreen(EndingScreen.this, KonnectingGame.ScreenType.MAIN_MENU); } }); certificateTable.setScale(0f); mainStage.addActor(certificateTable); StatsData tempData = SavedData.getStats(); int score = tempData.kronosScore1 + tempData.kronosScore2 + tempData.kronosScore3 + tempData.kronosScore4 + tempData.kronosScore5 + tempData.kronosScore6 + tempData.kronosScore7 + tempData.zappingScore1 + tempData.zappingScore2 + tempData.zappingScore3 + tempData.zappingScore4 + tempData.zappingScore5; final Label userLabel = new Label( SavedData.getUsername() + "\n\n" + score + "pt", new Label.LabelStyle(uiSkin.getFont("default-font"), Color.WHITE)); userLabel.setWrap(true); userLabel.setAlignment(Align.center); userLabel.getColor().a = 0f; certificateTable.add(userLabel).width(407f).row(); String correctComment = comments[0]; for (int i = scoreLimits.length - 1; i >= 0; i--) { if (score > scoreLimits[i]) { correctComment = comments[i]; break; } } final Label commentLabel = new Label(correctComment, new Label.LabelStyle(uiSkin.getFont("arial"), Color.WHITE)); commentLabel.setWrap(true); commentLabel.setFontScale(0.9f); commentLabel.setAlignment(Align.center); commentLabel.getColor().a = 0f; certificateTable.add(commentLabel).width(407f); Timeline.createSequence() .push(Tween.to(alien, ActorAccessor.MOVE_X, 1f).target(20f)) .pushPause(0.25f) .push(Tween.to(energy, ActorAccessor.SCALEXY, 1f).target(1f)) .push(Tween.to(energy, ActorAccessor.SCALEXY, 0.5f).target(0.8f)) .push(Tween.to(energy, ActorAccessor.SCALEXY, 0.5f).target(1f)) .push(Tween.to(certificateTable, ActorAccessor.SCALEXY, 0.5f).target(1f)) .beginParallel() .push(Tween.to(userLabel, ActorAccessor.ALPHA, 0.5f).target(1f)) .push(Tween.to(commentLabel, ActorAccessor.ALPHA, 0.5f).target(1f)) .end() .setCallback( new TweenCallback() { @Override public void onEvent(int type, BaseTween<?> source) { Assets.fanfareFX.setOnCompletionListener( new Music.OnCompletionListener() { @Override public void onCompletion(Music music) { Assets.fanfareFX.setOnCompletionListener(null); certificateTable.setTouchable(Touchable.enabled); } }); Assets.fanfareFX.play(); } }) .start(tweenManager); }