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 {
val buffer = new TextBuffer(40, 24)
def resolution = buffer.size
def resolution_=(value: (Int, Int)) = {
buffer.size = value
owner.updateGui(buffer.toString)

View File

@ -3,6 +3,8 @@ package li.cil.oc.common.block
import cpw.mods.fml.common.registry.GameRegistry
import li.cil.oc.Config
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 net.minecraft.block.Block
import net.minecraft.block.material.Material
@ -13,8 +15,6 @@ import net.minecraft.util.MathHelper
import net.minecraft.world.IBlockAccess
import net.minecraft.world.World
import net.minecraftforge.common.ForgeDirection
import li.cil.oc.common.CommonProxy
import li.cil.oc.OpenComputers
class BlockComputer extends Block(Config.blockComputerId, Material.iron) {
// ----------------------------------------------------------------------- //
@ -79,7 +79,7 @@ class BlockComputer extends Block(Config.blockComputerId, Material.iron) {
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)
player.openGui(OpenComputers, GuiType.Computer.id, world, x, y, z)
true
}
}

View File

@ -3,12 +3,13 @@ package li.cil.oc.common.block
import cpw.mods.fml.common.registry.GameRegistry
import li.cil.oc.Config
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 net.minecraft.block.Block
import net.minecraft.block.material.Material
import net.minecraft.world.World
import net.minecraft.entity.player.EntityPlayer
import li.cil.oc.OpenComputers
import net.minecraft.world.World
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 createTileEntity(world: World, metadata: Int) = new TileEntityScreen(world.isRemote)
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer,
side: Int, hitX: Float, hitY: Float, hitZ: Float) = {
// if (player.isSneaking())
// if (canWrench(player, x, y, z))
// 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
// }
player.openGui(OpenComputers, GuiType.Screen.id, world, x, y, z)
true
}
}

View File

@ -3,9 +3,9 @@ package li.cil.oc.common.components
import li.cil.oc.server.components.IComponent
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

View File

@ -6,7 +6,6 @@ import net.minecraft.inventory.Slot
import net.minecraft.item.ItemStack
class ContainerComputer(playerInventory: InventoryPlayer, computer: TileEntityComputer) extends GenericInventoryContainer(playerInventory, computer) {
// Show the computer's inventory.
// TODO nicer layout, separate for types, based on background image once it exists
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.tileentity.TileEntityComputer
import net.minecraft.client.gui.GuiButton
import net.minecraft.client.gui.GuiTextField
import net.minecraft.client.gui.inventory.GuiContainer
import net.minecraft.entity.player.InventoryPlayer
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)) {
val button = new GuiButton(1, 5, 4, "test")
System.out.println("new Gui")
override def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) = {
//draw text and stuff here
//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) = {
//draw your Gui here, only thing you need to change is the path
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.renderEngine.func_110577_a(new ResourceLocation(""));
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) = {
super.drawScreen(mouseX, mouseY, dt);
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 li.cil.oc.common.container.ContainerComputer
import li.cil.oc.common.tileentity.TileEntityComputer
import li.cil.oc.common.tileentity.TileEntityScreen
import net.minecraft.entity.player.EntityPlayer
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 {
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) =
world.getBlockTileEntity(x, y, z) match {
case tileEntity: TileEntityComputer =>
case tileEntity: TileEntityComputer if id == GuiType.Computer.id =>
new GuiComputer(player.inventory, tileEntity)
case tileEntity:TileEntityScreen =>
new ScreenGui(tileEntity)
case tileEntity: TileEntityScreen if id == GuiType.Screen.id =>
new GuiScreen(tileEntity)
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 li.cil.oc.client.components.{ Screen => ClientScreen }
import li.cil.oc.common.gui.GuiScreen
import li.cil.oc.server.components.{ Screen => ServerScreen }
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 {
def this() = this(false)
@ -14,18 +13,9 @@ class TileEntityScreen(isClient: Boolean) extends TileEntity {
if (isClient) new ClientScreen(this)
else new ServerScreen(this)
@SideOnly(Side.CLIENT)
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())
}
}
var gui: Option[GuiScreen] = None
private var _gui:ScreenGui = null
def gui = _gui
def gui_=(value:ScreenGui):Unit = _gui = value
def text = component.toString()
@SideOnly(Side.CLIENT)
def updateGui(value: () => String): Unit =
gui.foreach(_.textField.setText(value()))
}

View File

@ -14,7 +14,7 @@ class TextBuffer(var width: Int, var height: Int) {
def size_=(value: (Int, Int)): Unit = {
val (w, h) = value
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)
}
buffer = nbuffer

View File

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

View File

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