bool Object::roughMouseOverBox() { if (!hasModel_) { if (mouseX() < x_-originX) return false; if (mouseX() > x_-originX+zRotatedWidth_) return false; if (mouseY() < y_-originY) return false; if (mouseY() > y_-originY+zRotatedHeight_) return false; } return true; }
/** Check if mouse is over the Active console 'window' area */ bool mouseOverConsoleBox(void) { int gotMessages = getNumberConsoleMessages(); if (gotMessages && ((UDWORD)mouseX() > mainConsole.topX) && ((UDWORD)mouseY() > mainConsole.topY) && ((UDWORD)mouseX() < mainConsole.topX + mainConsole.width) && ((UDWORD)mouseY() < (mainConsole.topY + 4 + linePitch * gotMessages))) { return true; } return false; }
/** Check if mouse is over the History console 'window' area */ bool mouseOverHistoryConsoleBox(void) { int nudgeright = 0; if (isSecondaryWindowUp()) { // if a build/research/... is up, we need to move text over by this much nudgeright = RET_FORMWIDTH; } // enable below to see the hitbox of the history console window #if 0 if (isSecondaryWindowUp()) { iV_Box2(historyConsole.topX + nudgeright, historyConsole.topY, historyConsole.topX + historyConsole.width, (historyConsole.topY + 4 + linePitch * NumDisplayLines), WZCOL_RED, WZCOL_GREEN); } else { iV_Box2(historyConsole.topX, historyConsole.topY, historyConsole.topX + historyConsole.width, (historyConsole.topY + 4 + linePitch * NumDisplayLines), WZCOL_GREY, WZCOL_GREY); } #endif // check to see if mouse is in the area when console is enabled if (bConsoleDropped && ((UDWORD)mouseX() > historyConsole.topX + nudgeright) && ((UDWORD)mouseY() > historyConsole.topY) && ((UDWORD)mouseX() < historyConsole.topX + historyConsole.width) && ((UDWORD)mouseY() < (historyConsole.topY + 4 + linePitch * NumDisplayLines))) { if (mousePressed(MOUSE_WUP)) { updatepos--; } else if (mousePressed(MOUSE_WDN)) { updatepos++; } if (keyDown(KEY_LCTRL)) { showBackgroundColor = true; } else { showBackgroundColor = false; } return (true); } else { return (false); } }
/** true or false as to whether the mouse is presently over the console window */ BOOL mouseOverConsoleBox( void ) { if ( ((UDWORD)mouseX() > mainConsole.topX) // condition 1 && ((UDWORD)mouseY() > mainConsole.topY) // condition 2 && ((UDWORD)mouseX() < mainConsole.topX + mainConsole.width) //condition 3 && ((UDWORD)mouseY() < (mainConsole.topY + iV_GetTextLineSize()*numActiveMessages)) //condition 4 ) { return(true); } else { return(false); } }
/* Delete a widget from the screen */ void widgDelete(W_SCREEN *psScreen, UDWORD id) { W_CONTEXT sContext; ASSERT( psScreen != NULL, "widgDelete: Invalid screen pointer" ); /* Clear the keyboard focus if necessary */ if ((psScreen->psFocus != NULL) && (psScreen->psFocus->id == id)) { screenClearFocus(psScreen); } // NOTE: This is where it would crash because of a dangling pointer. See CheckpsMouseOverWidget() for info. // the mouse can't be over it anymore if (psMouseOverWidget && psMouseOverWidget->id == id) { psMouseOverWidget = NULL; } /* Set up the initial context */ sContext.psScreen = psScreen; sContext.psForm = (W_FORM *)psScreen->psForm; sContext.xOffset = 0; sContext.yOffset = 0; sContext.mx = mouseX(); sContext.my = mouseY(); (void)widgDeleteFromForm((W_FORM *)psScreen->psForm, id, &sContext); }
/*! * The mainloop. * Fetches events, executes appropriate code */ void mainLoop(void) { frameUpdate(); // General housekeeping // Screenshot key is now available globally if (keyPressed(KEY_F10)) { kf_ScreenDump(); inputLoseFocus(); // remove it from input stream } if (NetPlay.bComms || focusState == FOCUS_IN || !war_GetPauseOnFocusLoss()) { if (loop_GetVideoStatus()) { videoLoop(); // Display the video if neccessary } else switch (GetGameMode()) { case GS_NORMAL: // Run the gameloop code runGameLoop(); break; case GS_TITLE_SCREEN: // Run the titleloop code runTitleLoop(); break; default: break; } realTimeUpdate(); // Update realTime. } // Feed a bit of randomness into libcrypto. unsigned buf[] = {mouseX(), mouseY(), realTime, graphicsTime, gameTime, (unsigned) rand(), 4}; // http://xkcd.com/221/ RAND_add(buf, sizeof(buf), 1); }
bool Object::mouseOverCircle() { if (!hasModel_) { float radius = (width_ > height_) ? width_ : height_, mouseXDist = float(mouseX())-x_, mouseYDist = float(mouseY())-y_, mouseDist = (mouseXDist*mouseXDist)+(mouseYDist*mouseYDist); if (mouseDist <= (radius/2)*(radius/2)) return true; } return false; }
// TODO consider using QWidget::mouseDoubleClickEvent() for double-click void WzMainWindow::mousePressEvent(QMouseEvent *event) { mouseXPos = event->x(); mouseYPos = event->y(); Qt::MouseButtons presses = event->buttons(); // full state info for all buttons MOUSE_KEY_CODE idx = buttonToIdx(event->button()); // index of button that caused event if (idx == MOUSE_BAD) { debug(LOG_ERROR, "bad mouse idx"); // FIXME remove return; // not recognized mouse button } MousePress mousePress; mousePress.action = MousePress::Press; mousePress.key = idx; mousePress.pos = Vector2i(mouseXPos, mouseYPos); mousePresses.push_back(mousePress); aMouseState[idx].pressPos.x = mouseXPos; aMouseState[idx].pressPos.y = mouseYPos; if (aMouseState[idx].state == KEY_UP || aMouseState[idx].state == KEY_RELEASED || aMouseState[idx].state == KEY_PRESSRELEASE) { if (!presses.testFlag(Qt::MidButton)) //skip doubleclick check for wheel { // whether double click or not if (realTime - aMouseState[idx].lastdown < DOUBLE_CLICK_INTERVAL) { aMouseState[idx].state = KEY_DOUBLECLICK; aMouseState[idx].lastdown = 0; } else { aMouseState[idx].state = KEY_PRESSED; aMouseState[idx].lastdown = realTime; } } else //mouse wheel up/down was used, so notify. FIXME. { aMouseState[idx].state = KEY_PRESSED; aMouseState[idx].lastdown = 0; } if (idx == MOUSE_LMB || idx == MOUSE_RMB || idx == MOUSE_MMB) { dragKey = idx; dragX = mouseX(); dragY = mouseY(); } } }
/* Execute a set of widgets for one cycle. * Return the id of the widget that was activated, or 0 for none. */ UDWORD widgRunScreen(W_SCREEN *psScreen) { W_CONTEXT sContext; psScreen->psRetWidget = NULL; // Note which keys have been pressed pressed = WKEY_NONE; sContext.mx = mouseX(); sContext.my = mouseY(); if(getWidgetsStatus()) { if (mousePressed(MOUSE_LMB)) { pressed = WKEY_PRIMARY; sContext.mx = mousePressPos(MOUSE_LMB).x; sContext.my = mousePressPos(MOUSE_LMB).y; } else if (mousePressed(MOUSE_RMB)) { pressed = WKEY_SECONDARY; sContext.mx = mousePressPos(MOUSE_RMB).x; sContext.my = mousePressPos(MOUSE_RMB).y; } released = WKEY_NONE; if (mouseReleased(MOUSE_LMB)) { released = WKEY_PRIMARY; sContext.mx = mouseReleasePos(MOUSE_LMB).x; sContext.my = mouseReleasePos(MOUSE_LMB).y; } else if (mouseReleased(MOUSE_RMB)) { released = WKEY_SECONDARY; sContext.mx = mouseReleasePos(MOUSE_RMB).x; sContext.my = mouseReleasePos(MOUSE_RMB).y; } } /* Initialise the context */ sContext.psScreen = psScreen; sContext.psForm = (W_FORM *)psScreen->psForm; sContext.xOffset = 0; sContext.yOffset = 0; psMouseOverWidget = NULL; /* Process the screen's widgets */ widgProcessForm(&sContext); /* Process any user callback functions */ widgProcessCallbacks(&sContext); /* Return the ID of a pressed button or finished edit box if any */ return psScreen->psRetWidget ? psScreen->psRetWidget->id : 0; }
void Domain_new::CalculateMouseCoordinates() { if (camera) { float glX, glY, domX, domY; camera->GetUnprojectedPoint(newx, newy, &glX, &glY); if (fort14) { domX = fort14->GetUnprojectedX(glX); domY = fort14->GetUnprojectedY(glY); emit mouseX(domX); emit mouseY(domY); } else { emit mouseX(glX); emit mouseY(glY); } } else { emit mouseX(newx); emit mouseY(newy); } }
int QDeclarativeMouseArea::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QDeclarativeItem::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 16) qt_static_metacall(this, _c, _id, _a); _id -= 16; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< qreal*>(_v) = mouseX(); break; case 1: *reinterpret_cast< qreal*>(_v) = mouseY(); break; case 2: *reinterpret_cast< bool*>(_v) = hovered(); break; case 3: *reinterpret_cast< bool*>(_v) = pressed(); break; case 4: *reinterpret_cast< bool*>(_v) = isEnabled(); break; case 5: *reinterpret_cast< Qt::MouseButtons*>(_v) = pressedButtons(); break; case 6: *reinterpret_cast< Qt::MouseButtons*>(_v) = acceptedButtons(); break; case 7: *reinterpret_cast< bool*>(_v) = hoverEnabled(); break; case 8: *reinterpret_cast< QDeclarativeDrag**>(_v) = drag(); break; case 9: *reinterpret_cast< bool*>(_v) = preventStealing(); break; } _id -= 10; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 4: setEnabled(*reinterpret_cast< bool*>(_v)); break; case 6: setAcceptedButtons(*reinterpret_cast< Qt::MouseButtons*>(_v)); break; case 7: setHoverEnabled(*reinterpret_cast< bool*>(_v)); break; case 9: setPreventStealing(*reinterpret_cast< bool*>(_v)); break; } _id -= 10; } else if (_c == QMetaObject::ResetProperty) { _id -= 10; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 10; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 10; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 10; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 10; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 10; } #endif // QT_NO_PROPERTIES return _id; }
/* * Setup a tool tip. * The tip module will then wait until the correct points to * display and then remove the tool tip. * i.e. The tip will not be displayed immediately. * Calling this while another tip is being displayed will restart * the tip system. * psSource is the widget that started the tip. * x,y,width,height - specify the position of the button to place the * tip by. */ void tipStart(WIDGET *psSource, QString pNewTip, iV_fonts NewFontID, int x, int y, int width, int height) { ASSERT(psSource != NULL, "Invalid widget pointer"); tipState = TIP_WAIT; startTime = wzGetTicks(); mx = mouseX(); my = mouseY(); wx = x; wy = y; ww = width; wh = height; pTip = pNewTip.split('\n'); psWidget = psSource; FontID = NewFontID; }
bool Object::mouseOverBox() { if (!hasModel_) { vec2 vertex[4] = { vec2(x_-originX, y_-originY), vec2(x_-originX, y_-originY+height_), vec2(x_-originX+width_, y_-originY+height_), vec2(x_-originX+width_, y_-originY) }; if ((zRotation_ != 0.0f) && (zRotation_ != 180.0f)) for (short i = 0; i < 4; i++) vertex[i] *= get2dRotationMatrix(zRotation_); return vec2(mouseX(), mouseY()).polygonCollision(4, vertex); } return false; }
/* Start looking for a structure location */ void disp2DStartStructPosition(BASE_STATS *psStats) { UDWORD worldX, worldY; /* find the current mouse position */ disp2DToWorld(mouseX(),mouseY(), &worldX,&worldY); /* Set up the structure position */ structPosMode = SPM_POS; if (psStats->ref >= REF_STRUCTURE_START && psStats->ref < (REF_STRUCTURE_START + REF_RANGE)) { sStructPos.x = (worldX >> TILE_SHIFT) - ((STRUCTURE_STATS *)psStats)->baseWidth/2; sStructPos.y = (worldY >> TILE_SHIFT) - ((STRUCTURE_STATS *)psStats)->baseBreadth/2; sStructPos.width = ((STRUCTURE_STATS *)psStats)->baseWidth; sStructPos.height = ((STRUCTURE_STATS *)psStats)->baseBreadth; sStructPos.psStats = psStats; }
// //////////////////////////////////////////////////////////////////////////// // Returns TRUE if cancel pressed or a valid game slot was selected. // if when returning TRUE strlen(sRequestResult) != 0 then a valid game // slot was selected otherwise cancel was selected.. static BOOL _runLoadSave(BOOL bResetMissionWidgets) { UDWORD id=0; W_EDBINIT sEdInit; CHAR sTemp[MAX_STR_LENGTH]; CD_INDEX CDrequired; UDWORD iCampaign,i; W_CONTEXT context; BOOL bSkipCD = FALSE; id = widgRunScreen(psRequestScreen); if ( cdspan_ProcessCDChange(id) ) { return bRequestLoad; } strcpy(sRequestResult,""); // set returned filename to null; // cancel this operation... if(id == LOADSAVE_CANCEL || CancelPressed() ) { goto failure; } // clicked a load entry if( id >= LOADENTRY_START && id <= LOADENTRY_END ) { if(mode) // Loading, return that entry. { if( ((W_BUTTON *)widgGetFromID(psRequestScreen,id))->pText ) { sprintf(sRequestResult,"%s%s.%s",sPath, ((W_BUTTON *)widgGetFromID(psRequestScreen,id))->pText ,sExt); } else { goto failure; // clicked on an empty box } if( bLoadSaveMode == LOAD_FORCE || bLoadSaveMode ==SAVE_FORCE ) { goto successforce; // it's a force, dont check the cd. } /* check correct CD in drive */ iCampaign = getCampaign(sRequestResult,&bSkipCD); if ( iCampaign == 0 OR bSkipCD ) { DBPRINTF( ("getCampaign returned 0 or we're loading a skirmish game: assuming correct CD in drive\n") ); } CDrequired = getCDForCampaign( iCampaign ); if ( (iCampaign == 0) || cdspan_CheckCDPresent( CDrequired ) OR bSkipCD) { goto success; } else { bRequestLoad = FALSE; widgHide(psRequestScreen,LOADSAVE_FORM); showChangeCDBox( psRequestScreen, CDrequired, loadSaveCDOK, loadSaveCDCancel ); return FALSE; } } else // SAVING!add edit box at that position. { if( ! widgGetFromID(psRequestScreen,SAVEENTRY_EDIT)) { // add blank box. memset(&sEdInit, 0, sizeof(W_EDBINIT)); sEdInit.formID= LOADSAVE_FORM; sEdInit.id = SAVEENTRY_EDIT; sEdInit.style = WEDB_PLAIN; sEdInit.x = widgGetFromID(psRequestScreen,id)->x; sEdInit.y = widgGetFromID(psRequestScreen,id)->y; sEdInit.width = widgGetFromID(psRequestScreen,id)->width; sEdInit.height= widgGetFromID(psRequestScreen,id)->height; sEdInit.pText = ((W_BUTTON *)widgGetFromID(psRequestScreen,id))->pText; sEdInit.FontID= WFont; sEdInit.pBoxDisplay = displayLoadSaveEdit; widgAddEditBox(psRequestScreen, &sEdInit); sprintf(sTemp,"%s%s.%s", sPath, ((W_BUTTON *)widgGetFromID(psRequestScreen,id))->pText , sExt); widgHide(psRequestScreen,id); // hide the old button chosenSlotId = id; strcpy(sDelete,sTemp); // prepare the savegame name. sTemp[strlen(sTemp)-4] = '\0'; // strip extension // auto click in the edit box we just made. context.psScreen = psRequestScreen; context.psForm = (W_FORM *)psRequestScreen->psForm; context.xOffset = 0; context.yOffset = 0; context.mx = mouseX(); context.my = mouseY(); editBoxClicked((W_EDITBOX*)widgGetFromID(psRequestScreen,SAVEENTRY_EDIT), &context); } else { // clicked in a different box. shouldnt be possible!(since we autoclicked in editbox) } } } // finished entering a name. if( id == SAVEENTRY_EDIT) { if(!keyPressed(KEY_RETURN)) // enter was not pushed, so not a vaild entry. { widgDelete(psRequestScreen,SAVEENTRY_EDIT); //unselect this box, and go back .. widgReveal(psRequestScreen,chosenSlotId); return TRUE; } // scan to see if that game exists in another slot, if // so then fail. strcpy(sTemp,((W_EDITBOX *)widgGetFromID(psRequestScreen,id))->aText); for(i=LOADENTRY_START;i<LOADENTRY_END;i++) { if( i != chosenSlotId) { if( ((W_BUTTON *)widgGetFromID(psRequestScreen,i))->pText && strcmp( sTemp, ((W_BUTTON *)widgGetFromID(psRequestScreen,i))->pText ) ==0) { widgDelete(psRequestScreen,SAVEENTRY_EDIT); //unselect this box, and go back .. widgReveal(psRequestScreen,chosenSlotId); // move mouse to same box.. // SetMousePos(widgGetFromID(psRequestScreen,i)->x ,widgGetFromID(psRequestScreen,i)->y); audio_PlayTrack(ID_SOUND_BUILD_FAIL); return TRUE; } } } // return with this name, as we've edited it. if (strlen(((W_EDITBOX *)widgGetFromID(psRequestScreen,id))->aText)) { strcpy(sTemp,((W_EDITBOX *)widgGetFromID(psRequestScreen,id))->aText); removeWildcards(sTemp); sprintf(sRequestResult,"%s%s.%s", sPath, sTemp, sExt); deleteSaveGame(sDelete); //only delete game if a new game fills the slot } else { goto failure; // we entered a blank name.. } // we're done. saving. closeLoadSave(); bRequestLoad = FALSE; if (bResetMissionWidgets AND widgGetFromID(psWScreen,IDMISSIONRES_FORM) == NULL) { resetMissionWidgets(); //reset the mission widgets here if necessary } return TRUE; } return FALSE; // failed and/or cancelled.. failure: closeLoadSave(); bRequestLoad = FALSE; if (bResetMissionWidgets AND widgGetFromID(psWScreen,IDMISSIONRES_FORM) == NULL) { resetMissionWidgets(); } return TRUE; // success on load. success: setCampaignNumber( getCampaign(sRequestResult,&bSkipCD) ); successforce: closeLoadSave(); bRequestLoad = TRUE; return TRUE; }
static GAMECODE renderLoop() { if (bMultiPlayer && !NetPlay.isHostAlive && NetPlay.bComms && !NetPlay.isHost) { intAddInGamePopup(); } int clearMode = 0; if(getDrawShadows()) { clearMode |= CLEAR_SHADOW; } if (loopMissionState == LMS_SAVECONTINUE) { pie_SetFogStatus(false); clearMode = CLEAR_BLACK; } pie_ScreenFlip(clearMode);//gameloopflip HandleClosingWindows(); // Needs to be done outside the pause case. audio_Update(); wzShowMouse(true); INT_RETVAL intRetVal = INT_NONE; if (!paused) { /* Run the in game interface and see if it grabbed any mouse clicks */ if (!rotActive && getWidgetsStatus() && dragBox3D.status != DRAG_DRAGGING && wallDrag.status != DRAG_DRAGGING) { intRetVal = intRunWidgets(); } //don't process the object lists if paused or about to quit to the front end if (!gameUpdatePaused() && intRetVal != INT_QUIT) { if( dragBox3D.status != DRAG_DRAGGING && wallDrag.status != DRAG_DRAGGING && ( intRetVal == INT_INTERCEPT || ( radarOnScreen && CoordInRadar(mouseX(), mouseY()) && getHQExists(selectedPlayer) ) ) ) { // Using software cursors (when on) for these menus due to a bug in SDL's SDL_ShowCursor() wzSetCursor(CURSOR_DEFAULT); intRetVal = INT_INTERCEPT; } #ifdef DEBUG // check all flag positions for duplicate delivery points checkFactoryFlags(); #endif //handles callbacks for positioning of DP's process3DBuilding(); //ajl. get the incoming netgame messages and process them. // FIXME Previous comment is deprecated. multiPlayerLoop does some other weird stuff, but not that anymore. if (bMultiPlayer) { multiPlayerLoop(); } for (unsigned i = 0; i < MAX_PLAYERS; i++) { for (DROID *psCurr = apsDroidLists[i]; psCurr; psCurr = psCurr->psNext) { // Don't copy the next pointer - if droids somehow get destroyed in the graphics rendering loop, who cares if we crash. calcDroidIllumination(psCurr); } } /* update animations */ animObj_Update(); } if (!consolePaused()) { /* Process all the console messages */ updateConsoleMessages(); } if (!scrollPaused() && !getWarCamStatus() && dragBox3D.status != DRAG_DRAGGING && intMode != INT_INGAMEOP ) { scroll(); } } else // paused { // Using software cursors (when on) for these menus due to a bug in SDL's SDL_ShowCursor() wzSetCursor(CURSOR_DEFAULT); if(dragBox3D.status != DRAG_DRAGGING) { scroll(); } if(InGameOpUp || isInGamePopupUp) // ingame options menu up, run it! { unsigned widgval = widgRunScreen(psWScreen); intProcessInGameOptions(widgval); if(widgval == INTINGAMEOP_QUIT_CONFIRM || widgval == INTINGAMEOP_POPUP_QUIT) { if(gamePaused()) { kf_TogglePauseMode(); } intRetVal = INT_QUIT; } } if(bLoadSaveUp && runLoadSave(true) && strlen(sRequestResult)) { debug( LOG_NEVER, "Returned %s", sRequestResult ); if(bRequestLoad) { loopMissionState = LMS_LOADGAME; NET_InitPlayers(); // otherwise alliances were not cleared sstrcpy(saveGameName, sRequestResult); } else { char msgbuffer[256]= {'\0'}; if (saveInMissionRes()) { if (saveGame(sRequestResult, GTYPE_SAVE_START)) { sstrcpy(msgbuffer, _("GAME SAVED: ")); sstrcat(msgbuffer, sRequestResult); addConsoleMessage( msgbuffer, LEFT_JUSTIFY, NOTIFY_MESSAGE); } else { ASSERT( false,"Mission Results: saveGame Failed" ); sstrcpy(msgbuffer, _("Could not save game!")); addConsoleMessage( msgbuffer, LEFT_JUSTIFY, NOTIFY_MESSAGE); deleteSaveGame(sRequestResult); } } else if (bMultiPlayer || saveMidMission()) { if (saveGame(sRequestResult, GTYPE_SAVE_MIDMISSION))//mid mission from [esc] menu { sstrcpy(msgbuffer, _("GAME SAVED: ")); sstrcat(msgbuffer, sRequestResult); addConsoleMessage( msgbuffer, LEFT_JUSTIFY, NOTIFY_MESSAGE); } else { ASSERT(!"saveGame(sRequestResult, GTYPE_SAVE_MIDMISSION) failed", "Mid Mission: saveGame Failed" ); sstrcpy(msgbuffer, _("Could not save game!")); addConsoleMessage( msgbuffer, LEFT_JUSTIFY, NOTIFY_MESSAGE); deleteSaveGame(sRequestResult); } } else { ASSERT( false, "Attempt to save game with incorrect load/save mode" ); } } } } /* Check for quit */ bool quitting = false; if (intRetVal == INT_QUIT) { if (!loop_GetVideoStatus()) { //quitting from the game to the front end //so get a new backdrop quitting = true; pie_LoadBackDrop(SCREEN_RANDOMBDROP); } } if (!loop_GetVideoStatus() && !quitting) { if (!gameUpdatePaused()) { if (dragBox3D.status != DRAG_DRAGGING && wallDrag.status != DRAG_DRAGGING) { ProcessRadarInput(); } processInput(); //no key clicks or in Intelligence Screen if (intRetVal == INT_NONE && !InGameOpUp && !isInGamePopupUp) { processMouseClickInput(); } displayWorld(); } /* Display the in game interface */ pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_ON); pie_SetFogStatus(false); if(bMultiPlayer && bDisplayMultiJoiningStatus) { intDisplayMultiJoiningStatus(bDisplayMultiJoiningStatus); setWidgetsStatus(false); } if(getWidgetsStatus()) { intDisplayWidgets(); } pie_SetDepthBufferStatus(DEPTH_CMP_LEQ_WRT_ON); pie_SetFogStatus(true); } pie_GetResetCounts(&loopPieCount, &loopPolyCount, &loopStateChanges); if ((fogStatus & FOG_BACKGROUND) && (loopMissionState == LMS_SAVECONTINUE)) { pie_SetFogStatus(false); } if (!quitting) { /* Check for toggling display mode */ if ((keyDown(KEY_LALT) || keyDown(KEY_RALT)) && keyPressed(KEY_RETURN)) { screenToggleMode(); } } // deal with the mission state switch (loopMissionState) { case LMS_CLEAROBJECTS: missionDestroyObjects(); setScriptPause(true); loopMissionState = LMS_SETUPMISSION; break; case LMS_NORMAL: // default break; case LMS_SETUPMISSION: setScriptPause(false); if (!setUpMission(nextMissionType)) { return GAMECODE_QUITGAME; } break; case LMS_SAVECONTINUE: // just wait for this to be changed when the new mission starts break; case LMS_NEWLEVEL: //nextMissionType = MISSION_NONE; nextMissionType = LDS_NONE; return GAMECODE_NEWLEVEL; break; case LMS_LOADGAME: return GAMECODE_LOADGAME; break; default: ASSERT( false, "unknown loopMissionState" ); break; } if (quitting) { pie_SetFogStatus(false); pie_ScreenFlip(CLEAR_BLACK);//gameloopflip /* Check for toggling display mode */ if ((keyDown(KEY_LALT) || keyDown(KEY_RALT)) && keyPressed(KEY_RETURN)) { screenToggleMode(); } return GAMECODE_QUITGAME; } else if (loop_GetVideoStatus()) { audio_StopAll(); return GAMECODE_PLAYVIDEO; } return GAMECODE_CONTINUE; }
// //////////////////////////////////////////////////////////////////////////// // Returns true if cancel pressed or a valid game slot was selected. // if when returning true strlen(sRequestResult) != 0 then a valid game slot was selected // otherwise cancel was selected.. bool runLoadSave(bool bResetMissionWidgets) { static char sDelete[PATH_MAX]; UDWORD i, campaign; W_CONTEXT context; char NewSaveGamePath[PATH_MAX] = {'\0'}; WidgetTriggers const &triggers = widgRunScreen(psRequestScreen); unsigned id = triggers.empty()? 0 : triggers.front().widget->id; // Just use first click here, since the next click could be on another menu. sstrcpy(sRequestResult, ""); // set returned filename to null; // cancel this operation... if(id == LOADSAVE_CANCEL || CancelPressed() ) { goto cleanup; } if (bMultiPlayer) { ssprintf(NewSaveGamePath, "%s%s/", SaveGamePath, "skirmish"); } else { ssprintf(NewSaveGamePath, "%s%s/", SaveGamePath, "campaign"); } // clicked a load entry if( id >= LOADENTRY_START && id <= LOADENTRY_END ) { W_BUTTON *slotButton = (W_BUTTON *)widgGetFromID(psRequestScreen, id); if (mode) // Loading, return that entry. { if (!slotButton->pText.isEmpty()) { ssprintf(sRequestResult, "%s%s%s", NewSaveGamePath, ((W_BUTTON *)widgGetFromID(psRequestScreen,id))->pText.toUtf8().constData(), sExt); } else { return false; // clicked on an empty box } goto success; } else // SAVING!add edit box at that position. { if( ! widgGetFromID(psRequestScreen,SAVEENTRY_EDIT)) { WIDGET *parent = widgGetFromID(psRequestScreen, LOADSAVE_FORM); // add blank box. W_EDITBOX *saveEntryEdit = new W_EDITBOX(parent); saveEntryEdit->id = SAVEENTRY_EDIT; saveEntryEdit->setGeometry(slotButton->geometry()); saveEntryEdit->setString(slotButton->getString()); saveEntryEdit->setBoxColours(WZCOL_MENU_LOAD_BORDER, WZCOL_MENU_LOAD_BORDER, WZCOL_MENU_BACKGROUND); if (!slotButton->pText.isEmpty()) { ssprintf(sDelete, "%s%s%s", NewSaveGamePath, slotButton->pText.toUtf8().constData(), sExt); } else { sstrcpy(sDelete, ""); } slotButton->hide(); // hide the old button chosenSlotId = id; // auto click in the edit box we just made. context.xOffset = 0; context.yOffset = 0; context.mx = mouseX(); context.my = mouseY(); saveEntryEdit->clicked(&context); } else { // clicked in a different box. shouldnt be possible!(since we autoclicked in editbox) } } } // finished entering a name. if( id == SAVEENTRY_EDIT) { char sTemp[MAX_STR_LENGTH]; if(!keyPressed(KEY_RETURN) && !keyPressed(KEY_KPENTER)) // enter was not pushed, so not a vaild entry. { widgDelete(psRequestScreen,SAVEENTRY_EDIT); //unselect this box, and go back .. widgReveal(psRequestScreen,chosenSlotId); return true; } // scan to see if that game exists in another slot, if so then fail. sstrcpy(sTemp, widgGetString(psRequestScreen, id)); for(i=LOADENTRY_START;i<LOADENTRY_END;i++) { if( i != chosenSlotId) { if(!((W_BUTTON *)widgGetFromID(psRequestScreen,i))->pText.isEmpty() && strcmp(sTemp, ((W_BUTTON *)widgGetFromID(psRequestScreen,i))->pText.toUtf8().constData()) == 0) { widgDelete(psRequestScreen,SAVEENTRY_EDIT); //unselect this box, and go back .. widgReveal(psRequestScreen,chosenSlotId); // move mouse to same box.. // setMousePos(widgGetFromID(psRequestScreen,i)->pos.x ,widgGetFromID(psRequestScreen,i)->pos.y); audio_PlayTrack(ID_SOUND_BUILD_FAIL); return true; } } } // return with this name, as we've edited it. if (strlen(widgGetString(psRequestScreen, id))) { sstrcpy(sTemp, widgGetString(psRequestScreen, id)); removeWildcards(sTemp); snprintf(sRequestResult, sizeof(sRequestResult), "%s%s%s", NewSaveGamePath, sTemp, sExt); if (strlen(sDelete) != 0) { deleteSaveGame(sDelete); //only delete game if a new game fills the slot } } goto cleanup; } return false; // failed and/or cancelled.. cleanup: closeLoadSave(); bRequestLoad = false; if (bResetMissionWidgets && widgGetFromID(psWScreen,IDMISSIONRES_FORM) == NULL) { resetMissionWidgets(); //reset the mission widgets here if necessary } return true; // success on load. success: campaign = getCampaign(sRequestResult); setCampaignNumber(campaign); debug(LOG_WZ, "Set campaign for %s to %u", sRequestResult, campaign); closeLoadSave(); bRequestLoad = true; return true; }
int multiplayer(SDL_Window *win, SDL_Renderer *ren){ /* langue musique Done */ SDL_Surface *img_srf; SDL_Texture *img_txtu; SDL_Rect tapisPos; SDL_Rect but, butClick[3]; ServSetting serv; FILE *server_settings = NULL; strcpy(serv.ip, "127.0.0.1"); serv.port = 23; server_settings = fopen("server_settings.conf", "r"); if(server_settings != NULL){ while(fread(&serv, sizeof(ServSetting), 1, server_settings) && !feof(server_settings)); printf("serv ip: %s port: %d", serv.ip, serv.port); fclose(server_settings); } else{ perror("Open server_settings.conf"); } int loop = 1; int i, j; int lastclick = -1; int onIP = 1; char ip[32] = {0}; char port[16] = {0}; char _ip[33] = {0}; char _port[17] = {0}; //char filename[45] = {0}; strcpy(ip, serv.ip); sprintf(port, "%d", serv.port); TTF_Font *f; TTF_Font *fBig; SDL_Event event; f = loadFont("minecraft.ttf", 15); fBig = loadFont("minecraft.ttf", 25); img_srf = SDL_LoadBMP("grey_wool.bmp"); img_txtu = SDL_CreateTextureFromSurface(ren, img_srf); SDL_FreeSurface(img_srf); while(loop){ for(i = 0; i <= 14; i++){ for(j = 0; j <= 9; j++){ tapisPos.x = i*80; tapisPos.y = j*80; tapisPos.w = 80; tapisPos.h = 80; SDL_RenderCopy(ren, img_txtu, NULL, &tapisPos); } } text(ren, fBig, "Roku Kotore", 450, 50, -1, -1, 255, 255, 255, 255); color(ren, 50, 50, 70); but = text(ren, f, "Continuer", 500, 600, -1, -1, 255, 255, 255, 255); //----- butClick[0] = rect(ren, but.x - 100, but.y - 10, but.w + 200, but.h + 20, 1); // bouton text(ren, f, "Continuer", 500, 600, -1, -1, 255, 255, 255, 255); text(ren, f, "IP", 300, 300, -1, -1, 255, 255, 255, 255); text(ren, f, "PORT", 300, 400, -1, -1, 255, 255, 255, 255); color(ren, 10, 10, 10); but = text(ren, f, "#################################", 500, 300, -1, -1, 255, 255, 255, 255); //----- butClick[1] = rect(ren, but.x - 10, but.y - 10, but.w + 20, but.h + 20, 1); // bouton sprintf(_ip, " %s", ip); text(ren, f, _ip, 500, 300, -1, -1, 255, 255, 255, 255); if(onIP){ color(ren, 255, 255, 255); rect(ren, but.x - 10, but.y - 10, but.w + 20, but.h + 20, 0); } color(ren, 10, 10, 10); but = text(ren, f, "#################", 500, 400, -1, -1, 255, 255, 255, 255); //----- butClick[2] = rect(ren, but.x - 10, but.y - 10, but.w + 20, but.h + 20, 1); // bouton sprintf(_port, " %s", port); text(ren, f, _port, 500, 400, -1, -1, 255, 255, 255, 255); if(!onIP){ color(ren, 255, 255, 255); rect(ren, but.x - 10, but.y - 10, but.w + 20, but.h + 20, 0); } switch(lastclick){ case 0: strcpy(serv.ip, ip); sscanf(port, "%d", &serv.port); //printf("IP : %s PORT : %d\n", serv.ip, serv.port); server_settings = fopen("server_settings.conf", "w"); if(server_settings != NULL){ printf("savingIP : %s PORT : %d\n", serv.ip, serv.port); fwrite(&serv, sizeof(ServSetting), 1, server_settings); fclose(server_settings); } else{ perror("Open server_settings.conf (save)"); } loop = 0; break; case 1: onIP = 1; break; case 2: onIP = 0; break; } while(SDL_PollEvent(&event)){ switch(event.type){ case SDL_QUIT: loop = 0; break; case SDL_KEYDOWN: switch(event.key.keysym.sym){ case SDLK_BACKSPACE: if(onIP){ if(strlen(ip) > 0){ ip[strlen(ip)-1] = 0; } } else{ if(strlen(port) > 0){ port[strlen(port)-1] = 0; } } break; case SDLK_RETURN: break; case SDLK_ESCAPE: loop = 0; break; } break; case SDL_TEXTINPUT: if(onIP){ if(strlen(ip) < 32){ strcat(ip, event.text.text); } } else{ if(strlen(port) < 15){ strcat(port, event.text.text); } } break; case SDL_MOUSEBUTTONUP: switch(event.button.button){ case SDL_BUTTON_LEFT: for (i = 0; i < 3; i++) { if(mouseX() >= butClick[i].x && mouseX() <= butClick[i].x + butClick[i].w && mouseY() >= butClick[i].y && mouseY() <= butClick[i].y + butClick[i].h ){ lastclick = i; } } break; } break; } } drawScene(ren); } closeFont(f); closeFont(fBig); SDL_DestroyTexture(img_txtu); }
// //////////////////////////////////////////////////////////////////////////// // Returns true if cancel pressed or a valid game slot was selected. // if when returning true strlen(sRequestResult) != 0 then a valid game slot was selected // otherwise cancel was selected.. BOOL runLoadSave(BOOL bResetMissionWidgets) { UDWORD id=0; W_EDBINIT sEdInit; static char sDelete[PATH_MAX]; UDWORD i, campaign; W_CONTEXT context; id = widgRunScreen(psRequestScreen); sstrcpy(sRequestResult, ""); // set returned filename to null; // cancel this operation... if(id == LOADSAVE_CANCEL || CancelPressed() ) { goto cleanup; } // clicked a load entry if( id >= LOADENTRY_START && id <= LOADENTRY_END ) { if (mode) // Loading, return that entry. { if( ((W_BUTTON *)widgGetFromID(psRequestScreen,id))->pText ) { sprintf(sRequestResult,"%s%s.%s",sPath, ((W_BUTTON *)widgGetFromID(psRequestScreen,id))->pText ,sExt); } else { return false; // clicked on an empty box } goto success; } else // SAVING!add edit box at that position. { if( ! widgGetFromID(psRequestScreen,SAVEENTRY_EDIT)) { // add blank box. memset(&sEdInit, 0, sizeof(W_EDBINIT)); sEdInit.formID= LOADSAVE_FORM; sEdInit.id = SAVEENTRY_EDIT; sEdInit.style = WEDB_PLAIN; sEdInit.x = widgGetFromID(psRequestScreen,id)->x; sEdInit.y = widgGetFromID(psRequestScreen,id)->y; sEdInit.width = widgGetFromID(psRequestScreen,id)->width; sEdInit.height= widgGetFromID(psRequestScreen,id)->height; sEdInit.pText = ((W_BUTTON *)widgGetFromID(psRequestScreen,id))->pText; sEdInit.FontID= font_regular; sEdInit.pBoxDisplay = displayLoadSaveEdit; widgAddEditBox(psRequestScreen, &sEdInit); if (((W_BUTTON *)widgGetFromID(psRequestScreen,id))->pText != NULL) { snprintf(sDelete, sizeof(sDelete), "%s%s.%s", sPath, ((W_BUTTON *)widgGetFromID(psRequestScreen,id))->pText , sExt); } else { sstrcpy(sDelete, ""); } widgHide(psRequestScreen,id); // hide the old button chosenSlotId = id; // auto click in the edit box we just made. context.psScreen = psRequestScreen; context.psForm = (W_FORM *)psRequestScreen->psForm; context.xOffset = 0; context.yOffset = 0; context.mx = mouseX(); context.my = mouseY(); editBoxClicked((W_EDITBOX*)widgGetFromID(psRequestScreen,SAVEENTRY_EDIT), &context); } else { // clicked in a different box. shouldnt be possible!(since we autoclicked in editbox) } } } // finished entering a name. if( id == SAVEENTRY_EDIT) { char sTemp[MAX_STR_LENGTH]; if(!keyPressed(KEY_RETURN) && !keyPressed(KEY_KPENTER)) // enter was not pushed, so not a vaild entry. { widgDelete(psRequestScreen,SAVEENTRY_EDIT); //unselect this box, and go back .. widgReveal(psRequestScreen,chosenSlotId); return true; } // scan to see if that game exists in another slot, if so then fail. sstrcpy(sTemp, widgGetString(psRequestScreen, id)); for(i=LOADENTRY_START;i<LOADENTRY_END;i++) { if( i != chosenSlotId) { if( ((W_BUTTON *)widgGetFromID(psRequestScreen,i))->pText && strcmp( sTemp, ((W_BUTTON *)widgGetFromID(psRequestScreen,i))->pText ) ==0) { widgDelete(psRequestScreen,SAVEENTRY_EDIT); //unselect this box, and go back .. widgReveal(psRequestScreen,chosenSlotId); // move mouse to same box.. // SetMousePos(widgGetFromID(psRequestScreen,i)->pos.x ,widgGetFromID(psRequestScreen,i)->pos.y); audio_PlayTrack(ID_SOUND_BUILD_FAIL); return true; } } } // return with this name, as we've edited it. if (strlen(widgGetString(psRequestScreen, id))) { sstrcpy(sTemp, widgGetString(psRequestScreen, id)); removeWildcards(sTemp); snprintf(sRequestResult, sizeof(sRequestResult), "%s%s.%s", sPath, sTemp, sExt); if (strlen(sDelete) != 0) { deleteSaveGame(sDelete); //only delete game if a new game fills the slot } } goto cleanup; } return false; // failed and/or cancelled.. cleanup: closeLoadSave(); bRequestLoad = false; if (bResetMissionWidgets && widgGetFromID(psWScreen,IDMISSIONRES_FORM) == NULL) { resetMissionWidgets(); //reset the mission widgets here if necessary } return true; // success on load. success: campaign = getCampaign(sRequestResult); setCampaignNumber(campaign); debug(LOG_WZ, "Set campaign for %s to %u", sRequestResult, campaign); closeLoadSave(); bRequestLoad = true; return true; }
// ///////////////// ///////////////////////////////////////////////// // Main Front end game loop. TITLECODE titleLoop(void) { TITLECODE RetCode = TITLECODE_CONTINUE; pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_ON); pie_SetFogStatus(false); screen_RestartBackDrop(); pie_ShowMouse(true); // When we first init the game, firstcall is true. if (firstcall) { firstcall = false; // First check to see if --host was given as a command line option, if not, // then check --join and if neither, run the normal game menu. if( hostlaunch ) { ingame.bHostSetup = true; bMultiPlayer = true; bMultiMessages = true; game.type = SKIRMISH; // needed? changeTitleMode(MULTIOPTION); hostlaunch = false; // reset the bool to default state. } else if(strlen(iptoconnect) ) { changeTitleMode(GAMEFIND); // a ip/hostname was found, so go directly to the GAMEFIND screen } else { changeTitleMode(TITLE); // normal game, run main title screen. } // Using software cursors (when on) for these menus due to a bug in SDL's SDL_ShowCursor() pie_SetMouse(CURSOR_DEFAULT, war_GetColouredCursor()); } if (titleMode != MULTIOPTION && titleMode != MULTILIMIT && titleMode != STARTGAME) screen_disableMapPreview(); switch(titleMode) // run relevant title screen code. { // MULTIPLAYER screens case PROTOCOL: runConnectionScreen(); // multiplayer connection screen. break; case MULTIOPTION: runMultiOptions(); break; case GAMEFIND: runGameFind(); break; case MULTI: runMultiPlayerMenu(); break; case MULTILIMIT: runLimitScreen(); break; case KEYMAP: runKeyMapEditor(); break; case TITLE: runTitleMenu(); break; case SINGLE: runSinglePlayerMenu(); break; case TUTORIAL: runTutorialMenu(); break; // case GRAPHICS: // runGraphicsOptionsMenu(); // break; case CREDITS: runCreditsScreen(); break; // case DEMOMODE: // runDemoMenu(); // break; // case VIDEO: // runVideoOptionsMenu(); // break; case OPTIONS: runOptionsMenu(); break; case GAME: runGameOptionsMenu(); break; case GRAPHICS_OPTIONS: runGraphicsOptionsMenu(); break; case AUDIO_OPTIONS: runAudioOptionsMenu(); break; case VIDEO_OPTIONS: runVideoOptionsMenu(); break; case MOUSE_OPTIONS: runMouseOptionsMenu(); break; case QUIT: RetCode = TITLECODE_QUITGAME; break; case STARTGAME: case LOADSAVEGAME: initLoadingScreen(true);//render active if (titleMode == LOADSAVEGAME) { RetCode = TITLECODE_SAVEGAMELOAD; } else { RetCode = TITLECODE_STARTGAME; } return RetCode; // don't flip! case SHOWINTRO: pie_SetFogStatus(false); pie_ScreenFlip(CLEAR_BLACK); changeTitleMode(TITLE); RetCode = TITLECODE_SHOWINTRO; break; default: debug( LOG_FATAL, "unknown title screen mode" ); abort(); } NETflush(); // Send any pending network data. audio_Update(); pie_DrawMouse(mouseX(), mouseY()); pie_SetFogStatus(false); pie_ScreenFlip(CLEAR_BLACK);//title loop if ((keyDown(KEY_LALT) || keyDown(KEY_RALT)) /* Check for toggling display mode */ && keyPressed(KEY_RETURN)) { screenToggleMode(); } return RetCode; }
/* Update and possibly display the tip */ void tipDisplay() { SDWORD newMX, newMY; SDWORD currTime; SDWORD fw, topGap; switch (tipState) { case TIP_WAIT: /* See if the tip has to be shown */ newMX = mouseX(); newMY = mouseY(); currTime = wzGetTicks(); if (newMX == mx && newMY == my && (currTime - startTime > TIP_PAUSE)) { /* Activate the tip */ tipState = TIP_ACTIVE; /* Calculate the size of the tip box */ topGap = TIP_VGAP; iV_SetFont(FontID); lineHeight = iV_GetTextLineSize(); fw = 0; for (int n = 0; n < pTip.size(); ++n) { fw = std::max<int>(fw, iV_GetTextWidth(pTip[n].toUtf8().constData())); } tw = fw + TIP_HGAP * 2; th = topGap * 2 + lineHeight * pTip.size() + iV_GetTextBelowBase(); /* Position the tip box */ tx = clip(wx + ww / 2, 0, screenWidth - tw - 1); ty = std::max(wy + wh + TIP_VGAP, 0); if (ty + th >= (int)screenHeight) { /* Position the tip above the button */ ty = wy - th - TIP_VGAP; } /* Position the text */ fx = tx + TIP_HGAP; fy = ty + (th - lineHeight * pTip.size()) / 2 - iV_GetTextAboveBase(); /* Note the time */ startTime = wzGetTicks(); } else if (newMX != mx || newMY != my || mousePressed(MOUSE_LMB)) { mx = newMX; my = newMY; startTime = currTime; } break; case TIP_ACTIVE: /* Draw the tool tip */ pie_BoxFill(tx, ty, tx + tw, ty + th, WZCOL_FORM_TIP_BACKGROUND); iV_Line(tx + 1, ty + th - 2, tx + 1, ty + 1, WZCOL_FORM_DARK); iV_Line(tx + 2, ty + 1, tx + tw - 2, ty + 1, WZCOL_FORM_DARK); iV_Line(tx, ty + th, tx + tw, ty + th, WZCOL_FORM_DARK); iV_Line(tx + tw, ty + th - 1, tx + tw, ty, WZCOL_FORM_DARK); iV_Box(tx, ty, tx + tw - 1, ty + th - 1, WZCOL_FORM_LIGHT); iV_SetFont(FontID); iV_SetTextColour(TipColour); for (int n = 0; n < pTip.size(); ++n) { iV_DrawText(pTip[n].toUtf8().constData(), fx, fy + lineHeight * n); } break; default: break; } }