void ChatBox::mouseClicked(gcn::MouseEvent& mouseEvent){ if( mouseEvent.isConsumed() ){ return; } InfraellyWindow::mouseClicked(mouseEvent); //click from the chat area if( mouseEvent.getSource() == chatArea ){ chatArea->requestFocus(); typing = 0; } //click from the input field if( mouseEvent.getSource() == inputField ){ typing = 1; } //if click was from send button if( mouseEvent.getSource() == sendButton ){ // add the text from the text field into the chat area push_back( inputField->getText(), DO_CALLBACK|PUT_USERNAME ); //clear off the text field inputField->setText(""); //-------------------------- // play sound //------------------------ } }
void MiniStatusWindow::mouseMoved(gcn::MouseEvent &event) { Popup::mouseMoved(event); const int x = event.getX(); const int y = event.getY(); if (event.getSource() == mXpBar) { mTextPopup->show(x + getX(), y + getY(), strprintf("%u/%u", PlayerInfo::getAttribute(EXP), PlayerInfo::getAttribute(EXP_NEEDED)), strprintf("%s: %u", _("Need"), PlayerInfo::getAttribute(EXP_NEEDED) - PlayerInfo::getAttribute(EXP))); } else if (event.getSource() == mHpBar) { mTextPopup->show(x + getX(), y + getY(), strprintf("%u/%u", PlayerInfo::getAttribute(HP), PlayerInfo::getAttribute(MAX_HP))); } else if (event.getSource() == mMpBar) { mTextPopup->show(x + getX(), y + getY(), strprintf("%u/%u", PlayerInfo::getAttribute(MP), PlayerInfo::getAttribute(MAX_MP))); } else { mTextPopup->setVisible(false); } }
int Window::getResizeHandles(gcn::MouseEvent &event) { int resizeHandles = 0; const int y = event.getY(); if (mGrip && y > (int) mTitleBarHeight) { const int x = event.getX(); if (!getChildrenArea().isPointInRect(x, y) && event.getSource() == this) { resizeHandles |= (x > getWidth() - resizeBorderWidth) ? RIGHT : (x < resizeBorderWidth) ? LEFT : 0; resizeHandles |= (y > getHeight() - resizeBorderWidth) ? BOTTOM : (y < resizeBorderWidth) ? TOP : 0; } if (event.getSource() == mGrip) { mDragOffsetX = x; mDragOffsetY = y; resizeHandles |= BOTTOM | RIGHT; } } return resizeHandles; }
void NpcDialog::mouseClicked(gcn::MouseEvent &mouseEvent) { if (mouseEvent.getSource() == mItemList && isDoubleClick(mItemList->getSelected())) { action(gcn::ActionEvent(mButton, mButton->getActionEventId())); } if (mouseEvent.getSource() == mTextBox && isDoubleClick((int)(long)mTextBox)) { if (mActionState == NPC_ACTION_NEXT || mActionState == NPC_ACTION_CLOSE) action(gcn::ActionEvent(mButton, mButton->getActionEventId())); } }
void LoginBox::mouseClicked(gcn::MouseEvent& mouseEvent){ if( mouseEvent.getSource() == doneButton ){ if( isAlphNum(usernameTextField->getText()) && isAlphNum(passwordTextField->getText()) ) { infoReady = true; } else { infoReady = false; } } else if( mouseEvent.getSource() == cancelButton ){ setVisible(false); } }
void Windowiki::mousePressed(gcn::MouseEvent &event) { // Let Guichan move window to top and figure out title bar drag gcn::Window::mousePressed(event); const int x = event.getX(); const int y = event.getY(); mMouseResize = 0; // Activate resizing handles as appropriate if (event.getSource() == this && isResizable() && event.getButton() == gcn::MouseEvent::LEFT && !getChildrenArea().isPointInRect(x, y)) { mMouseResize |= (x > getWidth() - resizeBorderWidthiki) ? RIGHT : (x < resizeBorderWidthiki) ? LEFT : 0; mMouseResize |= (y > getHeight() - resizeBorderWidthiki) ? BOTTOM : (y < resizeBorderWidthiki) ? TOP : 0; } else if (event.getSource() == mGrip) { mDragOffsetX = x + mGrip->getX(); mDragOffsetY = y + mGrip->getY(); mMouseResize |= BOTTOM | RIGHT; mIsMoving = false; } if (event.getButton() == gcn::MouseEvent::LEFT) { const int x = event.getX(); const int y = event.getY(); // Handle close button if (mCloseButton) { gcn::Rectangle closeButtonRect( getWidth() - closeImage->getWidth() - getPadding(), getPadding(), closeImage->getWidth(), closeImage->getHeight()); if (closeButtonRect.isPointInRect(x, y)) { setVisible(false); } } // Handle window resizing } }
void ItemMakerBox::mouseClicked(gcn::MouseEvent& mouseEvent){ if( mouseEvent.isConsumed() ){ return; }; // Save Button if( mouseEvent.getSource() == saveBtn ){ mouseEvent.consume(); save( filenameFld->getText() ); } else // Load Button if( mouseEvent.getSource() == loadBtn ){ mouseEvent.consume(); load( filenameFld->getText() ); } else { setCaption(caption_); } }
void InventoryWindow::mouseClicked(gcn::MouseEvent &event) { Window::mouseClicked(event); if (event.getButton() == gcn::MouseEvent::RIGHT && event.getSource() == mItems) mItems->showPopupMenu(INVENTORY); }
// Show ItemTooltip void ItemAmountWindow::mouseMoved(gcn::MouseEvent &event) { if (event.getSource() == mItemIcon) { mItemPopup->setItem(mItem->getInfo()); mItemPopup->position(viewport->getMouseX(), viewport->getMouseY()); } }
void StorageWindow::mouseClicked(gcn::MouseEvent &event) { Window::mouseClicked(event); if (event.getButton() == gcn::MouseEvent::RIGHT && event.getSource() == mItems) mItems->showPopupMenu(STORAGE); }
void BuyDialog::mouseClicked(gcn::MouseEvent &mouseEvent) { if (mouseEvent.getSource() == mShopItemList && isDoubleClick(mShopItemList->getSelected())) { action(gcn::ActionEvent(mBuyButton, mBuyButton->getActionEventId())); } }
void ServerDialog::mouseClicked(gcn::MouseEvent &mouseEvent) { if (mouseEvent.getSource() == mServersList && isDoubleClick(mServersList->getSelected())) { action(gcn::ActionEvent(mConnectButton, mConnectButton->getActionEventId())); } }
void WorldSelectDialog::mouseClicked(gcn::MouseEvent &mouseEvent) { if (mouseEvent.getSource() == mWorldList && isDoubleClick(mWorldList->getSelected())) { action(gcn::ActionEvent(mChooseWorld, mChooseWorld->getActionEventId())); } }
void WorldEditor::mousePressed(gcn::MouseEvent& mouseEvent) { if (mouseEvent.getSource() != this) { return; } if (mDrawingNewRoom) { mDrawingNewRoom = false; return; } if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT) { if (mWorldPieces.find(mRoomSelector->getSelectedRoom()) == mWorldPieces.end()) { WorldPiece* worldPiece = new WorldPiece(mRoomSelector->getSelectedRoom()); mWorldPieces[mRoomSelector->getSelectedRoom()] = worldPiece; worldPiece->setPosition(mouseEvent.getX() - mouseEvent.getX() % 20, mouseEvent.getY() - mouseEvent.getY() % 15); worldPiece->addActionListener(this); add(worldPiece); } } else if (mouseEvent.getButton() == gcn::MouseEvent::LEFT) { if (!mNewRoomDialogWindow->isVisible() && getWidgetAt(mouseEvent.getX(), mouseEvent.getY()) == NULL) { mDrawingNewRoom = true; if (mouseEvent.getX() % 20 < 10) { mNewRoomX = mouseEvent.getX() - mouseEvent.getX() % 20; } else { mNewRoomX = mouseEvent.getX() - mouseEvent.getX() % 20 + 20; } if (mouseEvent.getY() % 15 < 8) { mNewRoomY = mouseEvent.getY() - mouseEvent.getY() % 15; } else { mNewRoomY = mouseEvent.getY() - mouseEvent.getY() % 15 + 15; } mNewRoomWidth = 0; mNewRoomHeight = 0; } } }
void Console::mouseClicked(gcn::MouseEvent& mouseEvent){ if( mouseEvent.isConsumed() ){ return; }; //click from the text area if( mouseEvent.getSource() == textArea ){ inputField->requestFocus(); }; //if click was from send button if( mouseEvent.getSource() == sendButton ){ // add the text from the text field into the text area push_back( inputField->getText(), DO_CALLBACK|PUT_USERNAME); //store command entered lastCommand = inputField->getText(); //clear off the text field inputField->setText(""); //-------------------------- // play sound //------------------------ inputField->requestFocus(); } }
void Window::mousePressed(gcn::MouseEvent &event) { // Let Guichan move window to top and figure out title bar drag gcn::Window::mousePressed(event); if (event.getButton() == gcn::MouseEvent::LEFT) { // Handle window resizing mouseResize = getResizeHandles(event); if (event.getSource() == this) requestFocus(); } }
void SoundCfg::mousePressed(gcn::MouseEvent& mouseEvent) { bool comp_has_mouse = false; if ( mouseEvent.getSource() == &mDescriptionBox ) comp_has_mouse = true; if ((comp_has_mouse == true) && mouseEvent.getButton() == gcn::MouseInput::LEFT) { mSettingsDirty = true; } gcn::Window::mousePressed ( mouseEvent ); }
void DropDown::mousePressed(gcn::MouseEvent& mouseEvent) { gcn::DropDown::mousePressed(mouseEvent); if (0 <= mouseEvent.getY() && mouseEvent.getY() < getHeight() && mouseEvent.getX() >= 0 && mouseEvent.getX() < getWidth() && mouseEvent.getButton() == gcn::MouseEvent::LEFT && mDroppedDown && mouseEvent.getSource() == mListBox) { mPushed = false; foldUp(); releaseModalMouseInputFocus(); distributeActionEvent(); } }
void LayerPanel::mouseClicked(gcn::MouseEvent& me) { gcn::Widget *src = me.getSource(); // poll the buttons for a click for(uint32 i = 0; i < LAYER_MAX; i++) { if(src == btnLayers[i]) { if(me.getButton() == gcn::MouseEvent::LEFT) _engine->GetDrawPanel()->SetActiveLayer(i); else if(me.getButton() == gcn::MouseEvent::RIGHT) _engine->ToggleLayerVisible(i); return; } } }
void PlayControlPanel::mouseClicked(gcn::MouseEvent &mouseEvent) { if (mouseEvent.isConsumed()) { return; } gcn::Widget* sourceWidget = mouseEvent.getSource(); if (sourceWidget == dynamic_cast<gcn::Widget*>(playButton)) { std::cout << "Click on PLAY button" << std::endl; changeState(PLAYING); } else if (sourceWidget == dynamic_cast<gcn::Widget*>(pauseButton)) { std::cout << "Click on PAUSE button" << std::endl; changeState(PAUSED); } else if (sourceWidget == dynamic_cast<gcn::Widget*>(stopButton)) { std::cout << "Click on STOP button" << std::endl; changeState(STOPPED); } mouseEvent.consume(); }
void MapperTilesetBox::mouseClicked(gcn::MouseEvent& mouseEvent){ InfraellyWindow::mouseClicked(mouseEvent); if( mouseEvent.isConsumed() ){ return; }; //if click was from closeTilesetButton if( mouseEvent.getSource() == closeTilesetButton ){ //consume mouse event mouseEvent.consume(); //get the pointer to the tileset to remove Tileset *toRemove = tilesetList->at( tilesetDropDown->getSelected() ); //check if the user is trying to dlete teh nullTS if( toRemove != tilesetList->at(0) ){ //store number to remove int removeIndex = tilesetDropDown->getSelected(); //change the selected ts to the nullTS tilesetDropDown->setSelected(0); //delete the entry from teh list tilesetList->removeElementAt( removeIndex ); //if there is a map activley associated if( world != NULL ){ //stip dependency from map working on //if there IS dependency if( !world->empty() ){ //cycle through layers for( size_t i = 0; i < world->size(); ++i ){ //cycle thru tiles for( size_t j = 0; j < world->getLayer(i).getHeight() * world->getLayer(i).getWidth(); ++j){ if( world->getLayer(i).index(j).getTileset() == toRemove ){ world->getLayer(i).index(j).setTileset(NULL); } } } } } //dependency of tileset stripped //delete the tileset cache::tilesets.erase(toRemove); //remove from selected tile selectedTile.setSource(NULL,0,0); } } //click from the tilesetImage if( mouseEvent.getSource() == tilesetImage ){ //consume mouse event mouseEvent.consume(); if( !tilesetList->empty() ){ Tileset *selectedTs = selectedTile.getTileset(); if( selectedTs != NULL ){ // tileset select int tileWidth = selectedTs->getTileWidth(); int tileHeight = selectedTs->getTileHeight(); // get the x-y co-ords reletive to the tileset region int col = mouseEvent.getX() - (tilesetImage->getX()+selectedTs->getXOffset()); int row = mouseEvent.getY() - (tilesetImage->getY()+selectedTs->getYOffset()); // if its a multiple of tilewidth/height (ie in the barrier between) if( col % tileWidth == 0){ ++col; }; if( row % tileHeight == 0){ ++row; }; // turn co-ords into row/col col = col/tileWidth; row = row/tileHeight; // calculate the amount of tiles off the screen int trueCol = tilesetImage->getX(); int trueRow = tilesetImage->getY(); // if its a multiple of tilewidth/height (ie in the barrier between) if( trueCol % tileWidth == 0){ ++col; }; if( trueRow % tileHeight == 0){ ++row; }; // turn co-ords into row/col trueCol = trueCol/tileWidth; trueRow = trueRow/tileHeight; //add the on screen offset to the offsecreen tiles trueCol += col-1; trueRow += row-1; //store the tile's new row-col selectedTile.setSource( selectedTs, trueCol, trueRow); //store attribute if on atrib ts if( selectedTile.getTileset() == attribTs ){ selectedTile.setAttribute(attribGrid[trueCol][trueRow]); } }// end if null }//end if empty list }//end if event from drop down*/ }
void Windowiki::mouseDragged(gcn::MouseEvent &event) { // Let Guichan handle title bar drag gcn::Window::mouseDragged(event); // Keep guichan window inside screen when it may be moved if (isMovable() && mIsMoving) { int newX = std::max(0, getX()); int newY = std::max(0, getY()); newX = std::min(windowikiContainer->getWidth() - getWidth(), newX); newY = std::min(windowikiContainer->getHeight() - getHeight(), newY); setPosition(newX, newY); } if (mMouseResize && !mIsMoving) { const int dx = event.getX() - mDragOffsetX + ((event.getSource() == mGrip) ? mGrip->getX() : 0); const int dy = event.getY() - mDragOffsetY + ((event.getSource() == mGrip) ? mGrip->getY() : 0); gcn::Rectangle newDim = getDimension(); if (mMouseResize & (TOP | BOTTOM)) { int newHeight = newDim.height + ((mMouseResize & TOP) ? -dy : dy); newDim.height = std::min(mMaxWinHeight, std::max(mMinWinHeight, newHeight)); if (mMouseResize & TOP) { newDim.y -= newDim.height - getHeight(); } } if (mMouseResize & (LEFT | RIGHT)) { int newWidth = newDim.width + ((mMouseResize & LEFT) ? -dx : dx); newDim.width = std::min(mMaxWinWidth, std::max(mMinWinWidth, newWidth)); if (mMouseResize & LEFT) { newDim.x -= newDim.width - getWidth(); } } // Keep guichan window inside screen (supports resizing any side) if (newDim.x < 0) { newDim.width += newDim.x; newDim.x = 0; } if (newDim.y < 0) { newDim.height += newDim.y; newDim.y = 0; } if (newDim.x + newDim.width > windowikiContainer->getWidth()) { newDim.width = windowikiContainer->getWidth() - newDim.x; } if (newDim.y + newDim.height > windowikiContainer->getHeight()) { newDim.height = windowikiContainer->getHeight() - newDim.y; } // Update mouse offset when dragging bottom or right border if (mMouseResize & BOTTOM) { mDragOffsetY += newDim.height - getHeight(); } if (mMouseResize & RIGHT) { mDragOffsetX += newDim.width - getWidth(); } // Set the new window and content dimensions setDimension(newDim); const gcn::Rectangle area = getChildrenArea(); mChrome->setSize(area.width, area.height); } }
void GlassSpinner::mousePressed(gcn::MouseEvent &e) { if(e.getSource()->getActionEventId() == "up") upSpin = true; else if(e.getSource()->getActionEventId() == "down") downSpin = true; }
void GCNPlatform::mouseClicked(gcn::MouseEvent& mouseEvent) { if (mouseEvent.getSource() == toplevel_container_.get() && mouseEvent.getButton() == gcn::MouseEvent::RIGHT) { blocker_->addTask(bind(&GCNPlatform::clearWindowStack, this)); } }
void Viewport::mousePressed(gcn::MouseEvent &event) { if (event.getSource() != this) return; // Check if we are alive and kickin' if (!mMap || !player_node || !player_node->isAlive()) return; // Check if we are busy if (PlayerInfo::isTalking()) return; mPlayerFollowMouse = false; mBeingPopup->setVisible(false); const int pixelX = event.getX() + (int) mPixelViewX; const int pixelY = event.getY() + (int) mPixelViewY; mHoverBeing = actorSpriteManager->findBeingByPixel(pixelX, pixelY); mHoverItem = actorSpriteManager->findItem(pixelX / mMap->getTileWidth(), pixelY / mMap->getTileHeight()); updateCursorType(); // Right click might open a popup if (event.getButton() == gcn::MouseEvent::RIGHT) { if (mHoverBeing && mHoverBeing != player_node) { mPopupMenu->showPopup(event.getX(), event.getY(), mHoverBeing); return; } else if (mHoverItem) { mPopupMenu->showPopup(event.getX(), event.getY(), mHoverItem); return; } } // If a popup is active, just remove it if (mPopupMenu->isVisible()) { mPopupMenu->setVisible(false); return; } // Left click can cause different actions if (event.getButton() == gcn::MouseEvent::LEFT) { // Interact with some being if (mHoverBeing) { if (mHoverBeing->canTalk()) mHoverBeing->talkTo(); else { // Ignore it if its dead if (mHoverBeing->isAlive()) { if (player_node->withinAttackRange(mHoverBeing) || keyboard.isKeyActive(keyboard.KEY_ATTACK)) player_node->attack(mHoverBeing, !keyboard.isKeyActive(keyboard.KEY_TARGET)); else player_node->setGotoTarget(mHoverBeing); } } // Picks up a item if we clicked on one } else if (mHoverItem) { player_node->pickUp(mHoverItem); } else if (player_node->getCurrentAction() == Being::SIT) { return; } // Just walk around else { player_node->stopAttack(); mPlayerFollowMouse = true; // Make the player go to the mouse position _followMouse(); } } else if (event.getButton() == gcn::MouseEvent::MIDDLE) { // Find the being nearest to the clicked position Being *target = actorSpriteManager->findNearestLivingBeing( pixelX, pixelY, 20, ActorSprite::MONSTER); if (target) player_node->setTarget(target); } }
void MapperGui::mouseClicked(gcn::MouseEvent& mouseEvent){ if( mouseEvent.isConsumed() ){ return; }; //click from the map image ( worldImagePlaceHolder ) if( mouseEvent.getSource() == worldImagePlaceHolder ){ //consume mouse event mouseEvent.consume(); //click from the tilesetImage if( world != NULL ){ if( world->empty() ){ return; }; int layerNum = layerToggleBox->getWorkingLayer(); Layer& workingLayer = world->getLayer(layerNum); // tileset select int tileWidth = workingLayer.getTileWidth(); int tileHeight = workingLayer.getTileHeight(); // get the x-y co-ords reletive to the tileset region int col = mouseEvent.getX() - worldImagePlaceHolder->getX(); int row = mouseEvent.getY() - worldImagePlaceHolder->getY(); // if its a multiple of tilewidth/height (ie in the barrier between) if( col % tileWidth == 0){ ++col; }; if( row % tileHeight == 0){ ++row; }; // turn co-ords into row/col col = col/tileWidth; row = row/tileHeight; // calculate the amount of tiles off the screen int trueCol = worldImagePlaceHolder->getX(); int trueRow = worldImagePlaceHolder->getY(); // if its a multiple of tilewidth/height (ie in the barrier between) if( trueCol % tileWidth == 0){ ++col; }; if( trueRow % tileHeight == 0){ ++row; }; // turn co-ords into row/col trueCol = trueCol/tileWidth; trueRow = trueRow/tileHeight; //add the on screen offset to the offsecreen tiles trueCol += col-1; trueRow += row-1; //check if within range if( (trueCol < workingLayer.getWidth()) && (trueRow < workingLayer.getHeight()) ){ //if left click if( mouseEvent.getButton() == gcn::MouseEvent::LEFT ){ //set the tile wher mouse is on map, to selected tile on ts //if the attrib ts is on if( tilesetBox->getSelectedTileset() == tilesetBox->getAttribTileset() ){ //only replace the attibute workingLayer.at(trueCol, trueRow).setAttribute( tilesetBox->getSelectedTile().getAttribute() ); } else { //replace old tile workingLayer.at(trueCol, trueRow) = tilesetBox->getSelectedTile(); } } else if( mouseEvent.getButton() == gcn::MouseEvent::MIDDLE ){ //fill layer, to selected tile on ts //if the attrib ts is on if( tilesetBox->getSelectedTileset() == tilesetBox->getAttribTileset() ){ //only replace the attibute for(int i = 0; i < workingLayer.getHeight(); ++i){ for(int j = 0; j < workingLayer.getWidth(); ++j){ workingLayer.at(j, i).setAttribute( tilesetBox->getSelectedTile().getAttribute() ); } } } else { //replace old tile for(int i = 0; i < workingLayer.getHeight(); ++i){ for(int j = 0; j < workingLayer.getWidth(); ++j){ workingLayer.at(j, i) = tilesetBox->getSelectedTile(); } } } } else if ( mouseEvent.getButton() == gcn::MouseEvent::RIGHT ){ //if the attrib ts is on if( tilesetBox->getSelectedTileset() == tilesetBox->getAttribTileset() ){ //clear attrib workingLayer.at(trueCol, trueRow).setAttribute( MapTile::REGULAR ); } else { //clear the tileset (delete tile) workingLayer.at(trueCol, trueRow).setSource( NULL, 0, 0 ); } } mapTouched = 1; } }//end if event from drop down } else //click from the tilset panel //load tileset button if( mouseEvent.getSource() == tilesetBox->getLoadTilesetButton() ){ mouseEvent.consume(); loadTilesetBox->setVisible( true ); loadTilesetBox->requestFocus(); } else //make tileset button if( mouseEvent.getSource() == tilesetBox->getMakeTilesetButton() ){ mouseEvent.consume(); makeTilesetBox->setVisible( true ); makeTilesetBox->requestFocus(); } else //close tileset button if( mouseEvent.getSource() == tilesetBox->getCloseTilesetButton() ){ mouseEvent.consume(); tilesetDetailsBox->setInfoSource( NULL ); } else //display tileset info if( mouseEvent.getSource() == tilesetBox->getTilesetDetailsButton() ){ mouseEvent.consume(); tilesetDetailsBox->setInfoSource( tilesetBox->getSelectedTileset() ); tilesetDetailsBox->setVisible( true ); tilesetDetailsBox->requestFocus(); } else // from file tool bar //new doc if( mouseEvent.getSource() == fileToolBar->getNewDocButton() ){ mouseEvent.consume(); loadMapBox->setVisible( true ); loadMapBox->requestFocus(); } else //save document if( mouseEvent.getSource() == fileToolBar->getSaveDocButton() ){ mouseEvent.consume(); if( world == NULL ){ alert("Theres no map to save (try the new map button =P)"); return; } if( world->size() == 0 ){ alert("Theres no map to save (try the new map button =P)"); return; } std::string a = world->getFilename() ; if( world->getFilename() == "NULL" || world->getFilename().empty() || isSpace(world->getFilename()) || world->getFilename() == "" ){ filenameBox->setFilename("data/maps/"); filenameBox->setVisible( true ); action = SAVEAS; } else { if( !world->saveMap(world->getFilename()) ){ alert( ("Cant save file: " + world->getFilename()) ); return; } else { alert("Saved"); } } } else // save as if( mouseEvent.getSource() == fileToolBar->getSaveAsButton() ){ mouseEvent.consume(); if( world == NULL ){ alert("Theres no map to save (try the new map button =P)"); return; } if( world->size() == 0 ){ alert("Theres no map to save (try the new map button =P)"); return; } action = SAVEAS; filenameBox->setFilename("data/maps/"); filenameBox->setVisible( true ); } else //open new doc (close current 1st) if( mouseEvent.getSource() == fileToolBar->getOpenDocButton() ){ mouseEvent.consume(); action = OPEN; filenameBox->setFilename("data/maps/"); filenameBox->setVisible( true ); } else //close (no save) and reOpen if( mouseEvent.getSource() == fileToolBar->getReopenDocButton() ){ mouseEvent.consume(); if( world != NULL ){ std::string filename = correctFilepath(world->getFilename()); //delete map notify("Releasing old world from memory"); world->unload(); //clear the tileset array notify("Releasing tilesets"); tilesetBox->freeTilesets(); //reopen notify("Reopening file"); if( !world->loadMap(filename) ){ alert( ("Cant open file: " + filename) ); } unNotify(); mapDetailsBox->setInfoSource( world ); // free old worldImage if( worldImage != NULL ){ SDL_FreeSurface(worldImage); worldImage = NULL; }; mapTouched = 1; action = NOTHING; } } else //close if( mouseEvent.getSource() == fileToolBar->getCloseDocButton() ){ mouseEvent.consume(); //delete map notify("Releasing old world from memory"); if( world != NULL ){ //delete worlds world->unload(); //clear the tileset array notify("Releasing tilesets"); tilesetBox->freeTilesets(); unNotify(); mapDetailsBox->setInfoSource( world ); // free old worldImage if( worldImage != NULL ){ SDL_FreeSurface(worldImage); worldImage = NULL; } mapTouched = 1; action = NOTHING; } } else //get details if( mouseEvent.getSource() == fileToolBar->getDetailsButton() ){ mouseEvent.consume(); mapDetailsBox->setVisible( true ); } }
void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent) { Window::mousePressed(mouseEvent); if (mouseEvent.getButton() == gcn::MouseEvent::LEFT) { // Checks if any of the presses were in the equip boxes. for (int i = EQUIP_LEGS_SLOT; i < EQUIP_VECTOREND; i++) { if (mouseEvent.getSource() == mEquipIcon[i]) { Item *item = (i != EQUIP_AMMO_SLOT) ? mInventory->getItem(mEquipment->getEquipment(i)) : mInventory->getItem(mEquipment->getArrows()); mItems->setEquipSlotsFilter(1 << i); if (item && (item->getInfo().getEquipSlots() & (1 << i))) { mItems->setSelectedItemIndex(item->getInvIndex()); mSelected = i; // Suppress the item popup in the ItemContainer, in case we // change item indicies. mItems->showItemPopup(false); } setSelected(i); break; // No point checking the other boxes } } // Clicking on the window background will reset the // items window to showing all equipment. // (Intuitive to me, but maybe it should be a button) if (mouseEvent.getSource() == this) { mItems->setEquipSlotsFilter((1 << EQUIP_VECTOREND) - 1); setSelected(-1); } } else if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT && mouseEvent.getSource() == mItems) { mItems->showPopupMenu(INVENTORY); } else if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT) { const int x = mouseEvent.getX(); const int y = mouseEvent.getY(); Item* item = getItem(x, y); if (!item) return; /* Convert relative to the window coordinates to absolute screen * coordinates. */ const int mx = x + getX(); const int my = y + getY(); mPopupMenu->setItem(item); mPopupMenu->showPopup(mx, my); } }
void Viewport::mousePressed(gcn::MouseEvent &event) { if (event.getSource() != this) return; // Check if we are alive and kickin' if (!mCurrentMap || !player_node || player_node->mAction == Being::DEAD) return; mPlayerFollowMouse = false; const int tileWidth = mCurrentMap->getTileWidth(); const int tileHeight = mCurrentMap->getTileHeight(); const int tilex = event.getX() / tileWidth + mTileViewX; const int tiley = event.getY() / tileHeight + mTileViewY; const int x = (int)((float) event.getX() + mPixelViewX); const int y = (int)((float) event.getY() + mPixelViewY); // Right click might open a popup if (event.getButton() == gcn::MouseEvent::RIGHT) { Being *being; FloorItem *floorItem; if ((being = beingManager->findBeingByPixel(x, y)) && being != player_node) { mPopupMenu->setType(BEING); showPopup(event.getX(), event.getY(), being); return; } else if ((floorItem = floorItemManager->findByCoordinates(tilex, tiley))) { mPopupMenu->setType(FLOOR_ITEM); mPopupMenu->setFloorItem(floorItem); mPopupMenu->showPopup(event.getX(), event.getY()); return; } } // If a popup is active, just remove it if (mPopupMenu->isVisible()) { mPopupMenu->setVisible(false); return; } // Left click can cause different actions if (event.getButton() == gcn::MouseEvent::LEFT) { Being *being; FloorItem *item; // Interact with some being // if ((being = beingManager->findBeing(tilex, tiley))) if ((being = beingManager->findBeingByPixel(x, y)) && being->mAction != Being::DEAD) { if (being->getType() == Being::NPC && NPC::mTalking == false) static_cast<NPC*>(being)->talk(); else if (player_node->withinAttackRange(being) && being->getType() != Being::NPC) { player_node->setGotoTarget(being); player_node->attack(being, true); } else player_node->setDestination(tilex, tiley); } // Pick up some item else if ((item = floorItemManager->findByCoordinates(tilex, tiley))) player_node->pickUp(item); else if (player_node->mAction == Being::SIT) return; // Just walk around else { player_node->stopAttack(); player_node->setDestination(tilex, tiley); mPlayerFollowMouse = true; } } else if (event.getButton() == gcn::MouseEvent::MIDDLE) { // Find the being nearest to the clicked position Being *target = beingManager->findBeingByPixel(x, y); if (target) player_node->setTarget(target); } }