cleanup and some fixes

This commit is contained in:
Florian Nücke 2013-09-14 17:17:32 +02:00
parent 75d8a52354
commit ae5a793a6b
13 changed files with 64 additions and 76 deletions

View File

@ -6,8 +6,9 @@ import li.cil.oc.common.util.TextBuffer
class Screen(owner: TileEntityScreen) extends IScreen { class Screen(owner: TileEntityScreen) extends IScreen {
val buffer = new TextBuffer(40, 24) val buffer = new TextBuffer(40, 24)
def resolution = buffer.size def resolution = buffer.size
def resolution_=(value: (Int, Int)) = { def resolution_=(value: (Int, Int)) = {
buffer.size = value buffer.size = value
owner.updateGui(buffer.toString) owner.updateGui(buffer.toString)

View File

@ -3,6 +3,8 @@ package li.cil.oc.common.block
import cpw.mods.fml.common.registry.GameRegistry import cpw.mods.fml.common.registry.GameRegistry
import li.cil.oc.Config import li.cil.oc.Config
import li.cil.oc.CreativeTab import li.cil.oc.CreativeTab
import li.cil.oc.OpenComputers
import li.cil.oc.common.gui.GuiType
import li.cil.oc.common.tileentity.TileEntityComputer import li.cil.oc.common.tileentity.TileEntityComputer
import net.minecraft.block.Block import net.minecraft.block.Block
import net.minecraft.block.material.Material import net.minecraft.block.material.Material
@ -13,8 +15,6 @@ import net.minecraft.util.MathHelper
import net.minecraft.world.IBlockAccess import net.minecraft.world.IBlockAccess
import net.minecraft.world.World import net.minecraft.world.World
import net.minecraftforge.common.ForgeDirection import net.minecraftforge.common.ForgeDirection
import li.cil.oc.common.CommonProxy
import li.cil.oc.OpenComputers
class BlockComputer extends Block(Config.blockComputerId, Material.iron) { class BlockComputer extends Block(Config.blockComputerId, Material.iron) {
// ----------------------------------------------------------------------- // // ----------------------------------------------------------------------- //
@ -79,7 +79,7 @@ class BlockComputer extends Block(Config.blockComputerId, Material.iron) {
else { else {
// Start the computer if it isn't already running and open the GUI. // Start the computer if it isn't already running and open the GUI.
world.getBlockTileEntity(x, y, z).asInstanceOf[TileEntityComputer].turnOn() world.getBlockTileEntity(x, y, z).asInstanceOf[TileEntityComputer].turnOn()
player.openGui(OpenComputers, 0, world, x, y, z) player.openGui(OpenComputers, GuiType.Computer.id, world, x, y, z)
true true
} }
} }

View File

@ -3,12 +3,13 @@ package li.cil.oc.common.block
import cpw.mods.fml.common.registry.GameRegistry import cpw.mods.fml.common.registry.GameRegistry
import li.cil.oc.Config import li.cil.oc.Config
import li.cil.oc.CreativeTab import li.cil.oc.CreativeTab
import li.cil.oc.OpenComputers
import li.cil.oc.common.gui.GuiType
import li.cil.oc.common.tileentity.TileEntityScreen import li.cil.oc.common.tileentity.TileEntityScreen
import net.minecraft.block.Block import net.minecraft.block.Block
import net.minecraft.block.material.Material import net.minecraft.block.material.Material
import net.minecraft.world.World
import net.minecraft.entity.player.EntityPlayer import net.minecraft.entity.player.EntityPlayer
import li.cil.oc.OpenComputers import net.minecraft.world.World
class BlockScreen extends Block(Config.blockScreenId, Material.iron) { class BlockScreen extends Block(Config.blockScreenId, Material.iron) {
// ----------------------------------------------------------------------- // // ----------------------------------------------------------------------- //
@ -28,19 +29,10 @@ class BlockScreen extends Block(Config.blockScreenId, Material.iron) {
override def hasTileEntity(metadata: Int) = true override def hasTileEntity(metadata: Int) = true
override def createTileEntity(world: World, metadata: Int) = new TileEntityScreen(world.isRemote) override def createTileEntity(world: World, metadata: Int) = new TileEntityScreen(world.isRemote)
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer,
side: Int, hitX: Float, hitY: Float, hitZ: Float) = { side: Int, hitX: Float, hitY: Float, hitZ: Float) = {
// if (player.isSneaking()) player.openGui(OpenComputers, GuiType.Screen.id, world, x, y, z)
// if (canWrench(player, x, y, z)) true
// setRotation(world, x, y, z, rotation(world, x, y, z) + 1)
// else
// false
// else {
// Start the computer if it isn't already running and open the GUI.
// world.getBlockTileEntity(x, y, z).asInstanceOf[TileEntityComputer].turnOn()
player.openGui(OpenComputers, 0, world, x, y, z)
true
// }
} }
} }

View File

@ -3,9 +3,9 @@ package li.cil.oc.common.components
import li.cil.oc.server.components.IComponent import li.cil.oc.server.components.IComponent
trait IScreen { trait IScreen {
def resolution_=(value: (Int, Int)): Unit def resolution: (Int, Int)
def resolution:(Int,Int) // Required for setter. def resolution_=(value: (Int, Int)): Unit
def set(col: Int, row: Int, s: String): Unit def set(col: Int, row: Int, s: String): Unit

View File

@ -6,7 +6,6 @@ import net.minecraft.inventory.Slot
import net.minecraft.item.ItemStack import net.minecraft.item.ItemStack
class ContainerComputer(playerInventory: InventoryPlayer, computer: TileEntityComputer) extends GenericInventoryContainer(playerInventory, computer) { class ContainerComputer(playerInventory: InventoryPlayer, computer: TileEntityComputer) extends GenericInventoryContainer(playerInventory, computer) {
// Show the computer's inventory. // Show the computer's inventory.
// TODO nicer layout, separate for types, based on background image once it exists // TODO nicer layout, separate for types, based on background image once it exists
for (slotY <- 0 until 3) { for (slotY <- 0 until 3) {

View File

@ -5,7 +5,6 @@ import org.lwjgl.opengl.GL11
import li.cil.oc.common.container.ContainerComputer import li.cil.oc.common.container.ContainerComputer
import li.cil.oc.common.tileentity.TileEntityComputer import li.cil.oc.common.tileentity.TileEntityComputer
import net.minecraft.client.gui.GuiButton import net.minecraft.client.gui.GuiButton
import net.minecraft.client.gui.GuiTextField
import net.minecraft.client.gui.inventory.GuiContainer import net.minecraft.client.gui.inventory.GuiContainer
import net.minecraft.entity.player.InventoryPlayer import net.minecraft.entity.player.InventoryPlayer
import net.minecraft.util.ResourceLocation import net.minecraft.util.ResourceLocation
@ -13,7 +12,7 @@ import net.minecraft.util.StatCollector
class GuiComputer(inventory: InventoryPlayer, val tileEntity: TileEntityComputer) extends GuiContainer(new ContainerComputer(inventory, tileEntity)) { class GuiComputer(inventory: InventoryPlayer, val tileEntity: TileEntityComputer) extends GuiContainer(new ContainerComputer(inventory, tileEntity)) {
val button = new GuiButton(1, 5, 4, "test") val button = new GuiButton(1, 5, 4, "test")
System.out.println("new Gui")
override def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) = { override def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) = {
//draw text and stuff here //draw text and stuff here
//the parameters for drawString are: string, x, y, color //the parameters for drawString are: string, x, y, color
@ -23,7 +22,6 @@ class GuiComputer(inventory: InventoryPlayer, val tileEntity: TileEntityComputer
} }
override def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) = { override def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) = {
//draw your Gui here, only thing you need to change is the path
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.renderEngine.func_110577_a(new ResourceLocation("")); this.mc.renderEngine.func_110577_a(new ResourceLocation(""));
val x = (width - xSize) / 2 val x = (width - xSize) / 2
@ -33,8 +31,8 @@ class GuiComputer(inventory: InventoryPlayer, val tileEntity: TileEntityComputer
override def drawScreen(mouseX: Int, mouseY: Int, dt: Float) = { override def drawScreen(mouseX: Int, mouseY: Int, dt: Float) = {
super.drawScreen(mouseX, mouseY, dt); super.drawScreen(mouseX, mouseY, dt);
button.drawButton(this.mc, mouseX, mouseY) button.drawButton(this.mc, mouseX, mouseY)
} }
override def doesGuiPauseGame = false
} }

View File

@ -3,9 +3,14 @@ package li.cil.oc.common.gui
import cpw.mods.fml.common.network.IGuiHandler import cpw.mods.fml.common.network.IGuiHandler
import li.cil.oc.common.container.ContainerComputer import li.cil.oc.common.container.ContainerComputer
import li.cil.oc.common.tileentity.TileEntityComputer import li.cil.oc.common.tileentity.TileEntityComputer
import li.cil.oc.common.tileentity.TileEntityScreen
import net.minecraft.entity.player.EntityPlayer import net.minecraft.entity.player.EntityPlayer
import net.minecraft.world.World import net.minecraft.world.World
import li.cil.oc.common.tileentity.TileEntityScreen
object GuiType extends Enumeration {
val Computer = Value("Computer")
val Screen = Value("Screen")
}
class GuiHandler extends IGuiHandler { class GuiHandler extends IGuiHandler {
override def getServerGuiElement(id: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int) = override def getServerGuiElement(id: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int) =
@ -17,10 +22,10 @@ class GuiHandler extends IGuiHandler {
override def getClientGuiElement(id: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int) = override def getClientGuiElement(id: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int) =
world.getBlockTileEntity(x, y, z) match { world.getBlockTileEntity(x, y, z) match {
case tileEntity: TileEntityComputer => case tileEntity: TileEntityComputer if id == GuiType.Computer.id =>
new GuiComputer(player.inventory, tileEntity) new GuiComputer(player.inventory, tileEntity)
case tileEntity:TileEntityScreen => case tileEntity: TileEntityScreen if id == GuiType.Screen.id =>
new ScreenGui(tileEntity) new GuiScreen(tileEntity)
case _ => null case _ => null
} }
} }

View File

@ -0,0 +1,26 @@
package li.cil.oc.common.gui
import li.cil.oc.common.tileentity.TileEntityScreen
class GuiScreen(val tileEntity: TileEntityScreen) extends net.minecraft.client.gui.GuiScreen {
tileEntity.gui = Some(this)
var textField: GuiMultilineTextField = null
override def initGui() = {
super.initGui()
val (w, h) = tileEntity.component.resolution
val (pixelWidth, pixelHeight) = (w * 5, h * 8)
val x = (width - pixelWidth) / 2
val y = (height - pixelHeight) / 2
textField = new GuiMultilineTextField(
this.fontRenderer, x, y, pixelWidth, pixelHeight)
textField.setText(tileEntity.component.toString)
}
override def drawScreen(mouseX: Int, mouseY: Int, dt: Float) = {
super.drawScreen(mouseX, mouseY, dt);
textField.drawTextBox()
}
override def doesGuiPauseGame = false
}

View File

@ -1,29 +0,0 @@
package li.cil.oc.common.gui
import net.minecraft.client.gui.GuiScreen
import li.cil.oc.common.tileentity.TileEntityScreen
class ScreenGui(val tileEntity: TileEntityScreen) extends GuiScreen {
tileEntity.gui_=(this)
var textField: GuiMultilineTextField = null
override def initGui() = {
super.initGui()
var(w,h) = tileEntity.component.resolution
println(" widht: "+w)
println("heigth:" +h)
w *=2
h *=2
var x = (width - w)/2
var y = (height -h)/2
textField = new GuiMultilineTextField(this.fontRenderer, x, y, w, h)
textField.setText(tileEntity.text)
}
override def drawScreen(mouseX: Int, mouseY: Int, dt: Float) = {
super.drawScreen(mouseX, mouseY, dt);
textField.drawTextBox()
}
}

View File

@ -2,10 +2,9 @@ package li.cil.oc.common.tileentity
import cpw.mods.fml.relauncher._ import cpw.mods.fml.relauncher._
import li.cil.oc.client.components.{ Screen => ClientScreen } import li.cil.oc.client.components.{ Screen => ClientScreen }
import li.cil.oc.common.gui.GuiScreen
import li.cil.oc.server.components.{ Screen => ServerScreen } import li.cil.oc.server.components.{ Screen => ServerScreen }
import net.minecraft.tileentity.TileEntity import net.minecraft.tileentity.TileEntity
import li.cil.oc.common.gui.ScreenGui
import li.cil.oc.common.gui.ScreenGui
class TileEntityScreen(isClient: Boolean) extends TileEntity { class TileEntityScreen(isClient: Boolean) extends TileEntity {
def this() = this(false) def this() = this(false)
@ -14,18 +13,9 @@ class TileEntityScreen(isClient: Boolean) extends TileEntity {
if (isClient) new ClientScreen(this) if (isClient) new ClientScreen(this)
else new ServerScreen(this) else new ServerScreen(this)
@SideOnly(Side.CLIENT) var gui: Option[GuiScreen] = None
def updateGui(value: () => String): Unit = {
// TODO if GUI is open, call value() to get the new display string and show it
println("CLIENT SCREEN: " + value())
if(_gui != null){
_gui.textField.setText(value())
}
}
private var _gui:ScreenGui = null @SideOnly(Side.CLIENT)
def gui = _gui def updateGui(value: () => String): Unit =
def gui_=(value:ScreenGui):Unit = _gui = value gui.foreach(_.textField.setText(value()))
def text = component.toString()
} }

View File

@ -14,7 +14,7 @@ class TextBuffer(var width: Int, var height: Int) {
def size_=(value: (Int, Int)): Unit = { def size_=(value: (Int, Int)): Unit = {
val (w, h) = value val (w, h) = value
val nbuffer = Array.fill(h, w)(' ') val nbuffer = Array.fill(h, w)(' ')
(0 to (h min height)) foreach { (0 until (h min height)) foreach {
y => Array.copy(buffer(y), 0, nbuffer(y), 0, w min width) y => Array.copy(buffer(y), 0, nbuffer(y), 0, w min width)
} }
buffer = nbuffer buffer = nbuffer

View File

@ -58,6 +58,10 @@ class GraphicsCard(val nbt: NBTTagCompound) extends IComponent {
def bind(value: Option[Screen]): Unit = { def bind(value: Option[Screen]): Unit = {
screen = value screen = value
screen.foreach(screen => {
screen.resolution = resolution
fill(0, 0, buffer.width, buffer.height, ' ')
})
writeToNBT() writeToNBT()
} }

View File

@ -7,11 +7,13 @@ import li.cil.oc.server.PacketSender
class Screen(val owner: TileEntityScreen) extends IScreen with IComponent { class Screen(val owner: TileEntityScreen) extends IScreen with IComponent {
id = 2 id = 2
def resolution = throw new NotImplementedError
def resolution_=(value: (Int, Int)) = { def resolution_=(value: (Int, Int)) = {
val (w, h) = value val (w, h) = value
PacketSender.sendScreenResolutionChange(owner, w, h) PacketSender.sendScreenResolutionChange(owner, w, h)
} }
def resolution = throw new NotImplementedError
def set(col: Int, row: Int, s: String) = def set(col: Int, row: Int, s: String) =
PacketSender.sendScreenSet(owner, col, row, s) PacketSender.sendScreenSet(owner, col, row, s)