Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-31-2010, 02:25 AM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
F2 Console / Replacement for the F2 Log Window

A console-like thingy instead of some crappy GUI controls for the F2 log, who wouldn't like that? I do, now that I'm done with this small project It pretty much renders the regular F2 log useless, but I can live with that; the question is, can you? I don't care. After all, it's up to you if you use this or not.

F2 to toggle, as usual. Hit C when the console has focus to clear its contents. Arrow keys to scroll. Enjoy!

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
// "hide" F2LogWindow_Window
  // don't destroy, because we'd get a crapload of errors
  
F2LogWindow_Window.y = -512;
  
  
sleep(0.1); // short delay; we seem need that
  
  
this.on      = false;
  
this.init    = true;
  
this.sliding = false;
  
  
CreateControls();
  
AddOldMessages();
}

function 
CreateControls() {
  new 
GuiShowImgCtrl("F2Console") {
    
x = 0; y = -256;
    
width = GraalControl.width;
    
height = 256;
    
    
polygon = { 0, 0, width, 0, width, height, 0, height };
    
red = green = blue = 0;
    
alpha = 0.75;
    
    new 
GuiScrollCtrl("F2ConsoleScroll") {
      
x = y = 0;
      
width = GraalControl.width;
      
height = 257;
      
      
useOwnProfile = true;
      
profile.border = 0;
      
profile.bitmap = "";
      
profile.fillcolor = { 0, 0, 0, 0 };
      
      
hScrollBar = "alwaysOff";
      
vScrollBar = "alwaysOn";
      
      new 
GuiMLTextCtrl("F2ConsoleText") {
        
x = y = 0;
        
width = GraalControl.width - 20;
        
height = 257;
        
        
useOwnProfile = true;
        
profile.fonttype = "Courier";
        
profile.fontsize = 12;
        
profile.fontcolor = { 255, 255, 255, 255 };
        
profile.fontcolorhl = { 0, 0, 0, 192 };
        
profile.fillcolorhl = { 255, 255, 255, 255 };
        
        
text = "";
      }
    }
  }
}

// grab the messages from the existing f2log
// and add them to the new one
function AddOldMessages() {
  
temp.types = { "game", "files", "scripts",
                 
"net", "graphics", "sounds" };
  
  for (
temp.i = 0; i < 5; i++) {
    
temp.msgs = ("F2LogWindow_Text" @ i).getText();
    
msgs = ReplaceText(msgs, "<font color=#007f00>", "");
    
msgs = ReplaceText(msgs, "<font color=#ff00ff>", "");
    
msgs = ReplaceText(msgs, "</font>", "");
    
msgs = ReplaceText(msgs, "\\n", char(255));
    
    
temp.bits = msgs.tokenize(char(255));
    for (
temp.b: temp.bits) {
      
// fix that one bug..
      
if (b.starts("Loading tile definitions for server Login") &&
          
b.length() != 41)
        
b = b.substring(41, -1);
      
      
AddConsoleMessage(b, types[i]);
    }
  }
}

function 
AddConsoleMessage(msg, mType) {
  
msg = "[" @ mType @ "]" SPC msg;
  if (
F2ConsoleText.text != "")
    
msg = "\n" @ msg;
  
  
F2ConsoleText.addText(msg, false);
  
F2ConsoleText.scrollToBottom();
}

// receiving a message
function onLogMessage(msg, r, g, b, mType)
  
AddConsoleMessage(msg, mType);

// open/close
function onKeyPressed(code) {
  if (
code != 113 || this.sliding || !this.init)
    return;
  
  if (!
this.on) {
    
this.on = true;
    
this.sliding = true;
    
    for (
temp.i = 0; i < 2; i++) {
      
F2Console.y += 128;
      
sleep(0.05);
    }
    
    
this.sliding = false;
    
F2ConsoleText.makeFirstResponder(true);
  } else {
    
this.on = false;
    
this.sliding = true;
    
    
GraalControl.makeFirstResponder(true);
    for (
temp.i = 0; i < 2; i++) {
      
F2Console.y -= 128;
      
sleep(0.05);
    }
    
    
this.sliding = false;
  }
}

// clear
function F2ConsoleText.onKeyDown(code, key) {
  if (
key == "c")
    
F2ConsoleText.text = "";
}

// Dusty's; thanks!
function ReplaceText(txt, a, b) {
  if (
txt.pos(a) < 0)
    return 
txt;
  
  
temp.len = a.length();
  
temp.txtpos = txt.positions(a);
  
temp.newtxt = txt.substring(0, txtpos[0]);
  
  for (
temp.i: temp.txtpos) {
    
temp.p = txt.substring(i + temp.len).pos(a);
    
temp.newtxt @= b; 
    
temp.newtxt @= txt.substring(i + temp.len, temp.p); 
  }
  
  return 
temp.newtxt; 
} 
Edit: Oh, I forgot the screenshot..
Attached Thumbnails
Click image for larger version

Name:	f2console.png
Views:	403
Size:	24.6 KB
ID:	51433  
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:20 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.