/****************************************************************************** LoopOnEvents - Process all the X events we get ******************************************************************************/ void LoopOnEvents() { int num; char buffer[10]; XEvent Event; Window dummyroot,dummychild; int x,x1,y,y1; unsigned int dummy1; if (Transient && !Checked) { XQueryPointer(dpy,win,&dummyroot,&dummychild,&x1,&y1,&x,&y,&dummy1); num=WhichButton(&buttons,x,y); if (num!=-1) { Pressed=1; ButPressed=num; SwitchButton(&buttons,num); } else Pressed=0; Checked=1; } while(XPending(dpy)) { XNextEvent(dpy,&Event); switch(Event.type) { case ButtonRelease: if (Pressed) { num=WhichButton(&buttons,Event.xbutton.x,Event.xbutton.y); if (num!=-1) { SendFvwmPipe(ClickAction[(Transient) ? 0:Event.xbutton.button-1], ItemID(&windows,num)); SwitchButton(&buttons,num); } } if (Transient) ShutMeDown(0); Pressed=0; ButPressed=-1; break; case ButtonPress: num=WhichButton(&buttons,Event.xbutton.x,Event.xbutton.y); if (num != -1) { SwitchButton(&buttons,num); ButPressed=num; } else ButPressed=-1; Pressed=1; break; case Expose: if (Event.xexpose.count==0) RedrawWindow(1); break; case KeyPress: num=XLookupString(&Event.xkey,buffer,10,NULL,0); if (num==1) { if (buffer[0]=='q' || buffer[0]=='Q') ShutMeDown(0); else if (buffer[0]=='i' || buffer[0]=='I') PrintList(&windows); else if (buffer[0]=='b' || buffer[0]=='B') PrintButtons(&buttons); } break; case ClientMessage: if ((Event.xclient.format==32) && (Event.xclient.data.l[0]==wm_del_win)) ShutMeDown(0); case EnterNotify: if (!SomeButtonDown(Event.xcrossing.state)) break; num=WhichButton(&buttons,Event.xcrossing.x,Event.xcrossing.y); if (num!=-1) { SwitchButton(&buttons,num); ButPressed=num; } else ButPressed=-1; Pressed=1; break; case LeaveNotify: if (!SomeButtonDown(Event.xcrossing.state)) break; if (ButPressed!=-1) SwitchButton(&buttons,ButPressed); Pressed=0; break; case MotionNotify: if (!Pressed) break; num=WhichButton(&buttons,Event.xmotion.x,Event.xmotion.y); if (num==ButPressed) break; if (ButPressed!=-1) SwitchButton(&buttons,ButPressed); if (num!=-1) { SwitchButton(&buttons,num); ButPressed=num; } else ButPressed=-1; break; } } }
/* ---------------------------------------------------------------------- * Author: Julian * Date: 27 January 2014 * Description: Handles the commands * ---------------------------------------------------------------------- */ void Console::newCommand(std::string command, std::string values) { std::transform(command.begin(), command.end(), command.begin(), ::tolower); std::vector<std::string> valueList; getValues(valueList, values, command); //========================================================================================================================== if(command == "clear_console" || // clear_console command == "clean_console") // clean_console clearAll(); //========================================================================================================================== else if(command == "exit") // exit context.renderWindow->close(); //========================================================================================================================== else if(command == "player_set_position") // player_set_position x:y { if(valueList.size() == 2) { const float xPos = stof(valueList[0]); const float yPos = stof(valueList[1]); context.player->setPosition(xPos, yPos); logInfo("Changed Player position to " + valueList[0] + " : " + valueList[1]); } else logError("Syntax is: player_set_position x:y"); } //========================================================================================================================== else if(command == "player_set_speed") // player_set_animation value { if(valueList.size() == 1) { context.player->setDefaultSpeed(stoi(valueList[0])); logInfo("Changed Player velocity to: " + valueList[0]); } else logError("Syntax is: player_set_speed value"); } //========================================================================================================================== else if(command == "player_play_animation") // player_play_animation value { if(valueList.size() == 1 && stoi(valueList[0]) <= TOTAL_ANIMATIONS) context.player->playAnimationOnce(stoi(valueList[0])); else if(valueList.size() == 1 && stoi(valueList[0]) == TOTAL_ANIMATIONS) logError("Your value is too large."); else logError("Syntax is: player_set_animation value"); } //========================================================================================================================== else if(command == "player_set_health") // player_set_health value { if(valueList.size() == 1) context.player->setHealth(stoi(valueList[0])); else logError("Syntax is: player_set_health value"); } //========================================================================================================================== else if(command == "show_collision") // show_collision value { if(valueList.size() == 1) context.player->showCollision(stoi(valueList[0]) !=0); // The !=0 is there in order to prevent a warning, ignore it else logError("Syntax is: show_collision value (1 or 0)"); } //========================================================================================================================== else if(command == "player_set_mana") // player_set_mana value { if(valueList.size() == 1) context.player->setMana(stoi(valueList[0])); else logError("Syntax is: player_set_mana value"); } //========================================================================================================================== else if(command == "player_get_position") // player_get_position { std::stringstream s, s2; s << context.player->getPosition().x / TILE_SIZE; s2 << (context.player->getPosition().y - TILE_SIZE/2) / TILE_SIZE; logInfo("You are at " + s.str() + ":" + s2.str()); } //========================================================================================================================== else if(command == "GFX_add" || command == "gfx_add") // GFX_add { if(valueList.size() == 1) { if(valueList[0] == "fade") context.effectManager->add(Effect(EffectType::FADE)); } else logError("Syntax is: GFX_add value (fade for example)"); } //========================================================================================================================== else if(command == "time_set") // time_set { if(valueList.size() == 3) { context.globalTime->setTime(std::stoi(valueList[0]), std::stoi(valueList[1]), std::stof(valueList[2])); std::stringstream stream; stream<<"Current time: "<<context.globalTime->getHours()<<":"<<context.globalTime->getMinutes()<<":"<<int(context.globalTime->getSeconds()); logInfo(stream.str()); } else logError("Syntax is: time_set hours:minutes:seconds"); } //========================================================================================================================== else if(command == "print") // print { if(valueList.size() == 1) logInfo(valueList[0]); else logError("Syntax is: print message"); } //========================================================================================================================== else if(command == "print_time") // print_time { if(valueList.size() == 0) { std::stringstream stream; stream<<"Current time: "<<context.globalTime->getHours()<<":"<<context.globalTime->getMinutes()<<":"<<int(context.globalTime->getSeconds()); logInfo(stream.str()); } else logError("Syntax is: print_time"); } //========================================================================================================================== else if(command == "help") // help { log(" clean_console\tclear_console\texit\tGFX_add <string>", {230, 200, 120}); log(" gfx_add <string>\titem_add <int>\titem_add <int:int>\tmap_load <string>", {230, 200, 120}); log(" map_reload\tplayer_get_position\tplayer_play_animation <int>", {230, 200, 120}); log(" player_set_health <int>\tplayer_set_mana <int>\tplayer_set_position <float:float>", {230, 200, 120}); log(" player_set_speed <int>\tplayer_set_sprite <string>\tprint <string>\tprint_time", {230, 200, 120}); log(" show_collision <int>\ttime_set <int:int:int>\ttoggle_gui", {230, 200, 120}); } //========================================================================================================================== else if (command == "toggle_gui") // toggle_gui { if (valueList.size() == 0) { context.player->setProperty("hideGUI", !context.player->getProperty("hideGUI")); } else logError("Syntax is: toggle_gui"); } //========================================================================================================================== else if(command == "map_load") // map_load name { if(valueList.size() == 1) { const std::string mapName = valueList[0] + ".tmx"; context.gameMap->loadMap(mapName); } else logError("Syntax is: map_load name"); } //========================================================================================================================== else if(command == "map_reload") // map_reload { if(valueList.size() == 0) { context.gameMap->reload(); logInfo("Updated the map with the latest changes."); } else logError("Syntax is: map_reload"); } //========================================================================================================================== else if(command == "player_set_sprite") // player_set_sprite { if(valueList.size() == 1) context.player->changeSprite(valueList[0]); else logError("Syntax is: player_set_sprite name"); } //========================================================================================================================== else if(command == "item_add") // item_add ID { if(valueList.size() == 2) context.player->getInventory().addItem(ItemID(stoi(valueList[0])), stoi(valueList[1])); else if(valueList.size() == 1) context.player->getInventory().addItem(ItemID(stoi(valueList[0]))); else logError("Syntax is: item_add ID AMMOUNT (amount is optional)"); } //========================================================================================================================== // No command is correct else logError("Unknown command."); }