Jump to content

L B

Members
  • Posts

    967
  • Joined

  • Last visited

Posts posted by L B

  1. Here you go with a simple implementation of my OOP drawing system. It's a simple button class that can be used in any way you like. Call "Button.Update()" right before "Graphics.Flip()". Feel free to make a list that updates all of them, I'm simply sharing this class. Couldn't make it part of any other release, really.

     

    	public enum ButtonState
    {
    	Idle,
    	Hover,
    	Clicked,
    	Down
    }
    
    public class Button
    {
    	public Texture IdleTexture { get; set; }
    	public Texture HoverTexture { get; set; }
    	public Texture ClickedTexture { get; set; }
    	public Texture DownTexture { get; set; }
    
    	public ButtonState State { get; private set; }
    	public Image Image { get; private set; }
    
    	public Button(Image image)
    	{
    		this.State = ButtonState.Idle;
    
    		this.Image = image;
    
    		this.IdleTexture = this.Image.Texture;
    		this.ClickedTexture = this.Image.Texture;
    		this.HoverTexture = this.Image.Texture;
    		this.DownTexture = this.Image.Texture;
    	}
    
    	public void Update()
    	{
    		this.State = ButtonState.Idle;
    
    		if (
    			Mouse.X >= this.Image.X && 
    			Mouse.Y >= this.Image.Y && 
    			Mouse.X <= this.Image.X + this.Image.Width && 
    			Mouse.Y <= this.Image.Y + this.Image.Height
    			)
    		{
    			this.State = ButtonState.Hover;
    
    			if (Mouse.ButtonDown(MouseButton.Left))
    			{
    				this.State = ButtonState.Down;
    			}
    
    			if (Mouse.ButtonHit(MouseButton.Left))
    			{
    				this.State = ButtonState.Clicked;
    			}
    		}
    
    		switch (this.State)
    		{
    			case ButtonState.Clicked:
    				this.Image.Texture = this.ClickedTexture;
    				break;
    
    			case ButtonState.Down:
    				this.Image.Texture = this.DownTexture;
    				break;
    
    			case ButtonState.Hover:
    				this.Image.Texture = this.HoverTexture;
    				break;
    
    			case ButtonState.Idle:
    				this.Image.Texture = this.IdleTexture;
    				break;
    		}
    
    		Drawing.SetBlend(BlendType.Alpha);
    		this.Image.Draw();
    		Drawing.SetBlend(BlendType.None);
    	}	}

  2. I think the main point is C# has memory management which can make complex apps a lot easier. However, most third party libraries you will find are written in C++, so I am not sure what the point of using C# is. There are easier languages that are cross-platform compatible like Java and BlitzMax. I think C# is still Windows-only. There might be some workarounds, but since it is MS you know they are probably never going to put real effort into Linux and Mac.

     

    There are other people who know a lot more about C# than me, so take that with a grain of salt.

     

    Without any intent to be offensive, most of the things you said are obsolete or wrong.

    First of all, there are few third party libraries that you will need for C#, considering it's backed up by a completele framework. In other cases, I have always found what I needed as 3rdPL to make my application work.

    The easiness of a language is really subjective, so I won't comment on this. C# is not Windows only anymore, since Mono is out of Beta and DotGNU is coming along pretty nicely, as far as I know. I have run many applications on Linux, although I do not have a Mac to test.

  3. Not to rip on you, but people want C# Source Code. I don't want to be responsible for a 3rd party DLL.

     

    Also, unless Josh has decided against it, you don't have to obfuscate your code. People can find their ways if they really want your code.

     

    Once the source is complete I'll post it, although a DLL can be used with any .NET language and is easier to integrate.

    If you don't obfuscate your code, this DLL gets distributed with your executable, and is just like giving away headers + engine.dll, which are the core of Leadwerks.

  4. xPos = ScreenWidth() / 4;

     

    So to transfer your value (0.25) to what could be used, use:

     

    int XPercentToPixel(float percent)
    {
       return percent * ScreenWidth();
    }
    
    int YPercentToPixe(float percent)
    {
       return percent * ScreenHeight();
    }

     

    If you have an alpha channel in a DDS file you render to the screen, transparency will be enabled. You cannot have alpha programmed, as far as I know.

     

    I suggest using the OOP drawing approach in my C# wrapper, if that's not too much of a hassle for you. Porting is easy too. More information here.

  5. One way to do that is to use

     

    light:SetParent(model)

     

    light = your light entity and model = your model

    How would I access these objects? I just want to place my streetlamp entity and it already has the light on it. I copied the code from the point light script into the streetlamp script, and it works fine. I have a point light, but at the origin of the model, which is way too low.

     

    How would I go making "entity.light" move up?

    I tried "entity.light:Move(0, -2, 0)" but this doesn't work.

     

    dofile("Scripts/base.lua") -- We need the base class entity
    
    function InitDialog(grid)
    base_InitDialog(grid)
    group=grid:AddGroup("Light")
    group:AddProperty("Resolution",PROPERTY_CHOICE,"256,512,1024,2048")
    group:AddProperty("linearoffset",PROPERTY_FLOAT,"0,1,2","Linear offset")
    group:AddProperty("multoffset",PROPERTY_FLOAT,"0,1,2","Multiplicative offset")
    group:AddProperty("Range",PROPERTY_FLOAT,"1,100,0")
    group:Expand(1)
    end
    
    function Spawn(model)
    local entity=base_Spawn(model)
    entity.model=model
    entity.light=CreatePointLight(10,model)
    return entity
    end
    
    function GetKey( model, key, value )
    local entity=entitytable[model]
    if entity==nil then return value end
    if entity.model==nil then return end
    if entity.light==nil then
    	return base_GetKey(model,key,value)
    else
    	if key=="linearoffset" then
    		return entity.light:GetShadowOffset(0,0)--..","..entity.light:GetShadowOffset(0,1)..","..entity.light:GetShadowOffset(0,2)
    	elseif key=="multoffset" then
    		return entity.light:GetShadowOffset(1,0)--..","..entity.light:GetShadowOffset(1,1)..","..entity.light:GetShadowOffset(1,2)
    	elseif key=="range" then
    		return entity.light:GetRange()
    	else
    		return base_GetKey(model,key,value)
    	end
    end
    
    end
    
    function SetKey(model, key,value)
    local entity=entitytable[model]
    if entity==nil then return 1 end
    if entity.model==nil then return 1 end
    if entity.light==nil then
    	base_SetKey(model,key,value)
    else
    	if key=="resolution" then
    		if value=="0" then
    			entity.light:SetShadowmapSize(256)
    		elseif value=="1" then
    			entity.light:SetShadowmapSize(512)
    		elseif value=="2" then
    			entity.light:SetShadowmapSize(1024)
    		elseif value=="3" then
    			entity.light:SetShadowmapSize(2048)
    		end
    	elseif key=="range" then
    		entity.light:SetRange(value)
    	elseif key=="shadowresolution" then
    		resolution=entity.light:GetShadowmapSize()
    		if resolution==256 then
    			return 0
    		elseif resolution==512 then
    			return 1
    		elseif resolution==1024 then
    			return 2	
    		elseif resolution==2048 then
    			return 3
    		else
    			return -1
    		end
    	elseif key=="multoffset" then
    		entity.light:SetShadowOffset(entity.light:GetShadowOffset(0,0),value,0)
    	elseif key=="linearoffset" then
    		entity.light:SetShadowOffset(value,entity.light:GetShadowOffset(1,0),0)
    	else
    		return base_SetKey(model,key,value)
    	end
    end
    return 1
    end
    
    --[[
    
    dofile("Scripts/baseclass.lua") -- We need the base class entity
    dofile("Scripts/table.lua") -- We need the table.Inherit function
    
    -- Set this script"s Entity table to an inherit of BaseClass"s entity table
    EntityNew = { }
    Entity = table.Inherit(EntityNew, Entity)
    
    function Entity:Spawn(model)
    if (model == nil) then Notify("Entity passed to Entity:Spawn is nil") end
    Entity.BaseClass:Spawn(model)
    -- Since the entity object is passed to the BaseCLass spawn, it is in Entity.BaseClass.model, we need to either remove the above line and uncomment the one below, or simply leave both
    -- If you are wondering why Entity.model isn"t inherited at the top of the script when we called table.Inherit, it is because we had not yet defined an Entity.model variable
    -- You will come to notice that variables we assign via BaseClass functions AFTER inheritence will not exist from this Entity scope. We can still access them via Entity.BaseClass.variablename
    --Entity.model = Entity.BaseClass.model -- Hold onto you for later use and add it to this scope 
    self.model = model
    model:SetKey("intensity","1")
    self.light = CreatePointLight(10,model)
    self.speed=1.0
    end
    
    function Entity:SetKey(key,value)
    if self.model==nil then return 1 end
    if self.light==nil then
    	self.BaseClass:SetKey(key,value)
    else
    	if key=="resolution" then
    		if value=="0" then
    			self.light:SetShadowmapSize(256)
    		elseif value=="1" then
    			self.light:SetShadowmapSize(512)
    		elseif value=="2" then
    			self.light:SetShadowmapSize(1024)
    		elseif value=="3" then
    			self.light:SetShadowmapSize(2048)
    		end
    	elseif key=="muloffset" then
    		self.light:SetShadowOffset(0,tonumber(value),0)
    	elseif key=="range" then
    		self.light:SetRange(value)
    	elseif key=="shadowresolution" then
    		resolution=self.light:GetShadowmapSize()
    		if resolution==256 then
    			return 0
    		elseif resolution==512 then
    			return 1
    		elseif resolution==1024 then
    			return 2	
    		elseif resolution==2048 then
    			return 3
    		else
    			return -1
    		end
    	else
    		return self.BaseClass:SetKey(key,value)
    	end
    end
    return 1
    end
    
    function Entity:InitDialog(grid)
    self.BaseClass:InitDialog(grid)
    group=grid:AddGroup( "Light" )
    group:AddProperty( "Resolution", "1|256,512,1024,2048", PROPERTY_CHOICE, "" )
    group:AddProperty( "muloffset","|0,1,2",PROPERTY_FLOAT,"Mult offset" )
    group:AddProperty( "range","|1,100,0",PROPERTY_FLOAT,"" )
    group:Expand(1)
    end
    
    function Entity:ReceiveMessage(message,extra)
    if message=="toggle" then
    	if self.model:Hidden()==1 then
    		self.model:Show()
    	else
    		self.model:Hide()
    	end
    else
    end
    end
    ]]--
    

×
×
  • Create New...