public override void LoadTranslations() { IntRef fileCount = IntRef.Create(0); string[] fileList = platform.DirectoryGetFiles(platform.PathCombine("data", "localization"), fileCount); //Iterate over all files in the directory for (int i = 0; i < fileCount.value; i++) { IntRef lineCount = IntRef.Create(0); string[] lineList = platform.FileReadAllLines(fileList[i], lineCount); //Iterate over each line in these files for (int j = 1; j < lineCount.value; j++) { if (platform.StringEmpty(lineList[j])) { //Skip line if empty continue; } IntRef splitCount = IntRef.Create(0); string[] splitList = platform.StringSplit(lineList[j], "=", splitCount); if (splitCount.value >= 2) { Add(lineList[0], splitList[0], splitList[1]); } } } //Add english default strings if not defined. AddEnglish(); }
internal void DrawAmmo(Game game) { Packet_Item item = game.d_Inventory.RightHand[game.ActiveMaterial]; if (item != null && item.ItemClass == Packet_ItemClassEnum.Block) { if (game.blocktypes[item.BlockId].IsPistol) { int loaded = game.LoadedAmmo[item.BlockId]; int total = game.TotalAmmo[item.BlockId]; string s = game.platform.StringFormat2("{0}/{1}", game.platform.IntToString(loaded), game.platform.IntToString(total - loaded)); FontCi font = new FontCi(); font.family = "Arial"; font.size = 18; game.Draw2dText(s, font, game.Width() - game.TextSizeWidth(s, 18) - 50, game.Height() - game.TextSizeHeight(s, 18) - 50, loaded == 0 ? IntRef.Create(Game.ColorFromArgb(255, 255, 0, 0)) : IntRef.Create(Game.ColorFromArgb(255, 255, 255, 255)), false); if (loaded == 0) { font.size = 14; string pressR = "Press R to reload"; game.Draw2dText(pressR, font, game.Width() - game.TextSizeWidth(pressR, 14) - 50, game.Height() - game.TextSizeHeight(s, 14) - 80, IntRef.Create(Game.ColorFromArgb(255, 255, 0, 0)), false); } } } }
public override void OnNewFrameDraw2d(Game game_, float deltaTime) { game = game_; if (!loaded) { loaded = true; LoadOptions(); } if (game.escapeMenuRestart) { game.escapeMenuRestart = false; SetEscapeMenuState(EscapeMenuState.Main); } if (game.guistate != GuiState.EscapeMenu) { return; } SetEscapeMenuState(escapemenustate); EscapeMenuMouse1(); for (int i = 0; i < widgetsCount; i++) { Button w = widgets[i]; game.Draw2dText1(w.Text, w.x, w.y, w.fontsize, IntRef.Create(w.selected ? w.fontcolorselected : w.fontcolor), false); } }
public override void OnNewFrameDraw3d(Game game, float deltaTime) { float one = 1; for (int i = 0; i < game.entitiesCount; i++) { Entity entity = game.entities[i]; if (entity == null) { continue; } if (entity.sprite == null) { continue; } Sprite b = entity.sprite; game.GLMatrixModeModelView(); game.GLPushMatrix(); game.GLTranslate(b.positionX, b.positionY, b.positionZ); Billboard(game); game.GLScale((one * 2 / 100), (one * 2 / 100), (one * 2 / 100)); game.GLTranslate(0 - b.size / 2, 0 - b.size / 2, 0); //d_Draw2d.Draw2dTexture(night ? moontexture : suntexture, 0, 0, ImageSize, ImageSize, null, Color.White); IntRef n = null; if (b.animationcount > 0) { float progress = one - (entity.expires.timeLeft / entity.expires.totalTime); n = IntRef.Create(game.platform.FloatToInt(progress * (b.animationcount * b.animationcount - 1))); } game.Draw2dTexture(game.GetTexture(b.image), 0, 0, b.size, b.size, n, b.animationcount, Game.ColorFromArgb(255, 255, 255, 255), true); game.GLPopMatrix(); } }
void DrawItem(int screenposX, int screenposY, Packet_Item item, int drawsizeX, int drawsizeY) { if (item == null) { return; } int sizex = dataItems.ItemSizeX(item); int sizey = dataItems.ItemSizeY(item); if (drawsizeX == 0 || drawsizeX == -1) { drawsizeX = CellDrawSize * sizex; drawsizeY = CellDrawSize * sizey; } if (item.ItemClass == Packet_ItemClassEnum.Block) { if (item.BlockId == 0) { return; } game.Draw2dTexture(game.terrainTexture, screenposX, screenposY, drawsizeX, drawsizeY, IntRef.Create(dataItems.TextureIdForInventory()[item.BlockId]), game.texturesPacked(), Game.ColorFromArgb(255, 255, 255, 255), false); if (item.BlockCount > 1) { FontCi font = new FontCi(); font.size = 8; game.Draw2dText(game.platform.IntToString(item.BlockCount), font, screenposX, screenposY, null, false); } } else { game.Draw2dBitmapFile(dataItems.ItemGraphics(item), screenposX, screenposY, drawsizeX, drawsizeY); } }
internal void DrawCraftingRecipes(Game game) { currentRecipes = new int[1024]; currentRecipesCount = 0; for (int i = 0; i < craftingrecipes2Count; i++) { Packet_CraftingRecipe r = craftingrecipes2[i]; if (r == null) { continue; } bool next = false; //can apply recipe? for (int k = 0; k < r.IngredientsCount; k++) { Packet_Ingredient ingredient = r.Ingredients[k]; if (ingredient == null) { continue; } if (craftingblocksFindAllCount(craftingblocks, craftingblocksCount, ingredient.Type) < ingredient.Amount) { next = true; break; } } if (!next) { currentRecipes[currentRecipesCount++] = i; } } int menustartx = game.xcenter(600); int menustarty = game.ycenter(currentRecipesCount * 80); if (currentRecipesCount == 0) { game.Draw2dText1(game.language.NoMaterialsForCrafting(), game.xcenter(200), game.ycenter(20), 12, null, false); return; } for (int i = 0; i < currentRecipesCount; i++) { Packet_CraftingRecipe r = craftingrecipes2[currentRecipes[i]]; for (int ii = 0; ii < r.IngredientsCount; ii++) { int xx = menustartx + 20 + ii * 130; int yy = menustarty + i * 80; game.Draw2dTexture(game.d_TerrainTextures.terrainTexture(), xx, yy, 32, 32, IntRef.Create(game.TextureIdForInventory[r.Ingredients[ii].Type]), game.texturesPacked(), Game.ColorFromArgb(255, 255, 255, 255), false); game.Draw2dText1(game.platform.StringFormat2("{0} {1}", game.platform.IntToString(r.Ingredients[ii].Amount), game.blocktypes[r.Ingredients[ii].Type].Name), xx + 50, yy, 12, IntRef.Create(i == craftingselectedrecipe ? Game.ColorFromArgb(255, 255, 0, 0) : Game.ColorFromArgb(255, 255, 255, 255)), false); } { int xx = menustartx + 20 + 400; int yy = menustarty + i * 80; game.Draw2dTexture(game.d_TerrainTextures.terrainTexture(), xx, yy, 32, 32, IntRef.Create(game.TextureIdForInventory[r.Output.Type]), game.texturesPacked(), Game.ColorFromArgb(255, 255, 255, 255), false); game.Draw2dText1(game.platform.StringFormat2("{0} {1}", game.platform.IntToString(r.Output.Amount), game.blocktypes[r.Output.Type].Name), xx + 50, yy, 12, IntRef.Create(i == craftingselectedrecipe ? Game.ColorFromArgb(255, 255, 0, 0) : Game.ColorFromArgb(255, 255, 255, 255)), false); } } }
IntRef SelectedMaterialSelectorSlot(PointRef scaledMouse) { if (scaledMouse.X >= MaterialSelectorStartX() && scaledMouse.Y >= MaterialSelectorStartY() && scaledMouse.X < MaterialSelectorStartX() + 10 * ActiveMaterialCellSize() && scaledMouse.Y < MaterialSelectorStartY() + 10 * ActiveMaterialCellSize()) { return(IntRef.Create((scaledMouse.X - MaterialSelectorStartX()) / ActiveMaterialCellSize())); } return(null); }
IntRef SelectedWearPlace(PointRef scaledMouse) { for (int i = 0; i < wearPlaceStartLength; i++) { PointRef p = wearPlaceStart[i]; p.X += InventoryStartX(); p.Y += InventoryStartY(); PointRef cells = wearPlaceCells[i]; if (scaledMouse.X >= p.X && scaledMouse.Y >= p.Y && scaledMouse.X < p.X + cells.X * CellDrawSize && scaledMouse.Y < p.Y + cells.Y * CellDrawSize) { return(IntRef.Create(i)); } } return(null); }
internal IntRef FreeHand(int ActiveMaterial_) { IntRef freehand = null; if (d_Inventory.RightHand[ActiveMaterial_] == null) { return(IntRef.Create(ActiveMaterial_)); } for (int i = 0; i < 10; i++) { if (d_Inventory.RightHand[i] == null) { return(freehand); } } return(null); }
public override void OnNewFrameDraw3d(Game game, float deltaTime) { for (int i = 0; i < game.entitiesCount; i++) { Entity e = game.entities[i]; if (e == null) { continue; } if (e.drawName == null) { continue; } if (i == game.LocalPlayerId) { continue; } if (e.networkPosition != null && (!e.networkPosition.PositionLoaded)) { continue; } int kKey = i; DrawName p = game.entities[i].drawName; if (p.OnlyWhenSelected) { continue; } float posX = p.TextX + e.position.x; float posY = p.TextY + e.position.y + e.drawModel.ModelHeight + game.one * 7 / 10; float posZ = p.TextZ + e.position.z; //TODO: if picking if ((game.Dist(game.player.position.x, game.player.position.y, game.player.position.z, posX, posY, posZ) < 20) || game.keyboardState[Game.KeyAltLeft] || game.keyboardState[Game.KeyAltRight]) { string name = p.Name; { float shadow = (game.one * game.GetLight(game.platform.FloatToInt(posX), game.platform.FloatToInt(posZ), game.platform.FloatToInt(posY))) / Game.maxlight; //do not interpolate player position if player is controlled by game world //if (EnablePlayerUpdatePositionContainsKey(kKey) && !EnablePlayerUpdatePosition(kKey)) //{ // posX = p.NetworkX; // posY = p.NetworkY; // posZ = p.NetworkZ; //} game.GLPushMatrix(); game.GLTranslate(posX, posY, posZ); //if (p.Type == PlayerType.Monster) //{ // GLTranslate(0, 1, 0); //} ModDrawSprites.Billboard(game); float scale = game.one * 2 / 100; game.GLScale(scale, scale, scale); //Color c = Color.FromArgb((int)(shadow * 255), (int)(shadow * 255), (int)(shadow * 255)); //TODO: Can't change text color because text has outline anyway. if (p.DrawHealth) { game.Draw2dTexture(game.WhiteTexture(), -26, -11, 52, 12, null, 0, Game.ColorFromArgb(255, 0, 0, 0), false); game.Draw2dTexture(game.WhiteTexture(), -25, -10, 50 * (game.one * p.Health), 10, null, 0, Game.ColorFromArgb(255, 255, 0, 0), false); } FontCi font = new FontCi(); font.size = 14; game.Draw2dText(name, font, -game.TextSizeWidth(name, font) / 2, 0, IntRef.Create(Game.ColorFromArgb(255, 255, 255, 255)), true); // GL.Translate(0, 1, 0); game.GLPopMatrix(); } } } }
public override void OnNewFrameDraw3d(Game game, float deltaTime) { for (int i = 0; i < game.entitiesCount; i++) { Entity e = game.entities[i]; if (e == null) { continue; } if (e.drawText == null) { continue; } if (e.networkPosition != null && (!e.networkPosition.PositionLoaded)) { continue; } int kKey = i; EntityDrawText p = game.entities[i].drawText; float posX = -game.platform.MathSin(e.position.roty) * p.dx + e.position.x; float posY = p.dy + e.position.y; float posZ = game.platform.MathCos(e.position.roty) * p.dz + e.position.z; //TODO: if picking if ((game.Dist(game.player.position.x, game.player.position.y, game.player.position.z, posX, posY, posZ) < 20) || game.keyboardState[Game.KeyAltLeft] || game.keyboardState[Game.KeyAltRight]) { string text = p.text; { float shadow = (game.one * game.GetLight(game.platform.FloatToInt(posX), game.platform.FloatToInt(posZ), game.platform.FloatToInt(posY))) / Game.maxlight; game.GLPushMatrix(); game.GLTranslate(posX, posY, posZ); game.GLRotate(180, 1, 0, 0); game.GLRotate(e.position.roty * 360 / (2 * Game.GetPi()), 0, 1, 0); float scale = game.one * 5 / 1000; game.GLScale(scale, scale, scale); FontCi font = new FontCi(); font.size = 14; game.Draw2dText(text, font, -game.TextSizeWidth(text, font) / 2, 0, IntRef.Create(Game.ColorFromArgb(255, 255, 255, 255)), true); game.GLPopMatrix(); } } } }
internal void CraftingMouse(Game game) { if (currentRecipes == null) { return; } int menustartx = game.xcenter(600); int menustarty = game.ycenter(currentRecipesCount * 80); if (game.mouseCurrentY >= menustarty && game.mouseCurrentY < menustarty + currentRecipesCount * 80) { craftingselectedrecipe = (game.mouseCurrentY - menustarty) / 80; } else { //craftingselectedrecipe = -1; } if (game.mouseleftclick) { if (currentRecipesCount != 0) { CraftingRecipeSelected(game, craftingTableposx, craftingTableposy, craftingTableposz, IntRef.Create(currentRecipes[craftingselectedrecipe])); } game.mouseleftclick = false; game.GuiStateBackToGame(); } }